nsmcp::CodexQuestionRun method connectBridge (protected)
<instance of nsmcp::CodexQuestionRun> connectBridge tools
Defined in /usr/local/ns/tcl/nsmcp/question-backend.tcl
- Parameters:
- tools (required)
- Testcases:
- No testcase defined.
Source code: set file [open [${:backend} cget -bridgeSecretFile] rb] try {set secret [string trim [read $file 4097] "\r\n"]} finally {close $file} if {[string length $secret] < 16 || [string length $secret] > 4096} {error "Invalid Codex bridge credential"} set timeout [expr {min(5.0,max(0.001,(${:deadline}-[clock milliseconds])/1000.0))}] lassign [ns_sockopen -timeout $timeout [${:backend} cget -bridgeHost] [${:backend} cget -bridgePort]] :channel :writeChannel foreach channel [list ${:channel} ${:writeChannel}] { fconfigure $channel -encoding utf-8 -translation lf -buffering line -blocking false } set fields [list bridge number 1 secret string $secret tools array $tools observer string ${:observer} timeout number [${:backend} cget -timeout]] puts ${:writeChannel} [ns_json value -- [list {} object $fields]] flush ${:writeChannel} while {1} { if {[clock milliseconds] >= ${:deadline}} {error "Codex bridge handshake timed out"} if {![:emit {type check}]} {error "Question cancelled"} set n [gets ${:channel} line] if {$n >= 0} {break} if {[eof ${:channel}]} {error "Codex bridge closed its connection"} if {[string bytelength $line] > 65536} {error "Invalid Codex bridge handshake"} ns_sleep 0.01 } if {[string bytelength $line] > 65536 || [catch {ns_json parse -- $line} reply] || ![dict exists $reply bridge] || [dict get $reply bridge] ne "1" || ![dict exists $reply ok] || [dict get $reply ok] ne "true"} { error "Codex bridge rejected or unavailable; check its secret and service configuration" }XQL Not present: Generic, PostgreSQL, Oracle
![[i]](/resources/acs-subsite/ZoomIn16.gif)