chat: add model switching and preloaded instructions
Expose the OpenCode model list and session model switch over the chat protocol, carry a per-session model provider on chat rows, and apply a preloaded behavior brief as a durable session instruction entry when a chat is created.
This commit is contained in:
@@ -46,6 +46,11 @@ const (
|
||||
// ChatBackends lists the installed chat harnesses the server can create a
|
||||
// session on. The reply is a bounded array of backend names.
|
||||
ChatBackends = "chat_backends"
|
||||
// ChatModels lists the models the chat's harness can switch to; its request
|
||||
// body is ChatQuery (the session id).
|
||||
ChatModels = "chat_models"
|
||||
// ChatModelSelect switches one session's model for subsequent turns.
|
||||
ChatModelSelect = "chat_model"
|
||||
// ChatStar records the operator's star on the server, so every browser and
|
||||
// device shows the same starred group. It takes a ChatQuery with SessionID
|
||||
// and Starred, and echoes the updated session like close/reopen.
|
||||
@@ -154,6 +159,21 @@ const (
|
||||
ChatRoleAssistant = "assistant"
|
||||
)
|
||||
|
||||
// ChatModel is one model the current chat harness can switch to. ID is the
|
||||
// provider's model id, Provider its provider id, Name the harness's display name.
|
||||
type ChatModel struct {
|
||||
ID string `json:"id"`
|
||||
Provider string `json:"provider"`
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
// ChatModelRequest switches the model for one session's subsequent turns.
|
||||
type ChatModelRequest struct {
|
||||
SessionID string `json:"session_id"`
|
||||
Provider string `json:"provider"`
|
||||
Model string `json:"model"`
|
||||
}
|
||||
|
||||
// ChatSession is one createable/listed OpenCode session, flattened for the
|
||||
// phone: the nested location.directory and time{created,updated} fields are
|
||||
// lifted to Directory, CreatedAt and UpdatedAt.
|
||||
@@ -161,12 +181,13 @@ type ChatSession struct {
|
||||
ID string `json:"id"`
|
||||
// Backend names the harness that owns this session: opencode, codex or
|
||||
// claude. Empty on older peers and for legacy OpenCode rows.
|
||||
Backend string `json:"backend,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
Agent string `json:"agent,omitempty"`
|
||||
Model string `json:"model,omitempty"`
|
||||
Directory string `json:"directory,omitempty"`
|
||||
ParentID string `json:"parent_id,omitempty"`
|
||||
Backend string `json:"backend,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
Agent string `json:"agent,omitempty"`
|
||||
Model string `json:"model,omitempty"`
|
||||
ModelProvider string `json:"model_provider,omitempty"`
|
||||
Directory string `json:"directory,omitempty"`
|
||||
ParentID string `json:"parent_id,omitempty"`
|
||||
// Tag marks the session kind. The only stored value is "operator" (a chat
|
||||
// the person created); pipeline stage sessions are never tagged and are never
|
||||
// listed by chat_sessions. Additive/omitempty so older peers ignore it.
|
||||
@@ -216,6 +237,10 @@ type ChatCreateRequest struct {
|
||||
// preserving older clients and the default.
|
||||
Backend string `json:"backend,omitempty"`
|
||||
OperationID string `json:"operation_id,omitempty"`
|
||||
// Instructions preloads the session's durable behavior instruction, when the
|
||||
// harness supports session instruction entries (OpenCode does). Best effort:
|
||||
// a harness without the surface still creates the chat.
|
||||
Instructions string `json:"instructions,omitempty"`
|
||||
// Ephemeral creates a chat for automated verification: the session is created,
|
||||
// bootstrapped and usable exactly like a normal one, but no operator-registry
|
||||
// row is written, so it can never appear in chat_sessions. It exists because a
|
||||
|
||||
@@ -194,6 +194,10 @@ type Message struct {
|
||||
// ChatBackends is the chat_backends reply: the installed harnesses a new
|
||||
// chat can use.
|
||||
ChatBackends []string `json:"chat_backends,omitempty"`
|
||||
// ChatModels is the chat_models reply: models the session's harness offers.
|
||||
ChatModels []ChatModel `json:"chat_models,omitempty"`
|
||||
// ModelRequest is the chat_model body and echoed selection.
|
||||
ModelRequest *ChatModelRequest `json:"chat_model,omitempty"`
|
||||
// ChatSubscribe attaches this connection to one session's shared stream; the
|
||||
// body names the session like ChatQuery. A chat_prompt response sets
|
||||
// ChatQueued when the prompt had to wait for an in-flight turn and was
|
||||
|
||||
Reference in New Issue
Block a user