Skip to content

fix: resolve webpack runtime error in resolution search#740

Open
ngoiyaeric wants to merge 4 commits into
mainfrom
fix/resolution-search-webpack-error-fix
Open

fix: resolve webpack runtime error in resolution search#740
ngoiyaeric wants to merge 4 commits into
mainfrom
fix/resolution-search-webpack-error-fix

Conversation

@ngoiyaeric

@ngoiyaeric ngoiyaeric commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

This PR fixes the 'TypeError: Cannot read properties of undefined (reading 'call')' by isolating server-only utilities from the shared @/lib/utils module. The mixed client/server imports in @/lib/utils were poisoning the client bundle, causing webpack runtime failures when client components (like ResolutionCarousel) imported common helpers like nanoid or cn.

Summary by CodeRabbit

  • Improvements
    • Improved AI model selection and provider initialization.
    • Added clearer handling for missing or invalid provider configuration.
    • Improved fallback behavior when a preferred model or provider is unavailable.
    • Added support for selecting vision-capable models when image analysis is required.
    • Improved client/server separation for model-related operations.

@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@vercel

vercel Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
qcx Ready Ready Preview, Comment Jul 15, 2026 3:51am

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@ngoiyaeric, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 56 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 164989f4-724a-4a48-8b46-ce637dc70d1e

📥 Commits

Reviewing files that changed from the base of the PR and between 8f961c9 and 0e1f214.

📒 Files selected for processing (7)
  • lib/actions/chat.ts
  • lib/actions/suggest.ts
  • lib/agents/inquire.tsx
  • lib/agents/query-suggestor.tsx
  • lib/agents/researcher.tsx
  • lib/agents/task-manager.tsx
  • lib/agents/writer.tsx

Walkthrough

The provider-selection getModel helper moves from lib/utils/index.ts to lib/utils/server.ts, retaining selected-model handling and provider fallbacks. Four agents/actions and the Mapbox hook update their imports, while the hook gains a client directive.

Changes

Model utility migration

Layer / File(s) Summary
Server-side model selection
lib/utils/index.ts, lib/utils/server.ts
Removes getModel from the general utility module and adds selected-model initialization plus xAI, Gemini, Bedrock, and OpenAI fallback handling to the server utility.
Caller import migration
lib/actions/system-prompt.ts, lib/agents/report/*, lib/agents/resolution-search.tsx, mapbox_mcp/hooks.ts
Updates getModel imports to the server utility; the Mapbox hook is marked as a client component.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • QueueLab/QCX#407: Both changes modify the async getModel helper and its call sites.
  • QueueLab/QCX#738: Both changes overlap in requireVision model routing and resolution-search usage.

Suggested reviewers: google-labs-jules[bot]

Poem

A bunny hops through server code,
Moving models down the proper road.
xAI, Gemini, Bedrock in line,
OpenAI waits as fallback fine.
Imports bloom where helpers belong—
Carrot-powered changes hop along!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: resolving a webpack runtime error tied to the resolution search flow.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/resolution-search-webpack-error-fix

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.

@charliecreates charliecreates Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Blocking finding

lib/utils/index.ts no longer exports getModel, but unchanged server-side callers still import it from the old barrel, including:

  • lib/agents/writer.tsx:5,35
  • lib/agents/researcher.tsx:13,147
  • lib/actions/system-prompt.ts:7,80
  • lib/actions/chat.ts:24

Because this PR only updates the imports in lib/agents/resolution-search.tsx:2 and mapbox_mcp/hooks.ts:3, these remaining imports resolve to a module without getModel and will fail TypeScript/Next compilation. Update every server-side caller to import getModel from @/lib/utils/server (or the corresponding relative server path) before merging.

I inspected the current head diff, surrounding call sites, discussion, and existing checks. Existing checks show Vercel – qcx failing, while Vercel Preview Comments and GitGuardian Security Checks pass; no test, lint, or build commands were run as part of this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/utils/server.ts`:
- Around line 20-58: Update the model-selection branches in the server model
factory so each persisted option maps to its actual supported model ID: replace
the legacy IDs for “Grok 4.2,” “Gemini 3,” “Gemini 3.1 Pro,” and “GPT-5.1” with
matching IDs, or explicitly reject any option without a supported ID. Do not
silently return older models from the Grok, Gemini, or OpenAI initialization
paths.
- Around line 66-110: Move provider fallback handling out of the model-selection
function and into the generation path that invokes generateText or streamObject.
Update the flow around the xAI, Gemini, Bedrock, and OpenAI provider handles so
provider/auth errors are caught during generation and the next configured
provider is attempted, while preserving the existing provider order and model
configuration.

In `@mapbox_mcp/hooks.ts`:
- Around line 1-5: Remove the server-only getModel import from the client hook
and keep hooks.ts client-safe. Move generateText and model selection into a
server action or route handler, then update the hook’s generation flow to call
that server boundary while preserving its current behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 81fab221-343d-4115-a0ca-d7a8f00543a6

📥 Commits

Reviewing files that changed from the base of the PR and between 93d19c0 and 8f961c9.

📒 Files selected for processing (7)
  • lib/actions/system-prompt.ts
  • lib/agents/report/executive-summary.ts
  • lib/agents/report/strategic-synthesis.ts
  • lib/agents/resolution-search.tsx
  • lib/utils/index.ts
  • lib/utils/server.ts
  • mapbox_mcp/hooks.ts
💤 Files with no reviewable changes (1)
  • lib/utils/index.ts
📜 Review details
🔇 Additional comments (5)
lib/utils/server.ts (1)

1-16: LGTM!

lib/actions/system-prompt.ts (1)

7-7: LGTM!

lib/agents/report/executive-summary.ts (1)

2-2: LGTM!

lib/agents/report/strategic-synthesis.ts (1)

2-2: LGTM!

lib/agents/resolution-search.tsx (1)

2-2: LGTM!

Comment thread lib/utils/server.ts
Comment on lines +20 to +58
case 'Grok 4.2':
if (xaiApiKey) {
const xai = createXai({
apiKey: xaiApiKey,
baseURL: 'https://api.x.ai/v1',
});
try {
const modelId = requireVision ? 'grok-vision-beta' : 'grok-2-1212';
return xai(modelId);
} catch (error) {
console.error('Selected model "Grok 4.2" is configured but failed to initialize.', error);
throw new Error('Failed to initialize selected model.');
}
} else {
console.error('User selected "Grok 4.2" but XAI_API_KEY is not set.');
throw new Error('Selected model is not configured.');
}
case 'Gemini 3':
case 'Gemini 3.1 Pro':
if (gemini3ProApiKey) {
const google = createGoogleGenerativeAI({
apiKey: gemini3ProApiKey,
});
try {
return google('gemini-1.5-pro-latest');
} catch (error) {
console.error('Selected model "Gemini 3.1 Pro" is configured but failed to initialize.', error);
throw new Error('Failed to initialize selected model.');
}
} else {
console.error('User selected "Gemini 3.1 Pro" but GEMINI_3_PRO_API_KEY is not set.');
throw new Error('Selected model is not configured.');
}
case 'GPT-5.1':
if (openaiApiKey) {
const openai = createOpenAI({
apiKey: openaiApiKey,
});
return openai('gpt-4o');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Honor the model selected by the user.

These branches silently substitute older models: Grok 4.2 returns grok-2-1212, both Gemini 3 choices return Gemini 1.5, and GPT-5.1 returns GPT-4o. Align the persisted option names with the actual model IDs or reject unsupported selections instead of returning a different model.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/utils/server.ts` around lines 20 - 58, Update the model-selection
branches in the server model factory so each persisted option maps to its actual
supported model ID: replace the legacy IDs for “Grok 4.2,” “Gemini 3,” “Gemini
3.1 Pro,” and “GPT-5.1” with matching IDs, or explicitly reject any option
without a supported ID. Do not silently return older models from the Grok,
Gemini, or OpenAI initialization paths.

Comment thread lib/utils/server.ts
Comment on lines +66 to +110
// Default behavior: Grok -> Gemini -> Bedrock -> OpenAI
if (xaiApiKey) {
const xai = createXai({
apiKey: xaiApiKey,
baseURL: 'https://api.x.ai/v1',
});
try {
const modelId = requireVision ? 'grok-vision-beta' : 'grok-latest';
return xai(modelId);
} catch (error) {
console.warn('xAI API unavailable, falling back to next provider:');
}
}

if (gemini3ProApiKey) {
const google = createGoogleGenerativeAI({
apiKey: gemini3ProApiKey,
});
try {
return google('gemini-1.5-pro-latest');
} catch (error) {
console.warn('Gemini 3.1 Pro API unavailable, falling back to next provider:', error);
}
}

if (awsAccessKeyId && awsSecretAccessKey) {
const bedrock = createAmazonBedrock({
bedrockOptions: {
region: awsRegion,
credentials: {
accessKeyId: awsAccessKeyId,
secretAccessKey: awsSecretAccessKey,
},
},
});
const model = bedrock(bedrockModelId, {
additionalModelRequestFields: { top_k: 350 },
});
return model;
}

const openai = createOpenAI({
apiKey: openaiApiKey,
});
return openai('gpt-4o');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== file list =="
git ls-files lib/utils/server.ts
echo

echo "== file size =="
wc -l lib/utils/server.ts
echo

echo "== outline =="
ast-grep outline lib/utils/server.ts --view expanded
echo

echo "== relevant lines =="
sed -n '1,220p' lib/utils/server.ts | cat -n
echo

echo "== search for consumers of the returned model =="
rg -n "create[A-Za-z]+\\(|generateText\\(|streamObject\\(|return .*openai\\(|return .*google\\(|return .*xai\\(" lib -g '!**/dist/**' -g '!**/build/**'

Repository: QueueLab/QCX

Length of output: 6969


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== getModel call sites =="
rg -n "\bgetModel\(" lib -g '!**/dist/**' -g '!**/build/**'
echo

echo "== AI SDK provider/generation docs lookup =="
python3 - <<'PY'
import urllib.request, urllib.parse, json, re
queries = [
    "ai sdk provider factory returns model object generateText streamObject network request happens later",
    "site:ai-sdk.dev createOpenAI model object generateText streamObject",
]
for q in queries:
    print(f"\nQUERY: {q}")
PY

Repository: QueueLab/QCX

Length of output: 1264


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== ai-sdk dependencies =="
rg -n '"`@ai-sdk/`|ai"' package.json pnpm-lock.yaml package-lock.json yarn.lock -g '!**/node_modules/**'
echo

echo "== provider factories in repo =="
rg -n "create(OpenAI|GoogleGenerativeAI|AmazonBedrock|Xai)\(" lib package.json -g '!**/node_modules/**'

Repository: QueueLab/QCX

Length of output: 684


🌐 Web query:

ai-sdk provider factory createOpenAI createGoogleGenerativeAI createXai returns language model object generateText streamObject network request happens later

💡 Result:

When you use factory functions like createOpenAI, createGoogleGenerativeAI, or createXai in the Vercel AI SDK, they do not initiate any network requests at the time of creation [1][2]. These functions simply return a provider instance—a configuration object containing the settings (such as API keys, base URLs, and headers) and the logic required to instantiate specific language models later [1][3][2]. The network request only occurs later, when you actually use the returned language model object in a function such as generateText or streamText [4][5][6]. At that point, the SDK uses the configuration defined in your provider instance to construct and execute the API call to the respective AI service [1][3][7].

Citations:


Move fallback selection to the generation path. createXai(...), google(...), bedrock(...), and openai(...) only return model handles; provider/auth failures surface when generateText or streamObject runs. As written, the first configured provider is returned immediately, so later fallbacks never execute.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/utils/server.ts` around lines 66 - 110, Move provider fallback handling
out of the model-selection function and into the generation path that invokes
generateText or streamObject. Update the flow around the xAI, Gemini, Bedrock,
and OpenAI provider handles so provider/auth errors are caught during generation
and the next configured provider is attempted, while preserving the existing
provider order and model configuration.

Comment thread mapbox_mcp/hooks.ts
Comment on lines +1 to +5
'use client';

import { useState, useCallback, useRef, useEffect } from 'react';
import { generateText } from 'ai';
import { getModel } from '@/lib/utils';
import { getModel } from '@/lib/utils/server';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🔴 Critical | 🏗️ Heavy lift

Do not import the server model utility into a Client Component.

'use client' makes this entire dependency graph client-side, but getModel reads server environment credentials and imports getSelectedModel. This recreates the mixed client/server bundle failure the PR is intended to fix. Move generateText and model selection behind a server action or route handler, then call that boundary from this hook.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@mapbox_mcp/hooks.ts` around lines 1 - 5, Remove the server-only getModel
import from the client hook and keep hooks.ts client-safe. Move generateText and
model selection into a server action or route handler, then update the hook’s
generation flow to call that server boundary while preserving its current
behavior.

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.

3 participants