Documentation
¶
Overview ¶
Package models holds the plain Go structs that gorm/gen generates type-safe repositories from. One file per model; shared fields live in Base. The SQL migrations (internal/pkg/db/migrations, run by the DB connection layer) are the source of truth for the schema — these struct tags are only gorm decoration, not a second schema definition. Never hand-edit the generated repositories; change a model or migration and re-run `make generate`.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Base ¶
Base is embedded by every model: a UUID id (primary key by gorm convention) plus timestamps and the soft-delete column.
type Chat ¶
type Chat struct {
Base
UserID uuid.UUID
Title string
ModelID string
Temperature *float64
TopP *float64
ReasoningEffort string
MaxOutputTokens *int
MaxHistoryTokens *int
// DisabledMCPServerIDs is the per-chat set of MCP server IDs whose tools
// are withheld from this chat's turns. Empty (the default) means every
// globally-enabled server is available. Explicit column tag: gorm's
// default namer would mangle the MCP/IDs acronyms. See core/chats filter.
//nolint:lll // struct tag + generic type won't fit 80 cols; not splittable
DisabledMCPServerIDs datatypes.JSONSlice[uuid.UUID] `gorm:"column:disabled_mcp_server_ids"`
}
Chat is one conversation, owned by a user. ModelID names the model profile (from chatz.yaml) the chat runs against. The generation settings are per-chat overrides: a nil pointer / empty ReasoningEffort means "unset" — the provider default applies (temperature/top_p/reasoning) or no cap is imposed (max_output/max_history tokens).
type LLMUsage ¶
type LLMUsage struct {
Base
Service string
Stage string
Model string
ReasoningEffort string
PromptTokens int64
CachedPromptTokens int64
CompletionTokens int64
ReasoningTokens int64
TotalTokens int64
DurationMs int64
UserID *uuid.UUID
ChatID *uuid.UUID
MessageID *uuid.UUID
RequestID string
ErrorMessage string
}
LLMUsage is one row per upstream LLM call, written best-effort by the usage decorator. Reasoning + cached tokens are broken out from totals so cost dashboards can attribute spend to the owning chat / message.
type MCPServer ¶
type MCPServer struct {
Base
Name string
Transport MCPTransport
Command string
Args datatypes.JSON
URL string
HeadersEnc []byte
EnvEnc []byte
Enabled bool
CreatedBy *uuid.UUID
}
MCPServer is an admin-added MCP server (config-file servers are held in memory, not here). Transport is stdio | http. For stdio, Command + Args spawn the process (EnvEnc holds any env-var secrets, AEAD-encrypted); for http, URL + HeadersEnc reach the endpoint. Both *Enc columns are sealed at rest — secrets never land in plaintext.
type MCPSource ¶
type MCPSource = string
MCPSource records whether a server came from the config file (read-only in the UI) or was added by an admin through the UI (fully editable).
type MCPToolExecution ¶
type MCPToolExecution struct {
Base
MessageID uuid.UUID
Server string
Tool string
Params datatypes.JSON
Result string
IsError bool
DurationMs int64
}
MCPToolExecution records one MCP tool call made while answering a message: which server + tool, the params, the result, and whether it errored. Keeps the tool timeline for a reloaded chat and feeds tool-latency metrics.
func (MCPToolExecution) TableName ¶
func (MCPToolExecution) TableName() string
TableName pins the table name.
type MCPTransport ¶
type MCPTransport = string
MCPTransport is how an MCP server is reached.
const ( MCPTransportStdio MCPTransport = "stdio" MCPTransportHTTP MCPTransport = "http" )
type Message ¶
type Message struct {
Base
Position int64 `gorm:"default:(-)"`
TurnID uuid.UUID `gorm:"default:(-)"`
TurnComplete *bool `gorm:"default:(-)"`
ModelID string
ChatID uuid.UUID
Role MessageRole
Content string
Reasoning string
ProviderReasoning datatypes.JSON
ToolCalls datatypes.JSON
ToolCallID string
IsError bool
// IsInjection marks a row a tool injected into the model's context rather
// than something the user or the model said. Injections are per-run
// scaffolding, so only one is ever stored: the trailing one a run ended on,
// kept so an interrupted turn is not silently missing the instruction that
// was pending when it stopped. The flag is what keeps it OUT of a rebuilt
// history — a row that exists as a record, not as conversation.
IsInjection bool
UISpec datatypes.JSON
InputTokens int64
OutputTokens int64
}
Message is one turn item in a chat. Role is user | assistant | tool, plus system for a stored injection (see IsInjection). Assistant rows may carry a Reasoning trace, streamed ToolCalls, and a rendered UISpec; tool rows carry the result keyed by ToolCallID plus whether it was an error (IsError). The set reconstructs the timeline.
type MessageRole ¶
type MessageRole = string
MessageRole is the author of a chat message. Finite domain enum; alias form (no methods) so it marshals to/from a plain string at the DB + JSON boundary.
const ( MessageRoleUser MessageRole = "user" MessageRoleAssistant MessageRole = "assistant" MessageRoleTool MessageRole = "tool" // MessageRoleSystem is only ever stored for a tool's message injection // that a run ended on. Ordinary system prompts are built per request and // never persisted, so a stored system row always has IsInjection set. MessageRoleSystem MessageRole = "system" )
type Session ¶
Session is a server-side login session. Only the hash of the opaque token is stored; the raw token lives in the client's HttpOnly cookie.