Files
enkly-ai/services/conversation/internal/domain/conversation.go
enkly 79ce8dc4c0
Some checks failed
Go CI Pipeline / build_and_test (push) Failing after 22m0s
Init Project
2026-10-30 18:06:55 +01:00

71 lines
2.2 KiB
Go

// Package domain is the Conversation bounded context's entities and
// repository interfaces — transplanted from internal/db/conversations.go.
package domain
import (
"context"
"errors"
"time"
)
var ErrNotFound = errors.New("conversation: not found")
type Conversation struct {
ID int64
UserID int64
Title string
CreatedAt time.Time
LastMessageAt time.Time
}
type Role string
const (
RoleUser Role = "user"
RoleAssistant Role = "assistant"
RoleSystem Role = "system"
RoleTool Role = "tool"
)
type Message struct {
ID int64
ConversationID int64
Role Role
Content string
ToolName string
CreatedAt time.Time
}
type ToolCall struct {
MessageID int64
ToolName string
ArgumentsJSON string
Result string
IsError bool
}
// ConversationRepository persists Conversation rows, scoped to a
// user_id on every read/write the same way db.conversations.go always
// did — a conversation belonging to another user is simply ErrNotFound,
// never a separate "forbidden" case, matching the monolith's behavior.
type ConversationRepository interface {
Create(ctx context.Context, userID int64, title string) (*Conversation, error)
Get(ctx context.Context, userID, conversationID int64) (*Conversation, error)
List(ctx context.Context, userID int64) ([]*Conversation, error)
MostRecent(ctx context.Context, userID int64) (*Conversation, error)
Rename(ctx context.Context, userID, conversationID int64, title string) (*Conversation, error)
// AutoTitle sets title only if the conversation's title still
// equals the default ("New conversation"), reporting whether it
// actually changed it.
AutoTitle(ctx context.Context, userID, conversationID int64, title string) (bool, error)
Delete(ctx context.Context, userID, conversationID int64) error
CountMessages(ctx context.Context, conversationID int64) (int, error)
}
// MessageRepository persists Message and ToolCall rows.
type MessageRepository interface {
Add(ctx context.Context, conversationID int64, role Role, content, toolName string) (*Message, error)
List(ctx context.Context, conversationID int64) ([]*Message, error)
AddToolCall(ctx context.Context, tc ToolCall) error
}