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:
@@ -151,6 +151,46 @@ func (m *chatManager) PromptWithMessageIDFiles(ctx context.Context, sessionID, t
|
||||
return m.PromptWithMessageID(ctx, sessionID, text, messageID)
|
||||
}
|
||||
|
||||
// SetInstruction forwards one preloaded behavior instruction to the session's
|
||||
// harness when it supports durable instruction entries.
|
||||
func (m *chatManager) SetInstruction(ctx context.Context, sessionID, key string, value any) error {
|
||||
adapter, err := m.brokerFor(ctx, sessionID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
instr, ok := adapter.(chatInstructioner)
|
||||
if !ok {
|
||||
return errors.New("this chat harness does not support session instructions")
|
||||
}
|
||||
return instr.SetInstruction(ctx, sessionID, key, value)
|
||||
}
|
||||
|
||||
// Models lists the models the session's harness offers for switching.
|
||||
func (m *chatManager) Models(ctx context.Context, sessionID string) ([]protocol.ChatModel, error) {
|
||||
adapter, err := m.brokerFor(ctx, sessionID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
modeler, ok := adapter.(chatModeler)
|
||||
if !ok {
|
||||
return nil, errors.New("this chat harness does not support changing models")
|
||||
}
|
||||
return modeler.Models(ctx, sessionID)
|
||||
}
|
||||
|
||||
// SwitchModel changes the session's model for subsequent turns.
|
||||
func (m *chatManager) SwitchModel(ctx context.Context, sessionID, provider, model string) error {
|
||||
adapter, err := m.brokerFor(ctx, sessionID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
modeler, ok := adapter.(chatModeler)
|
||||
if !ok {
|
||||
return errors.New("this chat harness does not support changing models")
|
||||
}
|
||||
return modeler.SwitchModel(ctx, sessionID, provider, model)
|
||||
}
|
||||
|
||||
func (m *chatManager) Stream(ctx context.Context, sessionID string, ready func(), emit func(protocol.ChatEventFrame) error) error {
|
||||
adapter, err := m.brokerFor(ctx, sessionID)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user