nsmcp::QuestionService method send (public)
<instance of nsmcp::QuestionService> send context question \ [ handle ] [ backendName ] [ browserTimezone ]
Defined in /usr/local/ns/tcl/nsmcp/question-service.tcl
Queue a question or follow-up with optional browser timezone context.
- Parameters:
- context (required)
- Authenticated owner and server context.
- question (required)
- Original question text, preserved for display.
- handle (optional)
- Existing conversation handle, or empty for a new conversation.
- backendName (optional)
- Backend selection for a new conversation, or empty for its default.
- browserTimezone (optional)
- Valid timezone used as the default unless the question overrides it; empty retains prior context or UTC.
- Returns:
- Rooted JSON triples describing the queued conversation.
- Testcases:
- No testcase defined.
Source code: if {$browserTimezone ne "" && (![regexp {^[A-Za-z0-9_+:/-]{1,128}$} $browserTimezone] || [catch {clock format 0 -timezone $browserTimezone}])} { error "Invalid browser timezone" } set question [string trim $question] if {$question eq "" || [string bytelength $question] > 16384} {error "Supply a question up to 16 KiB"} ns_mutex lock ${:mutex} try { if {$handle eq ""} { :cleanup foreach key [nsv_array names ${:store}] { set old [nsv_get ${:store} $key] if {[dict get $old expires] <= [clock seconds] && [dict get $old status] ni {queued running cancelling}} { :drop $key } } if {[llength [nsv_array names ${:store}]] >= ${:maxConversations}} {error "Conversation limit reached; remove an old conversation"} if {$backendName eq ""} {set backendName [:defaultBackend]} :provider $backendName set handle [ns_crypto::randombytes -encoding hex 32] set record [dict create principal [$context principal] server [$context server] backend $backendName status idle state {} turns {}] } else { set record [:owned $context $handle] if {![dict exists $record backend]} {dict set record backend [:defaultBackend]} if {$backendName ne "" && $backendName ne [dict get $record backend]} { error "Changing backend requires a new conversation" } } if {[dict get $record status] in {queued running cancelling}} {error "A question is already running in this conversation"} if {[llength [dict get $record turns]] >= ${:maxTurns}} {error "Conversation turn limit reached; start a new conversation"} if {$browserTimezone ne ""} {dict set record browserTimezone $browserTimezone} set turn [ns_crypto::randombytes -encoding hex 16] dict set record current $turn dict set record status queued dict set record expires [expr {[clock seconds]+int(${:lifetime})}] dict lappend record turns [dict create id $turn question $question answer {} status queued tools {} error {}] nsv_set ${:store} $handle $record try { ns_job queue -detached ${:queue} [list [self] run $handle $turn] } on error {message options} { dict set record status failed set last [lindex [dict get $record turns] end] dict set last status failed dict set last error "Unable to queue the question" dict set record turns [lreplace [dict get $record turns] end end $last] nsv_set ${:store} $handle $record return -options $options $message } } finally {ns_mutex unlock ${:mutex}} return [:poll $context $handle]XQL Not present: Generic, PostgreSQL, Oracle
![[i]](/resources/acs-subsite/ZoomIn16.gif)