conversation

package
v0.1.13 Latest Latest
Warning

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

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

Documentation

Overview

Package conversation contains conversation-domain contracts and helpers.

It defines conversation/message/turn mutable types, transcript helpers, and convenience options used by runtime services and SDK layers.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidInput = errInvalidInput{}

ErrInvalidInput is returned when required inputs are missing.

Functions

func DecodeInlineBody added in v0.1.8

func DecodeInlineBody(inline string, compression string) string

Types

type Client

type Client interface {
	GetConversation(ctx context.Context, id string, options ...Option) (*Conversation, error)
	GetConversations(ctx context.Context, input *Input) ([]*Conversation, error)
	PatchConversations(ctx context.Context, conversations *MutableConversation) error
	GetPayload(ctx context.Context, id string) (*Payload, error)
	PatchPayload(ctx context.Context, payload *MutablePayload) error
	PatchMessage(ctx context.Context, message *MutableMessage) error
	GetMessage(ctx context.Context, id string, options ...Option) (*Message, error)
	GetMessageByElicitation(ctx context.Context, conversationID, elicitationID string) (*Message, error)
	PatchModelCall(ctx context.Context, modelCall *MutableModelCall) error
	PatchToolCall(ctx context.Context, toolCall *MutableToolCall) error
	PatchTurn(ctx context.Context, turn *MutableTurn) error
	DeleteConversation(ctx context.Context, id string) error
	// DeleteMessage removes a message from the conversation and internal indexes.
	DeleteMessage(ctx context.Context, conversationID, messageID string) error
}

type Conversation

type Conversation agconv.ConversationView

func (*Conversation) GetTranscript

func (c *Conversation) GetTranscript() Transcript

func (*Conversation) HasConversationParent

func (c *Conversation) HasConversationParent() bool

type GeneratedFile

type GeneratedFile = gfread.GeneratedFileView

type GeneratedFileClient

type GeneratedFileClient interface {
	GetGeneratedFiles(ctx context.Context, input *gfread.Input) ([]*gfread.GeneratedFileView, error)
	PatchGeneratedFile(ctx context.Context, generatedFile *gfwrite.GeneratedFile) error
}

GeneratedFileClient is an optional extension implemented by concrete conversation clients that support generated-file persistence.

type GetRequest

type GetRequest struct {
	Id                string
	Since             string
	IncludeTranscript bool
	IncludeModelCall  bool
	IncludeToolCall   bool
}

GetRequest defines parameters to retrieve a conversation view.

type GetResponse

type GetResponse struct {
	Conversation *Conversation
}

GetResponse wraps the conversation view.

type IndexedMessages

type IndexedMessages map[string]*Message

func (IndexedMessages) BuildMatchIndex

func (n IndexedMessages) BuildMatchIndex(anchorID string, anchorTime time.Time) map[string]bool

BuildMatchIndex returns a set of tool-call opIds that should be included for a continuation anchored at anchorID/anchorTime.

type Input

type Input = agconv.ConversationInput

type Message

type Message agconv.MessageView

func (*Message) GetContent

func (m *Message) GetContent() string

GetContent returns the printable content for this message. - For tool-call messages, it prefers the response payload inline body. - For user/assistant messages, it returns the message content field.

func (*Message) GetContentPreferContent

func (m *Message) GetContentPreferContent() string

func (*Message) IsArchived

func (m *Message) IsArchived() bool

func (*Message) IsInterim

func (m *Message) IsInterim() bool

func (*Message) NewMutable

func (m *Message) NewMutable() *MutableMessage

func (*Message) ToolCallArguments

func (m *Message) ToolCallArguments() map[string]interface{}

ToolCallArguments returns parsed arguments for a tool-call message. It prefers the request payload inline JSON body when present. When parsing fails or no payload is present, it returns an empty map.

type MessageOption

type MessageOption func(m *MutableMessage)

MessageOption configures a MutableMessage prior to persistence.

func WithArchived

func WithArchived(v int) MessageOption

func WithAttachmentPayloadID

func WithAttachmentPayloadID(id string) MessageOption

func WithContent

func WithContent(content string) MessageOption

func WithContextSummary

func WithContextSummary(s string) MessageOption

Optional summaries/tags (set via raw fields when no setter exists)

func WithConversationID

func WithConversationID(id string) MessageOption

func WithCreatedAt

func WithCreatedAt(t time.Time) MessageOption

Metadata and attribution

func WithCreatedByUserID

func WithCreatedByUserID(id string) MessageOption

func WithElicitationID

func WithElicitationID(id string) MessageOption

func WithElicitationPayloadID

func WithElicitationPayloadID(id string) MessageOption

func WithId

func WithId(id string) MessageOption

Core identifiers and linkage

func WithInterim

func WithInterim(v int) MessageOption

func WithIteration

func WithIteration(v int) MessageOption

func WithLinkedConversationID

func WithLinkedConversationID(id string) MessageOption

func WithMode

func WithMode(mode string) MessageOption

func WithNarration added in v0.1.8

func WithNarration(preamble string) MessageOption

func WithParentMessageID

func WithParentMessageID(id string) MessageOption

func WithPhase added in v0.1.8

func WithPhase(phase string) MessageOption

func WithRawContent

func WithRawContent(content string) MessageOption

func WithRole

func WithRole(role string) MessageOption

Message content and semantics

func WithSequence

func WithSequence(v int) MessageOption

func WithStatus

func WithStatus(status string) MessageOption

func WithSupersededBy

func WithSupersededBy(id string) MessageOption

func WithTags

func WithTags(s string) MessageOption

func WithToolName

func WithToolName(name string) MessageOption

func WithTurnID

func WithTurnID(id string) MessageOption

func WithType

func WithType(typ string) MessageOption

func WithUpdatedAt

func WithUpdatedAt(t time.Time) MessageOption

type Messages

type Messages []*Message

func (Messages) LatestByCreatedAt

func (m Messages) LatestByCreatedAt() *Message

LatestByCreatedAt returns the last non-nil message by CreatedAt timestamp. When messages are empty or all nil, it returns nil.

func (Messages) SortByCreatedAt

func (m Messages) SortByCreatedAt(asc bool)

SortByCreatedAt sorts the messages in-place by CreatedAt. When asc is true, earlier messages come first; otherwise latest first.

func (Messages) SortedByCreatedAt

func (m Messages) SortedByCreatedAt(asc bool) Messages

SortedByCreatedAt returns a new slice with messages ordered by CreatedAt. When asc is true, earlier messages come first; otherwise latest first.

type MutableConversation

type MutableConversation = convw.Conversation

func NewConversation

func NewConversation() *MutableConversation

NewConversation allocates a mutable conversation with Has populated.

type MutableGeneratedFile

type MutableGeneratedFile = gfwrite.GeneratedFile

func NewGeneratedFile

func NewGeneratedFile() *MutableGeneratedFile

NewGeneratedFile allocates a mutable generated file with Has populated.

type MutableMessage

type MutableMessage = msgw.Message

func AddMessage

func AddMessage(ctx context.Context, cl Client, turn *runtimerequestctx.TurnMeta, opts ...MessageOption) (*MutableMessage, error)

AddMessage creates and persists a message attached to the given turn using the provided options. It sets sensible defaults: id (uuid), conversation/turn/parent ids from turn, and type "text" unless overridden. Returns the message id.

func NewMessage

func NewMessage() *MutableMessage

NewMessage allocates a mutable message with Has populated.

type MutableModelCall

type MutableModelCall = mcall.ModelCall

func NewModelCall

func NewModelCall() *MutableModelCall

NewModelCall allocates a mutable model call with Has populated.

type MutablePayload

type MutablePayload = payloadw.Payload

func NewPayload

func NewPayload() *MutablePayload

NewPayload allocates a mutable payload with Has populated.

type MutableToolCall

type MutableToolCall = toolcall.ToolCall

func NewToolCall

func NewToolCall() *MutableToolCall

NewToolCall allocates a mutable tool call with Has populated.

type MutableTurn

type MutableTurn = turnw.Turn

func NewTurn

func NewTurn() *MutableTurn

NewTurn allocates a mutable turn with Has populated.

type Option

type Option func(input *Input)

func WithIncludeModelCall

func WithIncludeModelCall(include bool) Option

func WithIncludeToolCall

func WithIncludeToolCall(include bool) Option

func WithIncludeTranscript

func WithIncludeTranscript(include bool) Option

func WithSince

func WithSince(since string) Option

WithSince sets the optional since parameter controlling transcript filtering.

func WithToolFeedSpec

func WithToolFeedSpec(ext []*tool.FeedSpec) Option

WithToolFeedSpec populates the transient FeedSpec list on the input so that OnRelation hooks can compute tool executions based on metadata.

type Payload

type Payload = payloadread.PayloadView

type ResponsePayloadView

type ResponsePayloadView = agconv.ModelCallStreamPayloadView

type Service

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

Service is a thin wrapper around API to support request/response types.

func NewService

func NewService(api Client) *Service

func (*Service) Get

func (s *Service) Get(ctx context.Context, req GetRequest) (*GetResponse, error)

Get fetches a conversation based on the request fields.

type ToolCallView

type ToolCallView = agconv.ToolCallView

type Transcript

type Transcript []*Turn

func (*Transcript) Filter

func (t *Transcript) Filter(f func(v *Message) bool) Messages

func (*Transcript) History

func (t *Transcript) History(minimal bool) []*binding.Message

func (Transcript) Last

func (t Transcript) Last() Transcript

func (*Transcript) LastAssistantMessage

func (t *Transcript) LastAssistantMessage() *Message

LastAssistantMessage returns the last assistant text message in this transcript. It scans turns from the end and messages from the end to preserve chronology.

func (*Transcript) LastAssistantMessageWithModelCall

func (t *Transcript) LastAssistantMessageWithModelCall() *Message

LastAssistantMessageWithModelCall returns the last assistant text message in this transcript that has a model call. It scans turns from the end and messages from the end to preserve chronology.

func (*Transcript) LastElicitationMessage

func (t *Transcript) LastElicitationMessage() *Message

func (Transcript) UniqueToolNames

func (t Transcript) UniqueToolNames() []string

UniqueToolNames returns a de-duplicated list of tool names (service/method) observed across all messages in the transcript, preserving encounter order.

type Turn

func (*Turn) Filter

func (t *Turn) Filter(f func(v *Message) bool) Messages

func (*Turn) GetMessages

func (t *Turn) GetMessages() Messages

func (*Turn) SetMessages

func (t *Turn) SetMessages(msg Messages)

func (*Turn) ToolCalls

func (t *Turn) ToolCalls() Messages

Directories

Path Synopsis
Package cancel provides conversation/turn cancellation registries.
Package cancel provides conversation/turn cancellation registries.

Jump to

Keyboard shortcuts

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