session

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(id string) error

Delete удаляет сессию с диска

Types

type Message

type Message struct {
	Role      Role       `json:"role"`
	Content   string     `json:"content"`
	ToolCalls []ToolCall `json:"tool_calls,omitempty"`
	CreatedAt time.Time  `json:"created_at"`
}

Message — одно сообщение в диалоге

type Role

type Role string

Role — роль участника диалога

const (
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
	RoleSystem    Role = "system"
	RoleTool      Role = "tool"
)

type Session

type Session struct {
	ID        string    `json:"id"`
	Title     string    `json:"title"`
	WorkDir   string    `json:"work_dir"`
	Provider  string    `json:"provider"`
	Model     string    `json:"model"`
	Messages  []Message `json:"messages"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Session — сессия диалога с AI

func LoadAll

func LoadAll() ([]*Session, error)

LoadAll загружает все сессии, отсортированные по дате (новые первые)

func New

func New(workDir, provider, model string) *Session

New создаёт новую сессию

func (*Session) APIMessages

func (s *Session) APIMessages() []map[string]string

APIMessages возвращает сообщения в формате для API (без tool results в отдельных полях)

func (*Session) AddMessage

func (s *Session) AddMessage(role Role, content string)

AddMessage добавляет сообщение в сессию

func (*Session) AddToolCall

func (s *Session) AddToolCall(tc ToolCall)

AddToolCall добавляет вызов инструмента к последнему сообщению ассистента

func (*Session) Save

func (s *Session) Save() error

Save сохраняет сессию на диск

type ToolCall

type ToolCall struct {
	Name   string            `json:"name"`
	Params map[string]string `json:"params"`
	Result string            `json:"result,omitempty"`
	Error  string            `json:"error,omitempty"`
}

ToolCall — вызов инструмента в сообщении

Jump to

Keyboard shortcuts

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