chatservice

package
v0.28.5 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package chatservice persists the conversation thread. Terminal output, file reads, and agent steps are stored here so the thread survives restarts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompactHistory

func CompactHistory(ctx context.Context, exec ChainExecutor, chain *taskengine.TaskChainDefinition, history []taskengine.Message, keep int) ([]taskengine.Message, error)

CompactHistory summarizes the older portion of a conversation into a single <compact-summary> user message. Leading system messages and the last `keep` messages are preserved verbatim; everything between them is replaced by the summary the chain produces.

The caller is responsible for setting the chain's template vars (model, provider, …) on ctx via taskengine.WithTemplateVars before calling.

Types

type ChainExecutor

type ChainExecutor interface {
	Execute(ctx context.Context, chain *taskengine.TaskChainDefinition, input any, inputType taskengine.DataType) (any, taskengine.DataType, []taskengine.CapturedStateUnit, error)
}

ChainExecutor runs a task chain over a history. It is satisfied by enginesvc.Engine.TaskService (execservice.TasksEnvService) — the seam lets CompactHistory stay free of the engine and cobra wiring so both the CLI (`session fork --summary`) and the ACP `/compact` command can call it.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(workspaceID string) *Manager

func (*Manager) AddInstruction

func (m *Manager) AddInstruction(ctx context.Context, tx libdb.Exec, id string, sendAt time.Time, message string) error

AddInstruction inserts a system message into an existing chat index.

func (*Manager) AppendMessage

func (m *Manager) AppendMessage(_ context.Context, messages []taskengine.Message, sendAt time.Time, message string, role string) ([]taskengine.Message, error)

AppendMessage appends a message to an in-memory slice (no DB write). Call PersistDiff afterwards to persist the result.

func (*Manager) ClearSession

func (m *Manager) ClearSession(ctx context.Context, tx libdb.Exec, sessionID string) error

ClearSession removes all messages for a session while keeping the index, so the session keeps its identity and name but starts a fresh conversation.

func (*Manager) DeleteSession

func (m *Manager) DeleteSession(ctx context.Context, tx libdb.Exec, sessionID string, identity string) error

DeleteSession removes all messages and the index for a session.

func (*Manager) ListMessages

func (m *Manager) ListMessages(ctx context.Context, tx libdb.Exec, subjectID string) ([]taskengine.Message, error)

ListMessages retrieves all stored messages for a given subject ID.

func (*Manager) PersistDiff

func (m *Manager) PersistDiff(ctx context.Context, tx libdb.Exec, subjectID string, hist []taskengine.Message) error

PersistDiff surgically appends only new messages by comparing existing IDs.

func (*Manager) RenameSession

func (m *Manager) RenameSession(ctx context.Context, tx libdb.Exec, sessionID string, name string) error

RenameSession updates the human-readable name of a session.

Jump to

Keyboard shortcuts

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