Skip to content

feat(assistant): update chat functionality#132

Merged
gaboesquivel merged 5 commits into
mainfrom
ai-stuff
Mar 10, 2026
Merged

feat(assistant): update chat functionality#132
gaboesquivel merged 5 commits into
mainfrom
ai-stuff

Conversation

@gaboesquivel
Copy link
Copy Markdown
Member

@gaboesquivel gaboesquivel commented Mar 10, 2026

  • Add username to buildUserInfoSpec and UserInfoComponent (backend + frontend)
  • Remove 'Tell me a joke' from assistant suggestions
  • Restore chat-assistant E2E: use authenticatedPage, remove skip
  • Chromium project depends on auth; update docs

Summary by CodeRabbit

  • New Features

    • Added optional Brave Search web-search tool and support for showing usernames in user profiles.
  • Bug Fixes

    • Enabled chat assistant e2e tests with authenticated flows.
  • Documentation

    • Removed disabled/skipped specs notes and updated E2E and self-hosted LLM docs for new auth/provider and Brave Search guidance.
  • Tests

    • Refactored chat e2e tests to use authenticated fixture and removed a "Tell me a joke" suggestion.
  • Chores

    • CI/local run scripts adjusted to prefer Ollama and optional test-skip flag added.

… E2E

- Add username to buildUserInfoSpec and UserInfoComponent (backend + frontend)
- Remove 'Tell me a joke' from assistant suggestions
- Restore chat-assistant E2E: use authenticatedPage, remove skip
- Chromium project depends on auth; update docs
@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
basilic-docs Ready Ready Preview, Comment Mar 10, 2026 7:23am
basilic-fastify Ready Ready Preview, Comment Mar 10, 2026 7:23am
basilic-next Ready Ready Preview, Comment Mar 10, 2026 7:23am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 10, 2026

Warning

Rate limit exceeded

@gaboesquivel has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 8 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7e371981-9de1-4845-a097-dcce83a45291

📥 Commits

Reviewing files that changed from the base of the PR and between 4963a27 and 0a63f5d.

📒 Files selected for processing (1)
  • apps/next/e2e/chat-assistant.spec.ts

Walkthrough

Removed docs about skipped chat tests, activated the chat-assistant e2e test using an authenticatedPage fixture, added username support across backend and frontend user-info flows, added an optional Brave Search tool and env var, removed one assistant suggestion, and adjusted Playwright/CI env for e2e.

Changes

Cohort / File(s) Summary
Documentation & E2E Docs
.cursor/rules/frontend/e2e-playwright.mdc, apps/docu/content/docs/testing/e2e-testing.mdx
Removed disabled/skipped-specs sections and updated E2E docs to reflect active chat-assistant test and new auth/provider guidance.
E2E Tests & Playwright
apps/next/e2e/chat-assistant.spec.ts, apps/next/playwright.config.ts, .github/workflows/next-e2e.yml, apps/next/scripts/run-e2e-local.mjs, scripts/run-qa.mjs
Activated chat-assistant test (uses authenticatedPage fixture), added chromium→auth dependency in Playwright config, removed OPEN_ROUTER usage from CI/local env, and added skipTests flag for QA script.
Backend — Brave Search & Env
apps/fastify/src/routes/ai/brave-search.ts, apps/fastify/src/lib/env.ts, apps/fastify/src/routes/ai/chat.ts
Added createBraveSearchTool and conditional tool wiring when BRAVE_SEARCH_API_KEY present; added BRAVE_SEARCH_API_KEY to env schema; extended user object and buildUserInfoSpec to include username.
Frontend — User Info & Chat UI
apps/next/components/assistant/user-info-catalog.tsx, apps/next/components/assistant/assistant-chat.tsx
UserInfo component and catalog schema now accept and render username; removed "Tell me a joke" suggestion from assistant suggestions.
Docs — Deployment
apps/docu/content/docs/deployment/self-hosted-llm.mdx
Added documentation for optional Brave Search tool and BRAVE_SEARCH_API_KEY usage.

Sequence Diagram(s)

sequenceDiagram
  participant Client as User / Browser
  participant Next as Next.js (E2E / UI)
  participant Fastify as Fastify Server
  participant Brave as Brave Search API

  Client->>Next: Open Assistant (via authenticated session)
  Next->>Fastify: Assistant tool request (braveSearch query)
  Fastify->>Brave: HTTP GET /search with X-Subscription-Token (BRAVE_SEARCH_API_KEY)
  Brave-->>Fastify: JSON results (or error status)
  Fastify->>Fastify: Format results -> numbered lines / fallback messages
  Fastify-->>Next: Tool response (formatted search results)
  Next-->>Client: Render assistant reply with web search results
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Tests hop awake beneath the moon,
Username badges join the tune,
Brave Search peeks at web’s wide sea,
One joke less, one tool set free,
Docs refreshed — the pipeline hums with glee.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is vague and overly broad, using non-descriptive language that does not convey the specific nature of the changes. Make the title more specific by highlighting the primary changes: consider 'feat(assistant): add username field and restore e2e tests' or similar to better reflect the main objectives.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ai-stuff

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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.

🧹 Nitpick comments (2)
apps/next/e2e/chat-assistant.spec.ts (1)

24-34: Pragmatic handling of OpenRouter credit exhaustion.

The early return for 402/insufficient credits errors allows tests to pass gracefully in CI when the OpenRouter account runs out of credits. This prevents flaky test failures due to billing issues rather than actual bugs.

Consider documenting this behavior in a comment for future maintainers:

📝 Optional: Add explanatory comment
     const chatError = sheet.getByTestId('chat-error')
     const errorVisible = await chatError.isVisible().catch(() => false)
     if (errorVisible) {
       const errorText = (await chatError.textContent()) ?? ''
+      // OpenRouter may return 402 when credits are exhausted.
+      // Pass the test gracefully to avoid CI failures due to billing issues.
       if (/402|insufficient|credits/i.test(errorText)) {
         process.stderr.write(
           '[E2E Chat] OpenRouter 402 insufficient credits - passing without validation\n',
         )
         return
       }
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/next/e2e/chat-assistant.spec.ts` around lines 24 - 34, Add a short
explanatory comment above the block that checks sheet.getByTestId('chat-error')
/ chatError.isVisible() and early-returns when errorText matches
/402|insufficient|credits/i, stating that the early return is intentional to
allow E2E tests to pass in CI when the OpenRouter account has exhausted credits
(OpenRouter 402/insufficient credits) and that this is a pragmatic choice to
avoid billing-related flakiness; reference the symbols chatError, errorVisible,
and errorText so future maintainers understand why the test bypasses validation.
apps/next/components/assistant/user-info-catalog.tsx (1)

41-47: Consider inferring props type from the Zod schema.

The inline props type duplicates the Zod schema definition. You could use Zod's inference to keep them in sync:

♻️ Optional refactor to infer type from schema
+type UserInfoProps = z.infer<typeof userInfoCatalog.components.UserInfo.props>
+
 function UserInfoComponent({
   props,
 }: {
-  props: {
-    name: string | null
-    email: string | null
-    joinedAt: string
-    image: string | null
-    username: string | null
-  }
+  props: UserInfoProps
 }) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/next/components/assistant/user-info-catalog.tsx` around lines 41 - 47,
Replace the duplicated inline props type with a Zod-inferred type: import the
Zod schema for this component (e.g., userInfoCatalogSchema) and use
z.infer<typeof userInfoCatalogSchema> for the props type of the UserInfoCatalog
component instead of the manual shape listing name, email, joinedAt, image,
username so the types stay in sync with the schema.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/next/components/assistant/user-info-catalog.tsx`:
- Around line 41-47: Replace the duplicated inline props type with a
Zod-inferred type: import the Zod schema for this component (e.g.,
userInfoCatalogSchema) and use z.infer<typeof userInfoCatalogSchema> for the
props type of the UserInfoCatalog component instead of the manual shape listing
name, email, joinedAt, image, username so the types stay in sync with the
schema.

In `@apps/next/e2e/chat-assistant.spec.ts`:
- Around line 24-34: Add a short explanatory comment above the block that checks
sheet.getByTestId('chat-error') / chatError.isVisible() and early-returns when
errorText matches /402|insufficient|credits/i, stating that the early return is
intentional to allow E2E tests to pass in CI when the OpenRouter account has
exhausted credits (OpenRouter 402/insufficient credits) and that this is a
pragmatic choice to avoid billing-related flakiness; reference the symbols
chatError, errorVisible, and errorText so future maintainers understand why the
test bypasses validation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 44096628-f498-453a-ab1c-aa55e3accb97

📥 Commits

Reviewing files that changed from the base of the PR and between 28a2bf1 and 5ff3177.

📒 Files selected for processing (7)
  • .cursor/rules/frontend/e2e-playwright.mdc
  • apps/docu/content/docs/testing/e2e-testing.mdx
  • apps/fastify/src/routes/ai/chat.ts
  • apps/next/components/assistant/assistant-chat.tsx
  • apps/next/components/assistant/user-info-catalog.tsx
  • apps/next/e2e/chat-assistant.spec.ts
  • apps/next/playwright.config.ts
💤 Files with no reviewable changes (1)
  • .cursor/rules/frontend/e2e-playwright.mdc

CI uses dummy OPEN_ROUTER_API_KEY when secret unset; OpenRouter rejects.
Re-add test.describe.skip with clear comment. Enable by adding
OLLAMA_BASE_URL or OPEN_ROUTER_API_KEY to GitHub secrets.
- Remove test.describe.skip from chat-assistant
- Force AI_PROVIDER=ollama and drop OPEN_ROUTER_API_KEY in run-e2e-local
- Remove OPEN_ROUTER_API_KEY from next-e2e workflow
- Update docs
- Add BRAVE_SEARCH_API_KEY env (optional, enables web search tool)
- Create braveSearch tool for up-to-date web results
- Format top 8 results for LLM synthesis
- Handle 401/403/429 and network errors
- Add QA_SKIP_TESTS=1 to skip test phases in pnpm qa
Copy link
Copy Markdown

@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.

🧹 Nitpick comments (3)
scripts/run-qa.mjs (1)

2-6: Consider updating the header comment to reflect the skip capability.

The comment lists the QA phases but doesn't mention that test and test:e2e can be skipped via QA_SKIP_TESTS=1.

📝 Suggested update
 /**
- * Run QA pipeline: install, checktypes, lint:fix, build, test, test:e2e.
+ * Run QA pipeline: install, checktypes, lint:fix, build, test, test:e2e.
+ * Set QA_SKIP_TESTS=1 to skip test and test:e2e phases.
  * Stops immediately on first failure and reports which phase failed.
  * Used by pnpm qa.
  */
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/run-qa.mjs` around lines 2 - 6, Update the file header comment in
scripts/run-qa.mjs to document that the test phases can be conditionally
skipped: mention that setting the environment variable QA_SKIP_TESTS=1 will skip
both the "test" and "test:e2e" phases when running the QA pipeline, and keep the
existing list of phases and the note that the script stops on first failure.
apps/fastify/src/routes/ai/brave-search.ts (2)

14-18: Consider adding Accept header for explicit JSON response.

The Brave Search API returns JSON by default, but explicitly requesting it is a defensive best practice.

📝 Suggested improvement
         const res = await fetch(url, {
-          headers: { 'X-Subscription-Token': apiKey },
+          headers: {
+            'X-Subscription-Token': apiKey,
+            Accept: 'application/json',
+          },
         })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/fastify/src/routes/ai/brave-search.ts` around lines 14 - 18, The fetch
call that constructs the Brave Search request (the url constant and the await
fetch(...) block) should explicitly request JSON by adding an 'Accept:
application/json' header alongside the existing 'X-Subscription-Token' header;
update the headers object in the fetch invocation (where headers: {
'X-Subscription-Token': apiKey }) to include the Accept header so the API
response is explicitly requested as JSON.

16-18: Consider adding a request timeout.

The fetch call has no timeout, which could cause the tool execution to hang indefinitely if the Brave API is unresponsive. This could block the chat response.

⏱️ Suggested improvement with AbortSignal
+        const controller = new AbortController()
+        const timeoutId = setTimeout(() => controller.abort(), 10000) // 10s timeout
         const res = await fetch(url, {
           headers: { 'X-Subscription-Token': apiKey },
+          signal: controller.signal,
         })
+        clearTimeout(timeoutId)

The catch block will handle AbortError and return the generic failure message.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/fastify/src/routes/ai/brave-search.ts` around lines 16 - 18, The fetch
call (fetch(url, { headers: { 'X-Subscription-Token': apiKey } })) can hang;
wrap it with an AbortController and a short timeout (e.g., 5–10s) and pass
signal to fetch to cancel the request if it exceeds the timeout. Create an
AbortController before calling fetch, set a timer to call controller.abort()
after the chosen timeout, then clear the timer after fetch completes; ensure the
surrounding error handling recognizes AbortError and returns the same generic
failure message as other errors. Update references around the res variable and
the fetch invocation so the signal is passed and the timer is properly cleaned
up.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/fastify/src/routes/ai/brave-search.ts`:
- Around line 14-18: The fetch call that constructs the Brave Search request
(the url constant and the await fetch(...) block) should explicitly request JSON
by adding an 'Accept: application/json' header alongside the existing
'X-Subscription-Token' header; update the headers object in the fetch invocation
(where headers: { 'X-Subscription-Token': apiKey }) to include the Accept header
so the API response is explicitly requested as JSON.
- Around line 16-18: The fetch call (fetch(url, { headers: {
'X-Subscription-Token': apiKey } })) can hang; wrap it with an AbortController
and a short timeout (e.g., 5–10s) and pass signal to fetch to cancel the request
if it exceeds the timeout. Create an AbortController before calling fetch, set a
timer to call controller.abort() after the chosen timeout, then clear the timer
after fetch completes; ensure the surrounding error handling recognizes
AbortError and returns the same generic failure message as other errors. Update
references around the res variable and the fetch invocation so the signal is
passed and the timer is properly cleaned up.

In `@scripts/run-qa.mjs`:
- Around line 2-6: Update the file header comment in scripts/run-qa.mjs to
document that the test phases can be conditionally skipped: mention that setting
the environment variable QA_SKIP_TESTS=1 will skip both the "test" and
"test:e2e" phases when running the QA pipeline, and keep the existing list of
phases and the note that the script stops on first failure.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d09b8421-599d-440f-a85c-e990784367ad

📥 Commits

Reviewing files that changed from the base of the PR and between 5ff3177 and 4963a27.

⛔ Files ignored due to path filters (1)
  • apps/fastify/.env-sample is excluded by !**/.env*
📒 Files selected for processing (8)
  • .github/workflows/next-e2e.yml
  • apps/docu/content/docs/deployment/self-hosted-llm.mdx
  • apps/docu/content/docs/testing/e2e-testing.mdx
  • apps/fastify/src/lib/env.ts
  • apps/fastify/src/routes/ai/brave-search.ts
  • apps/fastify/src/routes/ai/chat.ts
  • apps/next/scripts/run-e2e-local.mjs
  • scripts/run-qa.mjs
💤 Files with no reviewable changes (1)
  • .github/workflows/next-e2e.yml
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/docu/content/docs/testing/e2e-testing.mdx
  • apps/fastify/src/routes/ai/chat.ts

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.

1 participant