message

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package message defines Lightcode's canonical conversation message model.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneRaw

func CloneRaw(raw json.RawMessage) json.RawMessage

CloneRaw returns a copy of a raw JSON value.

Types

type ContentPart

type ContentPart struct {
	Type  ContentPartType
	Text  string
	URL   string
	Extra Extra
}

ContentPart is one canonical content item. Opaque parts preserve the full provider wire object in Extra.

func (ContentPart) MarshalJSON

func (p ContentPart) MarshalJSON() ([]byte, error)

MarshalJSON serializes content parts as OpenAI-compatible content objects.

func (*ContentPart) UnmarshalJSON

func (p *ContentPart) UnmarshalJSON(data []byte) error

UnmarshalJSON loads a content part and keeps non-canonical fields in Extra.

type ContentPartType

type ContentPartType string

ContentPartType is the canonical type of a message content part.

const (
	ContentPartText     ContentPartType = "text"
	ContentPartImageURL ContentPartType = "image_url"
	ContentPartOpaque   ContentPartType = "opaque"
)

type Extra

type Extra map[string]json.RawMessage

Extra stores provider-specific JSON fields as raw wire values.

func (Extra) Clone

func (e Extra) Clone() Extra

Clone returns a deep copy of Extra.

func (Extra) WithoutNulls

func (e Extra) WithoutNulls() Extra

WithoutNulls returns a copy without JSON null values.

type ExtraAccumulator

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

ExtraAccumulator accumulates streamed Extra values by first observed JSON kind.

func NewExtraAccumulator

func NewExtraAccumulator() *ExtraAccumulator

NewExtraAccumulator returns an empty accumulator.

func (*ExtraAccumulator) Add

func (a *ExtraAccumulator) Add(key string, value json.RawMessage) error

Add merges one raw JSON value into key's accumulated value.

func (*ExtraAccumulator) Extra

func (a *ExtraAccumulator) Extra() Extra

Extra returns the accumulated values with JSON null entries removed.

type FunctionCall

type FunctionCall struct {
	Name      string `json:"name,omitempty"`
	Arguments string `json:"arguments,omitempty"`
}

FunctionCall is the OpenAI-compatible function call payload.

type Message

type Message struct {
	Role            Role
	Content         []ContentPart
	Refusal         string
	ToolCalls       []ToolCall
	ToolCallID      string
	Name            string
	Extra           Extra
	Source          coremodel.ModelRef
	InternalKind    string
	DisplayMetadata map[string]any
}

Message is Lightcode's provider-independent message shape.

func NewText

func NewText(role Role, text string) Message

NewText returns a message with one text content part.

func (*Message) AppendText

func (m *Message) AppendText(text string)

AppendText appends text to the last text part, or creates one.

func (Message) MarshalJSON

func (m Message) MarshalJSON() ([]byte, error)

MarshalJSON serializes messages in the OpenAI-compatible shape, with Extra flattened as provider wire siblings and Lightcode private fields persisted.

func (Message) TextContent

func (m Message) TextContent() string

TextContent returns all text parts joined in order.

func (*Message) UnmarshalJSON

func (m *Message) UnmarshalJSON(data []byte) error

UnmarshalJSON loads both canonical fields and unknown provider wire siblings.

type Role

type Role string

Role is a canonical conversation role.

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

type ToolCall

type ToolCall struct {
	ID       string
	Type     string
	Function FunctionCall
	Extra    Extra
}

ToolCall is an assistant tool call with optional provider-specific data.

func (ToolCall) MarshalJSON

func (tc ToolCall) MarshalJSON() ([]byte, error)

MarshalJSON serializes tool calls with Extra flattened as siblings.

func (*ToolCall) UnmarshalJSON

func (tc *ToolCall) UnmarshalJSON(data []byte) error

UnmarshalJSON loads a tool call and keeps non-canonical fields in Extra.

Jump to

Keyboard shortcuts

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