Remove console logs and simplify AI chat prompt#1769
Conversation
WalkthroughThis update removes the AI-powered Gmail search query builder tool and its registrations, rewrites the AI assistant system prompt to a concise XML-like format, adds error handling and logging to agent logic, and eliminates debugging console logs from several frontend and hook files. Minor import order changes and explicit output options are also introduced. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ZeroDriver
participant OpenAI
participant Orchestrator
User->>ZeroDriver: searchThreads(query)
ZeroDriver->>OpenAI: generateText (refine query)
OpenAI-->>ZeroDriver: refined query
par
ZeroDriver->>ZeroDriver: inboxRag(refined query)
ZeroDriver->>ZeroDriver: listThreads(refined query)
end
ZeroDriver-->>User: thread IDs (from RAG or fallback to list)
User->>ZeroAgent: start chat session
ZeroAgent->>Orchestrator: processTools(rawTools)
Orchestrator-->>ZeroAgent: tools
ZeroAgent->>OpenAI: streamText (with tools)
OpenAI-->>ZeroAgent: AI response
ZeroAgent-->>User: streamed response
Possibly related PRs
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
There was a problem hiding this comment.
Bug: Debug Logs Added Despite Removal Goal
Debug console.log, console.warn, and console.error statements were added, notably within the useAgent configuration's onError handler and the inboxRag function. This contradicts the PR's stated goal of removing debug logs and maintaining a clean browser console in production.
apps/mail/components/ui/ai-sidebar.tsx#L351-L352
Zero/apps/mail/components/ui/ai-sidebar.tsx
Lines 351 to 352 in 815901b
apps/server/src/routes/agent/index.ts#L498-L510
Zero/apps/server/src/routes/agent/index.ts
Lines 498 to 510 in 815901b
BugBot free trial expires on July 31, 2025
Learn more in the Cursor dashboard.
Was this report helpful? Give feedback by reacting with 👍 or 👎
| agent: 'ZeroAgent', | ||
| name: activeConnection?.id ? String(activeConnection.id) : 'general', | ||
| host: `${import.meta.env.VITE_PUBLIC_BACKEND_URL}`, | ||
| onError: (e) => console.log(e), |
There was a problem hiding this comment.
Consider replacing console.log(e) with a more structured error handling approach. Directly logging error objects can expose sensitive information in production environments. A better pattern would be to log specific error properties or use a dedicated error logging service that properly sanitizes sensitive data:
onError: (e) => {
console.error('AI agent error:', e.message || 'Unknown error');
// Or use a structured logging approach
// errorLoggingService.captureError(e);
}This maintains the error tracking functionality while reducing security risks from exposing raw error objects.
| onError: (e) => console.log(e), | |
| onError: (e) => { | |
| console.error('AI agent error:', e.message || 'Unknown error'); | |
| // Or use a structured logging approach | |
| // errorLoggingService.captureError(e); | |
| }, |
Spotted by Diamond (based on custom rules)
Is this helpful? React 👍 or 👎 to let us know.
| max_num_results: 3, | ||
| ranking_options: { | ||
| if (!env.AUTORAG_ID) { | ||
| console.warn('[inboxRag] AUTORAG_ID not configured - RAG search disabled'); |
There was a problem hiding this comment.
Consider replacing the console.warn() with a more generic log message that doesn't expose configuration details. While this warning helps with debugging, it reveals internal system configuration status (AUTORAG_ID) which could potentially provide information useful in an attack. A better approach would be to log that "Search functionality is unavailable" without specifying which configuration parameter is missing, or implement proper application monitoring for configuration issues.
| console.warn('[inboxRag] AUTORAG_ID not configured - RAG search disabled'); | |
| console.warn('[inboxRag] Search functionality unavailable - missing configuration'); |
Spotted by Diamond (based on custom rules)
Is this helpful? React 👍 or 👎 to let us know.
| console.error(`[inboxRag] Search failed for query: "${query}"`, { | ||
| error: error instanceof Error ? error.message : 'Unknown error', | ||
| stack: error instanceof Error ? error.stack : undefined, | ||
| user: this.name, | ||
| }); | ||
|
|
There was a problem hiding this comment.
Consider sanitizing the error logging to avoid exposing sensitive information. The current implementation logs raw user queries and detailed error information including stack traces, which could potentially expose sensitive data or internal application structure.
A more secure approach would be to:
- Sanitize or redact the query parameter before logging
- Limit stack trace information in production environments
- Use a structured logging format that allows for easier filtering of sensitive fields
For example:
console.error(`[inboxRag] Search failed`, {
queryLength: query.length,
errorType: error instanceof Error ? error.constructor.name : 'Unknown',
errorMessage: error instanceof Error ? error.message : 'Unknown error',
user: this.name,
});| console.error(`[inboxRag] Search failed for query: "${query}"`, { | |
| error: error instanceof Error ? error.message : 'Unknown error', | |
| stack: error instanceof Error ? error.stack : undefined, | |
| user: this.name, | |
| }); | |
| console.error(`[inboxRag] Search failed`, { | |
| queryLength: query.length, | |
| errorType: error instanceof Error ? error.constructor.name : 'Unknown', | |
| errorMessage: error instanceof Error ? error.message : 'Unknown error', | |
| user: this.name, | |
| }); |
Spotted by Diamond (based on custom rules)
Is this helpful? React 👍 or 👎 to let us know.
There was a problem hiding this comment.
cubic analysis
2 issues found across 8 files • Review in cubic
React with 👍 or 👎 to teach cubic. You can also tag @cubic-dev-ai to give feedback, ask questions, or re-run the review.
| agent: 'ZeroAgent', | ||
| name: activeConnection?.id ? String(activeConnection.id) : 'general', | ||
| host: `${import.meta.env.VITE_PUBLIC_BACKEND_URL}`, | ||
| onError: (e) => console.log(e), |
There was a problem hiding this comment.
Using console.log for error handling here is inconsistent with the PR's stated goal of removing console logs and is not suitable for production error handling.
Prompt for AI agents
Address the following comment on apps/mail/components/ui/ai-sidebar.tsx at line 352:
<comment>Using console.log for error handling here is inconsistent with the PR's stated goal of removing console logs and is not suitable for production error handling.</comment>
<file context>
@@ -349,6 +349,7 @@ function AISidebar({ className }: AISidebarProps) {
agent: 'ZeroAgent',
name: activeConnection?.id ? String(activeConnection.id) : 'general',
host: `${import.meta.env.VITE_PUBLIC_BACKEND_URL}`,
+ onError: (e) => console.log(e),
});
const chatState = useAgentChat({
</file context>
| agent: 'ZeroAgent', | ||
| name: activeConnection?.id ? String(activeConnection.id) : 'general', | ||
| host: `${import.meta.env.VITE_PUBLIC_BACKEND_URL}`, | ||
| onError: (e) => console.log(e), |
There was a problem hiding this comment.
Rule violated: Detect React performance bottlenecks and rule breaking
Defining an anonymous function inline for the onError prop breaks the rule against inline function expressions in React props, which can cause unnecessary re-renders and performance issues. Move the function definition outside and pass a reference, or memoize it with useCallback.
Prompt for AI agents
Address the following comment on apps/mail/components/ui/ai-sidebar.tsx at line 352:
<comment>Defining an anonymous function inline for the onError prop breaks the rule against inline function expressions in React props, which can cause unnecessary re-renders and performance issues. Move the function definition outside and pass a reference, or memoize it with useCallback.</comment>
<file context>
@@ -349,6 +349,7 @@ function AISidebar({ className }: AISidebarProps) {
agent: 'ZeroAgent',
name: activeConnection?.id ? String(activeConnection.id) : 'general',
host: `${import.meta.env.VITE_PUBLIC_BACKEND_URL}`,
+ onError: (e) => console.log(e),
});
const chatState = useAgentChat({
</file context>
There was a problem hiding this comment.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
apps/server/src/lib/prompts.ts (1)
5-5: Remove or rename unused variable.The
CATEGORY_IDSvariable is declared but never used. Either remove it or prefix with underscore if intended for future use.-const CATEGORY_IDS = ['Important', 'All Mail', 'Personal', 'Updates', 'Promotions', 'Unread']; +const _CATEGORY_IDS = ['Important', 'All Mail', 'Personal', 'Updates', 'Promotions', 'Unread'];Or simply remove it if not needed:
-const CATEGORY_IDS = ['Important', 'All Mail', 'Personal', 'Updates', 'Promotions', 'Unread']; -
🧹 Nitpick comments (3)
apps/mail/app/(routes)/settings/notifications/page.tsx (1)
41-46: Fix the unused parameter warning.The
valuesparameter is no longer used after removing the console.log statement. Follow the ESLint suggestion to prefix unused parameters with underscore.- function onSubmit(values: z.infer<typeof formSchema>) { + function onSubmit(_values: z.infer<typeof formSchema>) {apps/mail/components/ui/ai-sidebar.tsx (1)
352-352: Good error handling addition, but consider structured logging.Adding the
onErrorcallback improves error handling. However, consider using a structured logging approach instead ofconsole.logfor production environments.- onError: (e) => console.log(e), + onError: (e) => { + console.error('Agent error:', e); + // Consider integrating with your logging service + },apps/server/src/routes/agent/mcp.ts (1)
26-26: Remove unused import.The
generateTextimport is no longer used after removing the Gmail search query tool.-import { generateText } from 'ai';
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
apps/mail/app/(routes)/settings/notifications/page.tsx(1 hunks)apps/mail/components/ui/ai-sidebar.tsx(1 hunks)apps/mail/hooks/use-hot-key.ts(1 hunks)apps/server/src/lib/prompts.ts(1 hunks)apps/server/src/routes/agent/index.ts(7 hunks)apps/server/src/routes/agent/mcp.ts(1 hunks)apps/server/src/routes/agent/tools.ts(1 hunks)apps/server/src/trpc/routes/ai/search.ts(2 hunks)
🧰 Additional context used
🧠 Learnings (4)
apps/mail/app/(routes)/settings/notifications/page.tsx (3)
Learnt from: retrogtx
PR: Mail-0/Zero#1328
File: apps/mail/lib/hotkeys/mail-list-hotkeys.tsx:202-209
Timestamp: 2025-06-18T17:26:50.918Z
Learning: In apps/mail/lib/hotkeys/mail-list-hotkeys.tsx, the switchCategoryByIndex function using hardcoded indices for category hotkeys does not break when users reorder categories, contrary to the theoretical index-shifting issue. The actual implementation has constraints or mechanisms that prevent hotkey targeting issues.
Learnt from: retrogtx
PR: Mail-0/Zero#1468
File: apps/server/src/trpc/routes/mail.ts:331-331
Timestamp: 2025-06-28T03:56:09.376Z
Learning: In apps/server/src/trpc/routes/mail.ts, the user indicated they are not using ISO format for the scheduleAt parameter, despite the frontend code showing toISOString() usage in the ScheduleSendPicker component.
Learnt from: retrogtx
PR: Mail-0/Zero#1354
File: apps/mail/components/ui/prompts-dialog.tsx:85-88
Timestamp: 2025-06-20T05:03:16.944Z
Learning: In React Hook Form, avoid using useEffect for form state synchronization when the values prop can handle reactive updates automatically. The values prop is specifically designed for this purpose and is more optimal than manual useEffect-based synchronization.
apps/mail/hooks/use-hot-key.ts (1)
Learnt from: retrogtx
PR: Mail-0/Zero#1328
File: apps/mail/lib/hotkeys/mail-list-hotkeys.tsx:202-209
Timestamp: 2025-06-18T17:26:50.918Z
Learning: In apps/mail/lib/hotkeys/mail-list-hotkeys.tsx, the switchCategoryByIndex function using hardcoded indices for category hotkeys does not break when users reorder categories, contrary to the theoretical index-shifting issue. The actual implementation has constraints or mechanisms that prevent hotkey targeting issues.
apps/server/src/lib/prompts.ts (1)
Learnt from: retrogtx
PR: Mail-0/Zero#1354
File: apps/mail/components/ui/prompts-dialog.tsx:148-159
Timestamp: 2025-06-20T05:34:41.297Z
Learning: In the prompt management system, users should be allowed to save empty prompts as this gives them the choice to disable certain AI functionality or start fresh. Validation should not prevent empty prompts from being saved.
apps/server/src/routes/agent/index.ts (1)
Learnt from: retrogtx
PR: Mail-0/Zero#1734
File: apps/server/src/lib/driver/google.ts:211-221
Timestamp: 2025-07-15T06:46:33.349Z
Learning: In apps/server/src/lib/driver/google.ts, the normalization of "draft" to "drafts" in the count() method is necessary because the navigation item in apps/mail/config/navigation.ts has id: 'drafts' (plural) while the Google API returns "draft" (singular). The nav-main.tsx component matches stats by comparing stat.label with item.id, so the backend must return "drafts" for the draft counter badge to appear in the sidebar.
🧬 Code Graph Analysis (1)
apps/server/src/lib/prompts.ts (1)
apps/mail/lib/prompts.ts (1)
getCurrentDateContext(112-112)
🪛 GitHub Actions: autofix.ci
apps/mail/app/(routes)/settings/notifications/page.tsx
[warning] 41-41: ESLint(no-unused-vars): Parameter 'values' is declared but never used. Unused parameters should start with a '_'.
apps/server/src/routes/agent/mcp.ts
[warning] 26-26: ESLint(no-unused-vars): Identifier 'generateText' is imported but never used.
apps/server/src/lib/prompts.ts
[warning] 5-5: ESLint(no-unused-vars): Variable 'CATEGORY_IDS' is declared but never used. Unused variables should start with a '_'.
apps/server/src/routes/agent/index.ts
[warning] 527-527: ESLint(no-unused-vars): Variable 'duration' is declared but never used. Unused variables should start with a '_'.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: cubic · AI code reviewer
- GitHub Check: Cursor BugBot
🔇 Additional comments (11)
apps/mail/app/(routes)/settings/notifications/page.tsx (1)
19-19: LGTM!The import reordering is a minor cleanup and doesn't affect functionality.
apps/server/src/trpc/routes/ai/search.ts (2)
6-6: LGTM!Import reordering improves code organization without functional impact.
31-31: Good practice to make output format explicit.Adding the
output: 'object'option makes the expected return format clear and improves API robustness.apps/mail/hooks/use-hot-key.ts (1)
12-12: Excellent cleanup of debug logging.Removing the console.log statements from key event handlers eliminates debugging noise while preserving all functionality. This aligns perfectly with the PR objective of cleaning up console logs.
Also applies to: 19-19, 30-30, 37-37
apps/server/src/routes/agent/mcp.ts (1)
18-18: LGTM on import cleanup.Removing unused imports related to the deleted Gmail search query tool is good cleanup.
apps/server/src/routes/agent/tools.ts (1)
6-6: LGTM!The import cleanup is appropriate after removing the Gmail search query builder tool and its dependencies.
apps/server/src/lib/prompts.ts (1)
329-506: Excellent prompt restructuring!The rewrite from narrative to structured XML format significantly improves:
- Clarity with explicit sections for role, criteria, and guidelines
- Safety with confirmation rules for bulk operations
- Maintainability with well-organized tool definitions
- User experience with concise, action-oriented responses
The emphasis on plain text output and internal reasoning is particularly well done.
apps/server/src/routes/agent/index.ts (4)
498-502: Good defensive programming!The environment variable check with early return and warning is a robust pattern that prevents runtime errors when RAG is not configured.
530-539: Excellent error handling implementation!The comprehensive error handling with detailed logging and graceful fallback ensures the application remains stable even when the AI search fails. The structured error object with stack trace aids debugging while the empty result prevents breaking the flow.
563-571: Smart query refinement approach!Using AI to refine natural language queries into proper Gmail search syntax before executing the search is a clever enhancement. The error handling with fallback to the original query ensures robustness.
888-903: Clean tool orchestration integration!The separation of raw tools and processed tools through the orchestrator provides better control over tool availability and processing. This architectural improvement enhances maintainability.
| async inboxRag(query: string) { | ||
| if (!env.AUTORAG_ID) return { result: 'Not enabled', data: [] }; | ||
| const answer = await env.AI.autorag(env.AUTORAG_ID).aiSearch({ | ||
| query: query, | ||
| // rewrite_query: true, | ||
| max_num_results: 3, | ||
| ranking_options: { | ||
| if (!env.AUTORAG_ID) { | ||
| console.warn('[inboxRag] AUTORAG_ID not configured - RAG search disabled'); | ||
| return { result: 'Not enabled', data: [] }; | ||
| } | ||
|
|
||
| try { | ||
| const startTime = Date.now(); | ||
| console.log(`[inboxRag] Executing AI search with parameters:`, { | ||
| query, | ||
| max_num_results: 3, | ||
| score_threshold: 0.3, | ||
| }, | ||
| // stream: true, | ||
| filters: { | ||
| type: 'eq', | ||
| key: 'folder', | ||
| value: `${this.name}/`, | ||
| }, | ||
| }); | ||
| return { result: answer.response, data: answer.data }; | ||
| folder_filter: `${this.name}/`, | ||
| }); | ||
|
|
||
| const answer = await env.AI.autorag(env.AUTORAG_ID).aiSearch({ | ||
| query: query, | ||
| // rewrite_query: true, | ||
| max_num_results: 3, | ||
| ranking_options: { | ||
| score_threshold: 0.3, | ||
| }, | ||
| // stream: true, | ||
| filters: { | ||
| type: 'eq', | ||
| key: 'folder', | ||
| value: `${this.name}/`, | ||
| }, | ||
| }); | ||
|
|
||
| const duration = Date.now() - startTime; | ||
|
|
||
| return { result: answer.response, data: answer.data }; | ||
| } catch (error) { | ||
| console.error(`[inboxRag] Search failed for query: "${query}"`, { | ||
| error: error instanceof Error ? error.message : 'Unknown error', | ||
| stack: error instanceof Error ? error.stack : undefined, | ||
| user: this.name, | ||
| }); | ||
|
|
||
| // Return empty result on error to prevent breaking the flow | ||
| return { result: 'Search failed', data: [] }; | ||
| } | ||
| } |
There was a problem hiding this comment.
Remove unused duration variable.
The duration variable is calculated but never used. Either remove it or use it for logging/metrics.
- const duration = Date.now() - startTime;
-
- return { result: answer.response, data: answer.data };
+ const duration = Date.now() - startTime;
+ console.log(`[inboxRag] Search completed in ${duration}ms`);
+
+ return { result: answer.response, data: answer.data };Or remove if not needed:
- const startTime = Date.now();
console.log(`[inboxRag] Executing AI search with parameters:`, {
query,
max_num_results: 3,
score_threshold: 0.3,
folder_filter: `${this.name}/`,
});
const answer = await env.AI.autorag(env.AUTORAG_ID).aiSearch({
query: query,
// rewrite_query: true,
max_num_results: 3,
ranking_options: {
score_threshold: 0.3,
},
// stream: true,
filters: {
type: 'eq',
key: 'folder',
value: `${this.name}/`,
},
});
- const duration = Date.now() - startTime;
-
return { result: answer.response, data: answer.data };📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| async inboxRag(query: string) { | |
| if (!env.AUTORAG_ID) return { result: 'Not enabled', data: [] }; | |
| const answer = await env.AI.autorag(env.AUTORAG_ID).aiSearch({ | |
| query: query, | |
| // rewrite_query: true, | |
| max_num_results: 3, | |
| ranking_options: { | |
| if (!env.AUTORAG_ID) { | |
| console.warn('[inboxRag] AUTORAG_ID not configured - RAG search disabled'); | |
| return { result: 'Not enabled', data: [] }; | |
| } | |
| try { | |
| const startTime = Date.now(); | |
| console.log(`[inboxRag] Executing AI search with parameters:`, { | |
| query, | |
| max_num_results: 3, | |
| score_threshold: 0.3, | |
| }, | |
| // stream: true, | |
| filters: { | |
| type: 'eq', | |
| key: 'folder', | |
| value: `${this.name}/`, | |
| }, | |
| }); | |
| return { result: answer.response, data: answer.data }; | |
| folder_filter: `${this.name}/`, | |
| }); | |
| const answer = await env.AI.autorag(env.AUTORAG_ID).aiSearch({ | |
| query: query, | |
| // rewrite_query: true, | |
| max_num_results: 3, | |
| ranking_options: { | |
| score_threshold: 0.3, | |
| }, | |
| // stream: true, | |
| filters: { | |
| type: 'eq', | |
| key: 'folder', | |
| value: `${this.name}/`, | |
| }, | |
| }); | |
| const duration = Date.now() - startTime; | |
| return { result: answer.response, data: answer.data }; | |
| } catch (error) { | |
| console.error(`[inboxRag] Search failed for query: "${query}"`, { | |
| error: error instanceof Error ? error.message : 'Unknown error', | |
| stack: error instanceof Error ? error.stack : undefined, | |
| user: this.name, | |
| }); | |
| // Return empty result on error to prevent breaking the flow | |
| return { result: 'Search failed', data: [] }; | |
| } | |
| } | |
| async inboxRag(query: string) { | |
| if (!env.AUTORAG_ID) { | |
| console.warn('[inboxRag] AUTORAG_ID not configured - RAG search disabled'); | |
| return { result: 'Not enabled', data: [] }; | |
| } | |
| try { | |
| const startTime = Date.now(); | |
| console.log(`[inboxRag] Executing AI search with parameters:`, { | |
| query, | |
| max_num_results: 3, | |
| score_threshold: 0.3, | |
| folder_filter: `${this.name}/`, | |
| }); | |
| const answer = await env.AI.autorag(env.AUTORAG_ID).aiSearch({ | |
| query: query, | |
| // rewrite_query: true, | |
| max_num_results: 3, | |
| ranking_options: { | |
| score_threshold: 0.3, | |
| }, | |
| // stream: true, | |
| filters: { | |
| type: 'eq', | |
| key: 'folder', | |
| value: `${this.name}/`, | |
| }, | |
| }); | |
| const duration = Date.now() - startTime; | |
| console.log(`[inboxRag] Search completed in ${duration}ms`); | |
| return { result: answer.response, data: answer.data }; | |
| } catch (error) { | |
| console.error(`[inboxRag] Search failed for query: "${query}"`, { | |
| error: error instanceof Error ? error.message : 'Unknown error', | |
| stack: error instanceof Error ? error.stack : undefined, | |
| user: this.name, | |
| }); | |
| return { result: 'Search failed', data: [] }; | |
| } | |
| } |
| async inboxRag(query: string) { | |
| if (!env.AUTORAG_ID) return { result: 'Not enabled', data: [] }; | |
| const answer = await env.AI.autorag(env.AUTORAG_ID).aiSearch({ | |
| query: query, | |
| // rewrite_query: true, | |
| max_num_results: 3, | |
| ranking_options: { | |
| if (!env.AUTORAG_ID) { | |
| console.warn('[inboxRag] AUTORAG_ID not configured - RAG search disabled'); | |
| return { result: 'Not enabled', data: [] }; | |
| } | |
| try { | |
| const startTime = Date.now(); | |
| console.log(`[inboxRag] Executing AI search with parameters:`, { | |
| query, | |
| max_num_results: 3, | |
| score_threshold: 0.3, | |
| }, | |
| // stream: true, | |
| filters: { | |
| type: 'eq', | |
| key: 'folder', | |
| value: `${this.name}/`, | |
| }, | |
| }); | |
| return { result: answer.response, data: answer.data }; | |
| folder_filter: `${this.name}/`, | |
| }); | |
| const answer = await env.AI.autorag(env.AUTORAG_ID).aiSearch({ | |
| query: query, | |
| // rewrite_query: true, | |
| max_num_results: 3, | |
| ranking_options: { | |
| score_threshold: 0.3, | |
| }, | |
| // stream: true, | |
| filters: { | |
| type: 'eq', | |
| key: 'folder', | |
| value: `${this.name}/`, | |
| }, | |
| }); | |
| const duration = Date.now() - startTime; | |
| return { result: answer.response, data: answer.data }; | |
| } catch (error) { | |
| console.error(`[inboxRag] Search failed for query: "${query}"`, { | |
| error: error instanceof Error ? error.message : 'Unknown error', | |
| stack: error instanceof Error ? error.stack : undefined, | |
| user: this.name, | |
| }); | |
| // Return empty result on error to prevent breaking the flow | |
| return { result: 'Search failed', data: [] }; | |
| } | |
| } | |
| async inboxRag(query: string) { | |
| if (!env.AUTORAG_ID) { | |
| console.warn('[inboxRag] AUTORAG_ID not configured - RAG search disabled'); | |
| return { result: 'Not enabled', data: [] }; | |
| } | |
| try { | |
| console.log(`[inboxRag] Executing AI search with parameters:`, { | |
| query, | |
| max_num_results: 3, | |
| score_threshold: 0.3, | |
| folder_filter: `${this.name}/`, | |
| }); | |
| const answer = await env.AI.autorag(env.AUTORAG_ID).aiSearch({ | |
| query: query, | |
| // rewrite_query: true, | |
| max_num_results: 3, | |
| ranking_options: { | |
| score_threshold: 0.3, | |
| }, | |
| // stream: true, | |
| filters: { | |
| type: 'eq', | |
| key: 'folder', | |
| value: `${this.name}/`, | |
| }, | |
| }); | |
| return { result: answer.response, data: answer.data }; | |
| } catch (error) { | |
| console.error(`[inboxRag] Search failed for query: "${query}"`, { | |
| error: error instanceof Error ? error.message : 'Unknown error', | |
| stack: error instanceof Error ? error.stack : undefined, | |
| user: this.name, | |
| }); | |
| return { result: 'Search failed', data: [] }; | |
| } | |
| } |
🧰 Tools
🪛 GitHub Actions: autofix.ci
[warning] 527-527: ESLint(no-unused-vars): Variable 'duration' is declared but never used. Unused variables should start with a '_'.
🤖 Prompt for AI Agents
In apps/server/src/routes/agent/index.ts around lines 497 to 540, the variable
'duration' is calculated but never used. Remove the declaration and assignment
of 'duration' since it serves no purpose, or alternatively, add a log statement
to output the duration for performance monitoring if desired.

Cleanup: Remove console logs and refactor AI chat prompt
Description
This PR removes unnecessary console logs from the codebase and refactors the AI chat prompt to be more concise and structured. The changes include:
Type of Change
Areas Affected
Testing Done
Checklist
Additional Notes
The AI chat prompt refactoring significantly improves readability while maintaining the same functionality. The removal of console logs helps keep the browser console clean in production.
By submitting this pull request, I confirm that my contribution is made under the terms of the project's license.
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Chores