-
Notifications
You must be signed in to change notification settings - Fork 0
Add creative-chat endpoint and frontend integration; switch defaults to Dashscope settings #13
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
base: main
Are you sure you want to change the base?
Add creative-chat endpoint and frontend integration; switch defaults to Dashscope settings #13
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const DEFAULT_API_KEY = | ||
| process.env.OPENAI_API_KEY || 'sk-2893a75c1cfd407aa601eab503ad918a'; |
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.
Remove hard-coded API key default
The server route embeds a literal API key as the fallback for DEFAULT_API_KEY. If this code is shipped or shared, that credential is exposed to anyone with repo or bundle access and can be abused for unauthorized API usage and billing. This should instead require an environment-provided key (and fail fast when missing) or use a non-secret placeholder that never leaves development.
Useful? React with 👍 / 👎.
| const completion = await createClient( | ||
| settings?.apiKey, | ||
| settings?.baseURL |
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.
Block user-controlled baseURL from receiving server key
The API allows callers to pass settings.baseURL from the request body while createClient falls back to the server’s default API key when settings.apiKey is omitted. If this endpoint is reachable by untrusted clients, a caller can set baseURL to an attacker-controlled host and receive the Authorization header containing the server key. Consider whitelisting allowed base URLs or requiring an explicit API key whenever a custom base URL is supplied.
Useful? React with 👍 / 👎.
Motivation
Description
app/api/creative-chat/route.tswhich creates an OpenAI-compatible client, applies aSYSTEM_PROMPT, sanitizes incoming chat messages, calls the chat completion API, and returns the assistant HTML fragment.app/translate/page.tsxto supportChatMessage.role,isChatting,chatError, enter-to-send, loading/disabled states, role-labelled chat history, and automatic appending of assistant HTML into the editor.apiKey,baseURL,model) from the settings modal to the new endpoint and updated client-side error handling for network/response failures.route.tsto readOPENAI_API_KEY,OPENAI_BASE_URL, andOPENAI_MODELfrom the environment and fall back to the Dashscope-compatible values (https://dashscope.aliyuncs.com/compatible-mode/v1andqwen3-plus).Testing
npm run devand confirmed the/translatepage served correctly (previous run)./translate, submitted a chat message and capturedartifacts/creative-chat.png, with the frontend chat flow and UI updates functioning as expected but the backend external model call failing withENETUNREACH.Codex Task