AgentWireProtocol class

The pure event/command mapping and version negotiation for protocol v1.

Constructors

AgentWireProtocol({int version = wireProtocolVersion})
Creates a protocol speaking version. Unsupported versions are a construction-time WireVersionError — a host cannot half-configure the mapping.

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
version → int
The negotiated version; every frame this instance produces carries it.
final

Methods

decodeCommand(Map<String, dynamic> frame) → WireCommand
Decodes a command frame. Unknown kinds return WireUnknownCommand; malformed known frames and unsupported versions throw WireProtocolException/WireVersionError — declared types are the only escapes.
decodeEvent(Map<String, dynamic> frame) → DecodedWireEvent
Decodes an event frame. Unknown kinds (and unknown_event itself) return UnknownWireEvent; malformed known frames and unsupported versions throw WireProtocolException/WireVersionError — declared types are the only escapes (a malformed field must not surface as a raw TypeError from a nested fromJson).
encodeApprovalRequest({required String id, required ApprovalRequest request}) → Map<String, dynamic>
Encodes an in-process ApprovalRequest as an approval_request frame.
encodeAskRequest({required String id, required List<AskQuestion> questions}) → Map<String, dynamic>
Encodes an in-process ask callback's questions as an ask_request.
encodeAssistantEvent(AssistantMessageEvent event) → Map<String, dynamic>
Encodes the nested provider-event discriminator of a message_update frame. partial is never duplicated here — the frame's message field IS the live partial.
encodeCommand(WireCommand command) → Map<String, dynamic>
Encodes a typed command into its canonical frame.
encodeEvent(AgentEvent event) → Map<String, dynamic>
Encodes event into a canonical frame at this protocol's version.
encodeSecretRequest({required String id, required String name, required String reason}) → Map<String, dynamic>
Encodes an in-process request_secret callback inputs as a secret_request.
encodeUnknownEvent({required String originalKind, Map<String, dynamic>? payload}) → Map<String, dynamic>
Builds the documented unknown_event passthrough frame — what a host emits when it must forward a frame it does not understand.
hello({List<int> versions = const [wireProtocolVersion], List<String> caps = const []}) → Map<String, dynamic>
Builds the client hello frame.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited
welcome({int negotiated = wireProtocolVersion, List<String> caps = const []}) → Map<String, dynamic>
Builds the server welcome frame for negotiated.

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

acceptHello(Map<String, dynamic> helloFrame, {List<String> caps = const []}) → ({AgentWireProtocol protocol, Map<String, dynamic> welcome})
Validates a client hello and negotiates the highest mutually supported version. The hello frame's own v participates in negotiation alongside the frame's versions array; negotiation is max-overlap and throws WireVersionError when there is no overlap (the loud unsupported-version error). WireProtocolException is thrown when the frame itself is malformed.
frameLine(Map<String, dynamic> frame) → String
Frames one message as a single NDJSON line (UTF-8 JSON object plus \n). One object per line — NOT JSONP.
isSecretField(String kind, String field) → bool
Whether field of frame kind kind is SECRET-class (E4). The anywhere-rule is NOT dead for registry kinds: a rawBody under secret_response must still be marked, so the registry check and the anywhere-rule OR together (?? would fall through on false).
negotiate(List<int> clientVersions) → int
The highest version from clientVersions this library supports.
parseLine(String line) → Map<String, dynamic>?
Parses one NDJSON line. Blank lines return null; garbage throws FormatException; a line whose JSON is not an object throws WireProtocolException.
redactForLog(Map<String, dynamic> frame) → Map<String, dynamic>
Deep-copies frame with every SECRET-class field replaced by the repo-standard [REDACTED:<kind>] marker — the layered redaction pipeline keys on the kind label, so nested maps inherit the frame's kind (unknown-kind frames mark as [REDACTED:unknown]). Use for LOGGING and PERSISTENCE copies only — the live frame keeps its values so the engine can work.