Skip to content

feat(text-asset): 支持文本类文件上传并作为会话上下文#719

Open
wynxing wants to merge 3 commits into
1024XEngineer:mainfrom
wynxing:file_upload
Open

feat(text-asset): 支持文本类文件上传并作为会话上下文#719
wynxing wants to merge 3 commits into
1024XEngineer:mainfrom
wynxing:file_upload

Conversation

@wynxing

@wynxing wynxing commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Close #701

概述

复用已有的图片上传入口与 session asset 存储链路,新增文本类文件(.txt/.md/.json/.yaml/.yml/.csv)支持。Runtime 在提交会话前将文本 asset 按 UTF-8 解码并内联为普通 text content part,Provider 层不感知"文件"概念。

变更内容

Go 后端

  • 策略层 (session/assets_policy.go)

    • 新增 TextAssetWhitelist:扩展名↔MIME 双向白名单,支持 WithExtensions 不可变扩展
    • 新增 TextAssetPolicy:字节/字符上限、截断策略、文件名长度限制
    • 硬上限兜底:4 MiB / 4M 字符,防止配置失控
  • 存储层 (session/asset_store.go, session/sqlite_store.go, session/asset_text.go)

    • AssetStore 新增 SetTextAssetPolicy 接口
    • 文本 asset 持久化与读取,UTF-8 校验
  • 输入准备 (session/input_preparer.go, runtime/input_prepare.go)

    • 解析附件时按 MIME 路由到文本/图片策略
    • 文本 asset 内联到 conversation parts,超长内容截断并附提示
    • 事件载荷新增 TextAssetCount 字段
  • Runtime (runtime/text_assets.go)

    • 文本 asset 运行时处理:读取→解码→截断→包装为带文件名边界的文本块
  • Config (config/runtime.go)

    • TextAssetEnabled 开关(默认开启)
    • MaxTextAssetBytes / MaxTextAssetChars 可配置限额
  • Gateway (gateway/network_server.go)

    • 网关层文本附件路由与策略注入

Web 前端

  • ChatInput: 支持文本文件选择,区分图片/文本附件校验逻辑,文本附件不依赖模型视觉能力
  • MessageItem: 用户消息中展示文本文件 chip(文件名、大小)
  • useComposerStore: 新增 resolveAttachmentKindacceptedTextMimeTypes、文本附件限额
  • format.ts: 新增 formatBytes 工具函数

文档

  • docs/gateway-rpc-api.md:更新 RPC API 文本附件说明
  • docs/guides/configuration.md:新增文本附件配置项文档

验收清单

  • Web 可上传并发送文本类文件
  • 文本输入和文本文件附件可一起发送
  • 超过限制的文本文件被拒绝或截断
  • 文件名仅作为上下文标签,不作为可信路径
  • Provider 差异不泄漏到上层
  • go test ./... 通过
  • Web 相关测试通过

测试

go test ./internal/session/... ./internal/runtime/... ./internal/config/... ./internal/gateway/...
cd web && npm test

回滚

保留上传存储能力,关闭 TextAssetEnabled 配置项即可禁用文本 asset 转上下文逻辑。

wynxing added 2 commits June 16, 2026 22:31
- 新增 TextAssetWhitelist/TextAssetPolicy 白名单与限额策略
- 支持 txt/md/json/yaml/yml/csv 文本附件(可配置开关)
- 文本 asset 在提交前内联到 conversation parts
- 前端 ChatInput/MessageItem 支持文本文件选择与展示
- 配置项:TextAssetEnabled、MaxTextAssetBytes/Chars
- 更新 gateway RPC API 与配置文档
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review findings:

I found two issues that can break text attachment behavior around configuration and the feature flag.

Comment thread internal/gateway/network_server.go Outdated
Comment thread internal/runtime/input_prepare.go
- 移除 gateway 硬编码文本大小拦截,由 runtime TextAssetPolicy 统一处理
- text_asset_enabled=false 时丢弃文本 asset image part,避免非 image/* mime 进入 provider 失败
- 丢弃时 emit EventError 通知用户
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.

Web 会话区支持文本类文件上传并作为会话上下文

1 participant