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:
@@ -55,6 +55,20 @@ type chatPromptWithFiles interface {
|
||||
PromptWithMessageIDFiles(context.Context, string, string, string, []opencode.PromptFile) error
|
||||
}
|
||||
|
||||
// chatInstructioner is the optional preloaded-behavior surface. OpenCode
|
||||
// implements session instruction entries; a harness without them still creates
|
||||
// the chat without instructions.
|
||||
type chatInstructioner interface {
|
||||
SetInstruction(ctx context.Context, sessionID, key string, value any) error
|
||||
}
|
||||
|
||||
// chatModeler is the optional model-selection surface. OpenCode implements it;
|
||||
// a harness without a model switch reports that clearly rather than pretending.
|
||||
type chatModeler interface {
|
||||
Models(ctx context.Context, sessionID string) ([]protocol.ChatModel, error)
|
||||
SwitchModel(ctx context.Context, sessionID, provider, model string) error
|
||||
}
|
||||
|
||||
// chatAnswerer is the optional form-answer surface. Test brokers and older
|
||||
// backends need not implement it; a broker that does not answers chat_answer
|
||||
// with a clear error rather than pretending the question was delivered.
|
||||
@@ -179,6 +193,12 @@ func handleChat(ctx context.Context, request protocol.Message, broker chatBroker
|
||||
case protocol.ChatBackends:
|
||||
handleChatBackends(request, broker, write)
|
||||
return true
|
||||
case protocol.ChatModels:
|
||||
handleChatModels(ctx, request, broker, write)
|
||||
return true
|
||||
case protocol.ChatModelSelect:
|
||||
handleChatModelSwitch(ctx, request, broker, write)
|
||||
return true
|
||||
case protocol.ChatShells:
|
||||
handleChatShells(ctx, request, broker, registry, write)
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user