Skip to content

add bocha web search tool#3142

Open
weijintaocode wants to merge 1 commit intosimstudioai:mainfrom
weijintaocode:addbocha
Open

add bocha web search tool#3142
weijintaocode wants to merge 1 commit intosimstudioai:mainfrom
weijintaocode:addbocha

Conversation

@weijintaocode
Copy link

Summary

Add Bocha Search Tool: integrates the Bocha AI Search API to provide web search capabilities

Type of Change

  • New feature

Testing

Tested Manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Demo

Input Configuration
image

Bocha Configuration
image

Agent Configuration and Execution Results
image

Bocha Output
image

@vercel
Copy link

vercel bot commented Feb 5, 2026

@weijintaocode is attempting to deploy a commit to the Sim Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 5, 2026

Greptile Overview

Greptile Summary

This PR integrates the BoCha AI Search API as a new search tool in Sim, following established patterns from similar integrations like DuckDuckGo and Exa.

Key Changes:

  • Implemented BoCha search tool with configurable parameters (freshness, summary, count, domain filtering)
  • Added UI block configuration for user-facing integration
  • Registered tool and block in respective registries
  • Added comprehensive multilingual documentation (EN, ZH, DE, ES, FR, JA)
  • Included BoCha icon SVG component

Issues Found:

  • Critical: Missing error handling for malformed API responses in transformResponse - will throw runtime errors if API structure changes
  • Type mismatch: Optional parameters in BoChaSearchParams interface don't use optional syntax, inconsistent with actual usage
  • Style: Import statements use inconsistent formatting (.ts extension, double quotes)
  • Minor: Typo in date format description

Confidence Score: 3/5

  • This PR has implementation issues that could cause runtime errors in production
  • Score reflects critical missing error handling in API response transformation that will cause crashes if API response structure is unexpected, plus type safety issues with optional parameters
  • Pay close attention to apps/sim/tools/bocha/search.ts (lacks error handling) and apps/sim/tools/bocha/types.ts (incorrect optional types)

Important Files Changed

Filename Overview
apps/sim/tools/bocha/search.ts implements BoCha search API integration but lacks error handling for malformed responses
apps/sim/tools/bocha/types.ts defines TypeScript types for BoCha integration with incorrect optional property declarations
apps/sim/blocks/blocks/bocha.ts defines UI block configuration with minor typo in date format description
apps/sim/blocks/registry.ts registers BoCha block with incorrect .ts extension in import
apps/sim/tools/registry.ts registers BoCha search tool with inconsistent quote style in import

Sequence Diagram

sequenceDiagram
    participant User
    participant SimUI as Sim UI (Block)
    participant Tool as BoCha Tool
    participant API as BoCha API
    
    User->>SimUI: Configure search parameters
    Note over SimUI: query, freshness, summary,<br/>count, include, exclude, apiKey
    
    User->>SimUI: Execute search
    SimUI->>Tool: Call bocha_search tool
    Note over Tool: Validate required params<br/>(query, apiKey)
    
    Tool->>API: POST /v1/web-search
    Note over API: Authorization: Bearer {apiKey}<br/>Body: search parameters
    
    alt Successful Response
        API-->>Tool: 200 OK with search results
        Note over Tool: Extract data.data.queryContext<br/>and data.data.webPages.value
        Tool-->>SimUI: Return formatted results
        SimUI-->>User: Display search results
    else Error Response
        API-->>Tool: Error response
        Tool-->>SimUI: Error (unhandled)
        SimUI-->>User: Display error
    end
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

5 files reviewed, 5 comments

Edit Code Review Agent Settings | Greptile

import { DropboxBlock } from '@/blocks/blocks/dropbox'
import { DSPyBlock } from '@/blocks/blocks/dspy'
import { DuckDuckGoBlock } from '@/blocks/blocks/duckduckgo'
import {BoChaBlock} from '@/blocks/blocks/bocha.ts'
Copy link
Contributor

Choose a reason for hiding this comment

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

unnecessary .ts extension in import

Suggested change
import {BoChaBlock} from '@/blocks/blocks/bocha.ts'
import {BoChaBlock} from '@/blocks/blocks/bocha'

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/blocks/registry.ts
Line: 26:26

Comment:
unnecessary `.ts` extension in import

```suggestion
import {BoChaBlock} from '@/blocks/blocks/bocha'
```

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

} from '@/tools/dropbox'
import { chainOfThoughtTool, predictTool, reactTool } from '@/tools/dspy'
import { duckduckgoSearchTool } from '@/tools/duckduckgo'
import {bochaSearchTool} from "@/tools/bocha"
Copy link
Contributor

Choose a reason for hiding this comment

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

inconsistent quote style (use single quotes)

Suggested change
import {bochaSearchTool} from "@/tools/bocha"
import {bochaSearchTool} from '@/tools/bocha'

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/tools/registry.ts
Line: 210:210

Comment:
inconsistent quote style (use single quotes)

```suggestion
import {bochaSearchTool} from '@/tools/bocha'
```

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +81 to +94
transformResponse: async (response: Response) => {
const data = await response.json()

return {
success: true,
output: {
query: data.data.queryContext.originalQuery,
results: data.data.webPages.value.map((result: any) => ({
title: result.name,
url: result.url,
snippet: result.snippet,
})),
},
}
Copy link
Contributor

Choose a reason for hiding this comment

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

no error handling for missing or malformed API response structure - will throw if data.data.queryContext or data.data.webPages.value are undefined

Suggested change
transformResponse: async (response: Response) => {
const data = await response.json()
return {
success: true,
output: {
query: data.data.queryContext.originalQuery,
results: data.data.webPages.value.map((result: any) => ({
title: result.name,
url: result.url,
snippet: result.snippet,
})),
},
}
transformResponse: async (response: Response) => {
const data = await response.json()
if (!data?.data?.queryContext?.originalQuery || !data?.data?.webPages?.value) {
throw new Error('Invalid API response structure')
}
return {
success: true,
output: {
query: data.data.queryContext.originalQuery,
results: data.data.webPages.value.map((result: any) => ({
title: result.name,
url: result.url,
snippet: result.snippet,
})),
},
}
},
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/tools/bocha/search.ts
Line: 81:94

Comment:
no error handling for missing or malformed API response structure - will throw if `data.data.queryContext` or `data.data.webPages.value` are undefined

```suggestion
  transformResponse: async (response: Response) => {
    const data = await response.json()

    if (!data?.data?.queryContext?.originalQuery || !data?.data?.webPages?.value) {
      throw new Error('Invalid API response structure')
    }

    return {
      success: true,
      output: {
        query: data.data.queryContext.originalQuery,
        results: data.data.webPages.value.map((result: any) => ({
          title: result.name,
          url: result.url,
          snippet: result.snippet,
        })),
      },
    }
  },
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +27 to +35
export interface BoChaSearchParams {
query: string
freshness: string
summary: boolean
count: number
include: string
exclude: string
apiKey: string
}
Copy link
Contributor

Choose a reason for hiding this comment

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

optional fields should use optional property syntax (?) to match how they're used in search.ts:72-76

Suggested change
export interface BoChaSearchParams {
query: string
freshness: string
summary: boolean
count: number
include: string
exclude: string
apiKey: string
}
export interface BoChaSearchParams {
query: string
freshness?: string
summary?: boolean
count?: number
include?: string
exclude?: string
apiKey: string
}

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/tools/bocha/types.ts
Line: 27:35

Comment:
optional fields should use optional property syntax (`?`) to match how they're used in `search.ts:72-76`

```suggestion
export interface BoChaSearchParams {
  query: string
  freshness?: string
  summary?: boolean
  count?: number
  include?: string
  exclude?: string
  apiKey: string
}
```

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

title: 'Freshness',
type: 'long-input',
placeholder: 'noLimit',
description: 'Search for web pages within a specified time range(noLimit/oneDay/oneWeek/oneMonth/oneYear/YYYY-MM-DD/YYYY-MM-DD/YYYY-MM-DD..YYYY-MM-DD)',
Copy link
Contributor

Choose a reason for hiding this comment

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

typo in description - duplicate YYYY-MM-DD in date format examples

Suggested change
description: 'Search for web pages within a specified time range(noLimit/oneDay/oneWeek/oneMonth/oneYear/YYYY-MM-DD/YYYY-MM-DD/YYYY-MM-DD..YYYY-MM-DD)',
description: 'Search for web pages within a specified time range(noLimit/oneDay/oneWeek/oneMonth/oneYear/YYYY-MM-DD/YYYY-MM-DD..YYYY-MM-DD)',
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/blocks/blocks/bocha.ts
Line: 28:28

Comment:
typo in description - duplicate `YYYY-MM-DD` in date format examples

```suggestion
            description: 'Search for web pages within a specified time range(noLimit/oneDay/oneWeek/oneMonth/oneYear/YYYY-MM-DD/YYYY-MM-DD..YYYY-MM-DD)',
```

How can I resolve this? If you propose a fix, please make it concise.

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.

1 participant