Consolidate toolspec schema definitions with reusable helpers#78
Consolidate toolspec schema definitions with reusable helpers#78
Conversation
Replace verbose inline map[string]any literals in schema functions with calls to shared helpers (StringProperty, BooleanProperty, NumberProperty, StringEnumProperty, BoundedNumberProperty, StringArrayProperty, ObjectSchema). Affected: WebSearchSchema, WebFetchSchema, MessageSchema, ImageGenerateSchema, MemorySearchSchema, BeeperDocsSchema. ~225 lines removed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughSummary by CodeRabbit
WalkthroughRefactored schema definitions in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
pkg/shared/toolspec/toolspec.go (2)
83-87: Consider adding a helper for minimum-only constraints.
maxCharsuses an inline map becauseBoundedNumberPropertyrequires both bounds. For consistency, consider adding aMinimumNumberPropertyhelper. Low priority since this is the only occurrence.♻️ Optional helper addition
func MinimumNumberProperty(description string, minimum float64) map[string]any { return map[string]any{ "type": "number", "description": description, "minimum": minimum, } }Then replace lines 83-87 with:
-"maxChars": map[string]any{ - "type": "number", - "description": "Maximum characters to return (truncates when exceeded).", - "minimum": 100, -}, +"maxChars": MinimumNumberProperty("Maximum characters to return (truncates when exceeded).", 100),🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/shared/toolspec/toolspec.go` around lines 83 - 87, Add a small helper to encapsulate number properties with only a minimum bound and replace the inline map used for "maxChars" with it: implement a MinimumNumberProperty(description string, minimum float64) that returns a map[string]any with "type":"number", "description" and "minimum", then update the "maxChars" definition (currently an inline map in toolspec.go) to call MinimumNumberProperty instead of duplicating the map; this keeps usage consistent with BoundedNumberProperty and improves readability.
282-282: Minor: description inconsistency forcountfield.Other schemas document the range in the description (e.g., "Number of results to return (1-10)"), but this one only mentions the default. Consider aligning for consistency:
-"count": BoundedNumberProperty("Optional: number of images to generate (default: 1).", 1, 10), +"count": BoundedNumberProperty("Optional: number of images to generate (1-10, default: 1).", 1, 10),🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/shared/toolspec/toolspec.go` at line 282, Update the description passed to the BoundedNumberProperty call for the "count" field so it includes the range like other schemas; change the string in the "count": BoundedNumberProperty(...) invocation to something like "Number of images to generate (1-10, default: 1)." so the description documents both range and default consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@pkg/shared/toolspec/toolspec.go`:
- Around line 83-87: Add a small helper to encapsulate number properties with
only a minimum bound and replace the inline map used for "maxChars" with it:
implement a MinimumNumberProperty(description string, minimum float64) that
returns a map[string]any with "type":"number", "description" and "minimum", then
update the "maxChars" definition (currently an inline map in toolspec.go) to
call MinimumNumberProperty instead of duplicating the map; this keeps usage
consistent with BoundedNumberProperty and improves readability.
- Line 282: Update the description passed to the BoundedNumberProperty call for
the "count" field so it includes the range like other schemas; change the string
in the "count": BoundedNumberProperty(...) invocation to something like "Number
of images to generate (1-10, default: 1)." so the description documents both
range and default consistently.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 98cda09f-05b7-47e7-a96d-9268e6ca6c02
📒 Files selected for processing (1)
pkg/shared/toolspec/toolspec.go
📜 Review details
⏰ 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). (6)
- GitHub Check: Lint
- GitHub Check: build-docker
- GitHub Check: build-agentremote-docker (arm64)
- GitHub Check: build-agentremote-docker (amd64)
- GitHub Check: build-docker
- GitHub Check: Lint
🔇 Additional comments (5)
pkg/shared/toolspec/toolspec.go (5)
69-77: Clean refactoring of WebSearchSchema.The migration to helper functions improves readability while preserving the schema semantics. The
BoundedNumberPropertyforcountcorrectly enforces the 1-10 range.
134-197: Well-structured refactoring of MessageSchema.Good decisions made here:
- Simple properties correctly use the new helpers
- Complex nested structures (
buttons,card) appropriately remain inline since they have non-trivial schemasStringArrayPropertycleanly handlesparticipantIdsandtargets
338-361: Well-designed helper functions.The three new helpers follow the established patterns:
StringEnumProperty- correctly constructs enum constraints with[]stringBoundedNumberProperty- usesfloat64for JSON number compatibilityStringArrayProperty- properly definesitemsschema inlineThese provide good abstractions for common JSON Schema patterns without over-engineering.
363-373: Good handling of conditional requirement.The
queryfield is described as "Required unless mode=list" - since JSON Schema's basicrequiredcan't express conditional requirements, documenting it in the description is the pragmatic approach. Full enforcement would needif/then/elseconstructs which would complicate the schema unnecessarily.
385-390: LGTM!Consistent use of
BoundedNumberPropertymatching the pattern inWebSearchSchema.
Summary
map[string]anyliterals with shared property helpersTest plan
go build ./...passesgo test ./...passesgo vet ./...passes🤖 Generated with Claude Code