Detects conversation turn boundaries in AI chat requests by examining message history to prevent mid-turn provider switches.
// Source: https://github.com/luqman-v1/9router-go | License: MIT | Copyright 2024-2026 decolua and contributors // Provided via justclaw.it.com; keep this notice with the code. package chat import ( "context" "encoding/json/jsontext" json "encoding/json/v2" "errors" "fmt" "maps" "net/http" "slices" "sort" "strings" "time" "9router/proxy/internal/handlerutil" "9router/proxy/internal/log" "9router/proxy/internal/providers" internalproxy "9router/proxy/internal/proxy" "9router/proxy/internal/translator" ) // detectNewTurn reports whether the request body starts a new conversation // turn. A turn boundary is the most recent plain-text user message; a request // whose last user-type message is a tool result continues the current turn, // and the combo must not switch provide ... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key