Skip to content

fix(custom-tools)#901

Merged
TimeBomb2018 merged 1 commit intorelease/v0.3.0from
fix/Timebomb_030
Apr 15, 2026
Merged

fix(custom-tools)#901
TimeBomb2018 merged 1 commit intorelease/v0.3.0from
fix/Timebomb_030

Conversation

@TimeBomb2018
Copy link
Copy Markdown
Collaborator

@TimeBomb2018 TimeBomb2018 commented Apr 15, 2026

coerce query and request body parameters to schema types

Summary by Sourcery

在发送请求之前,将自定义工具的 HTTP 请求参数强制转换为其定义的模式类型。

Bug 修复:

  • 确保查询参数在发送前被转换为其声明的模式类型,而不是始终以原始值发送。
  • 在构建 POST/PUT/PATCH 负载时,确保请求体属性被转换为其声明的模式类型。
Original summary in English

Summary by Sourcery

Coerce custom tool HTTP request parameters to match their defined schema types before sending requests.

Bug Fixes:

  • Ensure query parameters are converted to their declared schema types instead of always being sent as raw values.
  • Ensure request body properties are converted to their declared schema types when building POST/PUT/PATCH payloads.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Apr 15, 2026

审阅者指南

为自定义工具的 HTTP 请求实现了“基于 schema 的类型转换(type coercion)”,在发送请求之前,会根据 schema 将查询参数和 JSON 请求体字段转换为合适的原始类型(primitive types)。

更新后的自定义工具请求构建类图

classDiagram
    class CustomToolBase {
        +_build_request_url(operation: Dict~str, Any~, params: Dict~str, Any~) str
        +_build_request_headers(operation: Dict~str, Any~) Dict~str, str~
        +_coerce_param(value: Any, schema_type: str) Any
        +_build_request_data(operation: Dict~str, Any~, params: Dict~str, Any~) Dict~str, Any~
        +_send_http_request(operation: Dict~str, Any~, params: Dict~str, Any~) Any
    }

    note for CustomToolBase "_coerce_param is now used by _build_request_url and _build_request_data to coerce query and body parameters to schema types"
Loading

文件级变更

Change Details Files
添加一个共享的辅助方法,根据参数的 schema 类型对参数值进行转换,并用于查询参数。
  • 引入实例方法 _coerce_param(value, schema_type),在 schema 指定时,将值转换为 integer、number 或 boolean,并在转换错误时安全回退。
  • 更新 _build_request_url,根据每个参数声明的类型,将查询参数值传入 _coerce_param 进行转换,默认类型为 string。
api/app/core/tools/custom/base.py
将基于 schema 的类型转换应用到写操作的请求体属性。
  • _build_request_data 修改为实例方法,以便可以调用 _coerce_param,而不是直接返回原始参数值。
  • 使用 request_body.properties 中的属性 schema,在返回 payload 之前,将 POST/PUT/PATCH 请求的 JSON 请求体字段转换为正确的原始类型。
api/app/core/tools/custom/base.py

提示与命令

与 Sourcery 交互

  • 触发新的审阅: 在 pull request 上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 从审阅评论生成 GitHub issue: 通过回复某条审阅评论,请求 Sourcery 从该评论创建一个 issue。你也可以回复审阅评论 @sourcery-ai issue 来从该评论创建 issue。
  • 生成 pull request 标题: 在 pull request 标题中任意位置写上 @sourcery-ai,即可在任意时间生成标题。你也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文中任意位置写上 @sourcery-ai summary,即可在任意位置、任意时间生成 PR 摘要。你也可以在 pull request 中评论 @sourcery-ai summary 来(重新)生成摘要。
  • 生成审阅者指南: 在 pull request 上评论 @sourcery-ai guide,即可在任意时间(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在 pull request 上评论 @sourcery-ai resolve,即可一次性解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,这会很有用。
  • 关闭所有 Sourcery 审阅: 在 pull request 上评论 @sourcery-ai dismiss,即可关闭所有现有的 Sourcery 审阅。尤其适用于你希望从一次全新的审阅开始的情况——别忘了再评论 @sourcery-ai review 来触发新的审阅!

自定义你的体验

访问你的 dashboard 可以:

  • 启用或禁用审阅功能,例如 Sourcery 生成的 pull request 摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、删除或编辑自定义审阅指令。
  • 调整其他审阅设置。

获取帮助

Original review guide in English

Reviewer's Guide

Implements schema-aware type coercion for custom tool HTTP requests, ensuring query parameters and JSON body fields are converted to the appropriate primitive types before sending the request.

Class diagram for updated custom tool request building

classDiagram
    class CustomToolBase {
        +_build_request_url(operation: Dict~str, Any~, params: Dict~str, Any~) str
        +_build_request_headers(operation: Dict~str, Any~) Dict~str, str~
        +_coerce_param(value: Any, schema_type: str) Any
        +_build_request_data(operation: Dict~str, Any~, params: Dict~str, Any~) Dict~str, Any~
        +_send_http_request(operation: Dict~str, Any~, params: Dict~str, Any~) Any
    }

    note for CustomToolBase "_coerce_param is now used by _build_request_url and _build_request_data to coerce query and body parameters to schema types"
Loading

File-Level Changes

Change Details Files
Add a shared helper to coerce parameter values according to their schema type and use it for query parameters.
  • Introduce a _coerce_param(value, schema_type) instance method that converts values to integer, number, or boolean when specified, with safe fallbacks on conversion errors.
  • Update _build_request_url to pass query parameter values through _coerce_param based on each parameter's declared type, defaulting to string.
api/app/core/tools/custom/base.py
Apply schema-based type coercion to request body properties for write operations.
  • Change _build_request_data to be an instance method that can call _coerce_param instead of returning raw param values.
  • Use property schemas from request_body.properties to coerce POST/PUT/PATCH JSON body fields to the correct primitive type before returning the payload.
api/app/core/tools/custom/base.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - 我在这里给出了一些高层次的反馈:

  • 当前的布尔值转换逻辑(value.lower() not in ("false", "0", ""))可能过于宽松且有些出乎意料(例如,"no" 会变成 True);建议改为显式维护一份真值/假值字符串的白名单。
  • _coerce_param 辅助函数目前只处理原始的 type 值,并忽略了其他模式(schema)方面的信息,例如数组的 items 或嵌套对象的 schema;建议考虑如何处理或拒绝这些更复杂的类型,以避免出现静默的不匹配。
面向 AI Agent 的提示
Please address the comments from this code review:

## Overall Comments
- The boolean coercion logic (`value.lower() not in ("false", "0", "")`) may be too permissive and surprising (e.g., "no" becomes `True`); consider explicitly whitelisting truthy/falsey string values instead.
- The `_coerce_param` helper currently only handles primitive `type` values and ignores other schema aspects like `items` for arrays or nested object schemas; consider how you want to handle or reject those more complex types to avoid silent mismatches.

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've left some high level feedback:

  • The boolean coercion logic (value.lower() not in ("false", "0", "")) may be too permissive and surprising (e.g., "no" becomes True); consider explicitly whitelisting truthy/falsey string values instead.
  • The _coerce_param helper currently only handles primitive type values and ignores other schema aspects like items for arrays or nested object schemas; consider how you want to handle or reject those more complex types to avoid silent mismatches.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The boolean coercion logic (`value.lower() not in ("false", "0", "")`) may be too permissive and surprising (e.g., "no" becomes `True`); consider explicitly whitelisting truthy/falsey string values instead.
- The `_coerce_param` helper currently only handles primitive `type` values and ignores other schema aspects like `items` for arrays or nested object schemas; consider how you want to handle or reject those more complex types to avoid silent mismatches.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@TimeBomb2018 TimeBomb2018 merged commit d072eb1 into release/v0.3.0 Apr 15, 2026
1 check passed
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