Help us shape the future of Go! Take the 2026 Go Developer Survey

event

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: EUPL-1.2 Imports: 4 Imported by: 0

Documentation

Overview

Package event defines the session event log model.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithParent added in v0.4.0

func WithParent(payload any, parentCallID string) any

WithParent returns a copy of payload (a value type) with ParentCallID set. Other payload types, and an empty parentCallID, return payload unchanged.

Types

type AssistantDeltaPayload

type AssistantDeltaPayload struct {
	Text string `json:"text"`
}

AssistantDeltaPayload carries a streamed fragment of an assistant reply.

type AssistantMessagePayload

type AssistantMessagePayload struct {
	Text       string         `json:"text"`
	ToolCalls  []llm.ToolCall `json:"tool_calls,omitempty"`
	Incomplete bool           `json:"incomplete"`
	// ParentCallID is the call_id of the "agent" tool call that produced this
	// event inside a sub-agent run; empty for the main agent.
	ParentCallID string `json:"parent_call_id,omitempty"`
}

AssistantMessagePayload carries a complete assistant reply.

type ContextCompactedPayload

type ContextCompactedPayload struct {
	Summary      string `json:"summary"`
	Replaced     int    `json:"replaced"`
	TokensBefore int    `json:"tokens_before"`
	TokensAfter  int    `json:"tokens_after"`
	// HookContext is the additional context the SessionStart hooks (source
	// "compact") returned after the compaction, if any.
	HookContext string `json:"hook_context,omitempty"`
	// ParentCallID is the call_id of the "agent" tool call that produced this
	// event inside a sub-agent run; empty for the main agent.
	ParentCallID string `json:"parent_call_id,omitempty"`
}

ContextCompactedPayload records a context compaction: the first Replaced conversation messages (the system prompt excluded) were replaced by one user message carrying Summary. Token counts are estimates.

type ErrorPayload

type ErrorPayload struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	// ParentCallID is the call_id of the "agent" tool call that produced this
	// event inside a sub-agent run; empty for the main agent.
	ParentCallID string `json:"parent_call_id,omitempty"`
}

ErrorPayload reports a failure.

type Event

type Event struct {
	ID      string          `json:"id"` // "<session>-<seq>"
	Session string          `json:"session"`
	Seq     uint64          `json:"seq"`
	TS      time.Time       `json:"ts"`
	Type    Type            `json:"type"`
	Payload json.RawMessage `json:"payload"`
}

Event is one entry of a session log.

func New

func New(session string, seq uint64, ts time.Time, t Type, payload any) (Event, error)

New builds an event, marshalling payload into Payload.

type HookCompletedPayload added in v0.5.0

type HookCompletedPayload struct {
	RunID         string          `json:"run_id"`
	HookID        string          `json:"hook_id"`
	Event         string          `json:"event"`
	Status        string          `json:"status"`
	ExitCode      *int            `json:"exit_code,omitempty"`
	Decision      string          `json:"decision,omitempty"`
	Reason        string          `json:"reason,omitempty"`
	UpdatedInput  json.RawMessage `json:"updated_input,omitempty"`
	SystemMessage string          `json:"system_message,omitempty"`
	Stop          bool            `json:"stop,omitempty"`
	StopReason    string          `json:"stop_reason,omitempty"`
	Error         string          `json:"error,omitempty"`
	DurationMS    int64           `json:"duration_ms"`
	Stdout        string          `json:"stdout,omitempty"`
	Stderr        string          `json:"stderr,omitempty"`
	CallID        string          `json:"call_id,omitempty"`
	// ParentCallID is the call_id of the "agent" tool call that produced this
	// event inside a sub-agent run; empty for the main agent.
	ParentCallID string `json:"parent_call_id,omitempty"`
}

HookCompletedPayload closes a hook run started by the HookStarted event RunID. Status is "ok", "blocked", "error", "timeout" or "cancelled". Stdout and Stderr are truncated to 4096 bytes.

type HookStartedPayload added in v0.5.0

type HookStartedPayload struct {
	RunID   string `json:"run_id"`
	HookID  string `json:"hook_id"`
	Event   string `json:"event"`
	Type    string `json:"type"`
	Command string `json:"command,omitempty"`
	Prompt  string `json:"prompt,omitempty"`
	CallID  string `json:"call_id,omitempty"`
	// ParentCallID is the call_id of the "agent" tool call that produced this
	// event inside a sub-agent run; empty for the main agent.
	ParentCallID string `json:"parent_call_id,omitempty"`
}

HookStartedPayload opens a hook run. RunID is the ID of this event ("<session>-<seq>"); HookCompleted carries it back to pair the two events. Type is "command", "prompt" or "agent". Command and Prompt are truncated to 4096 bytes.

type JurisdictionWarningPayload

type JurisdictionWarningPayload struct {
	Provider llm.ProviderInfo `json:"provider"`
	// ParentCallID is the call_id of the "agent" tool call that produced this
	// event inside a sub-agent run; empty for the main agent.
	ParentCallID string `json:"parent_call_id,omitempty"`
}

JurisdictionWarningPayload warns that a provider lies outside the preferred jurisdiction.

type MCPServerInfo

type MCPServerInfo struct {
	ID           string           `json:"id"`
	Jurisdiction llm.Jurisdiction `json:"jurisdiction"`
	Country      string           `json:"country,omitempty"`
}

MCPServerInfo describes an active MCP server (values from the configuration).

type McpServerDownPayload

type McpServerDownPayload struct {
	Server string `json:"server"`
	Error  string `json:"error"`
	// ParentCallID is the call_id of the "agent" tool call that produced this
	// event inside a sub-agent run; empty for the main agent.
	ParentCallID string `json:"parent_call_id,omitempty"`
}

McpServerDownPayload reports an MCP server that is unreachable (at start or during a call). Error is user-facing text.

type PermissionRequestedPayload

type PermissionRequestedPayload struct {
	PermissionID string            `json:"permission_id"`
	Kind         string            `json:"kind"`
	Tool         string            `json:"tool"`
	Paths        []string          `json:"paths,omitempty"`
	Command      string            `json:"command"`
	Provider     *llm.ProviderInfo `json:"provider,omitempty"`
	// HookReason is the reason a PreToolUse hook gave for asking, if any.
	HookReason string `json:"hook_reason,omitempty"`
	// Args holds the arguments that will run when a PreToolUse hook's
	// updatedInput changed them (omitted otherwise): UIs preview these
	// instead of the model's original arguments.
	Args json.RawMessage `json:"args,omitempty"`
	// ParentCallID is the call_id of the "agent" tool call that produced this
	// event inside a sub-agent run; empty for the main agent.
	ParentCallID string `json:"parent_call_id,omitempty"`
}

PermissionRequestedPayload asks for approval of a tool or jurisdiction action. Kind is "tool" or "jurisdiction".

type PermissionResolvedPayload

type PermissionResolvedPayload struct {
	PermissionID string `json:"permission_id"`
	Allowed      bool   `json:"allowed"`
	Remember     bool   `json:"remember"`
	// ParentCallID is the call_id of the "agent" tool call that produced this
	// event inside a sub-agent run; empty for the main agent.
	ParentCallID string `json:"parent_call_id,omitempty"`
}

PermissionResolvedPayload records the answer to a permission request.

type RedactionAppliedPayload

type RedactionAppliedPayload struct {
	Counts map[string]int `json:"counts"`
	// ParentCallID is the call_id of the "agent" tool call that produced this
	// event inside a sub-agent run; empty for the main agent.
	ParentCallID string `json:"parent_call_id,omitempty"`
}

RedactionAppliedPayload counts secrets redacted before sending.

type RewoundFile added in v0.6.0

type RewoundFile struct {
	Path   string `json:"path"`
	Action string `json:"action"`
	Status string `json:"status"`
	Hash   string `json:"hash,omitempty"`
	Error  string `json:"error,omitempty"`
}

RewoundFile is the outcome of restoring one file during a rewind. Action describes what was done to the file and Status its result. Hash is the content hash after the rewind, empty if the file was deleted or unchanged.

type RewoundPayload added in v0.6.0

type RewoundPayload struct {
	ToSeq          uint64        `json:"to_seq"`
	Mode           string        `json:"mode"`
	Files          []RewoundFile `json:"files,omitempty"`
	UntrackedCalls int           `json:"untracked_calls,omitempty"`
	Note           string        `json:"note,omitempty"`
}

RewoundPayload records a rewind to the checkpoint taken before event ToSeq. Mode is the rewind mode (e.g. "code"). Files lists the per-file outcome; UntrackedCalls counts tool calls whose file changes were not tracked. Emitted by the main agent only, so it carries no ParentCallID.

type SessionStartedPayload

type SessionStartedPayload struct {
	Provider    llm.ProviderInfo `json:"provider"`
	ProjectRoot string           `json:"project_root"`
	// Resumed is true when the session was rebuilt from its persisted events.
	Resumed bool `json:"resumed,omitempty"`
	// Instructions lists the project instruction files loaded (e.g. AGENTS.md).
	Instructions []string `json:"instructions,omitempty"`
	// MCP lists the MCP servers active for the session (omitted when none).
	MCP []MCPServerInfo `json:"mcp,omitempty"`
}

SessionStartedPayload opens a session.

type Sink

type Sink interface {
	Write(e Event) error
}

Sink receives events as they are produced.

type SubagentCompletedPayload added in v0.4.0

type SubagentCompletedPayload struct {
	CallID     string `json:"call_id"`
	Status     string `json:"status"`
	Iterations int    `json:"iterations"`
}

SubagentCompletedPayload closes a sub-agent run. Status is "ok", "error" or "cancelled".

type SubagentStartedPayload added in v0.4.0

type SubagentStartedPayload struct {
	CallID      string `json:"call_id"`
	Agent       string `json:"agent"`
	Description string `json:"description"`
}

SubagentStartedPayload opens a sub-agent run launched by the "agent" tool call CallID.

type ToolCallRequestedPayload

type ToolCallRequestedPayload struct {
	CallID string          `json:"call_id"`
	Tool   string          `json:"tool"`
	Args   json.RawMessage `json:"args"`
	// ParentCallID is the call_id of the "agent" tool call that produced this
	// event inside a sub-agent run; empty for the main agent.
	ParentCallID string `json:"parent_call_id,omitempty"`
}

ToolCallRequestedPayload records a tool call requested by the model.

type ToolResultPayload

type ToolResultPayload struct {
	CallID     string `json:"call_id"`
	Tool       string `json:"tool"`
	Content    string `json:"content"`
	IsError    bool   `json:"is_error"`
	Path       string `json:"path"`
	HashBefore string `json:"hash_before"`
	HashAfter  string `json:"hash_after"`
	Denied     string `json:"denied,omitempty"`
	// NoCheckpoint is true when the call changed files but no checkpoint could be saved for them.
	NoCheckpoint bool `json:"no_checkpoint,omitempty"`
	// Untracked is true when the call may have changed files outside the checkpoint tracking (e.g. bash).
	Untracked bool `json:"untracked,omitempty"`
	// ParentCallID is the call_id of the "agent" tool call that produced this
	// event inside a sub-agent run; empty for the main agent.
	ParentCallID string `json:"parent_call_id,omitempty"`
}

ToolResultPayload records the outcome of a tool run. Denied is "policy" when the permission engine or a policy guard refused the call, "user" when the user refused a permission request, and empty otherwise.

type TurnCompletedPayload

type TurnCompletedPayload struct {
	Iterations int    `json:"iterations"`
	Reason     string `json:"reason"`
}

TurnCompletedPayload ends a turn. Reason is "done", "max_iterations", "incomplete", "blocked", "cancelled" or "context_too_large".

type Type

type Type string

Type names the kind of an event. Its value is the constant name.

const (
	SessionStarted      Type = "SessionStarted"
	UserMessage         Type = "UserMessage"
	ContextCompacted    Type = "ContextCompacted"
	JurisdictionWarning Type = "JurisdictionWarning"
	RedactionApplied    Type = "RedactionApplied"
	AssistantDelta      Type = "AssistantDelta"
	AssistantMessage    Type = "AssistantMessage"
	ToolCallRequested   Type = "ToolCallRequested"
	PermissionRequested Type = "PermissionRequested"
	PermissionResolved  Type = "PermissionResolved"
	ToolResult          Type = "ToolResult"
	McpServerDown       Type = "McpServerDown"
	TurnCompleted       Type = "TurnCompleted"
	Error               Type = "Error"
	SubagentStarted     Type = "SubagentStarted"
	SubagentCompleted   Type = "SubagentCompleted"
	HookStarted         Type = "HookStarted"
	HookCompleted       Type = "HookCompleted"
	Rewound             Type = "Rewound"
)

type UserMessagePayload

type UserMessagePayload struct {
	// Text is what the model receives.
	Text string `json:"text"`
	// Typed is what the user actually typed; UIs show it instead of Text when set.
	Typed string `json:"typed,omitempty"`
	// Skill is the name of the skill that produced Text, if any.
	Skill string `json:"skill,omitempty"`
	// SkillSHA256 is the hash of the skill file content used, if any.
	SkillSHA256 string `json:"skill_sha256,omitempty"`
	// HookContext is the additional context a hook returned for the model, if any.
	HookContext string `json:"hook_context,omitempty"`
	// Blocked is true when a hook blocked the message (feedback message).
	Blocked bool `json:"blocked,omitempty"`
	// Hook names the event that produced a feedback message: "Stop" or "SubagentStop".
	Hook string `json:"hook,omitempty"`
	// ParentCallID is the call_id of the "agent" tool call whose sub-agent
	// received this message (SubagentStop feedback); empty for the main agent.
	ParentCallID string `json:"parent_call_id,omitempty"`
}

UserMessagePayload carries a user message.

Jump to

Keyboard shortcuts

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