Module: Mistri::PartialJson

Defined in:
lib/mistri/partial_json.rb

Overview

Parses the JSON prefix a model has emitted so far, so in-flight tool-call arguments are readable before the closing brace arrives. Best effort by contract: never raises, drops a dangling key or half-written token, and returns {} for hopeless input.

Defined Under Namespace

Classes: Parser

Class Method Summary collapse

Class Method Details

.parse(text) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/mistri/partial_json.rb', line 11

def self.parse(text)
  s = text.to_s.strip
  return {} if s.empty?

  value = Parser.new(s).parse
  value.equal?(Parser::NOTHING) ? {} : value
rescue StandardError, SystemStackError
  {}
end