stream

package
v0.47.2 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventSystemInit       = "system.init"
	EventTaskStarted      = "system.task_started"
	EventTaskProgress     = "system.task_progress"
	EventTaskNotification = "system.task_notification"
	EventResult           = "result"
	EventError            = "error"
	EventToolCall         = "tool_call"
)

EventType constants for Claude stream-json output.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Type    string          // top-level type (e.g., "system", "result")
	Subtype string          // parsed from "type.subtype" format (e.g., "init")
	Raw     json.RawMessage // original JSON line
}

Event represents a parsed stream-json event.

func ParseLine

func ParseLine(line []byte) (Event, error)

ParseLine parses a single JSON line into an Event. The line must be a JSON object with a "type" field.

type InitData

type InitData struct {
	MCPServers []string `json:"mcp_servers,omitempty"`
	Tools      []string `json:"tools,omitempty"`
}

InitData holds data from a "system.init" event.

type Parser

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

Parser reads stream-json lines from an io.Reader and emits typed events.

func NewParser

func NewParser(r io.Reader) *Parser

NewParser creates a parser that reads from r.

func (*Parser) Next

func (p *Parser) Next() (Event, error)

Next returns the next event or io.EOF when the stream ends. Malformed lines are logged and skipped.

type ResultData

type ResultData struct {
	CostUSD    float64 `json:"cost_usd"`
	DurationMS int64   `json:"duration_ms"`
	SessionID  string  `json:"session_id"`
	Output     string  `json:"output,omitempty"`
}

ResultData holds extracted data from a "result" event.

Jump to

Keyboard shortcuts

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