-
Notifications
You must be signed in to change notification settings - Fork 0
feat: emoji suggestion via Gemini AI and theme cycle toggle #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
guid3d
wants to merge
18
commits into
develop
Choose a base branch
from
feat/emoji-suggestion
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+279
−3,841
Open
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1a87440
feat: add emoji suggestion feature using Google Generative AI
guid3d e088d41
chore: remove unused subproject worktree for sharp-lehmann
guid3d 433228e
fix: cannot add participant without typing in iban, optimize emoji pe…
guid3d a487eff
build: fix TypeScript errors blocking production build
guid3d 0e3ca6b
feat: add loading indicator to save button in UserSelectionModal
guid3d 51ea4bb
fix: set default color scheme for MantineProvider in RootLayout
guid3d f57f6f9
feat(theme): add auto color scheme to toggle cycle and fix indicator
guid3d fab046d
security(emoji-suggest): harden API against prompt injection and quot…
guid3d 3775caa
Potential fix for pull request finding
guid3d eaa362c
Potential fix for pull request finding
guid3d 5c35df0
Potential fix for pull request finding
guid3d 4aaa2cc
Potential fix for pull request finding
guid3d 3d1db6c
fix: avoid AI emoji overwrite in transaction edit flow
Copilot deaf187
fix: wire group name into emoji suggestion query
Copilot d976140
Apply suggestions from code review
guid3d 810ea22
fix: add missing upstash deps for emoji-suggest route
Copilot e650167
fix: restore group name emoji auto-apply behavior
Copilot 59b2378
revert: restore files to fab046d baseline
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Submodule sharp-lehmann
deleted from
0e187b
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { GoogleGenerativeAI } from "@google/generative-ai"; | ||
| import { NextRequest, NextResponse } from "next/server"; | ||
|
|
||
| const genAI = new GoogleGenerativeAI( | ||
| process.env.GOOGLE_GENERATIVE_AI_API_KEY! | ||
| ); | ||
|
|
||
| // In-memory store: IP → { request count, window expiry } | ||
| const rateLimitMap = new Map<string, { count: number; resetAt: number }>(); | ||
| const RATE_LIMIT = 20; // max requests per IP per window | ||
| const WINDOW_MS = 60_000; // 1 minute | ||
|
|
||
| // Returns true if IP has exceeded the rate limit. Prunes expired entries on each call. | ||
| function isRateLimited(ip: string): boolean { | ||
| const now = Date.now(); | ||
| for (const [key, val] of rateLimitMap) { | ||
| if (now > val.resetAt) rateLimitMap.delete(key); | ||
| } | ||
| const entry = rateLimitMap.get(ip); | ||
| if (!entry || now > entry.resetAt) { | ||
| rateLimitMap.set(ip, { count: 1, resetAt: now + WINDOW_MS }); | ||
| return false; | ||
| } | ||
| if (entry.count >= RATE_LIMIT) return true; | ||
| entry.count++; | ||
| return false; | ||
| } | ||
|
|
||
| export async function POST(req: NextRequest) { | ||
| const ip = | ||
| req.headers.get("x-forwarded-for")?.split(",")[0].trim() ?? "unknown"; | ||
|
|
||
| if (isRateLimited(ip)) { | ||
| return NextResponse.json( | ||
| { error: "Too many requests" }, | ||
| { status: 429 } | ||
| ); | ||
| } | ||
|
|
||
| let name: unknown; | ||
| try { | ||
| ({ name } = await req.json()); | ||
| } catch { | ||
| return NextResponse.json({ emojis: [] }); | ||
| } | ||
|
|
||
| if (!String(name ?? "").trim()) return NextResponse.json({ emojis: [] }); | ||
|
|
||
|
guid3d marked this conversation as resolved.
|
||
| // Sanitize: cap length and strip quote chars to prevent prompt injection | ||
| const safeName = String(name).trim().slice(0, 100).replace(/["\\`]/g, ""); | ||
| if (!safeName) return NextResponse.json({ emojis: [] }); | ||
|
|
||
| try { | ||
| const model = genAI.getGenerativeModel({ model: "gemini-2.5-flash-lite" }); | ||
| const result = await model.generateContent( | ||
| `Given the transaction name: "${safeName}", suggest 5 relevant emojis. Reply with ONLY the 5 emojis separated by spaces, nothing else. No words, no punctuation, just emojis.` | ||
| ); | ||
| const text = result.response.text().trim(); | ||
| // Segment by grapheme cluster so multi-codepoint emojis (e.g. 👨👩👧) aren't split, | ||
| // then keep only pictographic emojis (excludes digits/punctuation that match \p{Emoji}) | ||
| const emojis = [...new Intl.Segmenter().segment(text)] | ||
| .map((s) => s.segment) | ||
| .filter((s) => /\p{Extended_Pictographic}/u.test(s)) | ||
| .slice(0, 5); | ||
|
|
||
| return NextResponse.json({ emojis }); | ||
| } catch { | ||
| return NextResponse.json({ emojis: [] }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.