[codex] Add Bocha web search example#1341
Conversation
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds a new ChangesBocha Web Search VoltAgent Example
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
2 issues found across 10 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
examples/with-bocha-search/src/bocha.ts (1)
62-69: ⚡ Quick winClamp
countto a minimum bound inbuildBochaSearchRequest.Line 63 only enforces the max bound. Because this helper is exported, direct callers can pass
0/negative values and produce invalid request counts.Suggested patch
export function buildBochaSearchRequest(input: BochaSearchInput): BochaSearchRequest { - const count = Math.min(input.count ?? DEFAULT_RESULT_COUNT, MAX_RESULT_COUNT); + const requestedCount = input.count ?? DEFAULT_RESULT_COUNT; + const count = Math.max(1, Math.min(requestedCount, MAX_RESULT_COUNT)); const request: BochaSearchRequest = { query: input.query, freshness: input.freshness ?? "noLimit", summary: true, count, };🤖 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 `@examples/with-bocha-search/src/bocha.ts` around lines 62 - 69, The buildBochaSearchRequest function only enforces a maximum bound on count using Math.min(), allowing 0 or negative values to pass through when callers provide them directly. Update the count calculation to also enforce a minimum bound using Math.max() alongside the existing Math.min() call, ensuring that count cannot fall below a minimum threshold (such as 1) while still respecting the maximum bound.examples/with-bocha-search/src/tools.spec.ts (1)
5-22: ⚡ Quick winAdd a regression case for non-positive
countnormalization.Current tests assert max clamping, but not lower-bound behavior. Add coverage for
count: 0(and/or negative) to lock in safe request normalization.Suggested test addition
describe("Bocha search tool helpers", () => { it("builds a conservative Bocha search request", () => { @@ }); + + it("normalizes non-positive count to minimum bound", () => { + expect( + buildBochaSearchRequest({ + query: "agent news", + count: 0, + }), + ).toMatchObject({ + query: "agent news", + count: 1, + }); + });🤖 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 `@examples/with-bocha-search/src/tools.spec.ts` around lines 5 - 22, The test suite for buildBochaSearchRequest currently only covers positive count values with max clamping, but lacks coverage for non-positive (zero or negative) count values. Add a new test case that invokes buildBochaSearchRequest with count: 0 or a negative number and verifies that the function normalizes this to a safe minimum value, ensuring proper lower-bound behavior in the request normalization logic.
🤖 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 `@examples/with-bocha-search/package.json`:
- Around line 14-17: The example package.json is missing dependencies required
to run its test suite independently. Add the vitest package with version
"^3.2.4" to the devDependencies section alongside the existing `@types/node`, tsx,
and typescript entries. Additionally, add a "test" script to the scripts section
that runs the vitest command. This ensures the example can execute its
vitest.config.ts configuration and src/tools.spec.ts test file without relying
on the workspace root.
In `@examples/with-bocha-search/src/tools.ts`:
- Around line 72-80: Add a default timeout mechanism for the fetch call in the
Bocha API request handler. When options.abortSignal is not provided, create an
AbortController with a reasonable timeout value (e.g., 30 seconds) and use its
signal in the fetch call. This ensures the fetch operation will not hang
indefinitely if no explicit abort signal is passed through options. Store the
abort controller conditionally so you can use its signal in the fetch options,
falling back to options?.abortSignal if it exists.
In `@examples/with-bocha-search/tsconfig.json`:
- Around line 3-5: The moduleResolution setting in tsconfig.json is set to
"bundler" which allows extensionless imports, but the example is executed with
plain node command on the compiled dist output, and Node's ESM runtime cannot
resolve extensionless imports like "./tools" or "./bocha". Change the
moduleResolution value from "bundler" to "NodeNext" to align TypeScript's module
resolution with Node's ESM resolution behavior, or alternatively update all
source file imports to explicitly include .js file extensions before the build
step.
---
Nitpick comments:
In `@examples/with-bocha-search/src/bocha.ts`:
- Around line 62-69: The buildBochaSearchRequest function only enforces a
maximum bound on count using Math.min(), allowing 0 or negative values to pass
through when callers provide them directly. Update the count calculation to also
enforce a minimum bound using Math.max() alongside the existing Math.min() call,
ensuring that count cannot fall below a minimum threshold (such as 1) while
still respecting the maximum bound.
In `@examples/with-bocha-search/src/tools.spec.ts`:
- Around line 5-22: The test suite for buildBochaSearchRequest currently only
covers positive count values with max clamping, but lacks coverage for
non-positive (zero or negative) count values. Add a new test case that invokes
buildBochaSearchRequest with count: 0 or a negative number and verifies that the
function normalizes this to a safe minimum value, ensuring proper lower-bound
behavior in the request normalization logic.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: e430b03e-bf48-49fe-a3be-a5bbb71c844d
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (9)
examples/with-bocha-search/.env.exampleexamples/with-bocha-search/README.mdexamples/with-bocha-search/package.jsonexamples/with-bocha-search/src/bocha.tsexamples/with-bocha-search/src/index.tsexamples/with-bocha-search/src/tools.spec.tsexamples/with-bocha-search/src/tools.tsexamples/with-bocha-search/tsconfig.jsonexamples/with-bocha-search/vitest.config.ts
Summary
Adds a runnable Bocha Web Search example for VoltAgent.
Changes
examples/with-bocha-searchwith abochaSearchtyped tool..env.exampleforBOCHA_SEARCH_API_KEYand optionalBOCHA_SEARCH_API_URL.Validation
pnpm exec vitest run --config examples/with-bocha-search/vitest.config.tspnpm --filter voltagent-example-with-bocha-search buildpnpm biome check examples/with-bocha-searchpnpm install --frozen-lockfile --ignore-scripts --offline --reporter=append-onlypnpm --filter voltagent-example-with-bocha-search dev, verifiedhttp://localhost:3141returned HTTP 200.bochaSearchTool.execute(...)withoutBOCHA_SEARCH_API_KEYreturns a clear configuration error.Notes
No real API keys are committed. A live Bocha API query was not run in this environment because
BOCHA_SEARCH_API_KEYwas not configured.Summary by cubic
Adds a runnable Bocha Web Search example for VoltAgent. It includes a
bochaSearchtyped tool, helpers, docs, and tests so agents can fetch current, source-linked results.New Features
examples/with-bocha-searchwith abochaSearchtool wired into asearchAgentusing@voltagent/coreand@voltagent/server-hono..env.examplewithBOCHA_SEARCH_API_KEYand optionalBOCHA_SEARCH_API_URL, plus README with setup/run instructions.Bug Fixes
https://api.bochaai.com/v1/web-searchas the default endpoint whenBOCHA_SEARCH_API_URLis not set; added a test to verify the default is used.Written for commit 254c3d9. Summary will update on new commits.
Summary by CodeRabbit
with-bocha-searchexample integrating Bocha Web Search as a typed tool inside a VoltAgent..env.exampletemplate for required/optional API settings.