Skip to content

Better API Key Input hints #3086

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 2 commits into from
Jun 13, 2025
Merged

Better API Key Input hints #3086

merged 2 commits into from
Jun 13, 2025

Conversation

VNOsST
Copy link
Collaborator

@VNOsST VNOsST commented Jun 13, 2025

Implement toast when users click on example messages if they dont have an api key
Better message for disabled input field when users dont have API key
Link to Google AI Studio for users to get their API Key in the API key Input

Summary by CodeRabbit

  • New Features

    • Added user-facing messages guiding users to provide and obtain an API key.
    • Introduced a clickable link directing users to Google AI Studio for API key retrieval.
  • Enhancements

    • Improved user feedback when attempting actions without an API key, including toast notifications and updated input placeholders.
    • Updated API key validation error messages for clearer guidance.
  • Bug Fixes

    • Corrected typographical errors in Vietnamese translations for FAQ and account deletion messages.

implement toast when users click on example messages if they dont have an api key
Better message for disabled input field when users dont have API key
Link to Google AI Studio for users to get their API Key in the API key Input
Copy link
Contributor

coderabbitai bot commented Jun 13, 2025

Walkthrough

Localization files were updated to add new API key-related messages in English and Vietnamese. Components handling chat input, empty state, and dialog descriptions were modified to incorporate API key checks and display appropriate user guidance. The EmptyScreen component now requires a hasApiKey prop, enforcing API key presence before allowing user interactions.

Changes

File(s) Change Summary
apps/upskii/messages/en.json, apps/upskii/messages/vi.json Added new API key-related localization strings; fixed typos and added trailing commas in Vietnamese translations
apps/upskii/src/app/[locale]/(dashboard)/[wsId]/ai-chat/chat.tsx Passed new hasApiKey prop to EmptyScreen based on API key presence
apps/upskii/src/components/empty-screen.tsx Added hasApiKey prop; blocks example input if API key is missing; shows error toast if not present
apps/upskii/src/components/prompt-form.tsx Changed placeholder logic to show API key requirement message if API key is missing or input is disabled
apps/upskii/src/components/chat-panel.tsx Enhanced API dialog description to include a link for obtaining an API key
apps/upskii/src/components/form-apikey.tsx Updated API key regex validation error message to indicate format requirement instead of missing key

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant EmptyScreen
    participant Toast
    participant Chat

    User->>EmptyScreen: Clicks example message
    EmptyScreen-->>EmptyScreen: Check hasApiKey
    alt hasApiKey is true
        EmptyScreen->>Chat: setInput(message)
    else hasApiKey is false
        EmptyScreen->>Toast: Show "API key required" error
    end
Loading

Suggested labels

upskii

Suggested reviewers

  • vhpx

Poem

In the land of code where rabbits play,
New prompts now check if keys are okay.
If you hop in without your key,
A friendly toast will let you see!
English and Vietnamese got a tweak,
For a smoother chat—no API hide-and-seek! 🐇

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/upskii/src/components/chat-panel.tsx

Oops! Something went wrong! :(

ESLint: 9.28.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@typescript-eslint/parser' imported from /eslint.config.mjs
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9)
at packageResolve (node:internal/modules/esm/resolve:767:81)
at moduleResolve (node:internal/modules/esm/resolve:853:18)
at defaultResolve (node:internal/modules/esm/resolve:983:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38)
at #link (node:internal/modules/esm/module_job:201:49)

apps/upskii/src/components/form-apikey.tsx

Oops! Something went wrong! :(

ESLint: 9.28.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@typescript-eslint/parser' imported from /eslint.config.mjs
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9)
at packageResolve (node:internal/modules/esm/resolve:767:81)
at moduleResolve (node:internal/modules/esm/resolve:853:18)
at defaultResolve (node:internal/modules/esm/resolve:983:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38)
at #link (node:internal/modules/esm/module_job:201:49)

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch feat/better-apikey-hints
  • Post Copyable Unit Tests in Comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

graphite-app bot commented Jun 13, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@VNOsST VNOsST self-assigned this Jun 13, 2025
@VNOsST
Copy link
Collaborator Author

VNOsST commented Jun 13, 2025

@coderabbitai full review

Copy link

codecov bot commented Jun 13, 2025

Codecov Report

Attention: Patch coverage is 0% with 39 lines in your changes missing coverage. Please review.

Project coverage is 0.83%. Comparing base (720db37) to head (14e63b1).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
apps/upskii/src/components/chat-panel.tsx 0.00% 19 Missing ⚠️
apps/upskii/src/components/empty-screen.tsx 0.00% 9 Missing ⚠️
...c/app/[locale]/(dashboard)/[wsId]/ai-chat/chat.tsx 0.00% 6 Missing ⚠️
apps/upskii/src/components/form-apikey.tsx 0.00% 3 Missing ⚠️
apps/upskii/src/components/prompt-form.tsx 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3086      +/-   ##
==========================================
- Coverage    0.83%    0.83%   -0.01%     
==========================================
  Files        2494     2494              
  Lines      307830   307859      +29     
  Branches     2996     2996              
==========================================
  Hits         2582     2582              
- Misses     303119   303148      +29     
  Partials     2129     2129              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

coderabbitai bot commented Jun 13, 2025

✅ Actions performed

Full review triggered.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (5)
apps/upskii/src/components/prompt-form.tsx (1)

736-739: Placeholder conflates two different disable reasons

The current condition shows ai_chat.api_key_required when either

  1. disabled is true, or
  2. the API key is missing.

If the textarea is disabled for another reason (e.g. chat summarising, rate limiting), the message is misleading.
Split the logic so the placeholder reflects the actual cause:

-placeholder={
-  disabled || !apiKey
-    ? t('ai_chat.api_key_required')
-    : `${t('ai_chat.send_message')}`
-}
+placeholder={
+  !apiKey
+    ? t('ai_chat.api_key_required')
+    : disabled
+      ? t('ai_chat.input_disabled') /* add a new i18n key */
+      : t('ai_chat.send_message')
+}

This keeps the UX clear and avoids user confusion.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 737-738: apps/upskii/src/components/prompt-form.tsx#L737-L738
Added lines #L737 - L738 were not covered by tests

apps/upskii/messages/vi.json (1)

2910-2910: Typographical consistency in “Xóa tài khoản” message
The entry uses “xoá” (with diacritic on ‘á’) and is lowercase, whereas existing entries use “Xóa” (uppercase ‘X’, accent on ‘á’) consistently. Update the key’s text to match the established casing and accent placement.

Example diff:

-    "delete-account-message": "Tài khoản của bạn sẽ bị xóa vĩnh viễn và không thể phục hồi. Nhập địa chỉ email của bạn để xác nhận xoá tài khoản.",
+    "delete-account-message": "Tài khoản của bạn sẽ bị xóa vĩnh viễn và không thể phục hồi. Nhập địa chỉ email của bạn để xác nhận xóa tài khoản.",
apps/upskii/src/components/empty-screen.tsx (1)

17-17: Importing toast eagerly can bloat the bundle

If sonner is sizeable, consider import('sonner').then(m => m.toast…) inside the click handler so the extra KBs are only loaded when needed. Not critical but worth a thought for initial-render performance.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 17-17: apps/upskii/src/components/empty-screen.tsx#L17
Added line #L17 was not covered by tests

apps/upskii/src/components/chat-panel.tsx (2)

193-213: Hard-coded JSX fragments reduce i18n flexibility

The ‘Get API key’ sentence is now split between a translation string and hard-coded JSX. This makes future localisation (e.g., RTL languages) painful because word order may differ.

Consider exposing the whole sentence to the translator and interpolating the link, e.g.:

const link = (
  <Link
    href="https://aistudio.google.com/app/apikey"
    target="_blank"
    rel="noopener noreferrer"
    className="text-primary underline hover:no-underline"
  >
    Google AI Studio
  </Link>
);

{t.rich('api_input_description_full', { link })}

Then add "<0>Google AI Studio</0>" placeholders in the JSON file.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 193-206: apps/upskii/src/components/chat-panel.tsx#L193-L206
Added lines #L193 - L206 were not covered by tests


[warning] 208-210: apps/upskii/src/components/chat-panel.tsx#L208-L210
Added lines #L208 - L210 were not covered by tests


[warning] 212-212: apps/upskii/src/components/chat-panel.tsx#L212
Added line #L212 was not covered by tests


20-20: Unused ESLint disable comment?

/* eslint-disable no-unused-vars */ remains at the top, but the file doesn’t define any unused vars after your edits. Removing the pragma prevents masking real issues later.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 20-20: apps/upskii/src/components/chat-panel.tsx#L20
Added line #L20 was not covered by tests

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 720db37 and ff1822c.

📒 Files selected for processing (6)
  • apps/upskii/messages/en.json (1 hunks)
  • apps/upskii/messages/vi.json (3 hunks)
  • apps/upskii/src/app/[locale]/(dashboard)/[wsId]/ai-chat/chat.tsx (1 hunks)
  • apps/upskii/src/components/chat-panel.tsx (2 hunks)
  • apps/upskii/src/components/empty-screen.tsx (2 hunks)
  • apps/upskii/src/components/prompt-form.tsx (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
apps/upskii/src/app/[locale]/(dashboard)/[wsId]/ai-chat/chat.tsx (1)
apps/upskii/src/components/empty-screen.tsx (1)
  • EmptyScreen (19-186)
apps/upskii/src/components/empty-screen.tsx (3)
packages/ai/src/types.ts (1)
  • UseChatHelpers (6-6)
packages/types/src/db.ts (1)
  • AIChat (3-3)
packages/ui/src/components/ui/sonner.tsx (1)
  • toast (29-29)
🪛 GitHub Check: codecov/patch
apps/upskii/src/app/[locale]/(dashboard)/[wsId]/ai-chat/chat.tsx

[warning] 334-339: apps/upskii/src/app/[locale]/(dashboard)/[wsId]/ai-chat/chat.tsx#L334-L339
Added lines #L334 - L339 were not covered by tests

apps/upskii/src/components/empty-screen.tsx

[warning] 17-17: apps/upskii/src/components/empty-screen.tsx#L17
Added line #L17 was not covered by tests


[warning] 23-23: apps/upskii/src/components/empty-screen.tsx#L23
Added line #L23 was not covered by tests


[warning] 99-105: apps/upskii/src/components/empty-screen.tsx#L99-L105
Added lines #L99 - L105 were not covered by tests

apps/upskii/src/components/chat-panel.tsx

[warning] 20-20: apps/upskii/src/components/chat-panel.tsx#L20
Added line #L20 was not covered by tests


[warning] 193-206: apps/upskii/src/components/chat-panel.tsx#L193-L206
Added lines #L193 - L206 were not covered by tests


[warning] 208-210: apps/upskii/src/components/chat-panel.tsx#L208-L210
Added lines #L208 - L210 were not covered by tests


[warning] 212-212: apps/upskii/src/components/chat-panel.tsx#L212
Added line #L212 was not covered by tests

apps/upskii/src/components/prompt-form.tsx

[warning] 737-738: apps/upskii/src/components/prompt-form.tsx#L737-L738
Added lines #L737 - L738 were not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Deploy-Preview
  • GitHub Check: Deploy-Preview
🔇 Additional comments (1)
apps/upskii/src/components/empty-screen.tsx (1)

23-28: Adding a required hasApiKey prop is a breaking change – double-check all call-sites

hasApiKey is now mandatory, but only chat.tsx was updated according to the PR summary. Any other <EmptyScreen /> usage that wasn’t touched will now fail type-checking or, worse, silently render with undefined (always triggering the toast).

Two quick mitigations:

-export function EmptyScreen({
-  // chats,
-  setInput,
-  locale,
-  hasApiKey,
-}: …
+export function EmptyScreen({
+  // chats,
+  setInput,
+  locale,
+  hasApiKey = false,   // sensible default
+}: …

or keep it required but grep the repo to update every invocation.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 23-23: apps/upskii/src/components/empty-screen.tsx#L23
Added line #L23 was not covered by tests

@VNOsST VNOsST marked this pull request as ready for review June 13, 2025 06:00
@VNOsST VNOsST requested a review from vhpx June 13, 2025 06:00
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
apps/upskii/src/components/form-apikey.tsx (1)

42-44: Split-message validation looks good, but embed-once regex is brittle

👍 Using a separate api-key-required-format message cleanly separates “missing” vs “malformed” states.

Minor improvement: the AIza[0-9A-Za-z\-_]{35} pattern now lives solely in this component. If the key format ever changes you’ll have to hunt it down in multiple places (client, API route, tests, etc.). Consider extracting it to a shared constant (e.g. constants/api.ts) or even validating server-side only and re-using the same schema to avoid drift.

Also, unit tests that assert the new message key would prevent silent regressions (Codecov warns these lines are uncovered).

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 42-44: apps/upskii/src/components/form-apikey.tsx#L42-L44
Added lines #L42 - L44 were not covered by tests

apps/upskii/src/components/chat-panel.tsx (1)

20-20: Use <a> instead of next/link for external URLs

next/link is intended for internal navigation; for absolute URLs (https://…) it adds no benefit and can unintentionally prefetch or bloat the JS bundle.

-import Link from 'next/link';
+// For external links we can rely on a plain anchor tag

Then inline:

-<Link href="https://aistudio.google.com/app/apikey" …>Google AI Studio</Link>
+<a href="https://aistudio.google.com/app/apikey" target="_blank"
+   rel="noopener noreferrer"
+   className="text-primary underline hover:no-underline">
+  Google AI Studio
+</a>
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 20-20: apps/upskii/src/components/chat-panel.tsx#L20
Added line #L20 was not covered by tests

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ff1822c and 14e63b1.

📒 Files selected for processing (4)
  • apps/upskii/messages/en.json (2 hunks)
  • apps/upskii/messages/vi.json (4 hunks)
  • apps/upskii/src/components/chat-panel.tsx (2 hunks)
  • apps/upskii/src/components/form-apikey.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/upskii/messages/en.json
  • apps/upskii/messages/vi.json
🧰 Additional context used
🪛 GitHub Check: codecov/patch
apps/upskii/src/components/form-apikey.tsx

[warning] 42-44: apps/upskii/src/components/form-apikey.tsx#L42-L44
Added lines #L42 - L44 were not covered by tests

apps/upskii/src/components/chat-panel.tsx

[warning] 20-20: apps/upskii/src/components/chat-panel.tsx#L20
Added line #L20 was not covered by tests


[warning] 193-206: apps/upskii/src/components/chat-panel.tsx#L193-L206
Added lines #L193 - L206 were not covered by tests


[warning] 208-210: apps/upskii/src/components/chat-panel.tsx#L208-L210
Added lines #L208 - L210 were not covered by tests


[warning] 212-212: apps/upskii/src/components/chat-panel.tsx#L212
Added line #L212 was not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Deploy-Preview
  • GitHub Check: Deploy-Preview
  • GitHub Check: Verify generated types
  • GitHub Check: Deploy-Preview
  • GitHub Check: Deploy-Preview

Copy link
Member

@vhpx vhpx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @VNOsST.

@vhpx vhpx merged commit a0b8369 into main Jun 13, 2025
19 of 20 checks passed
@vhpx vhpx deleted the feat/better-apikey-hints branch June 13, 2025 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants