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:
@@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -109,6 +110,7 @@ func handleChatCreate(ctx context.Context, request protocol.Message, broker chat
|
||||
operationID := ""
|
||||
backend := "opencode"
|
||||
ephemeral := false
|
||||
instructions := ""
|
||||
if request.ChatCreate != nil {
|
||||
title = strings.TrimSpace(request.ChatCreate.Title)
|
||||
directory = strings.TrimSpace(request.ChatCreate.Directory)
|
||||
@@ -117,6 +119,7 @@ func handleChatCreate(ctx context.Context, request protocol.Message, broker chat
|
||||
backend = value
|
||||
}
|
||||
ephemeral = request.ChatCreate.Ephemeral
|
||||
instructions = strings.TrimSpace(request.ChatCreate.Instructions)
|
||||
}
|
||||
// Legacy clients did not carry a durable create identity. Give each received
|
||||
// request its own server-generated scope so their connection-local envelope
|
||||
@@ -177,6 +180,16 @@ func handleChatCreate(ctx context.Context, request protocol.Message, broker chat
|
||||
// Reserve the activation before calling the external service. If the
|
||||
// process dies after the call but before the success checkpoint, a retry
|
||||
// must report the ambiguous operation rather than append the skill twice.
|
||||
// Preload the web chat's behavior brief before the first turn. This is
|
||||
// best effort: an older OpenCode build or another harness without the
|
||||
// experimental instruction surface still gets a usable chat.
|
||||
if instructions != "" {
|
||||
if instr, ok := broker.(chatInstructioner); ok {
|
||||
if err := instr.SetInstruction(ctx, session.ID, "pipelines.behavior", instructions); err != nil {
|
||||
log.Printf("chat %s preload instructions: %v", session.ID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := registry.AdvanceChatCreate(ctx, operationID, "created", "activating"); err != nil {
|
||||
chatCreateConflictError(request, err, write)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user