feat: add webui http channel for chat and file upload

This commit is contained in:
2026-03-10 10:23:53 +08:00
parent bd41f48971
commit 49f6297631
6 changed files with 527 additions and 2 deletions

View File

@@ -117,6 +117,24 @@ func (o *Orchestrator) HandleMessageWithFiles(ctx context.Context, chatID, userI
return o.handleMessageInternal(ctx, chatID, userID, text, files)
}
// UploadAndCacheFiles 上传文件到 LLM 并缓存 file_id供后续同会话文本问答复用。
// 该方法不会写入 messages 表,仅更新内存中的 pending file 上下文。
func (o *Orchestrator) UploadAndCacheFiles(ctx context.Context, chatID, userID string, files []llm.InputFile) ([]string, error) {
if len(files) == 0 {
return nil, fmt.Errorf("no files provided")
}
uploadCtx := o.prepareFilePromptContext(ctx, files, nil)
if strings.TrimSpace(uploadCtx.FatalReason) != "" {
return nil, fmt.Errorf(uploadCtx.FatalReason)
}
ids := nonEmptyIDs(uploadCtx.FileIDs)
if len(ids) == 0 {
return nil, fmt.Errorf("file upload completed but no valid file_id returned")
}
o.appendPendingFiles(chatID, userID, uploadCtx.toPendingRefs())
return ids, nil
}
func (o *Orchestrator) handleMessageInternal(ctx context.Context, chatID, userID, text string, files []llm.InputFile) (string, error) {
// 为链路追踪设置唯一的 TraceID
traceID := logger.NewTraceID()