transcript

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package transcript assembles canonical replay messages from persisted session events.

Index

Constants

View Source
const (
	MarkerPromptCancel      = "transcript_marker.prompt_cancel"
	MarkerPromptTimeout     = "transcript_marker.prompt_timeout"
	MarkerPromptInterrupted = "transcript_marker.prompt_interrupted"
	MarkerPromptSteered     = "transcript_marker.prompt_steered"
	MarkerPromptQueued      = "transcript_marker.prompt_queued"
	MarkerPromptAccepted    = "transcript_marker.prompt_accepted"
	MarkerPromptDropped     = "transcript_marker.prompt_dropped"
	MarkerSessionUnhealthy  = "transcript_marker.session_unhealthy"
	MarkerSessionRecovered  = "transcript_marker.session_recovered"
	MarkerProviderFailure   = "transcript_marker.provider_failure"
	MarkerMCPAuthRequired   = "transcript_marker.mcp_auth_required"
)
View Source
const (
	UIRoleSystem    = "system"
	UIRoleUser      = "user"
	UIRoleAssistant = "assistant"
)
View Source
const CanonicalSchema = "agh.session.event.v1"

CanonicalSchema is the stored envelope schema for transcript-aware session events.

Variables

This section is empty.

Functions

func JoinUIMessageText

func JoinUIMessageText(messages []UIMessage) string

JoinUIMessageText joins visible text parts across all messages with newlines.

func MarshalAgentEvent

func MarshalAgentEvent(event acp.AgentEvent) (string, error)

MarshalAgentEvent converts a runtime ACP event into the canonical stored payload.

func RedactAgentEvent

func RedactAgentEvent(event acp.AgentEvent) acp.AgentEvent

RedactAgentEvent removes displayable secret material before an ACP event is stored, replayed, or streamed to a caller.

func UIMessageText

func UIMessageText(message UIMessage) string

UIMessageText returns the concatenated visible text parts for one UI message.

func UnmarshalAgentEvent

func UnmarshalAgentEvent(payload string) (acp.AgentEvent, error)

UnmarshalAgentEvent converts a canonical stored payload back into an ACP event.

Types

type Assembler

type Assembler interface {
	Assemble(events []store.SessionEvent) ([]Message, error)
}

Assembler assembles persisted session events into the canonical transcript shape.

type Marker

type Marker struct {
	Kind       string          `json:"kind"`
	OccurredAt time.Time       `json:"occurred_at"`
	Summary    string          `json:"summary"`
	Evidence   map[string]any  `json:"evidence,omitempty"`
	Diagnostic json.RawMessage `json:"diagnostic,omitempty"`
}

Marker is the canonical transcript marker payload persisted as a typed event.

func NewMarker

func NewMarker(kind string, summary string, occurredAt time.Time, evidence map[string]any) (Marker, error)

NewMarker builds a redacted marker payload from daemon-owned runtime evidence.

func ParseMarker

func ParseMarker(raw json.RawMessage) (Marker, bool)

ParseMarker decodes and validates a persisted marker payload.

func (Marker) AgentEvent

func (m Marker) AgentEvent(sessionID string, turnID string) (acp.AgentEvent, error)

AgentEvent converts the marker to the durable transcript marker event shape.

func (Marker) Normalize

func (m Marker) Normalize() Marker

Normalize returns a redacted, UTC-normalized marker copy.

func (Marker) Validate

func (m Marker) Validate() error

Validate ensures the marker is one of the closed runtime marker vocabulary.

type Message

type Message struct {
	ID               string          `json:"id"`
	Role             Role            `json:"role"`
	Content          string          `json:"content"`
	Thinking         string          `json:"thinking,omitempty"`
	ThinkingComplete bool            `json:"thinking_complete"`
	ToolName         string          `json:"tool_name,omitempty"`
	ToolInput        json.RawMessage `json:"tool_input,omitempty"`
	ToolResult       *ToolResult     `json:"tool_result,omitempty"`
	ToolError        bool            `json:"tool_error"`
	Timestamp        time.Time       `json:"timestamp"`
}

Message is the canonical replay message returned to transport callers.

func Assemble

func Assemble(events []store.SessionEvent) ([]Message, error)

Assemble returns the canonical replay transcript for the provided persisted events.

type Role

type Role string

Role is the renderable chat role emitted by the canonical transcript API.

const (
	RoleUser       Role = "user"
	RoleAssistant  Role = "assistant"
	RoleToolCall   Role = "tool_call"
	RoleToolResult Role = "tool_result"
	RoleSystem     Role = "system"
)

type ToolResult

type ToolResult struct {
	Stdout          string          `json:"stdout,omitempty"`
	Stderr          string          `json:"stderr,omitempty"`
	FilePath        string          `json:"file_path,omitempty"`
	Content         string          `json:"content,omitempty"`
	StructuredPatch json.RawMessage `json:"structured_patch,omitempty"`
	Error           string          `json:"error,omitempty"`
	RawOutput       json.RawMessage `json:"raw_output,omitempty"`
}

ToolResult is the canonical renderable tool output shape for replay.

type UIAgentEventPayload

type UIAgentEventPayload struct {
	Type       string                `json:"type"`
	SessionID  string                `json:"session_id,omitempty"`
	TurnID     string                `json:"turn_id,omitempty"`
	RequestID  string                `json:"request_id,omitempty"`
	Timestamp  string                `json:"timestamp,omitempty"`
	Text       string                `json:"text,omitempty"`
	Title      string                `json:"title,omitempty"`
	ToolCallID string                `json:"tool_call_id,omitempty"`
	StopReason string                `json:"stop_reason,omitempty"`
	Action     string                `json:"action,omitempty"`
	Resource   string                `json:"resource,omitempty"`
	Decision   string                `json:"decision,omitempty"`
	Error      string                `json:"error,omitempty"`
	Failure    *store.SessionFailure `json:"failure,omitempty"`
	Usage      *UITokenUsagePayload  `json:"usage,omitempty"`
	Runtime    *acp.RuntimeActivity  `json:"runtime,omitempty"`
	Raw        json.RawMessage       `json:"raw,omitempty"`
}

UIAgentEventPayload mirrors the prompt-stream data payload shape.

func UIAgentEventPayloadFromEvent

func UIAgentEventPayloadFromEvent(event acp.AgentEvent) UIAgentEventPayload

UIAgentEventPayloadFromEvent converts an ACP event into the prompt-stream data payload.

type UIMessage

type UIMessage struct {
	ID       string          `json:"id"`
	Role     string          `json:"role"`
	Metadata json.RawMessage `json:"metadata,omitempty"`
	Parts    []UIMessagePart `json:"parts"`
}

UIMessage mirrors the AI SDK UIMessage wire shape used by the web client.

func ToUIMessages

func ToUIMessages(events []store.SessionEvent) ([]UIMessage, error)

ToUIMessages projects persisted session events into AI SDK UIMessage objects.

type UIMessagePart

type UIMessagePart struct {
	Type        string          `json:"type"`
	ID          string          `json:"id,omitempty"`
	Text        string          `json:"text,omitempty"`
	State       string          `json:"state,omitempty"`
	ToolName    string          `json:"toolName,omitempty"`
	ToolCallID  string          `json:"toolCallId,omitempty"`
	Title       string          `json:"title,omitempty"`
	Input       json.RawMessage `json:"input,omitempty"`
	RawInput    json.RawMessage `json:"rawInput,omitempty"`
	Output      json.RawMessage `json:"output,omitempty"`
	ErrorText   string          `json:"errorText,omitempty"`
	Data        json.RawMessage `json:"data,omitempty"`
	Preliminary bool            `json:"preliminary,omitempty"`
}

UIMessagePart mirrors the AI SDK UIMessage part wire shape used by the web client.

type UITokenUsagePayload

type UITokenUsagePayload struct {
	TurnID           string   `json:"turn_id,omitempty"`
	InputTokens      *int64   `json:"input_tokens,omitempty"`
	OutputTokens     *int64   `json:"output_tokens,omitempty"`
	TotalTokens      *int64   `json:"total_tokens,omitempty"`
	ThoughtTokens    *int64   `json:"thought_tokens,omitempty"`
	CacheReadTokens  *int64   `json:"cache_read_tokens,omitempty"`
	CacheWriteTokens *int64   `json:"cache_write_tokens,omitempty"`
	ContextUsed      *int64   `json:"context_used,omitempty"`
	ContextSize      *int64   `json:"context_size,omitempty"`
	CostAmount       *float64 `json:"cost_amount,omitempty"`
	CostCurrency     *string  `json:"cost_currency,omitempty"`
	Timestamp        string   `json:"timestamp,omitempty"`
}

UITokenUsagePayload mirrors the prompt-stream token usage payload.

Jump to

Keyboard shortcuts

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