pig/obs/session
JSONL session writer — records SessionEvents to a file for replay.
OTP actor that receives SessionEvents and appends them as JSONL lines. Two modes:
record()— fire-and-forget, never blocks the agent.record_sync()— synchronous call, blocks until written. For testing.
Types
Replay error type for session reconstruction.
pub type ReplayError {
FileError(String)
ParseError(String)
}
Constructors
-
FileError(String) -
ParseError(String)
Opaque handle to the session writer actor.
pub opaque type SessionWriter
Values
pub fn decode_message() -> decode.Decoder(message.Message)
Decode a Message from JSON.
pub fn decode_tool_call() -> decode.Decoder(message.ToolCall)
Decode a ToolCall from JSON.
pub fn format_event(event: events.SessionEvent) -> String
Format a SessionEvent as a JSON string (pure function, no side effects).
pub fn record(
writer: SessionWriter,
event: events.SessionEvent,
) -> Nil
Record a session event. Fire-and-forget: does not block.
pub fn record_sync(
writer: SessionWriter,
event: events.SessionEvent,
) -> Nil
Record a session event synchronously. Blocks until the event is written to disk. Use this in tests for deterministic assertions.
pub fn replay(
path: String,
) -> Result(List(message.Message), ReplayError)
Replay a JSONL session file and reconstruct the message history.
This compatibility wrapper keeps the original message-only API. New code
that also needs the durable inference settings can use replay_with_settings.
pub fn replay_with_settings(
path: String,
) -> Result(
#(
List(message.Message),
option.Option(provider.InferenceSettings),
),
ReplayError,
)
Replay a JSONL session and return its history and latest persisted settings.
Sessions written before settings were persisted return None. Only an
explicit inference_settings_changed event changes the persisted setting;
requested settings on inference events describe that request only.
pub fn start(
path: String,
) -> Result(SessionWriter, actor.StartError)
Start a new session writer actor that appends events to the given file.
pub fn start_consumer(
path: String,
) -> Result(consumer_spec.StartedConsumer, actor.StartError)
Start a managed session consumer and return its owned endpoint.
pub fn stop_consumer(
consumer: consumer_spec.StartedConsumer,
) -> Nil
Stop a managed session consumer via its typed Stop message.
pub fn supervised(
path: String,
name: process.Name(consumer_spec.SupervisedMessage),
) -> supervision.ChildSpecification(Nil)
Create a supervised session consumer with a graceful drain control.