entity

package
v0.0.0-...-f7d2d6e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChatType    = "chat"
	CreateType  = "create"
	CreatedType = "created" // 服务端回执:会话已就绪,前端可以开始发送消息
	PingType    = "ping"
	PongType    = "pong"
	StopType    = "stop"
)

WebSocket message type constants.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatMessage

type ChatMessage struct {
	Id          uint      `gorm:"primaryKey" json:"id"`
	SessionId   uint      `gorm:"index" json:"session_id"`
	Start       uint64    `json:"start"`
	Offset      uint64    `json:"offset"`
	Role        string    `gorm:"size:32" json:"role"`
	Content     string    `gorm:"type:text" json:"content"`
	ToolCalls   string    `gorm:"type:text" json:"tool_calls,omitempty"`   // JSON-serialized tool calls
	ToolResults string    `gorm:"type:text" json:"tool_results,omitempty"` // JSON-serialized tool results
	CreatedAt   time.Time `json:"created_at"`
}

ChatMessage Chat message

func (ChatMessage) TableName

func (ChatMessage) TableName() string

type ChatSession

type ChatSession struct {
	Id        uint      `gorm:"primaryKey" json:"id"`
	Title     string    `gorm:"size:256" json:"title"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

ChatSession Chat session

func (ChatSession) TableName

func (ChatSession) TableName() string

type ChatSummary

type ChatSummary struct {
	Id        uint      `gorm:"primaryKey" json:"id"`
	SessionId uint      `gorm:"uniqueIndex" json:"session_id"`
	Start     uint64    `json:"start"`
	Role      string    `gorm:"size:32" json:"role"`
	Content   string    `gorm:"type:text" json:"content"` // JSON 序列化的 chat.Blocks
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

ChatSummary 会话压缩摘要:每个会话一条,Start 为压缩分界点。 Start 之前的历史消息在 LLM 上下文中由摘要内容取代,历史消息本身不删除。

func (ChatSummary) TableName

func (ChatSummary) TableName() string

type Message

type Message interface {
	Type() string
}

Message is the common interface shared by all incoming WebSocket messages. Each concrete message type carries only the fields relevant to itself, and is identified by Type().

func ParseMessage

func ParseMessage(data []byte) (Message, error)

ParseMessage 根据 JSON 中的 type 字段,将原始报文解析为对应的具体消息类型。 未知的 type 返回 (nil, nil),由调用方决定如何处理。

type WsChatMessage

type WsChatMessage struct {
	Message  string `json:"message"`
	Thinking string `json:"thinking,omitempty"` // 思考等级:off / low / medium / high
}

WsChatMessage 客户端发送的聊天文本消息。

func (*WsChatMessage) Type

func (m *WsChatMessage) Type() string

type WsCreateMessage

type WsCreateMessage struct {
	SessionId uint   `json:"session_id"`
	Start     uint64 `json:"start"`
}

WsCreateMessage 客户端请求创建/接入会话。

func (*WsCreateMessage) GetSessionId

func (m *WsCreateMessage) GetSessionId() string

GetSessionId 返回字符串形式的会话 ID。

func (*WsCreateMessage) Type

func (m *WsCreateMessage) Type() string

type WsCreatedMessage

type WsCreatedMessage struct {
	MsgType   string `json:"type"`
	SessionId uint   `json:"session_id"`
}

WsCreatedMessage 服务端成功接入会话后发给前端的确认消息。 type 字段参与 JSON 序列化,前端据此判断可以开始发送聊天消息。

func NewCreatedMessage

func NewCreatedMessage(sessionId uint) *WsCreatedMessage

NewCreatedMessage 创建一条会话就绪确认消息。

func (*WsCreatedMessage) Type

func (m *WsCreatedMessage) Type() string

type WsPingMessage

type WsPingMessage struct{}

WsPingMessage 心跳请求。

func (*WsPingMessage) Type

func (m *WsPingMessage) Type() string

type WsPongMessage

type WsPongMessage struct{}

WsPongMessage 心跳响应。

func (*WsPongMessage) Type

func (m *WsPongMessage) Type() string

type WsStopMessage

type WsStopMessage struct{}

WsStopMessage 请求停止当前会话的生成。

func (*WsStopMessage) Type

func (m *WsStopMessage) Type() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL