postApocalebtic commited on
Commit
1f0573c
·
1 Parent(s): cc0ce76

Local Server Fix

Browse files

Updated README for fix

Files changed (10) hide show
  1. MCP_RULES.md +94 -0
  2. README.md +60 -58
  3. dev-server.js +32 -0
  4. kill-server.js +52 -0
  5. middlewares/checkUser.js +31 -10
  6. package-lock.json +235 -5
  7. package.json +3 -0
  8. server.js +377 -175
  9. utils/fetch-utils.js +23 -0
  10. vite.config.ts +4 -2
MCP_RULES.md ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # MCP_RULES.md
2
+
3
+ ## Purpose
4
+
5
+ Define strict handling rules for the `mcp_cc_deepsite_generate_website_component` function so that user‑supplied prompts are collected verbatim and never altered before invocation.
6
+
7
+ ---
8
+
9
+ ## 1. Triggering the MCP
10
+
11
+ Whenever the user indicates they want to "generate a component", "make me a site", "use the site generator", etc.:
12
+
13
+ 1. **Do NOT immediately call the function.**
14
+ 2. **Prompt the user**:
15
+
16
+ > "Sure—please provide your _exact_ prompt for the site generator. I will not modify it in any way."
17
+
18
+ 3. Wait for the user's reply.
19
+
20
+ ---
21
+
22
+ ## 2. Verbatim Preservation
23
+
24
+ - Once the user replies with their prompt text, treat it as an **opaque string**.
25
+ - **Do not** paraphrase, normalize, trim, sanitize, or otherwise mutate that text.
26
+ - Forward it exactly as received into the MCP call.
27
+
28
+ ---
29
+
30
+ ## 3. Function Invocation Format
31
+
32
+ After you have the user's exact prompt, invoke:
33
+
34
+ ```json
35
+ {
36
+ "name": "mcp_cc_deepsite_generate_website_component",
37
+ "arguments": {
38
+ "prompt": "<USER_PROMPT_VERBATIM>",
39
+ "componentType": "<TYPE_FROM_USER_OR_FOLLOW‑UP>",
40
+ "framework": "<FRAMEWORK_FROM_USER_OR_FOLLOW‑UP>"
41
+ }
42
+ }
43
+ ```
44
+
45
+ - `prompt` must be the raw user text.
46
+ - `componentType` (e.g. `header`, `footer`, `card`, `hero`) and `framework` (e.g. `react`, `vue`) can be inferred or re‑confirmed by a follow‑up question if necessary.
47
+
48
+ ---
49
+
50
+ ## 4. Example Flow
51
+
52
+ **User**
53
+
54
+ > "I want a landing page hero section with a video background."
55
+
56
+ **Agent**
57
+
58
+ > "Great! Please give me your _exact_ prompt for the site generator. I'll use it verbatim."
59
+
60
+ **User**
61
+
62
+ > "Hero section with full‑screen video background, centered headline 'Welcome to DeepSite', and a pink 'Get Started' button."
63
+
64
+ **Agent** (function call)
65
+
66
+ ```json
67
+ {
68
+ "name": "mcp_cc_deepsite_generate_website_component",
69
+ "arguments": {
70
+ "prompt": "Hero section with full‑screen video background, centered headline 'Welcome to DeepSite', and a pink 'Get Started' button.",
71
+ "componentType": "hero",
72
+ "framework": "react"
73
+ }
74
+ }
75
+ ```
76
+
77
+ ---
78
+
79
+ ## 5. Integration
80
+
81
+ Embed these rules in your plugin's metadata (for example under `x-llm-intent-rules`), or include as part of your developer instructions so that any LLM driving the MCP:
82
+
83
+ - Knows to _always_ ask before calling.
84
+ - Guarantees zero alteration of the user's prompt.
85
+
86
+ ```yaml
87
+ # snippet from your plugin manifest
88
+ x-llm-intent-rules:
89
+ - intent: use_site_generator
90
+ ask_for_prompt: true
91
+ preserve_user_prompt: true
92
+ invocation:
93
+ function: mcp_cc_deepsite_generate_website_component
94
+ ```
README.md CHANGED
@@ -1,28 +1,23 @@
1
- ---
2
- title: Cc Site Maker
3
- emoji: 🏆
4
- colorFrom: pink
5
- colorTo: red
6
- sdk: docker
7
- pinned: false
8
- ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
11
-
12
- # Hugging Face MCP Server
13
-
14
- A server that integrates with Hugging Face for generating website components and text using AI models. This server implements the MCP protocol for easy integration with Claude and other AI assistants.
15
 
16
  ## Features
17
 
18
- - Direct integration with Hugging Face Inference API
19
- - Fallback to DeepSite Space API when needed
 
 
20
  - MCP protocol support for AI assistants
21
- - Generate website components using CodeLlama
22
- - Query text generation models
23
- - JWT authentication (optional for testing)
24
 
25
- ## Setup
 
 
 
 
 
 
 
26
 
27
  1. Install dependencies:
28
 
@@ -33,58 +28,65 @@ npm install
33
  2. Create a `.env` file with the following variables:
34
 
35
  ```
 
 
 
 
36
  DEFAULT_HF_TOKEN=your_huggingface_token
 
37
  MCP_PORT=4000
38
  MCP_JWT_SECRET=your_jwt_secret
39
  DEEPSITE_URL=https://huggingface.co/spaces/your-username/your-space
40
  ```
41
 
42
- 3. Start the server:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
- ```bash
45
- npm start
46
  ```
47
 
48
- ## API Endpoints
 
 
 
 
 
 
49
 
50
- ### MCP Protocol
 
 
 
 
 
 
 
 
 
 
51
 
52
  - `GET /mcp` - MCP protocol handshake
53
  - `GET /mcp/tools` - List available tools
54
  - `POST /mcp/run` - Execute a tool
55
 
56
- ### Direct API
57
-
58
- - `POST /generate` - Generate website component (backward compatibility)
59
- - `POST /generate/text` - Generate text using a Hugging Face model
60
- - `GET /health` - Health check
61
- - `GET /status` - Check connection status to Hugging Face and DeepSite
62
-
63
- ## Available Tools
64
-
65
- 1. `generate_website_component` - Generates React, Vue, or other framework components
66
- 2. `query_huggingface_model` - Query any text generation model on Hugging Face
67
-
68
- ## Example Usage
69
-
70
- ```javascript
71
- // Generate a website component
72
- const response = await fetch('http://localhost:4000/mcp/run', {
73
- method: 'POST',
74
- headers: {
75
- 'Content-Type': 'application/json',
76
- Authorization: 'Bearer your_jwt_token' // Optional for testing
77
- },
78
- body: JSON.stringify({
79
- tool: 'generate_website_component',
80
- parameters: {
81
- prompt: 'A responsive navigation bar with logo and login button',
82
- componentType: 'navbar',
83
- framework: 'react'
84
- }
85
- })
86
- });
87
-
88
- const data = await response.json();
89
- console.log(data.result);
90
  ```
 
1
+ # CC Site Maker
 
 
 
 
 
 
 
2
 
3
+ A web application that allows users to create websites using AI assistance. This project integrates with Hugging Face for generating website components and hosting static websites.
 
 
 
 
4
 
5
  ## Features
6
 
7
+ - Interactive HTML editor with Monaco Editor
8
+ - AI-powered website generation using DeepSeek model
9
+ - One-click deployment to Hugging Face Spaces
10
+ - Responsive design with Tailwind CSS
11
  - MCP protocol support for AI assistants
 
 
 
12
 
13
+ ## Tech Stack
14
+
15
+ - Frontend: React, TypeScript, Tailwind CSS, Monaco Editor
16
+ - Backend: Express.js, Node.js
17
+ - AI: Hugging Face Inference API with DeepSeek model
18
+ - Deployment: Hugging Face Spaces
19
+
20
+ ## Development Setup
21
 
22
  1. Install dependencies:
23
 
 
28
  2. Create a `.env` file with the following variables:
29
 
30
  ```
31
+ OAUTH_CLIENT_ID=your_huggingface_oauth_client_id
32
+ OAUTH_CLIENT_SECRET=your_huggingface_oauth_client_secret
33
+ APP_PORT=7860
34
+ REDIRECT_URI=http://localhost:7860/auth/login
35
  DEFAULT_HF_TOKEN=your_huggingface_token
36
+
37
  MCP_PORT=4000
38
  MCP_JWT_SECRET=your_jwt_secret
39
  DEEPSITE_URL=https://huggingface.co/spaces/your-username/your-space
40
  ```
41
 
42
+ 3. Start the development environment:
43
+
44
+ # Run both frontend (Vite) and backend server together
45
+
46
+ npm run dev:all
47
+
48
+ # Or run them separately:
49
+
50
+ # Frontend only
51
+
52
+ npm run dev
53
+
54
+ # Backend server only
55
+
56
+ npm run server
57
 
 
 
58
  ```
59
 
60
+ The development setup includes:
61
+
62
+ - Frontend running on: http://localhost:5173
63
+ - Backend API running on: http://localhost:7860
64
+ - API calls from frontend to backend are proxied automatically
65
+
66
+ ## Scripts
67
 
68
+ - `npm run dev:all` - Run both frontend and backend concurrently
69
+ - `npm start` - Start the MCP server for AI assistant integration
70
+
71
+ ### User Authentication
72
+
73
+ - `GET /api/login` - Get login URL for Hugging Face OAuth
74
+ - `GET /auth/login` - OAuth callback
75
+ - `GET /auth/logout` - Logout
76
+ - `GET /api/@me` - Get current user info
77
+
78
+ ### MCP Protocol (for AI assistants)
79
 
80
  - `GET /mcp` - MCP protocol handshake
81
  - `GET /mcp/tools` - List available tools
82
  - `POST /mcp/run` - Execute a tool
83
 
84
+ ## Troubleshooting
85
+
86
+ If you encounter connectivity issues:
87
+
88
+ 1. Make sure both frontend and backend servers are running
89
+ 2. Check that the ports (5173 for frontend, 7860 for backend) are available
90
+ 3. If you get API errors, try restarting both servers with `npm run dev:all`
91
+ 4. Check your .env configuration, especially the HF_TOKEN
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  ```
dev-server.js ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Development server wrapper
2
+ import { spawn } from 'child_process';
3
+ import fs from 'fs';
4
+
5
+ // Ensure environment variables are set correctly
6
+ process.env.NODE_ENV = 'development';
7
+ process.env.APP_PORT = '7860';
8
+
9
+ console.log('Starting development server on port 7860...');
10
+
11
+ // Start the server
12
+ const server = spawn('node', ['server.js'], {
13
+ env: process.env,
14
+ stdio: 'inherit'
15
+ });
16
+
17
+ // Handle server process events
18
+ server.on('error', (err) => {
19
+ console.error('Failed to start server process:', err);
20
+ });
21
+
22
+ process.on('SIGINT', () => {
23
+ console.log('Stopping development server...');
24
+ server.kill('SIGINT');
25
+ process.exit(0);
26
+ });
27
+
28
+ process.on('SIGTERM', () => {
29
+ console.log('Stopping development server...');
30
+ server.kill('SIGTERM');
31
+ process.exit(0);
32
+ });
kill-server.js ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Script to kill any existing processes on port 7860
2
+ import { execSync } from 'child_process';
3
+
4
+ const PORT = 7860;
5
+
6
+ try {
7
+ console.log(`Checking for processes using port ${PORT}...`);
8
+
9
+ // Different commands based on OS
10
+ let command;
11
+ if (process.platform === 'win32') {
12
+ command = `netstat -ano | findstr :${PORT}`;
13
+ } else {
14
+ command = `lsof -i :${PORT} | grep LISTEN | awk '{print $2}'`;
15
+ }
16
+
17
+ const result = execSync(command, { encoding: 'utf8' });
18
+
19
+ if (result) {
20
+ console.log(`Found processes using port ${PORT}. Attempting to kill...`);
21
+
22
+ if (process.platform === 'win32') {
23
+ // Extract PID from Windows netstat output
24
+ const pidMatches = result.match(/\s+(\d+)$/m);
25
+ if (pidMatches && pidMatches[1]) {
26
+ const pid = pidMatches[1];
27
+ execSync(`taskkill /F /PID ${pid}`);
28
+ console.log(`Killed process with PID ${pid}`);
29
+ }
30
+ } else {
31
+ // On Unix systems, kill processes directly from lsof output
32
+ const pids = result.trim().split('\n');
33
+ for (const pid of pids) {
34
+ if (pid) {
35
+ execSync(`kill -9 ${pid}`);
36
+ console.log(`Killed process with PID ${pid}`);
37
+ }
38
+ }
39
+ }
40
+
41
+ console.log(`Port ${PORT} is now available`);
42
+ } else {
43
+ console.log(`No processes found using port ${PORT}`);
44
+ }
45
+ } catch (error) {
46
+ // If no processes are found, lsof/netstat might return non-zero exit code
47
+ if (error.status !== 0 && !error.stdout && !error.stderr) {
48
+ console.log(`No processes found using port ${PORT}`);
49
+ } else {
50
+ console.error(`Error checking port ${PORT}:`, error.message);
51
+ }
52
+ }
middlewares/checkUser.js CHANGED
@@ -1,3 +1,8 @@
 
 
 
 
 
1
  const checkUser = async (req, res, next) => {
2
  const { hf_token } = req.cookies;
3
 
@@ -10,17 +15,25 @@ const checkUser = async (req, res, next) => {
10
  }
11
 
12
  try {
13
- const request_user = await fetch('https://huggingface.co/oauth/userinfo', {
14
- headers: {
15
- Authorization: `Bearer ${hf_token}`
16
- }
17
- });
 
 
 
 
18
 
19
  if (!request_user.ok) {
 
 
 
 
20
  res.clearCookie('hf_token', {
21
  httpOnly: false,
22
- secure: true,
23
- sameSite: 'none'
24
  });
25
 
26
  return res.status(401).send({
@@ -32,16 +45,24 @@ const checkUser = async (req, res, next) => {
32
 
33
  next();
34
  } catch (err) {
 
 
 
 
 
 
 
 
35
  res.clearCookie('hf_token', {
36
  httpOnly: false,
37
- secure: true,
38
- sameSite: 'none'
39
  });
40
 
41
  return res.status(401).send({
42
  ok: false,
43
  openLogin: true,
44
- message: err.message
45
  });
46
  }
47
  };
 
1
+ import { fetchWithTimeout } from '../utils/fetch-utils.js';
2
+
3
+ const isDev =
4
+ process.env.NODE_ENV === 'development' || process.env.NODE_ENV === undefined;
5
+
6
  const checkUser = async (req, res, next) => {
7
  const { hf_token } = req.cookies;
8
 
 
15
  }
16
 
17
  try {
18
+ const request_user = await fetchWithTimeout(
19
+ 'https://huggingface.co/oauth/userinfo',
20
+ {
21
+ headers: {
22
+ Authorization: `Bearer ${hf_token}`
23
+ }
24
+ },
25
+ 8000 // 8 second timeout
26
+ );
27
 
28
  if (!request_user.ok) {
29
+ console.error(
30
+ `HuggingFace API error in checkUser: ${request_user.status}`
31
+ );
32
+
33
  res.clearCookie('hf_token', {
34
  httpOnly: false,
35
+ secure: !isDev,
36
+ sameSite: isDev ? 'lax' : 'none'
37
  });
38
 
39
  return res.status(401).send({
 
45
 
46
  next();
47
  } catch (err) {
48
+ console.error('Error in checkUser middleware:', err);
49
+
50
+ // Handle timeout specifically
51
+ const message =
52
+ err.name === 'AbortError'
53
+ ? 'Request to authentication service timed out. Please try again later.'
54
+ : 'Unable to verify authentication. Please try again.';
55
+
56
  res.clearCookie('hf_token', {
57
  httpOnly: false,
58
+ secure: !isDev,
59
+ sameSite: isDev ? 'lax' : 'none'
60
  });
61
 
62
  return res.status(401).send({
63
  ok: false,
64
  openLogin: true,
65
+ message
66
  });
67
  }
68
  };
package-lock.json CHANGED
@@ -16,6 +16,7 @@
16
  "axios": "^1.8.4",
17
  "body-parser": "^1.20.3",
18
  "classnames": "^2.5.1",
 
19
  "cookie-parser": "^1.4.7",
20
  "cors": "^2.8.5",
21
  "dotenv": "^16.4.7",
@@ -2083,11 +2084,19 @@
2083
  "url": "https://github.com/sponsors/epoberezkin"
2084
  }
2085
  },
 
 
 
 
 
 
 
 
 
2086
  "node_modules/ansi-styles": {
2087
  "version": "4.3.0",
2088
  "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
2089
  "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
2090
- "dev": true,
2091
  "dependencies": {
2092
  "color-convert": "^2.0.1"
2093
  },
@@ -2439,7 +2448,6 @@
2439
  "version": "4.1.2",
2440
  "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
2441
  "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
2442
- "dev": true,
2443
  "dependencies": {
2444
  "ansi-styles": "^4.1.0",
2445
  "supports-color": "^7.1.0"
@@ -2497,6 +2505,20 @@
2497
  "resolved": "https://registry.npmjs.org/classnames/-/classnames-2.5.1.tgz",
2498
  "integrity": "sha512-saHYOzhIQs6wy2sVxTM6bUDsQO4F50V9RQ22qBpEdCW+I+/Wmke2HOl6lS6dTpdxVhb88/I6+Hs+438c3lfUow=="
2499
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2500
  "node_modules/clsx": {
2501
  "version": "2.1.1",
2502
  "resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.1.tgz",
@@ -2569,6 +2591,48 @@
2569
  "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
2570
  "dev": true
2571
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2572
  "node_modules/content-disposition": {
2573
  "version": "0.5.4",
2574
  "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
@@ -2687,6 +2751,22 @@
2687
  "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz",
2688
  "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="
2689
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2690
  "node_modules/debug": {
2691
  "version": "4.4.0",
2692
  "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz",
@@ -2842,6 +2922,12 @@
2842
  "integrity": "sha512-refir3NlutEZqlKaBLK0tzlVLe5P2wDKS7UQt/3SpibizgsRAPOsqQC3ffw1nlv3ze5gjRQZYHoPymgVZkplFA==",
2843
  "dev": true
2844
  },
 
 
 
 
 
 
2845
  "node_modules/encodeurl": {
2846
  "version": "2.0.0",
2847
  "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz",
@@ -2963,7 +3049,6 @@
2963
  "version": "3.2.0",
2964
  "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz",
2965
  "integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==",
2966
- "dev": true,
2967
  "engines": {
2968
  "node": ">=6"
2969
  }
@@ -3491,6 +3576,15 @@
3491
  "node": ">=6.9.0"
3492
  }
3493
  },
 
 
 
 
 
 
 
 
 
3494
  "node_modules/get-intrinsic": {
3495
  "version": "1.3.0",
3496
  "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
@@ -3586,7 +3680,6 @@
3586
  "version": "4.0.0",
3587
  "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
3588
  "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
3589
- "dev": true,
3590
  "engines": {
3591
  "node": ">=8"
3592
  }
@@ -3835,6 +3928,15 @@
3835
  "node": ">=0.10.0"
3836
  }
3837
  },
 
 
 
 
 
 
 
 
 
3838
  "node_modules/is-glob": {
3839
  "version": "4.0.3",
3840
  "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz",
@@ -4264,6 +4366,12 @@
4264
  "url": "https://github.com/sponsors/sindresorhus"
4265
  }
4266
  },
 
 
 
 
 
 
4267
  "node_modules/lodash.includes": {
4268
  "version": "4.3.0",
4269
  "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz",
@@ -5739,6 +5847,15 @@
5739
  "url": "https://opencollective.com/unified"
5740
  }
5741
  },
 
 
 
 
 
 
 
 
 
5742
  "node_modules/resize-observer-polyfill": {
5743
  "version": "1.5.1",
5744
  "resolved": "https://registry.npmjs.org/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz",
@@ -5831,6 +5948,15 @@
5831
  "queue-microtask": "^1.2.2"
5832
  }
5833
  },
 
 
 
 
 
 
 
 
 
5834
  "node_modules/safe-buffer": {
5835
  "version": "5.2.1",
5836
  "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
@@ -6005,6 +6131,18 @@
6005
  "node": ">=8"
6006
  }
6007
  },
 
 
 
 
 
 
 
 
 
 
 
 
6008
  "node_modules/side-channel": {
6009
  "version": "1.1.0",
6010
  "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz",
@@ -6149,6 +6287,11 @@
6149
  "url": "https://github.com/sponsors/wooorm"
6150
  }
6151
  },
 
 
 
 
 
6152
  "node_modules/stack-generator": {
6153
  "version": "2.0.10",
6154
  "resolved": "https://registry.npmjs.org/stack-generator/-/stack-generator-2.0.10.tgz",
@@ -6222,6 +6365,20 @@
6222
  "safe-buffer": "~5.2.0"
6223
  }
6224
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6225
  "node_modules/stringify-entities": {
6226
  "version": "4.0.4",
6227
  "resolved": "https://registry.npmjs.org/stringify-entities/-/stringify-entities-4.0.4.tgz",
@@ -6235,6 +6392,18 @@
6235
  "url": "https://github.com/sponsors/wooorm"
6236
  }
6237
  },
 
 
 
 
 
 
 
 
 
 
 
 
6238
  "node_modules/strip-json-comments": {
6239
  "version": "3.1.1",
6240
  "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz",
@@ -6272,7 +6441,6 @@
6272
  "version": "7.2.0",
6273
  "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
6274
  "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
6275
- "dev": true,
6276
  "dependencies": {
6277
  "has-flag": "^4.0.0"
6278
  },
@@ -6357,6 +6525,15 @@
6357
  "node": ">=0.6"
6358
  }
6359
  },
 
 
 
 
 
 
 
 
 
6360
  "node_modules/trim-lines": {
6361
  "version": "3.0.1",
6362
  "resolved": "https://registry.npmjs.org/trim-lines/-/trim-lines-3.0.1.tgz",
@@ -6741,17 +6918,70 @@
6741
  "node": ">=0.10.0"
6742
  }
6743
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6744
  "node_modules/wrappy": {
6745
  "version": "1.0.2",
6746
  "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
6747
  "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
6748
  },
 
 
 
 
 
 
 
 
 
6749
  "node_modules/yallist": {
6750
  "version": "3.1.1",
6751
  "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
6752
  "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==",
6753
  "dev": true
6754
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6755
  "node_modules/yocto-queue": {
6756
  "version": "0.1.0",
6757
  "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",
 
16
  "axios": "^1.8.4",
17
  "body-parser": "^1.20.3",
18
  "classnames": "^2.5.1",
19
+ "concurrently": "^8.2.2",
20
  "cookie-parser": "^1.4.7",
21
  "cors": "^2.8.5",
22
  "dotenv": "^16.4.7",
 
2084
  "url": "https://github.com/sponsors/epoberezkin"
2085
  }
2086
  },
2087
+ "node_modules/ansi-regex": {
2088
+ "version": "5.0.1",
2089
+ "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
2090
+ "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
2091
+ "license": "MIT",
2092
+ "engines": {
2093
+ "node": ">=8"
2094
+ }
2095
+ },
2096
  "node_modules/ansi-styles": {
2097
  "version": "4.3.0",
2098
  "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
2099
  "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
 
2100
  "dependencies": {
2101
  "color-convert": "^2.0.1"
2102
  },
 
2448
  "version": "4.1.2",
2449
  "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
2450
  "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
 
2451
  "dependencies": {
2452
  "ansi-styles": "^4.1.0",
2453
  "supports-color": "^7.1.0"
 
2505
  "resolved": "https://registry.npmjs.org/classnames/-/classnames-2.5.1.tgz",
2506
  "integrity": "sha512-saHYOzhIQs6wy2sVxTM6bUDsQO4F50V9RQ22qBpEdCW+I+/Wmke2HOl6lS6dTpdxVhb88/I6+Hs+438c3lfUow=="
2507
  },
2508
+ "node_modules/cliui": {
2509
+ "version": "8.0.1",
2510
+ "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz",
2511
+ "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==",
2512
+ "license": "ISC",
2513
+ "dependencies": {
2514
+ "string-width": "^4.2.0",
2515
+ "strip-ansi": "^6.0.1",
2516
+ "wrap-ansi": "^7.0.0"
2517
+ },
2518
+ "engines": {
2519
+ "node": ">=12"
2520
+ }
2521
+ },
2522
  "node_modules/clsx": {
2523
  "version": "2.1.1",
2524
  "resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.1.tgz",
 
2591
  "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
2592
  "dev": true
2593
  },
2594
+ "node_modules/concurrently": {
2595
+ "version": "8.2.2",
2596
+ "resolved": "https://registry.npmjs.org/concurrently/-/concurrently-8.2.2.tgz",
2597
+ "integrity": "sha512-1dP4gpXFhei8IOtlXRE/T/4H88ElHgTiUzh71YUmtjTEHMSRS2Z/fgOxHSxxusGHogsRfxNq1vyAwxSC+EVyDg==",
2598
+ "license": "MIT",
2599
+ "dependencies": {
2600
+ "chalk": "^4.1.2",
2601
+ "date-fns": "^2.30.0",
2602
+ "lodash": "^4.17.21",
2603
+ "rxjs": "^7.8.1",
2604
+ "shell-quote": "^1.8.1",
2605
+ "spawn-command": "0.0.2",
2606
+ "supports-color": "^8.1.1",
2607
+ "tree-kill": "^1.2.2",
2608
+ "yargs": "^17.7.2"
2609
+ },
2610
+ "bin": {
2611
+ "conc": "dist/bin/concurrently.js",
2612
+ "concurrently": "dist/bin/concurrently.js"
2613
+ },
2614
+ "engines": {
2615
+ "node": "^14.13.0 || >=16.0.0"
2616
+ },
2617
+ "funding": {
2618
+ "url": "https://github.com/open-cli-tools/concurrently?sponsor=1"
2619
+ }
2620
+ },
2621
+ "node_modules/concurrently/node_modules/supports-color": {
2622
+ "version": "8.1.1",
2623
+ "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz",
2624
+ "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==",
2625
+ "license": "MIT",
2626
+ "dependencies": {
2627
+ "has-flag": "^4.0.0"
2628
+ },
2629
+ "engines": {
2630
+ "node": ">=10"
2631
+ },
2632
+ "funding": {
2633
+ "url": "https://github.com/chalk/supports-color?sponsor=1"
2634
+ }
2635
+ },
2636
  "node_modules/content-disposition": {
2637
  "version": "0.5.4",
2638
  "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
 
2751
  "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz",
2752
  "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="
2753
  },
2754
+ "node_modules/date-fns": {
2755
+ "version": "2.30.0",
2756
+ "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz",
2757
+ "integrity": "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==",
2758
+ "license": "MIT",
2759
+ "dependencies": {
2760
+ "@babel/runtime": "^7.21.0"
2761
+ },
2762
+ "engines": {
2763
+ "node": ">=0.11"
2764
+ },
2765
+ "funding": {
2766
+ "type": "opencollective",
2767
+ "url": "https://opencollective.com/date-fns"
2768
+ }
2769
+ },
2770
  "node_modules/debug": {
2771
  "version": "4.4.0",
2772
  "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz",
 
2922
  "integrity": "sha512-refir3NlutEZqlKaBLK0tzlVLe5P2wDKS7UQt/3SpibizgsRAPOsqQC3ffw1nlv3ze5gjRQZYHoPymgVZkplFA==",
2923
  "dev": true
2924
  },
2925
+ "node_modules/emoji-regex": {
2926
+ "version": "8.0.0",
2927
+ "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
2928
+ "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
2929
+ "license": "MIT"
2930
+ },
2931
  "node_modules/encodeurl": {
2932
  "version": "2.0.0",
2933
  "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz",
 
3049
  "version": "3.2.0",
3050
  "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz",
3051
  "integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==",
 
3052
  "engines": {
3053
  "node": ">=6"
3054
  }
 
3576
  "node": ">=6.9.0"
3577
  }
3578
  },
3579
+ "node_modules/get-caller-file": {
3580
+ "version": "2.0.5",
3581
+ "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
3582
+ "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==",
3583
+ "license": "ISC",
3584
+ "engines": {
3585
+ "node": "6.* || 8.* || >= 10.*"
3586
+ }
3587
+ },
3588
  "node_modules/get-intrinsic": {
3589
  "version": "1.3.0",
3590
  "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
 
3680
  "version": "4.0.0",
3681
  "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
3682
  "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
 
3683
  "engines": {
3684
  "node": ">=8"
3685
  }
 
3928
  "node": ">=0.10.0"
3929
  }
3930
  },
3931
+ "node_modules/is-fullwidth-code-point": {
3932
+ "version": "3.0.0",
3933
+ "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
3934
+ "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
3935
+ "license": "MIT",
3936
+ "engines": {
3937
+ "node": ">=8"
3938
+ }
3939
+ },
3940
  "node_modules/is-glob": {
3941
  "version": "4.0.3",
3942
  "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz",
 
4366
  "url": "https://github.com/sponsors/sindresorhus"
4367
  }
4368
  },
4369
+ "node_modules/lodash": {
4370
+ "version": "4.17.21",
4371
+ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
4372
+ "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
4373
+ "license": "MIT"
4374
+ },
4375
  "node_modules/lodash.includes": {
4376
  "version": "4.3.0",
4377
  "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz",
 
5847
  "url": "https://opencollective.com/unified"
5848
  }
5849
  },
5850
+ "node_modules/require-directory": {
5851
+ "version": "2.1.1",
5852
+ "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
5853
+ "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==",
5854
+ "license": "MIT",
5855
+ "engines": {
5856
+ "node": ">=0.10.0"
5857
+ }
5858
+ },
5859
  "node_modules/resize-observer-polyfill": {
5860
  "version": "1.5.1",
5861
  "resolved": "https://registry.npmjs.org/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz",
 
5948
  "queue-microtask": "^1.2.2"
5949
  }
5950
  },
5951
+ "node_modules/rxjs": {
5952
+ "version": "7.8.2",
5953
+ "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.2.tgz",
5954
+ "integrity": "sha512-dhKf903U/PQZY6boNNtAGdWbG85WAbjT/1xYoZIC7FAY0yWapOBQVsVrDl58W86//e1VpMNBtRV4MaXfdMySFA==",
5955
+ "license": "Apache-2.0",
5956
+ "dependencies": {
5957
+ "tslib": "^2.1.0"
5958
+ }
5959
+ },
5960
  "node_modules/safe-buffer": {
5961
  "version": "5.2.1",
5962
  "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
 
6131
  "node": ">=8"
6132
  }
6133
  },
6134
+ "node_modules/shell-quote": {
6135
+ "version": "1.8.2",
6136
+ "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.2.tgz",
6137
+ "integrity": "sha512-AzqKpGKjrj7EM6rKVQEPpB288oCfnrEIuyoT9cyF4nmGa7V8Zk6f7RRqYisX8X9m+Q7bd632aZW4ky7EhbQztA==",
6138
+ "license": "MIT",
6139
+ "engines": {
6140
+ "node": ">= 0.4"
6141
+ },
6142
+ "funding": {
6143
+ "url": "https://github.com/sponsors/ljharb"
6144
+ }
6145
+ },
6146
  "node_modules/side-channel": {
6147
  "version": "1.1.0",
6148
  "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz",
 
6287
  "url": "https://github.com/sponsors/wooorm"
6288
  }
6289
  },
6290
+ "node_modules/spawn-command": {
6291
+ "version": "0.0.2",
6292
+ "resolved": "https://registry.npmjs.org/spawn-command/-/spawn-command-0.0.2.tgz",
6293
+ "integrity": "sha512-zC8zGoGkmc8J9ndvml8Xksr1Amk9qBujgbF0JAIWO7kXr43w0h/0GJNM/Vustixu+YE8N/MTrQ7N31FvHUACxQ=="
6294
+ },
6295
  "node_modules/stack-generator": {
6296
  "version": "2.0.10",
6297
  "resolved": "https://registry.npmjs.org/stack-generator/-/stack-generator-2.0.10.tgz",
 
6365
  "safe-buffer": "~5.2.0"
6366
  }
6367
  },
6368
+ "node_modules/string-width": {
6369
+ "version": "4.2.3",
6370
+ "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
6371
+ "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
6372
+ "license": "MIT",
6373
+ "dependencies": {
6374
+ "emoji-regex": "^8.0.0",
6375
+ "is-fullwidth-code-point": "^3.0.0",
6376
+ "strip-ansi": "^6.0.1"
6377
+ },
6378
+ "engines": {
6379
+ "node": ">=8"
6380
+ }
6381
+ },
6382
  "node_modules/stringify-entities": {
6383
  "version": "4.0.4",
6384
  "resolved": "https://registry.npmjs.org/stringify-entities/-/stringify-entities-4.0.4.tgz",
 
6392
  "url": "https://github.com/sponsors/wooorm"
6393
  }
6394
  },
6395
+ "node_modules/strip-ansi": {
6396
+ "version": "6.0.1",
6397
+ "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
6398
+ "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
6399
+ "license": "MIT",
6400
+ "dependencies": {
6401
+ "ansi-regex": "^5.0.1"
6402
+ },
6403
+ "engines": {
6404
+ "node": ">=8"
6405
+ }
6406
+ },
6407
  "node_modules/strip-json-comments": {
6408
  "version": "3.1.1",
6409
  "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz",
 
6441
  "version": "7.2.0",
6442
  "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
6443
  "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
 
6444
  "dependencies": {
6445
  "has-flag": "^4.0.0"
6446
  },
 
6525
  "node": ">=0.6"
6526
  }
6527
  },
6528
+ "node_modules/tree-kill": {
6529
+ "version": "1.2.2",
6530
+ "resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz",
6531
+ "integrity": "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==",
6532
+ "license": "MIT",
6533
+ "bin": {
6534
+ "tree-kill": "cli.js"
6535
+ }
6536
+ },
6537
  "node_modules/trim-lines": {
6538
  "version": "3.0.1",
6539
  "resolved": "https://registry.npmjs.org/trim-lines/-/trim-lines-3.0.1.tgz",
 
6918
  "node": ">=0.10.0"
6919
  }
6920
  },
6921
+ "node_modules/wrap-ansi": {
6922
+ "version": "7.0.0",
6923
+ "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
6924
+ "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
6925
+ "license": "MIT",
6926
+ "dependencies": {
6927
+ "ansi-styles": "^4.0.0",
6928
+ "string-width": "^4.1.0",
6929
+ "strip-ansi": "^6.0.0"
6930
+ },
6931
+ "engines": {
6932
+ "node": ">=10"
6933
+ },
6934
+ "funding": {
6935
+ "url": "https://github.com/chalk/wrap-ansi?sponsor=1"
6936
+ }
6937
+ },
6938
  "node_modules/wrappy": {
6939
  "version": "1.0.2",
6940
  "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
6941
  "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
6942
  },
6943
+ "node_modules/y18n": {
6944
+ "version": "5.0.8",
6945
+ "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
6946
+ "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==",
6947
+ "license": "ISC",
6948
+ "engines": {
6949
+ "node": ">=10"
6950
+ }
6951
+ },
6952
  "node_modules/yallist": {
6953
  "version": "3.1.1",
6954
  "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
6955
  "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==",
6956
  "dev": true
6957
  },
6958
+ "node_modules/yargs": {
6959
+ "version": "17.7.2",
6960
+ "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz",
6961
+ "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==",
6962
+ "license": "MIT",
6963
+ "dependencies": {
6964
+ "cliui": "^8.0.1",
6965
+ "escalade": "^3.1.1",
6966
+ "get-caller-file": "^2.0.5",
6967
+ "require-directory": "^2.1.1",
6968
+ "string-width": "^4.2.3",
6969
+ "y18n": "^5.0.5",
6970
+ "yargs-parser": "^21.1.1"
6971
+ },
6972
+ "engines": {
6973
+ "node": ">=12"
6974
+ }
6975
+ },
6976
+ "node_modules/yargs-parser": {
6977
+ "version": "21.1.1",
6978
+ "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz",
6979
+ "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==",
6980
+ "license": "ISC",
6981
+ "engines": {
6982
+ "node": ">=12"
6983
+ }
6984
+ },
6985
  "node_modules/yocto-queue": {
6986
  "version": "0.1.0",
6987
  "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",
package.json CHANGED
@@ -5,6 +5,8 @@
5
  "type": "module",
6
  "scripts": {
7
  "dev": "vite",
 
 
8
  "build": "tsc -b && vite build",
9
  "lint": "eslint .",
10
  "preview": "vite preview",
@@ -19,6 +21,7 @@
19
  "axios": "^1.8.4",
20
  "body-parser": "^1.20.3",
21
  "classnames": "^2.5.1",
 
22
  "cookie-parser": "^1.4.7",
23
  "cors": "^2.8.5",
24
  "dotenv": "^16.4.7",
 
5
  "type": "module",
6
  "scripts": {
7
  "dev": "vite",
8
+ "server": "node kill-server.js && node dev-server.js",
9
+ "dev:all": "node kill-server.js && concurrently \"npm run server\" \"npm run dev\"",
10
  "build": "tsc -b && vite build",
11
  "lint": "eslint .",
12
  "preview": "vite preview",
 
21
  "axios": "^1.8.4",
22
  "body-parser": "^1.20.3",
23
  "classnames": "^2.5.1",
24
+ "concurrently": "^8.2.2",
25
  "cookie-parser": "^1.4.7",
26
  "cors": "^2.8.5",
27
  "dotenv": "^16.4.7",
server.js CHANGED
@@ -13,14 +13,34 @@ import {
13
  } from '@huggingface/hub';
14
  import { InferenceClient } from '@huggingface/inference';
15
  import bodyParser from 'body-parser';
 
16
 
17
  import checkUser from './middlewares/checkUser.js';
18
  import { PROVIDERS } from './utils/providers.js';
19
  import { COLORS } from './utils/colors.js';
 
20
 
21
  // Load environment variables from .env file
22
  dotenv.config();
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  const app = express();
25
 
26
  const ipAddresses = new Map();
@@ -39,9 +59,23 @@ const externalApiRateLimit = new Map();
39
  const EXTERNAL_API_WINDOW_MS = 60000; // 1 minute window
40
  const MAX_REQUESTS_PER_WINDOW = 60; // 60 requests per minute
41
 
 
 
 
 
 
 
 
 
 
42
  app.use(cookieParser());
43
- app.use(bodyParser.json());
44
- app.use(cors());
 
 
 
 
 
45
  app.use(express.static(path.join(__dirname, 'dist')));
46
 
47
  const getPTag = (repoId) => {
@@ -60,6 +94,7 @@ app.get('/api/login', (_req, res) => {
60
  redirectUrl
61
  });
62
  });
 
63
  app.get('/auth/login', async (req, res) => {
64
  const { code } = req.query;
65
 
@@ -70,63 +105,119 @@ app.get('/auth/login', async (req, res) => {
70
  `${process.env.OAUTH_CLIENT_ID}:${process.env.OAUTH_CLIENT_SECRET}`
71
  ).toString('base64')}`;
72
 
73
- const request_auth = await fetch('https://huggingface.co/oauth/token', {
74
- method: 'POST',
75
- headers: {
76
- 'Content-Type': 'application/x-www-form-urlencoded',
77
- Authorization
78
- },
79
- body: new URLSearchParams({
80
- grant_type: 'authorization_code',
81
- code: code,
82
- redirect_uri: REDIRECT_URI
83
- })
84
- });
 
 
 
 
 
85
 
86
- const response = await request_auth.json();
 
 
 
87
 
88
- if (!response.access_token) {
89
- return res.redirect(302, '/');
90
- }
91
 
92
- res.cookie('hf_token', response.access_token, {
93
- httpOnly: false,
94
- secure: true,
95
- sameSite: 'none',
96
- maxAge: 30 * 24 * 60 * 60 * 1000
97
- });
98
 
99
- return res.redirect(302, '/');
 
 
 
 
 
 
 
 
 
 
 
100
  });
101
  app.get('/auth/logout', (req, res) => {
102
  res.clearCookie('hf_token', {
103
  httpOnly: false,
104
- secure: true,
105
- sameSite: 'none'
106
  });
107
  return res.redirect(302, '/');
108
  });
109
 
110
- app.get('/api/@me', checkUser, async (req, res) => {
111
  const { hf_token } = req.cookies;
112
- try {
113
- const request_user = await fetch('https://huggingface.co/oauth/userinfo', {
114
- headers: {
115
- Authorization: `Bearer ${hf_token}`
116
- }
 
117
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
  const user = await request_user.json();
120
  res.send(user);
121
  } catch (err) {
 
 
 
 
 
 
 
 
122
  res.clearCookie('hf_token', {
123
  httpOnly: false,
124
- secure: true,
125
- sameSite: 'none'
126
  });
 
127
  res.status(401).send({
128
  ok: false,
129
- message: err.message
 
130
  });
131
  }
132
  });
@@ -208,151 +299,223 @@ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-
208
  });
209
 
210
  app.post('/api/ask-ai', async (req, res) => {
211
- const { prompt, html, previousPrompt, provider } = req.body;
212
- if (!prompt) {
213
- return res.status(400).send({
214
- ok: false,
215
- message: 'Missing required fields'
216
- });
217
- }
 
218
 
219
- const { hf_token } = req.cookies;
220
- let token = hf_token;
221
- const ip =
222
- req.headers['x-forwarded-for']?.split(',')[0].trim() ||
223
- req.headers['x-real-ip'] ||
224
- req.socket.remoteAddress ||
225
- req.ip ||
226
- '0.0.0.0';
 
 
 
 
 
 
 
 
 
 
227
 
228
- if (!hf_token) {
229
- ipAddresses.set(ip, (ipAddresses.get(ip) || 0) + 1);
230
- if (ipAddresses.get(ip) > MAX_REQUESTS_PER_IP) {
231
- return res.status(429).send({
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
232
  ok: false,
233
- openLogin: true,
234
- message: 'Log In to continue using the service'
235
  });
236
  }
237
 
238
- token = process.env.DEFAULT_HF_TOKEN;
239
- }
240
 
241
- // Set up response headers for streaming
242
- res.setHeader('Content-Type', 'text/plain');
243
- res.setHeader('Cache-Control', 'no-cache');
244
- res.setHeader('Connection', 'keep-alive');
245
 
246
- const client = new InferenceClient(token);
247
- let completeResponse = '';
 
 
 
248
 
249
- let TOKENS_USED = prompt?.length;
250
- if (previousPrompt) TOKENS_USED += previousPrompt.length;
251
- if (html) TOKENS_USED += html.length;
 
 
 
 
 
 
 
 
 
 
 
 
 
252
 
253
- const DEFAULT_PROVIDER = PROVIDERS.novita;
254
- // const selectedProvider =
255
- // provider === "auto"
256
- // ? TOKENS_USED < PROVIDERS.sambanova.max_tokens
257
- // ? PROVIDERS.sambanova
258
- // : DEFAULT_PROVIDER
259
- // : PROVIDERS[provider] ?? DEFAULT_PROVIDER;
260
- const selectedProvider =
261
- provider === 'auto'
262
- ? DEFAULT_PROVIDER
263
- : PROVIDERS[provider] ?? DEFAULT_PROVIDER;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
 
265
- if (provider !== 'auto' && TOKENS_USED >= selectedProvider.max_tokens) {
266
- return res.status(400).send({
267
- ok: false,
268
- openSelectProvider: true,
269
- message: `Context is too long. ${selectedProvider.name} allow ${selectedProvider.max_tokens} max tokens.`
270
- });
271
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
272
 
273
- try {
274
- const chatCompletion = client.chatCompletionStream({
275
- model: MODEL_ID,
276
- provider: selectedProvider.id,
277
- messages: [
278
- {
279
- role: 'system',
280
- content: `ONLY USE HTML, CSS AND JAVASCRIPT. If you want to use ICON make sure to import the library first. Try to create the best UI possible by using only HTML, CSS and JAVASCRIPT. Use as much as you can TailwindCSS for the CSS, if you can't do something with TailwindCSS, then use custom CSS (make sure to import <script src="https://cdn.tailwindcss.com"></script> in the head). Also, try to ellaborate as much as you can, to create something unique. ALWAYS GIVE THE RESPONSE INTO A SINGLE HTML FILE`
281
- },
282
- ...(previousPrompt
283
- ? [
284
- {
285
- role: 'user',
286
- content: previousPrompt
287
- }
288
- ]
289
- : []),
290
- ...(html
291
- ? [
292
- {
293
- role: 'assistant',
294
- content: `The current code is: ${html}.`
295
- }
296
- ]
297
- : []),
298
- {
299
- role: 'user',
300
- content: prompt
301
- }
302
- ],
303
- ...(selectedProvider.id !== 'sambanova'
304
- ? {
305
- max_tokens: selectedProvider.max_tokens
306
  }
307
- : {})
308
- });
309
 
310
- while (true) {
311
- const { done, value } = await chatCompletion.next();
312
- if (done) {
313
- break;
314
- }
315
- const chunk = value.choices[0]?.delta?.content;
316
- if (chunk) {
317
- if (provider !== 'sambanova') {
318
- res.write(chunk);
319
- completeResponse += chunk;
 
320
 
321
- if (completeResponse.includes('</html>')) {
322
- break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
323
  }
 
 
 
 
 
 
 
 
 
 
324
  } else {
325
- let newChunk = chunk;
326
- if (chunk.includes('</html>')) {
327
- // Replace everything after the last </html> tag with an empty string
328
- newChunk = newChunk.replace(/<\/html>[\s\S]*/, '</html>');
329
- }
330
- completeResponse += newChunk;
331
- res.write(newChunk);
332
- if (newChunk.includes('</html>')) {
333
- break;
334
- }
335
  }
336
  }
337
- }
338
- // End the response stream
339
- res.end();
 
340
  } catch (error) {
341
- if (error.message.includes('exceeded your monthly included credits')) {
 
 
342
  return res.status(402).send({
343
  ok: false,
344
  openProModal: true,
345
  message: error.message
346
  });
347
  }
 
348
  if (!res.headersSent) {
349
  res.status(500).send({
350
  ok: false,
351
  message:
352
- error.message || 'An error occurred while processing your request.'
353
  });
354
  } else {
355
- // Otherwise end the stream
356
  res.end();
357
  }
358
  }
@@ -475,7 +638,17 @@ app.post('/api/external/ask-ai', async (req, res) => {
475
  res.setHeader('Cache-Control', 'no-cache');
476
  res.setHeader('Connection', 'keep-alive');
477
 
478
- const client = new InferenceClient(api_key);
 
 
 
 
 
 
 
 
 
 
479
  let completeResponse = '';
480
 
481
  let TOKENS_USED = prompt?.length;
@@ -533,42 +706,68 @@ app.post('/api/external/ask-ai', async (req, res) => {
533
  : {})
534
  });
535
 
536
- while (true) {
537
- const { done, value } = await chatCompletion.next();
538
- if (done) {
539
- break;
540
- }
541
- const chunk = value.choices[0]?.delta?.content;
542
- if (chunk) {
543
- if (provider !== 'sambanova') {
544
- res.write(chunk);
545
- completeResponse += chunk;
546
 
547
- if (completeResponse.includes('</html>')) {
 
 
 
 
 
548
  break;
549
  }
550
- } else {
551
- let newChunk = chunk;
552
- if (chunk.includes('</html>')) {
553
- newChunk = newChunk.replace(/<\/html>[\s\S]*/, '</html>');
554
- }
555
- completeResponse += newChunk;
556
- res.write(newChunk);
557
- if (newChunk.includes('</html>')) {
558
- break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
559
  }
560
  }
 
 
 
 
 
 
 
 
 
 
 
561
  }
562
- }
563
- res.end();
 
 
564
  } catch (error) {
565
- if (error.message.includes('exceeded your monthly included credits')) {
 
 
566
  return res.status(402).send({
567
  ok: false,
568
  openProModal: true,
569
  message: error.message
570
  });
571
  }
 
572
  if (!res.headersSent) {
573
  res.status(500).send({
574
  ok: false,
@@ -590,6 +789,9 @@ app.get('*', (_req, res) => {
590
  res.sendFile(path.join(__dirname, 'dist', 'index.html'));
591
  });
592
 
593
- app.listen(PORT, () => {
594
- console.log(`Server is running on port ${PORT}`);
 
 
 
595
  });
 
13
  } from '@huggingface/hub';
14
  import { InferenceClient } from '@huggingface/inference';
15
  import bodyParser from 'body-parser';
16
+ import fs from 'fs';
17
 
18
  import checkUser from './middlewares/checkUser.js';
19
  import { PROVIDERS } from './utils/providers.js';
20
  import { COLORS } from './utils/colors.js';
21
+ import { fetchWithTimeout } from './utils/fetch-utils.js';
22
 
23
  // Load environment variables from .env file
24
  dotenv.config();
25
 
26
+ // Define isDev early, before it's used
27
+ const isDev =
28
+ process.env.NODE_ENV === 'development' || process.env.NODE_ENV === undefined;
29
+
30
+ // Add global error handlers
31
+ process.on('uncaughtException', (error) => {
32
+ console.error('Uncaught Exception:', error);
33
+ // Don't exit the process in development to keep the server running
34
+ if (!isDev) {
35
+ process.exit(1);
36
+ }
37
+ });
38
+
39
+ process.on('unhandledRejection', (reason, promise) => {
40
+ console.error('Unhandled Rejection at:', promise, 'reason:', reason);
41
+ // Don't exit the process in development to keep the server running
42
+ });
43
+
44
  const app = express();
45
 
46
  const ipAddresses = new Map();
 
59
  const EXTERNAL_API_WINDOW_MS = 60000; // 1 minute window
60
  const MAX_REQUESTS_PER_WINDOW = 60; // 60 requests per minute
61
 
62
+ // Load MCP rules so they are always included in AI calls
63
+ const MCP_RULES_PATH = path.join(__dirname, 'MCP_RULES.md');
64
+ let mcpRulesContent = '';
65
+ try {
66
+ mcpRulesContent = fs.readFileSync(MCP_RULES_PATH, 'utf-8');
67
+ } catch (err) {
68
+ console.warn('Could not load MCP rules:', err);
69
+ }
70
+
71
  app.use(cookieParser());
72
+ app.use(bodyParser.json({ limit: '50mb' }));
73
+ app.use(
74
+ cors({
75
+ origin: isDev ? 'http://localhost:5173' : true,
76
+ credentials: true
77
+ })
78
+ );
79
  app.use(express.static(path.join(__dirname, 'dist')));
80
 
81
  const getPTag = (repoId) => {
 
94
  redirectUrl
95
  });
96
  });
97
+
98
  app.get('/auth/login', async (req, res) => {
99
  const { code } = req.query;
100
 
 
105
  `${process.env.OAUTH_CLIENT_ID}:${process.env.OAUTH_CLIENT_SECRET}`
106
  ).toString('base64')}`;
107
 
108
+ try {
109
+ const request_auth = await fetchWithTimeout(
110
+ 'https://huggingface.co/oauth/token',
111
+ {
112
+ method: 'POST',
113
+ headers: {
114
+ 'Content-Type': 'application/x-www-form-urlencoded',
115
+ Authorization
116
+ },
117
+ body: new URLSearchParams({
118
+ grant_type: 'authorization_code',
119
+ code: code,
120
+ redirect_uri: REDIRECT_URI
121
+ })
122
+ },
123
+ 10000
124
+ );
125
 
126
+ if (!request_auth.ok) {
127
+ console.error(`HuggingFace OAuth error: ${request_auth.status}`);
128
+ return res.redirect(302, '/?error=auth_failed');
129
+ }
130
 
131
+ const response = await request_auth.json();
 
 
132
 
133
+ if (!response.access_token) {
134
+ return res.redirect(302, '/?error=no_token');
135
+ }
 
 
 
136
 
137
+ res.cookie('hf_token', response.access_token, {
138
+ httpOnly: false,
139
+ secure: !isDev,
140
+ sameSite: isDev ? 'lax' : 'none',
141
+ maxAge: 30 * 24 * 60 * 60 * 1000
142
+ });
143
+
144
+ return res.redirect(302, '/');
145
+ } catch (error) {
146
+ console.error('Login error:', error);
147
+ return res.redirect(302, '/?error=auth_error');
148
+ }
149
  });
150
  app.get('/auth/logout', (req, res) => {
151
  res.clearCookie('hf_token', {
152
  httpOnly: false,
153
+ secure: !isDev,
154
+ sameSite: isDev ? 'lax' : 'none'
155
  });
156
  return res.redirect(302, '/');
157
  });
158
 
159
+ app.get('/api/@me', async (req, res) => {
160
  const { hf_token } = req.cookies;
161
+
162
+ if (!hf_token) {
163
+ return res.status(401).send({
164
+ ok: false,
165
+ openLogin: true,
166
+ message: 'Please log in to continue'
167
  });
168
+ }
169
+
170
+ try {
171
+ const request_user = await fetchWithTimeout(
172
+ 'https://huggingface.co/oauth/userinfo',
173
+ {
174
+ headers: {
175
+ Authorization: `Bearer ${hf_token}`
176
+ }
177
+ },
178
+ 8000 // 8 second timeout
179
+ );
180
+
181
+ if (!request_user.ok) {
182
+ const errorText = await request_user.text();
183
+ console.error(
184
+ `HuggingFace API error: ${request_user.status} - ${errorText}`
185
+ );
186
+
187
+ res.clearCookie('hf_token', {
188
+ httpOnly: false,
189
+ secure: !isDev,
190
+ sameSite: isDev ? 'lax' : 'none'
191
+ });
192
+
193
+ return res.status(401).send({
194
+ ok: false,
195
+ openLogin: true,
196
+ message: 'Session expired. Please log in again.'
197
+ });
198
+ }
199
 
200
  const user = await request_user.json();
201
  res.send(user);
202
  } catch (err) {
203
+ console.error('Error fetching user info:', err);
204
+
205
+ // Handle timeout specifically
206
+ const message =
207
+ err.name === 'AbortError'
208
+ ? 'Request to authentication service timed out. Please try again later.'
209
+ : err.message || 'An error occurred while fetching user information';
210
+
211
  res.clearCookie('hf_token', {
212
  httpOnly: false,
213
+ secure: !isDev,
214
+ sameSite: isDev ? 'lax' : 'none'
215
  });
216
+
217
  res.status(401).send({
218
  ok: false,
219
+ openLogin: true,
220
+ message
221
  });
222
  }
223
  });
 
299
  });
300
 
301
  app.post('/api/ask-ai', async (req, res) => {
302
+ try {
303
+ const { prompt, html, previousPrompt, provider } = req.body;
304
+ if (!prompt) {
305
+ return res.status(400).send({
306
+ ok: false,
307
+ message: 'Missing required fields'
308
+ });
309
+ }
310
 
311
+ const { hf_token } = req.cookies;
312
+ let token = hf_token;
313
+ const ip =
314
+ req.headers['x-forwarded-for']?.split(',')[0].trim() ||
315
+ req.headers['x-real-ip'] ||
316
+ req.socket.remoteAddress ||
317
+ req.ip ||
318
+ '0.0.0.0';
319
+
320
+ if (!hf_token) {
321
+ ipAddresses.set(ip, (ipAddresses.get(ip) || 0) + 1);
322
+ if (ipAddresses.get(ip) > MAX_REQUESTS_PER_IP) {
323
+ return res.status(429).send({
324
+ ok: false,
325
+ openLogin: true,
326
+ message: 'Log In to continue using the service'
327
+ });
328
+ }
329
 
330
+ token = process.env.DEFAULT_HF_TOKEN;
331
+ if (!token) {
332
+ console.error('No DEFAULT_HF_TOKEN defined in environment variables');
333
+ return res.status(500).send({
334
+ ok: false,
335
+ message: 'Server configuration error. Please try again later.'
336
+ });
337
+ }
338
+ }
339
+
340
+ // Set up response headers for streaming
341
+ res.setHeader('Content-Type', 'text/plain');
342
+ res.setHeader('Cache-Control', 'no-cache');
343
+ res.setHeader('Connection', 'keep-alive');
344
+
345
+ let client;
346
+ try {
347
+ client = new InferenceClient(token);
348
+ } catch (error) {
349
+ console.error('Error creating InferenceClient:', error);
350
+ return res.status(500).send({
351
  ok: false,
352
+ message: 'Failed to initialize AI client. Please try again.'
 
353
  });
354
  }
355
 
356
+ let completeResponse = '';
 
357
 
358
+ let TOKENS_USED = prompt?.length || 0;
359
+ if (previousPrompt) TOKENS_USED += previousPrompt.length || 0;
360
+ if (html) TOKENS_USED += html.length || 0;
 
361
 
362
+ // Make sure provider is defined
363
+ let selectedProviderName = provider;
364
+ if (!selectedProviderName || !PROVIDERS[selectedProviderName]) {
365
+ selectedProviderName = 'auto';
366
+ }
367
 
368
+ const DEFAULT_PROVIDER = PROVIDERS.novita;
369
+ const selectedProvider =
370
+ selectedProviderName === 'auto'
371
+ ? DEFAULT_PROVIDER
372
+ : PROVIDERS[selectedProviderName] ?? DEFAULT_PROVIDER;
373
+
374
+ if (
375
+ selectedProviderName !== 'auto' &&
376
+ TOKENS_USED >= selectedProvider.max_tokens
377
+ ) {
378
+ return res.status(400).send({
379
+ ok: false,
380
+ openSelectProvider: true,
381
+ message: `Context is too long. ${selectedProvider.name} allow ${selectedProvider.max_tokens} max tokens.`
382
+ });
383
+ }
384
 
385
+ // Prepend MCP rules as a system message
386
+ const messages = [
387
+ {
388
+ role: 'system',
389
+ content: 'Do not modify the prompt. Forward it exactly as received.'
390
+ },
391
+ {
392
+ role: 'system',
393
+ content: `ONLY USE HTML, CSS AND JAVASCRIPT. If you want to use ICON make sure to import the library first. Try to create the best UI possible by using only HTML, CSS and JAVASCRIPT. Use as much as you can TailwindCSS for the CSS, if you can't do something with TailwindCSS, then use custom CSS (make sure to import <script src="https://cdn.tailwindcss.com"></script> in the head). Also, try to ellaborate as much as you can, to create something unique. ALWAYS GIVE THE RESPONSE INTO A SINGLE HTML FILE`
394
+ },
395
+ ...(previousPrompt ? [{ role: 'user', content: previousPrompt }] : []),
396
+ ...(html
397
+ ? [{ role: 'assistant', content: `The current code is: ${html}.` }]
398
+ : []),
399
+ { role: 'user', content: prompt }
400
+ ];
401
+
402
+ let chatCompletion;
403
+ try {
404
+ chatCompletion = client.chatCompletionStream({
405
+ model: MODEL_ID,
406
+ provider: selectedProvider.id,
407
+ messages,
408
+ ...(selectedProvider.id !== 'sambanova'
409
+ ? { max_tokens: selectedProvider.max_tokens }
410
+ : {})
411
+ });
412
+ } catch (error) {
413
+ console.error('Error creating chat completion stream:', error);
414
+ return res.status(500).send({
415
+ ok: false,
416
+ message: 'Failed to start AI processing. Please try again.'
417
+ });
418
+ }
419
 
420
+ let isResponseComplete = false;
421
+
422
+ const streamHandler = async () => {
423
+ try {
424
+ while (!isResponseComplete) {
425
+ let nextValue;
426
+ try {
427
+ nextValue = await chatCompletion.next();
428
+ } catch (error) {
429
+ console.error('Error getting next value from stream:', error);
430
+ isResponseComplete = true;
431
+ if (!res.headersSent) {
432
+ return res.status(500).send({
433
+ ok: false,
434
+ message: 'Stream interrupted. Please try again.'
435
+ });
436
+ } else {
437
+ return res.end();
438
+ }
439
+ }
440
 
441
+ const { done, value } = nextValue;
442
+ if (done) {
443
+ isResponseComplete = true;
444
+ break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
445
  }
 
 
446
 
447
+ const chunk = value.choices[0]?.delta?.content;
448
+ if (chunk) {
449
+ if (selectedProviderName !== 'sambanova') {
450
+ try {
451
+ res.write(chunk);
452
+ } catch (error) {
453
+ console.error('Error writing chunk to response:', error);
454
+ isResponseComplete = true;
455
+ break;
456
+ }
457
+ completeResponse += chunk;
458
 
459
+ if (completeResponse.includes('</html>')) {
460
+ isResponseComplete = true;
461
+ break;
462
+ }
463
+ } else {
464
+ let newChunk = chunk;
465
+ if (chunk.includes('</html>')) {
466
+ // Replace everything after the last </html> tag with an empty string
467
+ newChunk = newChunk.replace(/<\/html>[\s\S]*/, '</html>');
468
+ }
469
+ completeResponse += newChunk;
470
+ try {
471
+ res.write(newChunk);
472
+ } catch (error) {
473
+ console.error('Error writing chunk to response:', error);
474
+ isResponseComplete = true;
475
+ break;
476
+ }
477
+ if (newChunk.includes('</html>')) {
478
+ isResponseComplete = true;
479
+ break;
480
+ }
481
+ }
482
  }
483
+ }
484
+ // Ensure we end the response
485
+ res.end();
486
+ } catch (error) {
487
+ console.error('Stream processing error:', error);
488
+ if (!res.headersSent) {
489
+ res.status(500).send({
490
+ ok: false,
491
+ message: error.message || 'Error while streaming the response'
492
+ });
493
  } else {
494
+ res.end();
 
 
 
 
 
 
 
 
 
495
  }
496
  }
497
+ };
498
+
499
+ // Start processing the stream
500
+ streamHandler();
501
  } catch (error) {
502
+ console.error('Global error in /api/ask-ai endpoint:', error);
503
+
504
+ if (error.message?.includes('exceeded your monthly included credits')) {
505
  return res.status(402).send({
506
  ok: false,
507
  openProModal: true,
508
  message: error.message
509
  });
510
  }
511
+
512
  if (!res.headersSent) {
513
  res.status(500).send({
514
  ok: false,
515
  message:
516
+ error.message || 'An unexpected error occurred. Please try again.'
517
  });
518
  } else {
 
519
  res.end();
520
  }
521
  }
 
638
  res.setHeader('Cache-Control', 'no-cache');
639
  res.setHeader('Connection', 'keep-alive');
640
 
641
+ let client;
642
+ try {
643
+ client = new InferenceClient(api_key);
644
+ } catch (error) {
645
+ console.error('Error creating external InferenceClient:', error);
646
+ return res.status(500).send({
647
+ ok: false,
648
+ message: 'Failed to initialize AI client. Please try again.'
649
+ });
650
+ }
651
+
652
  let completeResponse = '';
653
 
654
  let TOKENS_USED = prompt?.length;
 
706
  : {})
707
  });
708
 
709
+ let isResponseComplete = false;
 
 
 
 
 
 
 
 
 
710
 
711
+ const streamHandler = async () => {
712
+ try {
713
+ while (!isResponseComplete) {
714
+ const { done, value } = await chatCompletion.next();
715
+ if (done) {
716
+ isResponseComplete = true;
717
  break;
718
  }
719
+
720
+ const chunk = value.choices[0]?.delta?.content;
721
+ if (chunk) {
722
+ if (provider !== 'sambanova') {
723
+ res.write(chunk);
724
+ completeResponse += chunk;
725
+
726
+ if (completeResponse.includes('</html>')) {
727
+ isResponseComplete = true;
728
+ break;
729
+ }
730
+ } else {
731
+ let newChunk = chunk;
732
+ if (chunk.includes('</html>')) {
733
+ newChunk = newChunk.replace(/<\/html>[\s\S]*/, '</html>');
734
+ }
735
+ completeResponse += newChunk;
736
+ res.write(newChunk);
737
+ if (newChunk.includes('</html>')) {
738
+ isResponseComplete = true;
739
+ break;
740
+ }
741
+ }
742
  }
743
  }
744
+ res.end();
745
+ } catch (error) {
746
+ console.error('External API stream processing error:', error);
747
+ if (!res.headersSent) {
748
+ res.status(500).send({
749
+ ok: false,
750
+ message: error.message || 'Error while streaming the response'
751
+ });
752
+ } else {
753
+ res.end();
754
+ }
755
  }
756
+ };
757
+
758
+ // Start processing the stream
759
+ streamHandler();
760
  } catch (error) {
761
+ console.error('External API request error:', error);
762
+
763
+ if (error.message?.includes('exceeded your monthly included credits')) {
764
  return res.status(402).send({
765
  ok: false,
766
  openProModal: true,
767
  message: error.message
768
  });
769
  }
770
+
771
  if (!res.headersSent) {
772
  res.status(500).send({
773
  ok: false,
 
789
  res.sendFile(path.join(__dirname, 'dist', 'index.html'));
790
  });
791
 
792
+ app.listen(PORT, '0.0.0.0', () => {
793
+ console.log(`Server is running at http://localhost:${PORT}`);
794
+ console.log(`API endpoints available at http://localhost:${PORT}/api/`);
795
+ console.log(`NODE_ENV: ${process.env.NODE_ENV || 'development'}`);
796
+ console.log(`isDev: ${isDev}`);
797
  });
utils/fetch-utils.js ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Fetch with timeout utility function to prevent hanging requests
3
+ * @param {string} url - The URL to fetch
4
+ * @param {Object} options - Fetch options
5
+ * @param {number} timeout - Timeout in milliseconds
6
+ * @returns {Promise<Response>} - The fetch response
7
+ */
8
+ export const fetchWithTimeout = async (url, options, timeout = 10000) => {
9
+ const controller = new AbortController();
10
+ const id = setTimeout(() => controller.abort(), timeout);
11
+
12
+ try {
13
+ const response = await fetch(url, {
14
+ ...options,
15
+ signal: controller.signal
16
+ });
17
+ clearTimeout(id);
18
+ return response;
19
+ } catch (error) {
20
+ clearTimeout(id);
21
+ throw error;
22
+ }
23
+ };
vite.config.ts CHANGED
@@ -11,8 +11,10 @@ export default defineConfig({
11
  server: {
12
  proxy: {
13
  '/api': {
14
- target: 'http://localhost:5173',
15
- changeOrigin: true
 
 
16
  }
17
  }
18
  }
 
11
  server: {
12
  proxy: {
13
  '/api': {
14
+ target: 'http://localhost:7860',
15
+ changeOrigin: true,
16
+ secure: false,
17
+ rewrite: (path) => path
18
  }
19
  }
20
  }