Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { SearchSection } from '@/components/search-section'
import SearchRelated from '@/components/search-related'
import { GeoJsonLayer } from '@/components/map/geojson-layer'
import { ResolutionCarousel } from '@/components/resolution-carousel'
import { getCurrentUserIdOnServer } from '@/lib/auth/get-current-user'
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Redundant dynamic import — getCurrentUserIdOnServer is already statically imported.

Line 25 adds a static import, but lines 641–643 in onSetAIState still dynamically import the same module. The dynamic import is now unnecessary overhead and a maintenance inconsistency.

♻️ Suggested fix
-    const { getCurrentUserIdOnServer } = await import(
-      '@/lib/auth/get-current-user'
-    )
-    const actualUserId = await getCurrentUserIdOnServer()
+    const actualUserId = await getCurrentUserIdOnServer()

Also applies to: 641-643

🤖 Prompt for AI Agents
In `@app/actions.tsx` at line 25, Redundant dynamic import: remove the dynamic
import of getCurrentUserIdOnServer inside onSetAIState and use the already
statically imported getCurrentUserIdOnServer instead; update the onSetAIState
implementation to call getCurrentUserIdOnServer() directly (replace await
import(...).then(m => m.getCurrentUserIdOnServer()) or similar), and remove any
unused dynamic-import variables so the static import at the top is the single
source of truth.

import { ResolutionImage } from '@/components/resolution-image'
import { CopilotDisplay } from '@/components/copilot-display'
import RetrieveSection from '@/components/retrieve-section'
Expand Down Expand Up @@ -397,7 +398,7 @@ async function submit(formData?: FormData, skip?: boolean) {
} as CoreMessage)
}

const userId = 'anonymous'
const userId = (await getCurrentUserIdOnServer()) || 'anonymous'
const currentSystemPrompt = (await getSystemPrompt(userId)) || ''
Comment on lines 400 to 402

Choose a reason for hiding this comment

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

Fetching the user ID on every submit() call may add avoidable latency, especially if getCurrentUserIdOnServer() hits an auth provider/DB each time. If submit() can be invoked multiple times in a single request lifecycle (e.g., via retries/stream steps) or if it’s called frequently, consider reading the user ID once at the top-level request boundary (or caching within the request) and threading it through.

Also consider whether 'anonymous' should be a shared bucket. As implemented, all unauthenticated users will share the same system prompt record (if stored), which can cause cross-user leakage of prompt customization if anonymous prompts are persisted and editable anywhere in the UI.

Suggestion

Consider caching the user ID for the lifetime of the request, and ensure anonymous prompts are not globally shared unless that’s intentional.

Example approach:

  • Resolve once at the top of submit() and pass it down to any inner functions that need it.
  • If you want per-session anonymous prompts, key by session ID (or avoid persistence for anonymous users).

Reply with "@CharlieHelps yes please" if you'd like me to add a commit implementing request-scoped caching and/or a safer anonymous-keying strategy.

const mapProvider = formData?.get('mapProvider') as 'mapbox' | 'google'
Comment on lines 400 to 403

Choose a reason for hiding this comment

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

submit() now hits getCurrentUserIdOnServer() unconditionally, even when skip is true. If skip is used for preview/fast-path flows (or other scenarios where the action doesn’t need user-scoped prompt), this introduces avoidable server work and potential latency. Also, getSystemPrompt(userId) is called even when currentSystemPrompt may not be used depending on later control flow.

Consider moving user/system-prompt resolution behind the branch that actually needs it, or at least behind if (!skip) if that matches intended behavior.

Suggestion

If skip is intended to bypass any model/task execution, gate the user lookup and prompt fetch behind the non-skip path (or lazily fetch only when needed). For example:

let currentSystemPrompt = ''
if (!skip) {
  const userId = (await getCurrentUserIdOnServer()) || 'anonymous'
  currentSystemPrompt = (await getSystemPrompt(userId)) || ''
}

If you still need the prompt in skip mode, consider documenting why with an inline comment, or caching the userId/prompt at a higher level if submit() is called frequently.

Reply with "@CharlieHelps yes please" if you’d like me to add a commit with this refactor.


Expand Down
2 changes: 1 addition & 1 deletion components/settings/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export type SettingsFormValues = z.infer<typeof settingsFormSchema>
// Default values
const defaultValues: Partial<SettingsFormValues> = {
systemPrompt:
"You are a planetary copilot, an AI assistant designed to help users with information about planets, space exploration, and astronomy. Provide accurate, educational, and engaging responses about our solar system and beyond.",
"You are an AI assistant designed to help users with geospatial data, mapping, and environment-aware insights. Provide accurate and helpful responses based on the available tools and context.",
selectedModel: "Grok 4.2",
users: [],
}
Comment on lines 54 to 59
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Minor terminology inconsistency with surrounding UI text.

The default prompt now describes a "geospatial data, mapping, and environment-aware insights" assistant, but system-prompt-form.tsx (line 22) still uses the placeholder "Enter the system prompt for your planetary copilot..." and line 183 of this file still reads "Customize the behavior and persona of your planetary copilot". Consider aligning the terminology for a consistent user experience.

🤖 Prompt for AI Agents
In `@components/settings/components/settings.tsx` around lines 54 - 59, The
defaultValues.constant for systemPrompt is inconsistent with the UI copy that
uses "planetary copilot"; update the systemPrompt string inside defaultValues
(and, if preferred, the placeholder in system-prompt-form.tsx and the heading
text around the component) so all three references use the same terminology
(e.g., "planetary copilot") and matching wording about
geospatial/mapping/environment-aware behavior; locate the symbols defaultValues
and systemPrompt in the settings component and the placeholder/heading text in
system-prompt-form.tsx and make the copy identical for a consistent UX.

Expand Down