Documentation
¶
Overview ¶
Package structs 定义存储层的数据结构与 GORM 模型
包含消息、会话、代理等核心业务实体的数据库映射
Index ¶
- Variables
- type Chats
- func (c *Chats) ClearToolCalling()
- func (c *Chats) GetContext() context.Context
- func (c *Chats) HasToolCalling() bool
- func (c *Chats) KillTool()
- func (c *Chats) ResetLatest()
- func (c *Chats) SetContext(ctx context.Context)
- func (c *Chats) SetLatest(ctx map[string]any, typ map[string]string)
- func (c *Chats) SetToolCalling(id string, resp any, typ string)
- func (c *Chats) SetToolKillFn(fn func())
- func (c *Chats) SnapshotLatest() (map[string]any, map[string]string)
- func (c *Chats) SnapshotToolCalling() (map[string]any, map[string]string, map[string]bool)
- func (c *Chats) TakeFinalToolCalling() (map[string]any, map[string]string)
- func (c *Chats) TakeStreamingToolCalling() (map[string]any, map[string]string)
- type ClassifySegment
- type Configs
- type Messages
- type MessagesRefer
- type MessagesReferList
- type MessagesReferType
- type MessagesRole
- type ReferFiles
- type Scopes
- type SubAgents
- type Terminals
- type Traces
Constants ¶
This section is empty.
Variables ¶
var Tables = []any{ &Chats{}, &Messages{}, &SubAgents{}, &Terminals{}, &Scopes{}, &Configs{}, &Traces{}, &ReferFiles{}, &ClassifySegment{}, }
Tables 所有表
Functions ¶
This section is empty.
Types ¶
type Chats ¶
type Chats struct {
ID uint32 `gorm:"primaryKey;autoIncrement"`
LastModelID uint32
NowAgent string
Root string
TraceID uint64
State state.State
Title string // 用户设置的标题(/title 命令写入)
AITitle string // AI 生成的标题(自动生成/compress 重生成写入)
ReasoningEffort string
Stop bool `gorm:"-" json:"-"`
DB *gorm.DB `gorm:"-" json:"-"`
CurrentAgentID string `gorm:"-" json:"-"`
CurrentAgentConfig structs.AgentConfig `gorm:"-" json:"-"`
CurrentActivatePath string `gorm:"-" json:"-"`
EnableScopes map[string]bool `gorm:"-" json:"-"`
TemporyDataOfRequest map[string]any `gorm:"-" json:"-"`
TemporyDataOfSession map[string]any `gorm:"-" json:"-"`
InTestFlag bool `gorm:"-" json:"-"`
ReferCount int32 `gorm:"-" json:"-"`
ToolCallingContext map[string]any `gorm:"-" json:"-"`
ToolCallingType map[string]string `gorm:"-" json:"-"`
CurrentToolID string `gorm:"-" json:"-"`
CurrentMessageID uint64 `gorm:"-" json:"-"`
ToolState uint64 `gorm:"-" json:"-"`
LatestToolCallingContext map[string]any `gorm:"-" json:"-"`
LatestToolCallingType map[string]string `gorm:"-" json:"-"`
// ToolCallingStreaming 标记每个工具调用 id 是否为流式增量预览(true)还是最终状态(false)。
// OnHook 写入时按 session.State 判定:StateReciving/StateRequesting(AI 正在生成)→ 增量;
// StateToolCalling(审批后执行)→ 最终。SetCallback 据此选事件名。
ToolCallingStreaming map[string]bool `gorm:"-" json:"-"`
// ToolKillFn 由当前正在执行的工具注册,loop.Stop() 调用它来中断工具
ToolKillFn func() `gorm:"-" json:"-"`
// contains filtered or unexported fields
}
Chats 对话列表
func (*Chats) ClearToolCalling ¶ added in v0.3.5
func (c *Chats) ClearToolCalling()
ClearToolCalling 清空当前工具调用上下文(进 WaitApprove 前防止限流跳过的残留)。
func (*Chats) GetContext ¶ added in v0.2.8
GetContext 线程安全地获取会话上下文,如果未设置则返回 background
func (*Chats) HasToolCalling ¶ added in v0.3.5
HasToolCalling 判断当前是否存在待广播的工具调用上下文。
func (*Chats) KillTool ¶ added in v0.2.10
func (c *Chats) KillTool()
KillTool 调用当前工具注册的停止函数(如果有)。 由 loop.Stop() 调用,用于中断正在执行的工具。
func (*Chats) ResetLatest ¶ added in v0.3.5
func (c *Chats) ResetLatest()
ResetLatest 重置最近一次工具调用快照(审批/拒绝完成、新一轮用户输入前调用)。
func (*Chats) SetContext ¶ added in v0.2.8
SetContext 线程安全地设置会话上下文
func (*Chats) SetToolCalling ¶ added in v0.3.5
SetToolCalling 线程安全地写入工具调用上下文(工具 OnHook 在流式解析/执行阶段调用)。 自动初始化 map,供流式增量预览与最终调用信息广播读取。 阶段标记按 session.State 判定:StateReciving/StateRequesting(AI 正在生成工具调用)为流式增量, 其余(如 StateToolCalling 审批后执行)为最终状态。
func (*Chats) SetToolKillFn ¶ added in v0.2.10
func (c *Chats) SetToolKillFn(fn func())
SetToolKillFn 注册一个函数,用于在 Stop() 被调用时中断当前正在执行的工具。 工具在自己的执行开始时调用此方法注册自己的停止逻辑(如杀死进程), 执行结束后调用 SetToolKillFn(nil) 清理。 每个工具可以定义"不同的stop"——这是给所有工具统一的中断入口。
func (*Chats) SnapshotLatest ¶ added in v0.3.5
SnapshotLatest 返回最近一次工具调用快照的副本(供 WaitApprove 文本拼接、SessionLoad 重放)。
func (*Chats) SnapshotToolCalling ¶ added in v0.3.5
SnapshotToolCalling 在锁内拷贝当前工具调用上下文并清空,返回副本。 广播等网络 I/O 应在锁外进行,避免长时间阻塞 OnHook 的写入。
func (*Chats) TakeFinalToolCalling ¶ added in v0.3.5
TakeFinalToolCalling 快照并移除所有最终状态(非流式标记)条目,保留流式条目。 供 SetCallback 在任意回调时立即广播审批后/执行后的最终 tool_call, 不依赖 session.State 判断(审批后空 AIResponse 与新一轮流式存在 State 竞态)。
type ClassifySegment ¶ added in v0.3.0
type ClassifySegment struct {
ID uint64 `gorm:"primaryKey;autoIncrement"`
ChatID uint32 `gorm:"index"`
MessageID uint64 `gorm:"index"`
Label string `gorm:"type:text"`
Text string `gorm:"type:text"`
TempPath string `gorm:"type:text"`
}
ClassifySegment 分类段信息表 记录用户消息经 prompt 分类器分割后的每个段的标签信息。 prompt: 自然语言指令,log: 日志/堆栈,code: 代码片段
type Configs ¶
type Configs struct {
LastChatID uint32
}
Configs 全局表 注意:不要给该表加主键列——SQLite 无法对已有表执行 "ADD PRIMARY KEY", 会破坏 AutoMigrate 并导致旧数据库升级失败。读写请走 storage/configs.go 的 Find/Delete+Create 方案(GORM Save/First 对无主键模型会报 "WHERE conditions required")。
type Messages ¶
type Messages struct {
ID uint64 `gorm:"primaryKey;autoIncrement"`
ChatID uint32
AgentID *string
Delta string `gorm:"type:text"`
Summary string `gorm:"type:text"`
ThinkingDelta string `gorm:"type:text"`
Chats *Chats `gorm:"foreignKey:ChatID;constraints:OnDelete:RESTRICT;OnUpdate:CASCADE"`
// SubAgents SubAgents `gorm:"foreignKey:AgentID;constraints:OnDelete:RESTRICT;OnUpdate:CASCADE"`
Refers MessagesReferList `gorm:"type:bytes;serialize:gob"`
ToolCallingJSONString string `gorm:"type:text"`
// ToolFinished bool `gorm:"default:false"`
Time uint64 `gorm:"autoCreateTime"`
ModelName string
ModelID uint32
Type MessagesRole
PromptTokens uint32
CompletionTokens uint32
TotalTokens uint32
CachedTokens uint32
}
Messages 消息列表
type MessagesRefer ¶
type MessagesRefer struct {
FilePath string
FileType MessagesReferType
FileFromLine int32
FileFromCol int32
FileToLine int32
FileToCol int32
Origin []byte
}
MessagesRefer 消息引用
type MessagesReferList ¶
type MessagesReferList []MessagesRefer
MessagesReferList 消息引用
func (*MessagesReferList) Scan ¶
func (m *MessagesReferList) Scan(src any) error
Scan 实现 sql.Scanner 接口,用于 GORM 从数据库读取
type MessagesReferType ¶
type MessagesReferType uint8
MessagesReferType 消息引用类型
const ( MessagesReferTypeFile MessagesReferType = iota MessagesReferTypeText MessagesReferTypeImage )
消息引用类型
type MessagesRole ¶
type MessagesRole uint8
MessagesRole 消息类型
const ( MessagesRoleUser MessagesRole = iota MessagesRoleAgent MessagesRoleTool MessagesRoleCommunicate )
消息引用类型
type ReferFiles ¶
type ReferFiles struct {
ChatID uint32 `gorm:"primaryKey"`
Path string `gorm:"primaryKey"`
Content string `gorm:"type:text"`
ReadOnly bool
Chats Chats `gorm:"foreignKey:ChatID;constraints:OnDelete:RESTRICT;OnUpdate:CASCADE"`
}
ReferFiles 引用的文件列表
type Scopes ¶
type Scopes struct {
ChatID uint32 `gorm:"primaryKey;column:chat_id"`
Name string `gorm:"primaryKey;column:name"`
Enabled bool `gorm:"column:enabled"`
Chats *Chats `gorm:"foreignKey:ChatID;references:ID"`
}
Scopes 存储命名空间启用状态
type SubAgents ¶
type SubAgents struct {
ID string `gorm:"primaryKey"`
// ChatID uint32
AgentID string
BindPath string
Deleted bool
LastSummary string
}
SubAgents 子 agents 列表