-
Notifications
You must be signed in to change notification settings - Fork 0
Development 03 #3
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9c51d84
feat: refactor WikiArticleViewer to simplify page view tracking; add …
halilibrahimcelik 55d27ac
feat: add LinkButton component for navigation; refactor Navbar and r…
halilibrahimcelik a8d61d4
feat: refactor Navbar component; remove SignInButton and clean up imp…
halilibrahimcelik 80a3419
feat: enhance Navbar and Articles components; add ShinyText component…
halilibrahimcelik 69eb0d0
feat: implement article summarization feature in WikiArticleViewer; a…
halilibrahimcelik f3ed570
feat: enhance AI response handling in route.ts; add validation error …
halilibrahimcelik eda69f4
feat: update content validation in RequestBodySchema; add Tooltip com…
halilibrahimcelik a9bff8e
feat: integrate Sonner for toast notifications in WikiArticleViewer a…
halilibrahimcelik bc07e2d
feat: enhance article deletion handling; improve error management in …
halilibrahimcelik 4a46a16
feat: add AI gateway API key to CI/CD workflow for enhanced integration
halilibrahimcelik f35f9d0
feat: refactor imports and formatting in multiple files; enhance tool…
halilibrahimcelik e70c0b4
Initial plan
Copilot 39c5981
fix: address PR review comments - auth, deps, UX, abort, dedup, types
Copilot 8646ae4
fix: sync pnpm-lock.yaml with package.json (remove @openrouter/sdk)
Copilot 47ca5ab
Merge pull request #4 from halilibrahimcelik/copilot/sub-pr-3
halilibrahimcelik 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
There are no files selected for viewing
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 |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| { | ||
| "cSpell.words": ["neondatabase", "Wikimasters"] | ||
| "cSpell.words": ["gsap", "neondatabase", "Wikimasters"] | ||
| } |
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,157 @@ | ||
| "use server"; | ||
| import { NextRequest, NextResponse } from "next/server"; | ||
| import { ZodError, z } from "zod"; | ||
|
|
||
| const RequestBodySchema = z.object({ | ||
| prompt: z.object({ | ||
| text: z.string(), | ||
| content: z | ||
| .string() | ||
| .min(10, "Content is too short") | ||
| .max(7000, "Content too large"), // ✅ validation rules | ||
| }), | ||
| }); | ||
| // ✅ define response types | ||
| export type AISuccessResponse = { | ||
| created: number; | ||
| content: string; | ||
| }; | ||
|
|
||
| export type AIErrorResponse = { | ||
| error: string; | ||
| }; | ||
|
|
||
| type AIResponse = AISuccessResponse | AIErrorResponse; | ||
|
|
||
| type OpenRouterMessage = { | ||
| role: string; | ||
| content: string; | ||
| }; | ||
|
|
||
| type OpenRouterChoice = { | ||
| index: number; | ||
| finish_reason: string; | ||
| message: OpenRouterMessage; | ||
| logprobs: null | object; | ||
| }; | ||
| type OpenRouterResponse = { | ||
| id: string; | ||
| model: string; | ||
| object: string; | ||
| created: number; | ||
| choices: OpenRouterChoice[]; | ||
| usage: { | ||
| prompt_tokens: number; | ||
| completion_tokens: number; | ||
| total_tokens: number; | ||
| cost: number; | ||
| }; | ||
| }; | ||
| export const POST = async ( | ||
| request: NextRequest, | ||
| ): Promise<NextResponse<AIResponse>> => { | ||
| try { | ||
| const { | ||
| prompt: { text, content }, | ||
| } = RequestBodySchema.parse(await request.json()); // ✅ validated + typed | ||
| const response = await fetch( | ||
| "https://openrouter.ai/api/v1/chat/completions", | ||
| { | ||
| method: "POST", | ||
| headers: { | ||
| Authorization: `Bearer ${process.env.AI_GATEWAY_API_KEY}`, | ||
| "HTTP-Referer": process.env.SITE_URL ?? "", // Optional. Site URL for rankings on openrouter.ai. | ||
| "X-Title": process.env.SITE_NAME ?? "", // Optional. Site title for rankings on openrouter.ai. | ||
| "Content-Type": "application/json", | ||
| }, | ||
| body: JSON.stringify({ | ||
| model: "openai/gpt-5-nano", | ||
| messages: [ | ||
| { | ||
| role: "user", | ||
| content: [ | ||
| { | ||
| type: "text", | ||
| text, | ||
| }, | ||
| { | ||
| type: "text", | ||
| text: content, | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }), | ||
| }, | ||
| ); | ||
|
|
||
| if (!response.ok) { | ||
| let errorText = ""; | ||
| try { | ||
| errorText = await response.text(); | ||
| } catch { | ||
| // ignore body parsing errors for non-OK responses | ||
| } | ||
| const status = | ||
| response.status >= 400 && response.status <= 599 | ||
| ? response.status | ||
| : 502; | ||
| return NextResponse.json<AIErrorResponse>( | ||
| { | ||
| error: | ||
| errorText || | ||
| `Upstream OpenRouter error: ${response.status} ${response.statusText}`, | ||
| }, | ||
| { status }, | ||
| ); | ||
| } | ||
|
|
||
| let rawData: unknown; | ||
| try { | ||
| rawData = await response.json(); | ||
| } catch { | ||
| return NextResponse.json<AIErrorResponse>( | ||
| { error: "Failed to parse response from AI provider" }, | ||
| { status: 502 }, | ||
| ); | ||
| } | ||
|
|
||
| const data = rawData as Partial<OpenRouterResponse>; | ||
| const choice = data.choices?.[0]; | ||
| const messageContent = | ||
| choice?.message && typeof choice.message.content === "string" | ||
| ? choice.message.content | ||
| : undefined; | ||
|
|
||
| if (typeof data.created !== "number" || !messageContent) { | ||
| return NextResponse.json<AIErrorResponse>( | ||
| { error: "Invalid response from AI provider" }, | ||
| { status: 502 }, | ||
| ); | ||
| } | ||
|
|
||
| return NextResponse.json( | ||
| { | ||
| created: data.created, | ||
| content: messageContent, | ||
| }, | ||
| { status: 200 }, | ||
| ); | ||
| } catch (error) { | ||
| if (error instanceof ZodError) { | ||
| return NextResponse.json<AIErrorResponse>( | ||
| { | ||
| error: error.message, | ||
| }, | ||
| { status: 400 }, | ||
| ); | ||
| } | ||
| console.error("API Error:", error); | ||
| return NextResponse.json<AIErrorResponse>( | ||
| { | ||
| error: "Failed to process the prompt", | ||
| }, | ||
| { status: 500 }, | ||
| ); | ||
| } | ||
| }; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1 @@ | ||
| export { Navbar } from "./navbar"; | ||
| export { SignInButton } from "./signin-button"; | ||
| export { SignOutButton } from "./signup-button"; |
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 was deleted.
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stackServerApp.getUser({ or: "redirect" })should guarantee a user, but this still falls back to a hard-coded"mockUserId". That can mask auth issues and may cause incorrect authorization results.Prefer treating
useras non-null after redirect (or explicitly handle the null case with a redirect/throw) and passuser.iddirectly.