Skip to content

feat(im): add file_processing_strategy for IM channels — support direct-to-conversation file handling#1563

Open
Libres-coder wants to merge 1 commit into
Tencent:mainfrom
Libres-coder:main
Open

feat(im): add file_processing_strategy for IM channels — support direct-to-conversation file handling#1563
Libres-coder wants to merge 1 commit into
Tencent:mainfrom
Libres-coder:main

Conversation

@Libres-coder

Copy link
Copy Markdown

Summary

IM channels currently only support uploading files to a knowledge base (kb strategy). If no knowledge_base_id is configured, files are rejected with an error. This PR adds a file_processing_strategy field with two modes:

  • kb (default) — Upload files to knowledge base (existing behavior)
  • direct — Parse file content and inject it directly into the agent conversation context

Changes

Backend (Go):

File Change
internal/im/types.go Add FileProcessingStrategy type, constants (FileProcessingStrategyKB, FileProcessingStrategyDirect), and field on IMChannel
internal/im/service.go Update HandleMessage to dispatch based on strategy; add handleFileMessageDirect and processFileDirect; update buildIMQARequest to accept MessageAttachments
internal/handler/im.go Accept file_processing_strategy in create/update request structs

Database:

File Change
migrations/versioned/000040_im_file_strategy.up.sql Add file_processing_strategy column with CHECK constraint ('kb', 'direct')
migrations/versioned/000040_im_file_strategy.down.sql Rollback script

Frontend:

File Change
frontend/src/api/agent/index.ts Add file_processing_strategy to IMChannel and IMChannelOverview interfaces
frontend/src/components/IMChannelPanel.vue Add strategy radio group; KB selector shown only when strategy is kb
frontend/src/i18n/locales/zh-CN.ts Chinese translations
frontend/src/i18n/locales/en-US.ts English translations
frontend/src/i18n/locales/ru-RU.ts Russian translations
frontend/src/i18n/locales/ko-KR.ts Korean translations

How direct strategy works

  1. Download file from IM platform
  2. For text-based files (txt, md, csv, json, code, etc.) — read directly as UTF-8 text (max 50k chars, truncated with note if exceeded)
  3. For binary files (pdf, docx, etc.) — attach metadata note suggesting KB strategy
  4. Create MessageAttachment and inject into QA pipeline via buildIMQARequest
  5. Supports both streaming and non-streaming output modes

Backward Compatibility

  • Default value is 'kb', preserving existing behavior for all existing channels
  • BeforeCreate / BeforeSave hooks ensure empty values default to 'kb'
  • No breaking changes to API or database schema

Add file_processing_strategy field to IM channels, supporting two modes:
- kb (default): upload files to knowledge base (existing behavior)
- direct: parse file content and inject into conversation context

Backend:
- Add FileProcessingStrategy type and constants to IMChannel model
- Update HandleMessage to dispatch based on strategy
- Add handleFileMessageDirect and processFileDirect functions
- Update buildIMQARequest to accept MessageAttachments
- Update handler to accept file_processing_strategy in requests

Database:
- Add migration 000040: file_processing_strategy column with CHECK constraint

Frontend:
- Add file_processing_strategy to IMChannel and IMChannelOverview interfaces
- Add strategy radio group with conditional KB selector in IMChannelPanel
- Add i18n translations for zh-CN, en-US, ru-RU, ko-KR
@Libres-coder

Copy link
Copy Markdown
Author

ptal,thx!

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