Merge: search finds chats and opens them

This commit is contained in:
2026-11-03 13:02:16 +00:00
31 changed files with 1659 additions and 118 deletions
+2 -36
View File
@@ -701,42 +701,8 @@ func findMatch(value any, text string) (string, bool) {
return "", false
}
// searchSnippet reduces text to a single clean line and centers a short window
// on the first case-insensitive match, folding runes so UTF-8 boundaries are
// never split and the result is always well-formed.
func searchSnippet(text, query string) string {
normalized := protocol.NormalizeText(text)
runes := []rune(normalized)
index := protocol.RuneIndexFold(runes, []rune(query))
if index < 0 {
return truncateRunes(normalized, 80)
}
const margin = 40
start := index - margin
if start < 0 {
start = 0
}
end := index + len([]rune(query)) + margin
if end > len(runes) {
end = len(runes)
}
snippet := string(runes[start:end])
if start > 0 {
snippet = "…" + snippet
}
if end < len(runes) {
snippet = snippet + "…"
}
return snippet
}
func truncateRunes(text string, limit int) string {
runes := []rune(text)
if len(runes) <= limit {
return text
}
return string(runes[:limit]) + "…"
}
// searchSnippet is the shared protocol snippet window.
func searchSnippet(text, query string) string { return protocol.SearchSnippet(text, query) }
func searchPipelineTarget(id int64) string { return fmt.Sprintf("pipeline:%d", id) }
+71 -1
View File
@@ -24,6 +24,12 @@ const (
SearchKindStep = "step"
SearchKindField = "field"
SearchKindArtifact = "artifact"
// SearchKindChat narrows to operator chat sessions. It is not part of
// SearchKinds: the store's all-kind search never includes chats, so an
// older client's reply is unchanged. A client asks for chats with this
// kind as its own request, which the server answers concurrently with
// (and never ahead of or blocking) the run/artifact search.
SearchKindChat = "chat"
)
// SearchKinds is the accepted Kind vocabulary in display order; the CLI help
@@ -52,6 +58,13 @@ const (
// SearchMaxScanSteps bounds how many recorded steps one query inspects while
// scanning input/output/transcript field text.
SearchMaxScanSteps = 2000
// SearchMaxScanChats bounds how many of the most recently used operator
// chats one chat search reads message text from; titles and directories
// of every listed chat are always matched.
SearchMaxScanChats = 24
// SearchChatMessagesPerChat is how many of a chat's newest messages one
// chat search reads.
SearchChatMessagesPerChat = 100
// SearchMaxScanBytes bounds the total field bytes (input_json + output_json +
// evidence_json + transcript) one query decodes and searches before it stops
// and reports Truncated.
@@ -85,12 +98,15 @@ type SearchResponse struct {
ScannedBytes int `json:"scanned_bytes"`
Cap int `json:"cap"`
ScanBoundBytes int `json:"scan_bound_bytes"`
// ScannedChats is how many chat transcripts a chat search read message
// text from (kind chat only); additive, so older peers ignore it.
ScannedChats int `json:"scanned_chats,omitempty"`
}
// SearchResult is one typed, navigable match. Kind selects which payload is
// set; Target is a stable token an existing CLI command can resolve
// (pipeline:<id>, pipeline:<id>:v<version>, run:<id>, run:<id>:<sequence>,
// run:<id>:<sequence>:<field>, or an artifact URL). Score and MatchedField
// run:<id>:<sequence>:<field>, an artifact URL, or chat:<session id>). Score and MatchedField
// expose the ranking tier and why the hit matched so a client can re-rank;
// Recency is the hit's sortable UTC timestamp.
type SearchResult struct {
@@ -105,6 +121,7 @@ type SearchResult struct {
Step *SearchStep `json:"step,omitempty"`
Field *SearchField `json:"field,omitempty"`
Artifact *SearchArtifact `json:"artifact,omitempty"`
Chat *SearchChat `json:"chat,omitempty"`
}
// SearchPipeline is a pipeline name/identity hit: its latest version and stage count.
@@ -166,6 +183,24 @@ type SearchArtifact struct {
URL string `json:"url"`
}
// SearchChat is an operator chat session hit: its registry facts and, for a
// message-text match, the matching message's id, role and a snippet around
// the first match. MatchedField is "title", "directory" or "message".
type SearchChat struct {
SessionID string `json:"session_id"`
Title string `json:"title"`
Directory string `json:"directory,omitempty"`
Backend string `json:"backend,omitempty"`
Closed bool `json:"closed,omitempty"`
UpdatedAt int64 `json:"updated_at,omitempty"`
MessageID string `json:"message_id,omitempty"`
Role string `json:"role,omitempty"`
Snippet string `json:"snippet,omitempty"`
}
// SearchChatTarget is a chat hit's target token.
func SearchChatTarget(sessionID string) string { return "chat:" + sessionID }
// Label is the compact human description of a hit, built from the result's
// typed payload rather than its target token, so it is the single definition
// shared by the CLI and the TUI. A text-field hit's snippet is deliberately not
@@ -198,10 +233,45 @@ func (r SearchResult) Label() string {
if r.Artifact != nil {
return fmt.Sprintf("run %d · step %d · %s · %s", r.Artifact.RunID, r.Artifact.Sequence, r.Artifact.Name, r.Artifact.ContentType)
}
case SearchKindChat:
if r.Chat != nil {
label := "chat · " + r.Chat.Title
if r.Chat.Directory != "" {
label += " · " + r.Chat.Directory
}
return label
}
}
return r.Target
}
// SearchSnippet reduces text to a single clean line and centers a short window
// on the first case-insensitive match, folding runes so UTF-8 boundaries are
// never split and the result is always well-formed. Text with no match is
// truncated from its start.
func SearchSnippet(text, query string) string {
normalized := NormalizeText(text)
runes := []rune(normalized)
index := RuneIndexFold(runes, []rune(query))
if index < 0 {
if len(runes) <= 80 {
return normalized
}
return string(runes[:80]) + "…"
}
const margin = 40
start := max(index-margin, 0)
end := min(index+len([]rune(query))+margin, len(runes))
snippet := string(runes[start:end])
if start > 0 {
snippet = "…" + snippet
}
if end < len(runes) {
snippet = snippet + "…"
}
return snippet
}
// RuneIndexFold returns the rune index where query first matches text
// case-insensitively, or -1 when it does not. It folds runes rather than bytes
// so a caller never splits a UTF-8 boundary, and an empty query never matches.
+67
View File
@@ -0,0 +1,67 @@
package protocol
import (
"encoding/json"
"slices"
"strings"
"testing"
)
// TestSearchChatResultRoundTrip pins the additive chat hit: its payload and
// ScannedChats survive the wire, and a reply without them encodes neither key,
// so an older peer's search_results body is unchanged.
func TestSearchChatResultRoundTrip(t *testing.T) {
response := Message{Type: SearchResults, ID: "c1", SearchResults: &SearchResponse{
Query: "flaky", Kind: SearchKindChat, Cap: 50, ScannedChats: 3,
Results: []SearchResult{{
Kind: SearchKindChat, Target: SearchChatTarget("ses_abc"), Score: 1, MatchedField: "message",
Chat: &SearchChat{SessionID: "ses_abc", Title: "Fix CI", Directory: "/work/repo", Backend: "claude", MessageID: "m9", Role: "assistant", Snippet: "the flaky test", UpdatedAt: 1700000000000},
}},
}}
encoded, err := json.Marshal(response)
if err != nil {
t.Fatal(err)
}
var echoed Message
if err := json.Unmarshal(encoded, &echoed); err != nil {
t.Fatal(err)
}
got := echoed.SearchResults
if got == nil || got.ScannedChats != 3 || got.Kind != SearchKindChat || len(got.Results) != 1 {
t.Fatalf("chat search response lost: %+v", got)
}
hit := got.Results[0]
if hit.Target != "chat:ses_abc" || hit.Chat == nil || *hit.Chat != *response.SearchResults.Results[0].Chat {
t.Fatalf("chat payload lost: %+v", hit)
}
if label := hit.Label(); label != "chat · Fix CI · /work/repo" {
t.Fatalf("label = %q", label)
}
plain, err := json.Marshal(SearchResponse{Results: []SearchResult{{Kind: SearchKindRun, Target: "run:1"}}})
if err != nil {
t.Fatal(err)
}
if strings.Contains(string(plain), "scanned_chats") || strings.Contains(string(plain), `"chat"`) {
t.Fatalf("a run-only reply encodes chat keys: %s", plain)
}
}
// TestSearchKindChatIsNotAStoreKind keeps chats out of the all-kind store
// vocabulary, so an older client's default search never changes shape.
func TestSearchKindChatIsNotAStoreKind(t *testing.T) {
if slices.Contains(SearchKinds, SearchKindChat) {
t.Fatalf("SearchKinds = %v, chat must be requested on its own", SearchKinds)
}
}
func TestSearchSnippetWindowsTheMatch(t *testing.T) {
text := strings.Repeat("a", 60) + " Needle here " + strings.Repeat("b", 60)
got := SearchSnippet(text, "needle")
if !strings.HasPrefix(got, "…") || !strings.HasSuffix(got, "…") || !strings.Contains(got, "Needle") {
t.Fatalf("snippet = %q", got)
}
if got := SearchSnippet("short\nline", "zzz"); got != "short line" {
t.Fatalf("unmatched short snippet = %q", got)
}
}
+228
View File
@@ -0,0 +1,228 @@
package server
import (
"context"
"sort"
"strings"
"time"
"git.a-wan.net/alan/pipelines/internal/pipeline"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
// chatSearchBudget bounds how long one chat search waits for transcript
// readback. Registry (title/directory) hits never wait on it; a transcript
// still unread when it expires is left out and the reply says Truncated.
// It is short because a client that serializes its requests (the app does)
// holds its next request behind this reply. It is a variable so a test can
// shorten it.
var chatSearchBudget = time.Second
// chatSearchConcurrency is how many transcripts one chat search reads at once.
const chatSearchConcurrency = 4
// Chat hit scores: a title match outranks a directory match, which outranks a
// message-text match; recency breaks ties.
const (
chatScoreTitleExact = 4
chatScoreTitle = 3
chatScoreDirectory = 2
chatScoreMessage = 1
)
// isChatSearch reports a search request narrowed to chats. It is answered by
// searchChats, off the connection's read loop, so it never delays the
// run/artifact search a client sends beside it.
func isChatSearch(request protocol.Message) bool {
return request.Type == protocol.Search && request.Search != nil &&
strings.TrimSpace(request.Search.Kind) == protocol.SearchKindChat
}
// chatSearchReply answers one kind=chat search request.
func chatSearchReply(ctx context.Context, request protocol.Message, broker chatBroker, registry operatorRegistry) protocol.Message {
if registry == nil {
return protocol.Message{Type: protocol.Error, ID: request.ID, Error: "chat search unavailable: operator session registry is not configured on this server"}
}
response, err := searchChats(ctx, *request.Search, broker, registry)
if err != nil {
return protocol.Message{Type: protocol.Error, ID: request.ID, Error: err.Error()}
}
return protocol.Message{Type: protocol.SearchResults, ID: request.ID, SearchResults: response}
}
// searchChats matches the operator's chat sessions: the title and directory of
// every listed registry session (one bounded statement), then the newest
// SearchChatMessagesPerChat messages of up to SearchMaxScanChats of the most
// recently used sessions the registry did not already match, read through the
// chat broker concurrently within chatSearchBudget. One session yields at most
// one hit, its best match. A blank query lists the most recent chats.
func searchChats(ctx context.Context, req protocol.SearchRequest, broker chatBroker, registry operatorRegistry) (*protocol.SearchResponse, error) {
query := strings.TrimSpace(req.Query)
response := &protocol.SearchResponse{
Query: req.Query,
Kind: protocol.SearchKindChat,
Results: []protocol.SearchResult{},
Cap: chatSearchLimit(req.Limit),
ScanBoundBytes: protocol.SearchMaxScanBytes,
}
sessions, err := registry.OperatorSessions(ctx)
if err != nil {
return nil, err
}
var results []protocol.SearchResult
var unmatched []pipeline.OperatorSession
for _, session := range sessions {
if query == "" {
results = append(results, chatSearchHit(session, 0, ""))
continue
}
switch {
case strings.EqualFold(session.Title, query):
results = append(results, chatSearchHit(session, chatScoreTitleExact, "title"))
case containsFold(session.Title, query):
results = append(results, chatSearchHit(session, chatScoreTitle, "title"))
case containsFold(session.Directory, query):
results = append(results, chatSearchHit(session, chatScoreDirectory, "directory"))
default:
unmatched = append(unmatched, session)
}
}
if query != "" && broker != nil && len(unmatched) > 0 {
if len(unmatched) > protocol.SearchMaxScanChats {
unmatched = unmatched[:protocol.SearchMaxScanChats]
}
hits, scanned, complete := searchChatTranscripts(ctx, broker, unmatched, query)
results = append(results, hits...)
response.ScannedChats = scanned
if !complete {
response.Truncated = true
}
}
sort.SliceStable(results, func(i, j int) bool {
a, b := results[i], results[j]
if a.Score != b.Score {
return a.Score > b.Score
}
if a.Recency != b.Recency {
return a.Recency > b.Recency
}
return a.Target < b.Target
})
if len(results) > response.Cap {
results = results[:response.Cap]
response.Truncated = true
}
if results != nil {
response.Results = results
}
return response, nil
}
// chatSearchLimit clamps a requested cap like the store's search does.
func chatSearchLimit(limit int) int {
if limit <= 0 {
return protocol.SearchDefaultLimit
}
return min(limit, protocol.SearchMaxLimit)
}
// chatTranscriptHit is one transcript read's outcome.
type chatTranscriptHit struct {
hit *protocol.SearchResult
scanned bool
}
// searchChatTranscripts reads each session's newest messages with bounded
// concurrency and returns the message hits that arrived within the budget,
// how many transcripts were read, and whether every read finished. Workers
// that outlive the budget see a canceled context and write into a buffered
// channel, so none of them blocks or leaks past its own read.
func searchChatTranscripts(ctx context.Context, broker chatBroker, sessions []pipeline.OperatorSession, query string) ([]protocol.SearchResult, int, bool) {
ctx, cancel := context.WithTimeout(ctx, chatSearchBudget)
defer cancel()
jobs := make(chan pipeline.OperatorSession, len(sessions))
for _, session := range sessions {
jobs <- session
}
close(jobs)
out := make(chan chatTranscriptHit, len(sessions))
for range min(chatSearchConcurrency, len(sessions)) {
go func() {
for session := range jobs {
if ctx.Err() != nil {
out <- chatTranscriptHit{}
continue
}
out <- searchChatTranscript(ctx, broker, session, query)
}
}()
}
var hits []protocol.SearchResult
scanned := 0
for range sessions {
select {
case result := <-out:
if result.scanned {
scanned++
}
if result.hit != nil {
hits = append(hits, *result.hit)
}
case <-ctx.Done():
return hits, scanned, false
}
}
return hits, scanned, scanned == len(sessions)
}
// searchChatTranscript matches query against the text parts of one session's
// newest messages, newest first, and returns a hit for the newest match.
func searchChatTranscript(ctx context.Context, broker chatBroker, session pipeline.OperatorSession, query string) chatTranscriptHit {
page, err := broker.Messages(ctx, session.ID, protocol.SearchChatMessagesPerChat, "")
if err != nil || ctx.Err() != nil {
return chatTranscriptHit{}
}
for i := len(page.Messages) - 1; i >= 0; i-- {
message := page.Messages[i]
for _, part := range message.Parts {
if part.Type != protocol.ChatPartText || !containsFold(part.Text, query) {
continue
}
hit := chatSearchHit(session, chatScoreMessage, "message")
hit.Chat.MessageID = message.ID
hit.Chat.Role = message.Role
hit.Chat.Snippet = protocol.SearchSnippet(part.Text, query)
return chatTranscriptHit{hit: &hit, scanned: true}
}
}
return chatTranscriptHit{scanned: true}
}
func chatSearchHit(session pipeline.OperatorSession, score int, field string) protocol.SearchResult {
backend := session.Backend
if backend == "" {
backend = "opencode"
}
hit := protocol.SearchResult{
Kind: protocol.SearchKindChat,
Target: protocol.SearchChatTarget(session.ID),
Score: score,
MatchedField: field,
Chat: &protocol.SearchChat{
SessionID: session.ID,
Title: session.Title,
Directory: session.Directory,
Backend: backend,
Closed: session.ClosedAt > 0,
UpdatedAt: session.UpdatedAt,
},
}
if session.UpdatedAt > 0 {
hit.Recency = time.UnixMilli(session.UpdatedAt).UTC().Format(time.RFC3339)
}
return hit
}
func containsFold(value, query string) bool {
return query != "" && strings.Contains(strings.ToLower(value), strings.ToLower(query))
}
+166
View File
@@ -0,0 +1,166 @@
package server
import (
"context"
"testing"
"time"
"github.com/coder/websocket"
"github.com/coder/websocket/wsjson"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
// transcriptChat serves a fixed newest page per session. A session listed in
// slow blocks until its read is canceled, like a harness that never answers.
type transcriptChat struct {
*fakeChat
pages map[string][]protocol.ChatMessage
slow map[string]bool
}
func (c *transcriptChat) Messages(ctx context.Context, sessionID string, limit int, _ string) (protocol.ChatHistoryPage, error) {
if c.slow[sessionID] {
<-ctx.Done()
return protocol.ChatHistoryPage{}, ctx.Err()
}
if limit != protocol.SearchChatMessagesPerChat {
return protocol.ChatHistoryPage{}, context.Canceled
}
return protocol.ChatHistoryPage{Messages: c.pages[sessionID]}, nil
}
func chatText(id, role, text string) protocol.ChatMessage {
return protocol.ChatMessage{ID: id, Role: role, Parts: []protocol.ChatPart{{Type: protocol.ChatPartText, Text: text}}}
}
func chatSearchFixture(t *testing.T, broker *transcriptChat) (context.Context, *websocket.Conn) {
t.Helper()
store := newOperatorStore(t)
ctx, _, conn := dialChatOptions(t, Options{Chat: broker, OperatorRegistry: store})
rows := []struct{ id, directory, title, backend string }{
{"ses_title", "/work/site", "Flaky test hunt", "claude"},
{"ses_dir", "/work/flaky-repo", "Docs pass", "codex"},
{"ses_text", "/work/api", "API refactor", ""},
{"ses_none", "/work/other", "Unrelated", ""},
{"ses_slow", "/work/slow", "Slow harness", ""},
}
for _, row := range rows {
if err := store.RecordOperatorSession(ctx, row.id, row.directory, row.title, protocol.ChatSessionTagOperator); err != nil {
t.Fatal(err)
}
if row.backend != "" {
if err := store.SetOperatorSessionBackend(ctx, row.id, row.backend); err != nil {
t.Fatal(err)
}
}
}
return ctx, conn
}
func chatSearch(t *testing.T, ctx context.Context, conn *websocket.Conn, id, query string) {
t.Helper()
writeChat(t, ctx, conn, protocol.Message{Type: protocol.Search, ID: id, Search: &protocol.SearchRequest{Query: query, Kind: protocol.SearchKindChat}})
}
func readReply(t *testing.T, ctx context.Context, conn *websocket.Conn, id string) protocol.Message {
t.Helper()
for {
var reply protocol.Message
if err := wsjson.Read(ctx, conn, &reply); err != nil {
t.Fatalf("read reply %s: %v", id, err)
}
if reply.ID == id {
return reply
}
}
}
func TestChatSearchMatchesTitleDirectoryAndMessageText(t *testing.T) {
broker := &transcriptChat{fakeChat: scriptedChat(), pages: map[string][]protocol.ChatMessage{
"ses_text": {
chatText("m1", protocol.ChatRoleUser, "Why is the build flaky?"),
chatText("m2", protocol.ChatRoleAssistant, "The FLAKY part is the retry loop in client.go."),
{ID: "m3", Role: protocol.ChatRoleAssistant, Parts: []protocol.ChatPart{{Type: protocol.ChatPartReasoning, Text: "flaky reasoning is not searched"}}},
},
"ses_none": {chatText("n1", protocol.ChatRoleUser, "nothing relevant")},
"ses_title": {chatText("t1", protocol.ChatRoleUser, "flaky again")},
}}
ctx, conn := chatSearchFixture(t, broker)
chatSearch(t, ctx, conn, "c1", "flaky")
reply := readReply(t, ctx, conn, "c1")
if reply.Type != protocol.SearchResults || reply.SearchResults == nil {
t.Fatalf("reply = %+v", reply)
}
got := reply.SearchResults
if got.Kind != protocol.SearchKindChat || got.Truncated || got.ScannedChats != 3 {
t.Fatalf("bounds = kind %q truncated %v scanned %d, want chat, complete, 3 transcripts (title/dir hits skip readback)", got.Kind, got.Truncated, got.ScannedChats)
}
if len(got.Results) != 3 {
t.Fatalf("results = %+v, want title, directory and message hits", got.Results)
}
title, dir, text := got.Results[0], got.Results[1], got.Results[2]
if title.Target != "chat:ses_title" || title.MatchedField != "title" || title.Chat.Backend != "claude" || title.Chat.Snippet != "" {
t.Fatalf("title hit = %+v %+v", title, title.Chat)
}
if dir.Target != "chat:ses_dir" || dir.MatchedField != "directory" || dir.Chat.Directory != "/work/flaky-repo" || dir.Chat.Backend != "codex" {
t.Fatalf("directory hit = %+v %+v", dir, dir.Chat)
}
if text.Target != "chat:ses_text" || text.MatchedField != "message" || text.Chat.MessageID != "m2" || text.Chat.Role != protocol.ChatRoleAssistant || text.Chat.Backend != "opencode" {
t.Fatalf("message hit = %+v %+v (want the newest matching text part)", text, text.Chat)
}
if text.Chat.Snippet != "The FLAKY part is the retry loop in client.go." || text.Chat.Title != "API refactor" || text.Recency == "" {
t.Fatalf("message hit facts = %+v", text.Chat)
}
}
// TestChatSearchBudgetNeverBlocksOtherReplies: a harness that never answers
// only costs its own transcript. The connection keeps answering other requests
// while the chat search waits, and the chat reply still arrives within the
// budget with the registry and finished-transcript hits, marked Truncated.
func TestChatSearchBudgetNeverBlocksOtherReplies(t *testing.T) {
previous := chatSearchBudget
chatSearchBudget = 400 * time.Millisecond
t.Cleanup(func() { chatSearchBudget = previous })
broker := &transcriptChat{fakeChat: scriptedChat(), slow: map[string]bool{"ses_slow": true}, pages: map[string][]protocol.ChatMessage{
"ses_text": {chatText("m1", protocol.ChatRoleUser, "a flaky retry")},
}}
ctx, conn := chatSearchFixture(t, broker)
started := time.Now()
chatSearch(t, ctx, conn, "c1", "flaky")
writeChat(t, ctx, conn, protocol.Message{Type: protocol.Ping, ID: "p1"})
var first protocol.Message
if err := wsjson.Read(ctx, conn, &first); err != nil {
t.Fatal(err)
}
if first.ID != "p1" {
t.Fatalf("first reply = %s %s, want the ping answered while transcripts load", first.ID, first.Type)
}
reply := readReply(t, ctx, conn, "c1")
if elapsed := time.Since(started); elapsed > 3*time.Second {
t.Fatalf("chat search took %v, budget is %v", elapsed, chatSearchBudget)
}
got := reply.SearchResults
if got == nil || !got.Truncated || len(got.Results) != 3 {
t.Fatalf("reply = %+v, want three hits and Truncated", got)
}
if got.Results[2].Target != "chat:ses_text" {
t.Fatalf("message hit missing: %+v", got.Results)
}
}
func TestChatSearchBlankListsRecentAndNeedsRegistry(t *testing.T) {
broker := &transcriptChat{fakeChat: scriptedChat()}
ctx, conn := chatSearchFixture(t, broker)
chatSearch(t, ctx, conn, "b1", " ")
reply := readReply(t, ctx, conn, "b1")
if reply.SearchResults == nil || len(reply.SearchResults.Results) != 5 || reply.SearchResults.ScannedChats != 0 {
t.Fatalf("blank chat search = %+v, want every listed chat and no transcript reads", reply.SearchResults)
}
ctx, _, bare := dialChatOptions(t, Options{Chat: broker})
chatSearch(t, ctx, bare, "n1", "x")
if reply := readReply(t, ctx, bare, "n1"); reply.Type != protocol.Error {
t.Fatalf("no-registry chat search = %+v, want an error", reply)
}
}
+15
View File
@@ -217,6 +217,11 @@ func HandlerWithOptions(ctx context.Context, options Options, stores ...*pipelin
if notes != nil {
defer notes.detach(clientID)
}
// A chat search runs beside the read loop so its transcript readback
// never delays the run search sent with it; a newer one cancels the
// previous, whose reply the client would discard as stale anyway.
cancelChatSearch := func() {}
defer func() { cancelChatSearch() }()
for {
var request protocol.Message
if err := wsjson.Read(connCtx, conn, &request); err != nil {
@@ -227,6 +232,16 @@ func HandlerWithOptions(ctx context.Context, options Options, stores ...*pipelin
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "pipeline authoring is disabled on this execution server; ask the operator to publish through an explicitly enabled authoring server"})
continue
}
if isChatSearch(request) {
cancelChatSearch()
searchCtx, cancel := context.WithCancel(connCtx)
cancelChatSearch = cancel
go func(request protocol.Message) {
defer cancel()
_ = write(chatSearchReply(searchCtx, request, options.Chat, registry))
}(request)
continue
}
if handleChat(connCtx, request, options.Chat, hub, registry, clientID, write) {
continue
}