session

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package session stores an agent conversation as an append-only JSON-lines journal.

Events are the portable transcript. Items are opaque, append-only provider state: a provider hands them out and takes the same bytes back on resume. Metadata belongs to the caller.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kind

type Kind string

Kind is what one journal line holds.

const (
	Head  Kind = "head"
	Event Kind = "event"
	Item  Kind = "item"
)

The kinds of line in a journal.

type Line

type Line struct {
	Kind Kind      `json:"kind"`
	Time time.Time `json:"time"`

	ID       string          `json:"id,omitempty"`
	Metadata json.RawMessage `json:"metadata,omitempty"`
	Event    *agent.Event    `json:"event,omitempty"`
	Payload  json.RawMessage `json:"payload,omitempty"`
}

Line is one journal record. Head records include the original session ID.

type Session

type Session struct {
	ID       string
	Metadata json.RawMessage
	Started  time.Time
	Touched  time.Time
	Events   []agent.Event
	Items    []json.RawMessage
}

Session is a stored conversation.

func List

func List(directory string) ([]*Session, error)

List loads stored sessions, most recently touched first.

func Read

func Read(directory string, id string) (*Session, error)

Read loads one stored session.

type Writer

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

Writer appends records to a session. The file is made by the first record, so an unused session leaves nothing behind.

func Create

func Create(directory string, metadata json.RawMessage) (*Writer, error)

Create starts a session in directory with caller-owned metadata.

func Open

func Open(directory string, id string) (*Writer, error)

Open continues an existing session.

func (*Writer) Close

func (w *Writer) Close() error

Close closes a session that has been stored.

func (*Writer) Event

func (w *Writer) Event(event agent.Event) error

Event appends one portable conversation event.

func (*Writer) ID

func (w *Writer) ID() string

ID is the session's time-ordered identifier.

func (*Writer) Item

func (w *Writer) Item(payload json.RawMessage) error

Item appends one opaque provider-state item.

func (*Writer) Stored

func (w *Writer) Stored() bool

Stored reports whether the lazy writer has made a file.

Jump to

Keyboard shortcuts

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