nsmcp::QuestionBackend method canonicalResult (public)

 <instance of nsmcp::QuestionBackend[i]> canonicalResult json

Defined in /usr/local/ns/tcl/nsmcp/question-backend.tcl

Remove redundant textual copies of structured tool evidence. Retain typed structured content and unrelated content blocks; leave nonmatching input unchanged.

Parameters:
json (required)
Serialized JSON supplied by the backend transport.
Returns:
The canonical JSON result string.

Testcases:
No testcase defined.
Source code:
if {[catch {
    ns_json parse -output triples -- $json
} root] || [lindex $root 1] ne "object"} {
    return $json
}
if {[catch {
    ns_json triples gettype -path structuredContent -- $root
}]} {
    return $json
}
set structured [list {} [ns_json triples gettype -path structuredContent -- $root] [ns_json triples getvalue -output triples -path structuredContent -- $root]]
set duplicate [ns_json value -- $structured]
set fields {}
foreach {key type value} [lindex $root 2] {
    if {$key eq "content" && $type eq "array"} {
        set content {}
        set index 0
        foreach {i kind members} $value {
            set omit false
            if {$kind eq "object"} {
                set item [ns_json parse [ns_json value -- [list {} object $members]]]
                if {[dict exists $item type] && [dict get $item type] eq "text"
                    && [dict exists $item text] && [dict get $item text] eq $duplicate} {
                    set omit true
                }
            }
            if {!$omit} {
                lappend content $index $kind $members
                incr index
            }
        }
        set value $content
    }
    lappend fields $key $type $value
}
return [ns_json value -- [list {} object $fields]]
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: