Skip to content

feat: 提升 WebFetch 网页正文提取与模型可消费性#77

Merged
minorcell merged 1 commit into
1024XEngineer:mainfrom
Cai-Tang-www:main
Mar 28, 2026
Merged

feat: 提升 WebFetch 网页正文提取与模型可消费性#77
minorcell merged 1 commit into
1024XEngineer:mainfrom
Cai-Tang-www:main

Conversation

@Cai-Tang-www

@Cai-Tang-www Cai-Tang-www commented Mar 28, 2026

Copy link
Copy Markdown
Collaborator

变更说明

本次改动在不破坏 TUI -> Runtime -> Provider -> Tools 主链路的前提下,重构了 webfetch,让它从“返回原始 HTTP Body”提升为“返回更适合模型消费的网页文本内容”。

主要改动

  • webfetch 增加工具级配置:
    • tools.webfetch.max_response_bytes
    • tools.webfetch.supported_content_types
  • 在应用启动阶段通过配置装配 webfetch
  • 重构 webfetch 执行流程,拆分为:
    • 参数解析
    • URL 校验
    • 限长读取响应
    • Content-Type 判定
    • 内容提取
    • 统一成功/失败结果格式
  • 增加 HTML 正文提取能力:
    • 跳过 scriptstylenoscriptsvgcanvasheadtemplate
    • 优先提取可见正文文本
    • 页面存在 <title> 时一并返回
  • 对不支持的非文本响应做显式拒绝
  • 在返回结果 metadata 中补充:
    • url
    • status
    • content_type
    • truncated
    • title

预期收益

  • 降低模型处理网页内容时的噪声和 token 成本
  • 提高网页阅读类任务的可用性和回答质量
  • webfetch 更符合 Agent 工具定位

测试验证

已补充并更新以下测试:

  • internal/tools/webfetch
    • HTML 提取
    • 空内容处理
    • 文本 / JSON 响应
    • 非文本类型拒绝
    • 大响应截断
    • HTTP 错误格式化
    • 非法参数 / 非法 URL / 请求失败
  • internal/config
    • webfetch 默认值
    • 配置校验
    • 配置 round-trip
    • 兼容旧配置
  • internal/app
    • 启动装配使用 webfetch 配置

执行验证:

go test ./...

close #78

@codecov

codecov Bot commented Mar 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.01254% with 51 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/tools/webfetch/tool.go 83.24% 21 Missing and 9 partials ⚠️
internal/config/model.go 80.88% 8 Missing and 5 partials ⚠️
internal/tools/webfetch/html.go 85.96% 4 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

@minorcell minorcell merged commit f68e6a6 into 1024XEngineer:main Mar 28, 2026
2 checks passed
minorcell pushed a commit that referenced this pull request May 16, 2026
fix(repository): normalize backslashes in git HEAD blob spec
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.

feat: 提升 WebFetch 网页正文提取能力与模型可消费性

2 participants