pub struct PartialJsonParser { /* private fields */ }Expand description
Streaming structural parser for partial Anthropic SSE tool-input JSON.
Feed each InputJsonDelta string via push. When the result is
PrefixState::ValidPrefix with an empty missing_required, the engine may
synthesize a ToolCall and speculatively dispatch it.
§Examples
use zeph_core::agent::speculative::partial_json::{PartialJsonParser, PrefixState};
let mut p = PartialJsonParser::new();
// Simulate incremental SSE deltas
p.push(r#"{"command": "ls "#);
let state = p.push(r#"-la"}"#);
assert!(matches!(state, PrefixState::ValidPrefix { .. }));Implementations§
Source§impl PartialJsonParser
impl PartialJsonParser
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new parser. Call set_required to configure
the list of required schema keys before the first push.
Sourcepub fn set_required(&mut self, required: Vec<String>)
pub fn set_required(&mut self, required: Vec<String>)
Set the list of keys required by the tool’s input_schema.
Keys in this list that are absent from the accumulated buffer are reported as
missing_required in PrefixState::ValidPrefix.
Sourcepub fn push(&mut self, delta: &str) -> PrefixState
pub fn push(&mut self, delta: &str) -> PrefixState
Append delta and re-scan the buffer.
Returns the current PrefixState. May be called repeatedly; each call
replaces the previous result.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PartialJsonParser
impl RefUnwindSafe for PartialJsonParser
impl Send for PartialJsonParser
impl Sync for PartialJsonParser
impl Unpin for PartialJsonParser
impl UnsafeUnpin for PartialJsonParser
impl UnwindSafe for PartialJsonParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request