Files
MyGoNavi/internal/ai/provider/provider.go
Syngnat 06dd9507ee feat(ai): 补齐 Cursor 与 CodeBuddy 会话态聊天链路
- 新增 SessionChatProvider 接口,补齐非流式对话的会话态复用能力
- 为 Cursor Agent 和 CodeBuddy CLI 同步实现流式与非流式会话续接及状态持久化
- CustomProvider 补充会话态透传,统一 custom provider 的会话复用行为
- Service 新增 AIChatSendInSession,聊天主链路非流式回退改走带 session 的发送接口
- 保留原 AIChatSend 无状态语义,避免标题生成和记忆压缩污染主会话上下文
- 补充前后端定向测试,覆盖会话恢复、续接发送和前端回退分流
2026-06-18 13:35:08 +08:00

42 lines
1.2 KiB
Go

package provider
import (
"context"
"encoding/json"
"GoNavi-Wails/internal/ai"
)
// Provider AI 模型提供者接口
type Provider interface {
// Chat 发送消息并获取完整响应
Chat(ctx context.Context, req ai.ChatRequest) (*ai.ChatResponse, error)
// ChatStream 发送消息并以流式返回
ChatStream(ctx context.Context, req ai.ChatRequest, callback func(ai.StreamChunk)) error
// Name 返回 Provider 名称
Name() string
// Validate 校验配置是否有效
Validate() error
}
// SessionStreamProvider 表示支持按会话复用上游状态的流式 Provider。
// state 为 Provider 自己维护的持久化状态;返回值为更新后的状态快照。
type SessionStreamProvider interface {
ChatStreamWithState(
ctx context.Context,
state json.RawMessage,
req ai.ChatRequest,
callback func(ai.StreamChunk),
) (json.RawMessage, error)
}
// SessionChatProvider 表示支持按会话复用上游状态的非流式 Provider。
// state 为 Provider 自己维护的持久化状态;返回值为响应体和更新后的状态快照。
type SessionChatProvider interface {
ChatWithState(
ctx context.Context,
state json.RawMessage,
req ai.ChatRequest,
) (*ai.ChatResponse, json.RawMessage, error)
}