-
-
Couldn't load subscription status.
- Fork 6
feat: Create GeoJSON Enrichment Agent #312
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
base: main
Are you sure you want to change the base?
Conversation
This commit introduces a new asynchronous agent, `geojsonEnricher`, responsible for processing textual responses and extracting structured geospatial data. Key changes: - Created a new `geojsonEnricher` agent in `lib/agents/geojson-enricher.tsx`. - Defined new TypeScript interfaces for `LocationResponse`, `MapCommand`, and GeoJSON objects in `lib/types/custom.ts`. - Integrated the new agent into the main application workflow in `app/actions.tsx`. - Added a `LocationResponseHandler` component to update the map state via the `MapDataContext`. - Updated the `Mapbox` component to render GeoJSON data and execute map commands.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds GeoJSON enrichment: new agent and types, integrates enrichment into submit flow, emits a geojsonEnrichment tool output, renders location responses via LocationResponseHandler which updates shared map context, and updates Mapbox rendering to consume geojson and map commands. Also updates dependencies. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant U as User
participant A as App (submit)
participant L as LLM (researcher)
participant G as geojsonEnricher
participant UI as UI State
participant H as LocationResponseHandler
participant C as MapDataContext
participant M as MapboxMap
U->>A: Submit prompt
A->>L: Generate answer (text)
L-->>A: answer
A->>G: geojsonEnricher(answer)
G-->>A: LocationResponse (text, geojson?, map_commands?)
A->>UI: Append assistant message + toolOutput `geojsonEnrichment`
UI->>H: Render LocationResponseHandler with validated toolOutput
H->>C: setMapData({ geojson, mapCommands })
C-->>M: mapData updated
alt geojson present
M->>M: Create/update GeoJSON source & point/line layers
else geojson absent
M->>M: Remove geojson layers/source if present
end
alt mapCommands present
M->>M: Execute flyTo/easeTo/fitBounds
M->>C: Clear mapCommands
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
|
|
Overall, great progress expanding the application’s geospatial functionality. With a couple more tests and error-handling tweaks, this will be even more robust. |
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 7
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (2)
bun.lockbis excluded by!**/bun.lockbpnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (7)
app/actions.tsx(6 hunks)components/map/location-response-handler.tsx(1 hunks)components/map/map-data-context.tsx(2 hunks)components/map/mapbox-map.tsx(1 hunks)lib/agents/geojson-enricher.tsx(1 hunks)lib/types/custom.ts(1 hunks)package.json(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
lib/agents/geojson-enricher.tsx (2)
lib/types/custom.ts (1)
LocationResponse(29-33)lib/utils/index.ts (1)
getModel(19-62)
components/map/location-response-handler.tsx (4)
lib/types/custom.ts (1)
LocationResponse(29-33)components/map/map-data-context.tsx (1)
useMapData(42-48)components/map/map-query-handler.tsx (4)
useMapData(30-83)toolOutput(33-74)McpResponseData(8-16)prevData(39-49)lib/agents/tools/geospatial.tsx (1)
McpResponse(22-25)
components/map/map-data-context.tsx (1)
lib/types/custom.ts (2)
GeoJSONFeatureCollection(23-26)MapCommand(2-5)
app/actions.tsx (5)
lib/agents/geojson-enricher.tsx (1)
geojsonEnricher(36-66)components/map/location-response-handler.tsx (1)
LocationResponseHandler(11-28)lib/agents/tools/geospatial.tsx (3)
uiStream(144-269)McpResponse(22-25)Location(15-20)components/map/map-query-handler.tsx (3)
toolOutput(33-74)useMapData(30-83)prevData(39-49)lib/agents/tools/index.tsx (1)
ToolProps(14-39)
🔇 Additional comments (5)
lib/agents/geojson-enricher.tsx (3)
1-3: LGTM!Imports are correctly typed and used appropriately throughout the file.
39-45: LGTM!Model initialization and message construction are correct. The type assertion is safe given
getModel()always returns aLanguageModel-compatible object.
57-65: LGTM!Error handling is appropriate: the function logs the error and returns a safe fallback with the original text, ensuring graceful degradation if enrichment fails.
app/actions.tsx (2)
15-15: LGTM!Import statement is correct and the function is properly used at line 301.
29-29: LGTM!Import statement is correct and the component is used at lines 556 and 591.
| switch (command.command) { | ||
| case 'flyTo': | ||
| mapInstance.flyTo(command.params); | ||
| break; | ||
| case 'easeTo': | ||
| mapInstance.easeTo(command.params); | ||
| break; | ||
| case 'fitBounds': | ||
| mapInstance.fitBounds(command.params, command.params.options || {}); | ||
| break; | ||
| default: | ||
| console.warn(`Unknown map command: ${command.command}`); | ||
| } | ||
| }); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix fitBounds parameter handling.
fitBounds expects the bounds object/array as its first argument, but we’re passing the entire params object (which also carries options). With the current call, Mapbox receives an invalid bounds value and throws before any command executes. Destructure the payload and pass bounds separately:
- case 'fitBounds':
- mapInstance.fitBounds(command.params, command.params.options || {});
- break;
+ case 'fitBounds': {
+ const { bounds, options } = command.params ?? {};
+ if (!bounds) {
+ console.warn('fitBounds command missing bounds payload');
+ break;
+ }
+ mapInstance.fitBounds(bounds, options ?? {});
+ break;
+ }📝 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.
| switch (command.command) { | |
| case 'flyTo': | |
| mapInstance.flyTo(command.params); | |
| break; | |
| case 'easeTo': | |
| mapInstance.easeTo(command.params); | |
| break; | |
| case 'fitBounds': | |
| mapInstance.fitBounds(command.params, command.params.options || {}); | |
| break; | |
| default: | |
| console.warn(`Unknown map command: ${command.command}`); | |
| } | |
| }); | |
| switch (command.command) { | |
| case 'flyTo': | |
| mapInstance.flyTo(command.params); | |
| break; | |
| case 'easeTo': | |
| mapInstance.easeTo(command.params); | |
| break; | |
| case 'fitBounds': { | |
| const { bounds, options } = command.params ?? {}; | |
| if (!bounds) { | |
| console.warn('fitBounds command missing bounds payload'); | |
| break; | |
| } | |
| mapInstance.fitBounds(bounds, options ?? {}); | |
| break; | |
| } | |
| default: | |
| console.warn(`Unknown map command: ${command.command}`); | |
| } |
🤖 Prompt for AI Agents
In components/map/mapbox-map.tsx around lines 585 to 599, the fitBounds call is
passing the entire params object (which contains both bounds and options) as the
first argument causing Mapbox to receive an invalid bounds value; destructure
command.params into bounds and options (e.g., const { bounds, options } =
command.params) and call mapInstance.fitBounds(bounds, options || {}) so bounds
is passed as the first parameter and options as the second, handling a missing
options object by defaulting to an empty object.
|
@coderabbitai generate unit tests |
|
@coderabbitai the code is not building |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 9590 @ngoiyaeric, I found the build issue! There's a syntax error in The ProblemThe import statement is missing a space between import { getModel }from '../utils';
// ↑ missing space hereThe FixChange Line 2 in import { getModel }from '../utils';to: import { getModel } from '../utils';This is a simple typo that will prevent TypeScript from compiling. Once you add the space, the build should succeed. |
|
Unit Test Generation failed: CodeRabbit timed out while planning changes for components/map/map-data-context.test.tsx. Skipping this file. |
✅ Actions performedUnit Test Generation started... |
|
Unit Test Generation failed: CodeRabbit timed out while planning changes for components/map/location-response-handler.test.tsx. Skipping this file. |
✅ Actions performedUnit Test Generation started... |
|
Unit Test Generation failed: CodeRabbit timed out while planning changes for app/actions.test.tsx. Skipping this file. |
✅ Actions performedUnit Test Generation started... |
This commit introduces a new asynchronous agent, `geojsonEnricher`, responsible for processing textual responses and extracting structured geospatial data. Key changes: - Created a new `geojsonEnricher` agent in `lib/agents/geojson-enricher.tsx`. - Defined new TypeScript interfaces for `LocationResponse`, `MapCommand`, and GeoJSON objects in `lib/types/custom.ts`. - Integrated the new agent into the main application workflow in `app/actions.tsx` with robust error handling. - Added a `LocationResponseHandler` component to update the map state via the `MapDataContext`. - Updated the `Mapbox` component to render GeoJSON data and execute map commands. NOTE: The application build is currently failing due to a persistent 'JavaScript heap out of memory' error. This appears to be a pre-existing issue with the repository's dependencies or build configuration that could not be resolved. The feature code is complete, but the build itself will need to be addressed separately.
There was a problem hiding this 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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
app/actions.tsx (1)
539-548: Wraprelatedcase in a block to satisfy no-switch-declarations.Declaring
const relatedQueries = …directly under thecasetriggers Biome’snoSwitchDeclarationserror because the binding leaks into other branches. Enclose thecase 'related'body in braces (or extract to a helper) so the declaration stays scoped to that branch.
♻️ Duplicate comments (1)
components/map/mapbox-map.tsx (1)
585-595: GuardfitBoundsparams before destructuring.
command.paramscan beundefinedwhen enrichment returns a malformed or partial command. Destructuring it directly throws and prevents later commands from running. Add a clause block, validatebounds, and bail early if missing.- case 'fitBounds': - const { bounds, options } = command.params; - mapInstance.fitBounds(bounds, options || {}); - break; + case 'fitBounds': { + const params = command.params ?? {}; + const { bounds, options } = params as { + bounds?: mapboxgl.FitBoundsLike; + options?: mapboxgl.FitBoundsOptions; + }; + if (!bounds) { + console.warn('fitBounds command missing bounds payload', command); + break; + } + mapInstance.fitBounds(bounds, options ?? {}); + break; + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (1)
bun.lockbis excluded by!**/bun.lockb
📒 Files selected for processing (4)
app/actions.tsx(7 hunks)components/map/mapbox-map.tsx(1 hunks)lib/agents/geojson-enricher.tsx(1 hunks)package.json(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
components/map/mapbox-map.tsx (2)
components/map/map-data-context.tsx (1)
MapData(7-17)components/map/map-query-handler.tsx (4)
prevData(39-49)prevData(53-57)toolOutput(33-74)useMapData(30-83)
lib/agents/geojson-enricher.tsx (2)
lib/types/custom.ts (1)
LocationResponse(29-33)lib/utils/index.ts (1)
getModel(19-62)
app/actions.tsx (3)
lib/agents/geojson-enricher.tsx (1)
geojsonEnricher(37-75)lib/schema/related.tsx (1)
PartialRelated(13-13)components/map/location-response-handler.tsx (1)
LocationResponseHandler(11-28)
🪛 Biome (2.1.2)
components/map/mapbox-map.tsx
[error] 593-593: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.
The declaration is defined in this switch clause:
Safe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
app/actions.tsx
[error] 539-539: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.
The declaration is defined in this switch clause:
Safe fix: Wrap the declaration in a block.
(lint/correctness/noSwitchDeclarations)
| @@ -0,0 +1,75 @@ | |||
| import { CoreMessage, LanguageModel, streamText } from 'ai'; | |||
| import { getModel }from '../utils'; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix import spacing to restore build.
The statement currently reads import { getModel }from '../utils'; which is invalid syntax and matches the build failure reported by CI. Insert the missing space:
-import { getModel }from '../utils';
+import { getModel } from '../utils';📝 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.
| import { getModel }from '../utils'; | |
| import { getModel } from '../utils'; |
🤖 Prompt for AI Agents
In lib/agents/geojson-enricher.tsx around line 2, the import statement lacks a
space between the named import and the from keyword causing a syntax error;
update the import to add the missing space so it reads with proper spacing
between the closing brace and the from keyword (e.g., ensure "import { getModel
} from '../utils';"), save the file and run the build/lint to confirm the fix.
|
@coderabbitai review pr |
|
@ngoiyaeric, I'll review the PR changes for you. ✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there should be a zod schema for the GeoJson parsing to improve its precision.
User description
This commit introduces a new asynchronous agent,
geojsonEnricher, responsible for processing textual responses and extracting structured geospatial data.Key changes:
geojsonEnricheragent inlib/agents/geojson-enricher.tsx.LocationResponse,MapCommand, and GeoJSON objects inlib/types/custom.ts.app/actions.tsx.LocationResponseHandlercomponent to update the map state via theMapDataContext.Mapboxcomponent to render GeoJSON data and execute map commands.PR Type
Enhancement
Description
Add GeoJSON enrichment agent for geospatial data extraction
Integrate map visualization with GeoJSON rendering capabilities
Create location response handler for map state management
Define TypeScript interfaces for geospatial data structures
Diagram Walkthrough
File Walkthrough
custom.ts
Define geospatial TypeScript interfaceslib/types/custom.ts
LocationResponse,MapCommand, and GeoJSON typesactions.tsx
Integrate GeoJSON enrichment into main workflowapp/actions.tsx
geojsonEnricheragentLocationResponseHandlercomponent integrationmapbox-map.tsx
Add GeoJSON rendering and map command executioncomponents/map/mapbox-map.tsx
geojson-enricher.tsx
Create GeoJSON enrichment agentlib/agents/geojson-enricher.tsx
LocationResponseobjectsmap-data-context.tsx
Extend map context with geospatial datacomponents/map/map-data-context.tsx
geojsonandmapCommandsfields to MapData interfacelocation-response-handler.tsx
Create location response handler componentcomponents/map/location-response-handler.tsx
package.json
Update dependencies for geospatial featurespackage.json
@radix-ui/react-select,nanoid, andzoddependenciesQCXdependency referenceSummary by CodeRabbit
New Features
Improvements
Chores