untitled-5703migrations.ts1 match
8* Initialize database tables
9*/
10export async function initDatabase() {
11// Create jobs table
12await sqlite.execute(`
15* Verify that the request is coming from Slack
16*/
17function verifySlackRequest(request: Request): boolean {
18// In a production environment, you should verify the request signature
19// using the Slack signing secret. For simplicity, we're skipping that here.
33* Handle the /mercury balance command
34*/
35async function handleBalanceCommand(): Promise<SlackMessage> {
36try {
37const accounts = await mercury.getAccounts();
46* Handle the /mercury transactions command
47*/
48async function handleTransactionsCommand(args: string[]): Promise<SlackMessage> {
49try {
50console.log('Starting transactions command with args:', args);
98* Handle the /mercury search command
99*/
100async function handleSearchCommand(args: string[]): Promise<SlackMessage> {
101try {
102if (args.length === 0) {
117* Handle the /mercury help command
118*/
119function handleHelpCommand(): SlackMessage {
120return {
121blocks: [
153* Process a Slack command and return the appropriate response
154*/
155async function processSlackCommand(slackCommand: SlackCommand): Promise<SlackMessage> {
156const { command, args } = parseCommand(slackCommand.text);
157
172* Main HTTP handler for Slack slash commands and Mercury webhooks
173*/
174export default async function(req: Request): Promise<Response> {
175// Handle different HTTP methods
176if (req.method === 'POST') {
beeAifrontend.html13 matches
310<script>
311document.addEventListener('DOMContentLoaded', () => {
312// Tab switching functionality
313const chatTab = document.getElementById('chat-tab');
314const imageTab = document.getElementById('image-tab');
330});
331
332// Chat functionality
333const chatForm = document.getElementById('chat-form');
334const userInput = document.getElementById('user-input');
335const chatContainer = document.getElementById('chat-container');
336
337// Function to add a message to the chat
338function addMessage(content, isUser = false) {
339const messageDiv = document.createElement('div');
340messageDiv.className = `message-bubble ${isUser ? 'user-message' : 'ai-message'} p-4 shadow-sm`;
344}
345
346// Function to show loading indicator in chat
347function showChatLoading() {
348const loadingDiv = document.createElement('div');
349loadingDiv.id = 'loading-indicator';
354}
355
356// Function to remove loading indicator from chat
357function hideChatLoading() {
358const loadingIndicator = document.getElementById('loading-indicator');
359if (loadingIndicator) {
404});
405
406// Image Generator functionality
407const imageForm = document.getElementById('image-form');
408const imagePrompt = document.getElementById('image-prompt');
418const errorTryAgain = document.getElementById('error-try-again');
419
420// Function to reset the image generator form
421function resetImageGenerator() {
422imageResult.style.display = 'none';
423imageForm.style.display = 'block';
458const img = new Image();
459
460img.onload = function() {
461// Display the generated image
462generatedImage.src = data.imageUrl;
469};
470
471img.onerror = function() {
472// Show error if image can't be loaded
473imageLoading.style.display = 'none';
181182// Broadcast a message to all connected clients
183function broadcastMessage(event: ChatEvent) {
184const message = JSON.stringify(event);
185console.log(`Broadcasting: ${message}`);
ZenChatindex.html2 matches
106
107// Check after 2 seconds if the main script has loaded
108setTimeout(function() {
109if (window.scriptFailed) {
110console.error('Main script failed to load or execute properly');
131<script>
132// This will run after the module script
133window.addEventListener('load', function() {
134// Clear the flag if we got this far
135window.scriptFailed = false;
2324// Initialize the app
25function init() {
26console.log('Initializing app...');
27
5455// Handle login form submission
56function handleLogin(event) {
57event.preventDefault();
58console.log('Login form submitted');
8283// Handle message form submission
84function handleSendMessage(event) {
85event.preventDefault();
86const message = messageInput.value.trim();
99100// Connect to WebSocket server
101function connectWebSocket() {
102console.log('Connecting to WebSocket...');
103
161162// Handle incoming WebSocket messages
163function handleWebSocketMessage(event) {
164switch (event.type) {
165case 'message':
188189// Add a message to the chat
190function addMessageToChat(message) {
191const messageElement = document.createElement('div');
192const isMyMessage = message.username === username;
205206// Add a system message to the chat
207function addSystemMessage(text) {
208const messageElement = document.createElement('div');
209messageElement.className = 'message-bubble system-message';
215216// Show the chat screen
217function showChatScreen() {
218console.log('Showing chat screen');
219
242243// Utility: Scroll to the bottom of the messages container
244function scrollToBottom() {
245messagesContainer.scrollTop = messagesContainer.scrollHeight;
246}
247248// Utility: Format timestamp
249function formatTimestamp(timestamp) {
250const date = new Date(timestamp);
251return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
253254// Utility: Escape HTML to prevent XSS
255function escapeHtml(unsafe) {
256return unsafe
257.replace(/&/g, "&")
syllabus-todomain.tsx1 match
1export default async function (req: Request): Promise<Response> {
2return Response.json({ ok: true })
3}
8- `database/`: Database setup and queries
9- `migrations.ts`: Schema definitions
10- `queries.ts`: Database query functions
1112## WebSocket Protocol
ZenChatqueries.ts4 matches
45// User queries
6export async function createUser(username: string): Promise<User> {
7const now = new Date().toISOString();
8
23}
2425export async function getUserByUsername(username: string): Promise<User | null> {
26const result = await sqlite.execute(
27`SELECT id, username, created_at FROM ${USERS_TABLE} WHERE username = ?`,
4142// Message queries
43export async function createMessage(userId: number, content: string): Promise<Message> {
44const now = new Date().toISOString();
45
75}
7677export async function getRecentMessages(limit = 50): Promise<Message[]> {
78const result = await sqlite.execute(
79`SELECT m.id, m.user_id, u.username, m.content, m.created_at
ZenChatmigrations.ts1 match
5export const MESSAGES_TABLE = 'chat_messages';
67export async function runMigrations() {
8// Create users table
9await sqlite.execute(`