You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
β Request throttle: Added 3-second minimum gap between AI requests (lastRequestTime ref) as a client-side layer on top of the worker's rate limiting.
β AI flashcard answers: Added parseMarkdown() pass on all Gemini flashcard answers before storage. Changed the worker's flashcard system prompt to request markdown (**bold**) instead of raw HTML (<strong>) β matching how chat responses are already handled, no new dependency needed.
β User messages: Added escapeHtml() helper and applied it before storing user input. A user typing <img src=x onerror=alert(1)> now renders as escaped text, not executable HTML.
- New file that Cloudflare Pages/Netlify serves as HTTP response headers
- Production only allows notes.gobinath.com origins. localhost origins are enabled only when ENVIRONMENT=development (read from worker/.dev.vars via wrangler dev). The .dev.vars file is added to .gitignore.
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,6 +45,40 @@ npm run docs:build # Build static files to .vitepress/dist
45
45
npm run docs:preview # Preview the production build
46
46
```
47
47
48
+
### AI Study Assistant (Worker Development)
49
+
50
+
The AI chatbot uses a Cloudflare Worker as a proxy to Google Gemini. The frontend at `http://localhost:5173` calls the **deployed** production worker by default β you don't need to run the worker locally just to work on content or styling.
51
+
52
+
If you want to test AI features locally (against a local worker), follow these steps:
53
+
54
+
**Prerequisites**: [Wrangler CLI](https://developers.cloudflare.com/workers/wrangler/install-and-update/) (`npm install -g wrangler`) and a [Google Gemini API key](https://aistudio.google.com/app/apikey).
55
+
56
+
**1. Create `worker/.dev.vars`** (this file is gitignored β never commit it):
57
+
```
58
+
ENVIRONMENT=development
59
+
GEMINI_API_KEY=your-gemini-api-key-here
60
+
```
61
+
62
+
**2. Run the worker locally:**
63
+
```bash
64
+
cd worker
65
+
npm install
66
+
wrangler dev
67
+
```
68
+
The worker runs at `http://localhost:8787` by default.
69
+
70
+
**3. Point the frontend at your local worker:**
71
+
72
+
In `.vitepress/theme/components/AIChatBot.vue`, temporarily change:
73
+
```js
74
+
constWORKER_URL='http://localhost:8787'
75
+
```
76
+
**Revert this change before submitting a PR.**
77
+
78
+
**Why `.dev.vars`?**
79
+
80
+
The worker uses environment-gated CORS. In production (`ENVIRONMENT=production`, set in `wrangler.toml`), only `notes.gobinath.com` is allowed as a request origin. Setting `ENVIRONMENT=development` in `.dev.vars` tells the worker to also accept `localhost` origins when running via `wrangler dev`. The `.dev.vars` file is read automatically by `wrangler dev` and is gitignored to prevent secrets from being committed.
Copy file name to clipboardExpand all lines: worker/src/index.js
+6-4Lines changed: 6 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,9 @@
4
4
* Handles CORS, rate limiting, and input validation.
5
5
*/
6
6
7
-
constALLOWED_ORIGINS=[
7
+
constPROD_ORIGINS=[
8
8
'https://notes.gobinath.com',
9
9
'https://gobinathmallaiyan.github.io',
10
-
'http://localhost:5173',
11
-
'http://localhost:4173',
12
10
];
13
11
14
12
constGEMINI_URL=
@@ -104,7 +102,7 @@ function buildFlashcardPrompt(pageContent) {
104
102
system_instruction: {
105
103
parts: [
106
104
{
107
-
text: `You are a flashcard generator for certification exam preparation. Given study notes, create 8-12 high-quality flashcards that test key concepts. Return ONLY a valid JSON array of objects with "question" (string) and "answer" (string with HTML formatting like <strong>, <em>, <br>, <ul><li>). Focus on: definitions, comparisons, decision rules, and exam-relevant facts. Do not wrap the JSON in markdown code fences.`,
105
+
text: `You are a flashcard generator for certification exam preparation. Given study notes, create 8-12 high-quality flashcards that test key concepts. Return ONLY a valid JSON array of objects with "question" (string) and "answer" (string using markdown formatting like **bold**, *italic*, and - bullet points for lists). Focus on: definitions, comparisons, decision rules, and exam-relevant facts. Do not wrap the JSON in markdown code fences.`,
108
106
},
109
107
],
110
108
},
@@ -127,6 +125,10 @@ function buildFlashcardPrompt(pageContent) {
0 commit comments