refactor: remove personas
Personas were a misread requirement: SOUL is the chat identity and identities are per action. The selected persona's prompt never reached the model. Drops the resource, /personality, the chat selector, the settings page and ChatService.SetPersona, and deletes stored persona documents.
This commit is contained in:
46 files changed
+384
-1416
No files matched your search
@@ -31,7 +31,7 @@ func stepVocabulary() (*workflow.Manager, error) { return workflowsteps.NewManag
|
||||
// (main.go's Run) before buildDaemon captures the client.
|
||||
//
|
||||
// It is deliberately not part of openStateStoreAdapter, which the gateway root
|
||||
// shares: the gateway reads catalog, runtime settings and personas, never a
|
||||
// shares: the gateway reads catalog, runtime settings and SOUL, never a
|
||||
// workflow definition, so registering a vocabulary there would be the dead
|
||||
// vocabulary this shape removed from internal/app/archiemessaging -- a root that
|
||||
// cannot consume it must not be failed by it.
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/tools"
|
||||
)
|
||||
|
||||
// setupChatRuntime wires the model runtime, tool registry, persona registry,
|
||||
// setupChatRuntime wires the model runtime, tool registry, SOUL,
|
||||
// chat task creator/controller, default chat identity and the release-update
|
||||
// service. The daemon and the standalone Gateway build through this one
|
||||
// constructor so the two processes cannot diverge.
|
||||
@@ -41,20 +41,6 @@ func (b *server) setupChatRuntime(ctx context.Context, cfg config.Config, actor
|
||||
chatModels.SetModelCatalog(catalog)
|
||||
b.chatModels = chatModels
|
||||
|
||||
// ── Persona registry ─────────────────────────────────────────────
|
||||
if b.personas == nil {
|
||||
personas, version, err := b.controlPlane.Personas(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("load personas: %w", err)
|
||||
}
|
||||
b.personas = gateway.NewPersonaRegistry(nil)
|
||||
b.applyPersonas(personas, version)
|
||||
b.applyStatus.Report(ctx, controlplane.PersonasKind, version, nil)
|
||||
if err := b.watchPersonas(ctx, version); err != nil {
|
||||
return fmt.Errorf("watch personas: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// ── SOUL ─────────────────────────────────────────────────────────
|
||||
if b.soul == nil {
|
||||
soul, version, err := b.controlPlane.Soul(ctx)
|
||||
@@ -167,40 +153,9 @@ func watchStatus[T any](
|
||||
})
|
||||
}
|
||||
|
||||
// watchPersonas keeps the persona stream established for the life of the
|
||||
// process. The first stream is opened synchronously, so a control plane that
|
||||
// cannot be watched at all fails the boot that asked for it rather than
|
||||
// leaving the process running personas it can no longer update; after that the
|
||||
// watch reconnects instead of ending (see servicekit.KeepWatch).
|
||||
func (b *server) watchPersonas(ctx context.Context, version int64) error {
|
||||
updates, err := b.controlPlane.WatchPersonas(ctx, version)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
watchStatus(ctx, b.applyStatus.Report, b.log,
|
||||
controlplane.PersonasKind, "personas", version, updates,
|
||||
b.controlPlane.WatchPersonas,
|
||||
func(update controlplane.AppliedPersonas) int64 { return update.Version },
|
||||
func(update controlplane.AppliedPersonas) error { return update.Err },
|
||||
func(update controlplane.AppliedPersonas) error {
|
||||
b.applyPersonas(update.Collection, update.Version)
|
||||
return nil
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *server) applyPersonas(collection agent.PersonaCollection, version int64) {
|
||||
personas := make([]gateway.Persona, 0, len(collection.Personas))
|
||||
for _, persona := range collection.Personas {
|
||||
personas = append(personas, gateway.Persona{Name: persona.Name, Prompt: persona.Prompt})
|
||||
}
|
||||
b.personas.Replace(personas, collection.Default)
|
||||
b.log.Info("personas applied", "version", version)
|
||||
}
|
||||
|
||||
// watchSoul keeps the soul stream established for the life of the process, so
|
||||
// a dashboard edit reaches the next turn without a restart. The stream rides
|
||||
// the same outage bookkeeping as personas (watchStatus).
|
||||
// the same outage bookkeeping as curators (watchStatus).
|
||||
func (b *server) watchSoul(ctx context.Context, version int64) error {
|
||||
updates, err := b.controlPlane.WatchSoul(ctx, version)
|
||||
if err != nil {
|
||||
@@ -235,7 +190,6 @@ func (b *server) setupGatewayChat(ctx context.Context, actor gateway.ChatTaskAct
|
||||
router.Limiter = b.rateLimiter
|
||||
router.Version = fmt.Sprintf("Archie\nGateway: %s\nRuntime: %s", buildinfo.Version, buildinfo.Runtime)
|
||||
router.Models = b.chatModels
|
||||
router.Personas = b.personas
|
||||
router.Updates = b.updateService
|
||||
router.InitSessions(b.chatSessionStore)
|
||||
configureTaskCommands(router, b.chatTasks, b.chatController, chatTaskListerAdapter{tasks: b.stateStore.Tasks}, b.defaultChatIdentity)
|
||||
@@ -269,7 +223,7 @@ func (b *server) setupGatewayChat(ctx context.Context, actor gateway.ChatTaskAct
|
||||
router.Log = b.log
|
||||
return &gateway.LocalChatAdapter{
|
||||
Router: router, Sessions: b.chatSessionStore, Turns: gateway.NewTurns(b.log),
|
||||
Models: b.chatModels, Personas: b.personas, TaskActor: actor, Tasks: b.stateStore,
|
||||
Models: b.chatModels, TaskActor: actor, Tasks: b.stateStore,
|
||||
VoiceAvailable: b.transcriber != nil,
|
||||
}, nil
|
||||
}
|
||||
@@ -85,7 +85,6 @@ type server struct {
|
||||
mcpMu sync.Mutex
|
||||
mcpApplied map[string]appliedMCPServer
|
||||
chatModels *chatModelManager
|
||||
personas *gateway.PersonaRegistry
|
||||
soul *soulSource
|
||||
memEngines *domainmemory.Registry
|
||||
curatorRegistry *curator.Registry
|
||||
|
||||
@@ -152,34 +152,6 @@ type AppliedSettings struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
func (c *Client) Personas(ctx context.Context) (agent.PersonaCollection, int64, error) {
|
||||
response, err := c.rpc.Query(ctx, &pb.QueryRequest{Kind: PersonasKind})
|
||||
if err != nil {
|
||||
return agent.PersonaCollection{}, 0, controlplanerpc.ClientError(err)
|
||||
}
|
||||
collection, err := decodePersonas(response.Resource.ValueJson)
|
||||
return collection, response.Resource.Version, err
|
||||
}
|
||||
|
||||
type AppliedPersonas struct {
|
||||
Collection agent.PersonaCollection
|
||||
Version int64
|
||||
Err error
|
||||
}
|
||||
|
||||
func (c *Client) WatchPersonas(ctx context.Context, afterVersion int64) (<-chan AppliedPersonas, error) {
|
||||
stream, err := c.rpc.Watch(ctx, &pb.WatchRequest{Kind: PersonasKind, AfterVersion: afterVersion})
|
||||
if err != nil {
|
||||
return nil, controlplanerpc.ClientError(err)
|
||||
}
|
||||
return watchUpdates(ctx, stream,
|
||||
func(resource *pb.Resource) AppliedPersonas {
|
||||
collection, err := decodePersonas(resource.ValueJson)
|
||||
return AppliedPersonas{Collection: collection, Version: resource.Version, Err: err}
|
||||
},
|
||||
func(err error) AppliedPersonas { return AppliedPersonas{Err: err} }), nil
|
||||
}
|
||||
|
||||
func (c *Client) Soul(ctx context.Context) (agent.Soul, int64, error) {
|
||||
response, err := c.rpc.Query(ctx, &pb.QueryRequest{Kind: SoulKind})
|
||||
if err != nil {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
// Schemas are not declared here: each Definition names its document type, and
|
||||
// Definition.Descriptor derives the JSON Schema from it (internal/app/controlplane/schema.go).
|
||||
func builtinDefinitions(steps workflow.StepRegistry, settings map[string]any) []Definition {
|
||||
definitions := []Definition{taskPolicyDefinition(), workflowDefinition(), workflowDefinitionsDefinition(steps, settings), workflowEnablementDefinition(), personaDefinition(), curatorDefinition(), soulDefinition(), scheduleDefinition(), agentProfileDefinition(), playbooksDefinition(), skillsDefinition(), credentialBindingsDefinition(), identityGrantsDefinition(), reviewSettingsDefinition(), orgModelPolicyDefinition()}
|
||||
definitions := []Definition{taskPolicyDefinition(), workflowDefinition(), workflowDefinitionsDefinition(steps, settings), workflowEnablementDefinition(), curatorDefinition(), soulDefinition(), scheduleDefinition(), agentProfileDefinition(), playbooksDefinition(), skillsDefinition(), credentialBindingsDefinition(), identityGrantsDefinition(), reviewSettingsDefinition(), orgModelPolicyDefinition()}
|
||||
definitions = append(definitions, modelDefinitions()...)
|
||||
definitions = append(definitions, operationalDefinitions()...)
|
||||
return definitions
|
||||
|
||||
@@ -14,7 +14,7 @@ func TestInstanceOnlyKindsRefuseOtherOrgs(t *testing.T) {
|
||||
}{
|
||||
{"another org writes an instance setting", "acme", ToolSettingsKind, true},
|
||||
{"the system org writes an instance setting", storecontract.DefaultOrgID, ToolSettingsKind, false},
|
||||
{"another org writes an org-scoped kind", "acme", PersonasKind, false},
|
||||
{"another org writes an org-scoped kind", "acme", SoulKind, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package controlplane
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/domain/agent"
|
||||
)
|
||||
|
||||
const PersonasKind = "personas"
|
||||
|
||||
func personaDefinition() Definition {
|
||||
return Definition{
|
||||
Kind: PersonasKind,
|
||||
Title: "Personas",
|
||||
Document: agent.PersonaCollection{},
|
||||
ApplyMode: "live",
|
||||
Seed: func(config.Config) any { return agent.ShippedPersonas() },
|
||||
Validate: func(input []byte) error {
|
||||
return validateAs(input, func(collection agent.PersonaCollection) error { return collection.Validate() })
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func decodePersonas(input []byte) (agent.PersonaCollection, error) {
|
||||
var collection agent.PersonaCollection
|
||||
err := json.Unmarshal(input, &collection)
|
||||
return collection, err
|
||||
}
|
||||
@@ -24,7 +24,6 @@ var gatewayCommandSpecs = []commandSpec{
|
||||
{Command: "version", Description: "Show installed Archie versions", Usage: "/version"},
|
||||
{Command: "update", Description: "Check for Archie updates", Usage: "/update"},
|
||||
{Command: "model", Description: "Choose a provider and model or switch directly", Usage: "/model [provider/model]"},
|
||||
{Command: "personality", Description: "Choose a communication style", Usage: "/personality [name]"},
|
||||
{Command: "spawn", Description: "Create a tracked task", Usage: "/spawn [identity=name] [repo=owner/name] [workflow=name] <title>"},
|
||||
{Command: "settings", Description: "Inspect or change runtime settings", Usage: "/settings [list|get <kind>|set <kind> <field>=<value> ...]"},
|
||||
{Command: "approve", Description: "Approve a waiting task", Usage: "/approve [identity=name] <task-id>"},
|
||||
|
||||
@@ -1,145 +0,0 @@
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/go-telegram/bot"
|
||||
"github.com/go-telegram/bot/models"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
||||
)
|
||||
|
||||
const personalityCallbackPrefix = "personality:"
|
||||
|
||||
func isPersonalityRequest(text string) bool {
|
||||
fields := strings.Fields(text)
|
||||
if len(fields) == 0 {
|
||||
return false
|
||||
}
|
||||
command, _, _ := strings.Cut(fields[0], "@")
|
||||
return command == "/personality"
|
||||
}
|
||||
|
||||
func (g *Gateway) handlePersonalityCommand(
|
||||
ctx context.Context,
|
||||
b *bot.Bot,
|
||||
msg *models.Message,
|
||||
client messaging.ChatContract,
|
||||
) {
|
||||
snap, err := client.Snapshot(ctx)
|
||||
if err != nil || !snap.PersonasAvailable {
|
||||
g.sendMessage(ctx, b, msg.Chat.ID, msg.MessageThreadID,
|
||||
"Personality switching is not configured.")
|
||||
return
|
||||
}
|
||||
|
||||
text := strings.TrimSpace(msg.Text)
|
||||
fields := strings.Fields(text)
|
||||
if len(fields) == 1 {
|
||||
// No args: show inline keyboard.
|
||||
g.sendPersonalitySelector(ctx, b, msg, snap.Personas)
|
||||
return
|
||||
}
|
||||
|
||||
// Direct switch by name.
|
||||
name := strings.ToLower(fields[1])
|
||||
ok, err := client.SetPersona(ctx, "", name)
|
||||
if err != nil || !ok {
|
||||
g.sendMessage(ctx, b, msg.Chat.ID, msg.MessageThreadID,
|
||||
fmt.Sprintf("Unknown personality %q. Use /personality to browse.", name))
|
||||
return
|
||||
}
|
||||
g.sendMessage(ctx, b, msg.Chat.ID, msg.MessageThreadID,
|
||||
fmt.Sprintf("Personality set to %q.", name))
|
||||
}
|
||||
|
||||
func (g *Gateway) sendPersonalitySelector(
|
||||
ctx context.Context,
|
||||
b *bot.Bot,
|
||||
msg *models.Message,
|
||||
personas []string,
|
||||
) {
|
||||
if len(personas) == 0 {
|
||||
g.sendMessage(ctx, b, msg.Chat.ID, msg.MessageThreadID,
|
||||
"No personalities configured.")
|
||||
return
|
||||
}
|
||||
|
||||
params := &bot.SendMessageParams{
|
||||
ChatID: msg.Chat.ID,
|
||||
Text: "Choose a personality:",
|
||||
ReplyMarkup: g.personalityKeyboard(personas),
|
||||
}
|
||||
if msg.MessageThreadID != 0 {
|
||||
params.MessageThreadID = msg.MessageThreadID
|
||||
}
|
||||
if _, err := b.SendMessage(ctx, params); err != nil {
|
||||
g.log.Error("send personality selector failed", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Gateway) personalityKeyboard(personas []string) *models.InlineKeyboardMarkup {
|
||||
rows := make([][]models.InlineKeyboardButton, 0, len(personas))
|
||||
for _, name := range personas {
|
||||
rows = append(rows, []models.InlineKeyboardButton{{
|
||||
Text: name,
|
||||
CallbackData: personalityCallbackPrefix + name,
|
||||
}})
|
||||
}
|
||||
return &models.InlineKeyboardMarkup{InlineKeyboard: rows}
|
||||
}
|
||||
|
||||
func (g *Gateway) handlePersonalityCallback(
|
||||
ctx context.Context,
|
||||
b *bot.Bot,
|
||||
update *models.Update,
|
||||
client messaging.ChatContract,
|
||||
) {
|
||||
query := update.CallbackQuery
|
||||
if query == nil {
|
||||
return
|
||||
}
|
||||
if !g.isSenderAllowed(query.From.ID) {
|
||||
g.log.Warn("personality callback from unauthorized sender",
|
||||
"user_id", query.From.ID)
|
||||
g.answerModelCallback(ctx, b, query.ID,
|
||||
"You are not authorised to use this bot.", true)
|
||||
return
|
||||
}
|
||||
snap, err := client.Snapshot(ctx)
|
||||
if err != nil || !snap.PersonasAvailable {
|
||||
g.answerModelCallback(ctx, b, query.ID,
|
||||
"Personality switching is not configured.", true)
|
||||
return
|
||||
}
|
||||
|
||||
name := strings.TrimPrefix(query.Data, personalityCallbackPrefix)
|
||||
ok, err := client.SetPersona(ctx, "", name)
|
||||
if err != nil || !ok {
|
||||
g.answerModelCallback(ctx, b, query.ID,
|
||||
fmt.Sprintf("Unknown personality %q.", name), true)
|
||||
return
|
||||
}
|
||||
|
||||
g.answerModelCallback(ctx, b, query.ID,
|
||||
fmt.Sprintf("Personality set to %q.", name), false)
|
||||
|
||||
// Update the selector message to acknowledge the selection.
|
||||
params := &bot.EditMessageTextParams{
|
||||
Text: fmt.Sprintf("Personality set to %q.", name),
|
||||
}
|
||||
switch {
|
||||
case query.Message.Message != nil:
|
||||
params.ChatID = query.Message.Message.Chat.ID
|
||||
params.MessageID = query.Message.Message.ID
|
||||
case query.InlineMessageID != "":
|
||||
params.InlineMessageID = query.InlineMessageID
|
||||
default:
|
||||
return
|
||||
}
|
||||
if _, err := b.EditMessageText(ctx, params); err != nil {
|
||||
g.log.Warn("update personality selector failed", "error", err)
|
||||
}
|
||||
}
|
||||
@@ -537,10 +537,6 @@ func (g *Gateway) defaultHandler(client messaging.ChatContract) bot.HandlerFunc
|
||||
g.handleModelCommand(ctx, b, msg, client)
|
||||
return
|
||||
}
|
||||
if isPersonalityRequest(msg.Text) {
|
||||
g.handlePersonalityCommand(ctx, b, msg, client)
|
||||
return
|
||||
}
|
||||
g.submitTurn(ctx, b, msg, client)
|
||||
}
|
||||
}
|
||||
@@ -564,8 +560,6 @@ func (g *Gateway) handleCallback(ctx context.Context, b *bot.Bot, update *models
|
||||
g.handleModelCancelCallback(ctx, b, update)
|
||||
case update.CallbackQuery.Data == modelNoopCallback:
|
||||
g.handleModelNoopCallback(ctx, b, update)
|
||||
case strings.HasPrefix(update.CallbackQuery.Data, personalityCallbackPrefix):
|
||||
g.handlePersonalityCallback(ctx, b, update, client)
|
||||
case strings.HasPrefix(update.CallbackQuery.Data, updateCallbackPrefix):
|
||||
g.handleUpdateCallback(ctx, b, update)
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -29,7 +29,6 @@ const (
|
||||
ChatService_Answer_FullMethodName = "/gateway.v1.ChatService/Answer"
|
||||
ChatService_Cancel_FullMethodName = "/gateway.v1.ChatService/Cancel"
|
||||
ChatService_StopTasks_FullMethodName = "/gateway.v1.ChatService/StopTasks"
|
||||
ChatService_SetPersona_FullMethodName = "/gateway.v1.ChatService/SetPersona"
|
||||
ChatService_ApplyTaskAction_FullMethodName = "/gateway.v1.ChatService/ApplyTaskAction"
|
||||
ChatService_ApplyOperatorTaskAction_FullMethodName = "/gateway.v1.ChatService/ApplyOperatorTaskAction"
|
||||
ChatService_SaveSession_FullMethodName = "/gateway.v1.ChatService/SaveSession"
|
||||
@@ -63,7 +62,6 @@ type ChatServiceClient interface {
|
||||
Answer(ctx context.Context, in *AnswerRequest, opts ...grpc.CallOption) (*AnswerResponse, error)
|
||||
Cancel(ctx context.Context, in *CancelRequest, opts ...grpc.CallOption) (*CancelResponse, error)
|
||||
StopTasks(ctx context.Context, in *StopTasksRequest, opts ...grpc.CallOption) (*StopTasksResponse, error)
|
||||
SetPersona(ctx context.Context, in *SetPersonaRequest, opts ...grpc.CallOption) (*SetPersonaResponse, error)
|
||||
ApplyTaskAction(ctx context.Context, in *ApplyTaskActionRequest, opts ...grpc.CallOption) (*ApplyTaskActionResponse, error)
|
||||
ApplyOperatorTaskAction(ctx context.Context, in *ApplyOperatorTaskActionRequest, opts ...grpc.CallOption) (*ApplyOperatorTaskActionResponse, error)
|
||||
SaveSession(ctx context.Context, in *SaveSessionRequest, opts ...grpc.CallOption) (*SaveSessionResponse, error)
|
||||
@@ -201,16 +199,6 @@ func (c *chatServiceClient) StopTasks(ctx context.Context, in *StopTasksRequest,
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *chatServiceClient) SetPersona(ctx context.Context, in *SetPersonaRequest, opts ...grpc.CallOption) (*SetPersonaResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(SetPersonaResponse)
|
||||
err := c.cc.Invoke(ctx, ChatService_SetPersona_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *chatServiceClient) ApplyTaskAction(ctx context.Context, in *ApplyTaskActionRequest, opts ...grpc.CallOption) (*ApplyTaskActionResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(ApplyTaskActionResponse)
|
||||
@@ -395,7 +383,6 @@ type ChatServiceServer interface {
|
||||
Answer(context.Context, *AnswerRequest) (*AnswerResponse, error)
|
||||
Cancel(context.Context, *CancelRequest) (*CancelResponse, error)
|
||||
StopTasks(context.Context, *StopTasksRequest) (*StopTasksResponse, error)
|
||||
SetPersona(context.Context, *SetPersonaRequest) (*SetPersonaResponse, error)
|
||||
ApplyTaskAction(context.Context, *ApplyTaskActionRequest) (*ApplyTaskActionResponse, error)
|
||||
ApplyOperatorTaskAction(context.Context, *ApplyOperatorTaskActionRequest) (*ApplyOperatorTaskActionResponse, error)
|
||||
SaveSession(context.Context, *SaveSessionRequest) (*SaveSessionResponse, error)
|
||||
@@ -454,9 +441,6 @@ func (UnimplementedChatServiceServer) Cancel(context.Context, *CancelRequest) (*
|
||||
func (UnimplementedChatServiceServer) StopTasks(context.Context, *StopTasksRequest) (*StopTasksResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method StopTasks not implemented")
|
||||
}
|
||||
func (UnimplementedChatServiceServer) SetPersona(context.Context, *SetPersonaRequest) (*SetPersonaResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method SetPersona not implemented")
|
||||
}
|
||||
func (UnimplementedChatServiceServer) ApplyTaskAction(context.Context, *ApplyTaskActionRequest) (*ApplyTaskActionResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method ApplyTaskAction not implemented")
|
||||
}
|
||||
@@ -702,24 +686,6 @@ func _ChatService_StopTasks_Handler(srv interface{}, ctx context.Context, dec fu
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _ChatService_SetPersona_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(SetPersonaRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ChatServiceServer).SetPersona(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ChatService_SetPersona_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ChatServiceServer).SetPersona(ctx, req.(*SetPersonaRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _ChatService_ApplyTaskAction_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ApplyTaskActionRequest)
|
||||
if err := dec(in); err != nil {
|
||||
@@ -1069,10 +1035,6 @@ var ChatService_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "StopTasks",
|
||||
Handler: _ChatService_StopTasks_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "SetPersona",
|
||||
Handler: _ChatService_SetPersona_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ApplyTaskAction",
|
||||
Handler: _ChatService_ApplyTaskAction_Handler,
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Persona struct {
|
||||
Name string `json:"name"`
|
||||
Prompt string `json:"prompt"`
|
||||
}
|
||||
|
||||
type PersonaCollection struct {
|
||||
Default string `json:"default"`
|
||||
Personas []Persona `json:"personas"`
|
||||
}
|
||||
|
||||
func (c PersonaCollection) Validate() error {
|
||||
if len(c.Personas) == 0 {
|
||||
return fmt.Errorf("at least one persona is required")
|
||||
}
|
||||
defaultName := normalizePersonaName(c.Default)
|
||||
seen := make(map[string]struct{}, len(c.Personas))
|
||||
for _, persona := range c.Personas {
|
||||
name := normalizePersonaName(persona.Name)
|
||||
if name == "" || strings.TrimSpace(persona.Prompt) == "" {
|
||||
return fmt.Errorf("persona name and prompt are required")
|
||||
}
|
||||
if _, exists := seen[name]; exists {
|
||||
return fmt.Errorf("duplicate persona %q", name)
|
||||
}
|
||||
seen[name] = struct{}{}
|
||||
}
|
||||
if _, exists := seen[defaultName]; !exists {
|
||||
return fmt.Errorf("default persona %q does not exist", c.Default)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func normalizePersonaName(name string) string {
|
||||
return strings.ToLower(strings.TrimSpace(name))
|
||||
}
|
||||
|
||||
func ShippedPersonas() PersonaCollection {
|
||||
return PersonaCollection{Default: "archie", Personas: []Persona{
|
||||
{Name: "archie", Prompt: archieIdentity},
|
||||
{Name: "helpful", Prompt: "You are a helpful, friendly AI assistant."},
|
||||
{Name: "concise", Prompt: "You are a concise assistant. Keep responses brief and to the point."},
|
||||
{Name: "technical", Prompt: "You are a technical expert. Provide detailed, accurate technical information."},
|
||||
{Name: "creative", Prompt: "You are a creative assistant. Think outside the box and offer innovative solutions."},
|
||||
{Name: "teacher", Prompt: "You are a patient teacher. Explain concepts clearly with examples."},
|
||||
}}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ func Applicability() map[string][]string {
|
||||
for _, kind := range []string{"task-policy", "provider-settings", "model-aliases", "repository-policies", "scheduling-policy", "tool-settings", "plugin-settings", "review-settings", "channel-settings", "container-runtime-policies", "credential-bindings", "identity-grants", "agent-profiles", "workflow-execution-settings", "extension-settings", "workflow-definitions", "workflow-enablement", "schedules", "eda-playbooks"} {
|
||||
kinds[kind] = []string{Daemon}
|
||||
}
|
||||
for _, kind := range []string{"provider-settings", "model-aliases", "tool-settings", "extension-settings", "personas", "soul", "skills", "curators"} {
|
||||
for _, kind := range []string{"provider-settings", "model-aliases", "tool-settings", "extension-settings", "soul", "skills", "curators"} {
|
||||
kinds[kind] = append(kinds[kind], Gateway)
|
||||
}
|
||||
for _, kind := range []string{"channel-settings", "extension-settings"} {
|
||||
|
||||
@@ -23,7 +23,6 @@ type ChatContract interface { //nolint:interfacebloat // wire contract intention
|
||||
// every queued or running task the conversation origin created. It
|
||||
// returns the tasks it stopped.
|
||||
StopTasks(ctx context.Context, origin string, taskID int64) ([]int64, error)
|
||||
SetPersona(context.Context, string, string) (bool, error)
|
||||
ChatTaskActionContract
|
||||
}
|
||||
|
||||
|
||||
@@ -9,16 +9,13 @@ type ChatSnapshot struct {
|
||||
Providers []string
|
||||
ActiveModel string
|
||||
ActiveProvider string
|
||||
Personas []string
|
||||
ActivePersonas map[string]string
|
||||
// Version is the Gateway's rendered component-version block. Channel
|
||||
// frontends display it rather than stamping their own build, so a
|
||||
// partially upgraded deployment cannot report itself as matched.
|
||||
Version string
|
||||
CancellationAvailable bool
|
||||
// VoiceAvailable reports that a voice clip is transcribed into the turn.
|
||||
VoiceAvailable bool
|
||||
PersonasAvailable bool
|
||||
VoiceAvailable bool
|
||||
}
|
||||
|
||||
// ChatReply is the blocking reply from Route.
|
||||
|
||||
@@ -10,7 +10,7 @@ var localCommands = []string{
|
||||
"/new", "/reset", "/topic", "/retry", "/undo",
|
||||
"/title", "/branch", "/fork", "/compress", "/compact",
|
||||
"/whoami", "/profile", "/sessions", "/resume", "/delete", "/agents",
|
||||
"/personality", "/help", "/version", "/update",
|
||||
"/help", "/version", "/update",
|
||||
}
|
||||
|
||||
// CommandSpec describes a local command for adapter-provided discovery.
|
||||
@@ -45,7 +45,6 @@ var localCommandSpecs = []CommandSpec{
|
||||
{Command: "/resume", Description: "Switch to a conversation", Usage: "/resume <session-id>"},
|
||||
{Command: "/delete", Description: "Delete a conversation and its history", Usage: "/delete <session-id>"},
|
||||
{Command: "/agents", Description: "List tasks currently being worked", Usage: "/agents"},
|
||||
{Command: "/personality", Description: "Choose a communication style", Usage: "/personality [name]"},
|
||||
{Command: "/help", Description: "See what Archie can do", Usage: "/help"},
|
||||
{Command: "/version", Description: "Show installed Archie versions", Usage: "/version"},
|
||||
{Command: "/update", Description: "Check for Archie updates", Usage: "/update"},
|
||||
|
||||
@@ -21,7 +21,6 @@ type LocalChatAdapter struct {
|
||||
Sessions SessionStore
|
||||
Turns *Turns
|
||||
Models ModelManager
|
||||
Personas *PersonaRegistry
|
||||
TaskActor ChatTaskActor
|
||||
// Tasks reads the tasks /stop acts on.
|
||||
Tasks TaskReader
|
||||
@@ -44,7 +43,7 @@ func (a *LocalChatAdapter) Snapshot(ctx context.Context) (ChatSnapshot, error) {
|
||||
if err != nil {
|
||||
return ChatSnapshot{}, err
|
||||
}
|
||||
s := ChatSnapshot{Sessions: sessions, Models: []string{}, Providers: []string{}, Personas: []string{}, ModelsByProvider: map[string][]string{}, ActivePersonas: map[string]string{}, CancellationAvailable: a.Turns != nil, PersonasAvailable: a.Personas != nil, VoiceAvailable: a.VoiceAvailable, Version: a.Router.Version}
|
||||
s := ChatSnapshot{Sessions: sessions, Models: []string{}, Providers: []string{}, ModelsByProvider: map[string][]string{}, CancellationAvailable: a.Turns != nil, VoiceAvailable: a.VoiceAvailable, Version: a.Router.Version}
|
||||
if a.Models != nil {
|
||||
s.Models, err = a.Models.ModelsFor(ctx)
|
||||
if err != nil {
|
||||
@@ -66,12 +65,6 @@ func (a *LocalChatAdapter) Snapshot(ctx context.Context) (ChatSnapshot, error) {
|
||||
s.Providers = append(s.Providers, provider)
|
||||
}
|
||||
slices.Sort(s.Providers)
|
||||
if a.Personas != nil {
|
||||
s.Personas = slices.Clone(a.Personas.List())
|
||||
for _, session := range sessions {
|
||||
s.ActivePersonas[session.SessionID] = a.Personas.ActiveName(session.SessionID)
|
||||
}
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
@@ -174,16 +167,6 @@ func haltAction(status string) (taskstate.Action, bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *LocalChatAdapter) SetPersona(ctx context.Context, id, name string) (bool, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if a.Personas == nil {
|
||||
return false, ErrChatCapabilityUnavailable
|
||||
}
|
||||
return a.Personas.SetActive(id, strings.ToLower(name)), nil
|
||||
}
|
||||
|
||||
func (a *LocalChatAdapter) ApplyTaskAction(ctx context.Context, identity string, taskID int64, action taskstate.Action, res taskactions.ActionPayload) (TaskActionResult, error) {
|
||||
if a.TaskActor == nil {
|
||||
return TaskActionResult{}, ErrChatCapabilityUnavailable
|
||||
|
||||
@@ -44,7 +44,6 @@ var dashboardPages = []DashboardPage{
|
||||
{Path: "/settings/models", Label: "Models", Description: "Model aliases and providers."},
|
||||
{Path: "/settings/repositories", Label: "Repositories", Description: "Watched repositories and gate overrides."},
|
||||
{Path: "/settings/identities", Label: "Identities", Description: "Actors and their lifecycle."},
|
||||
{Path: "/settings/personas", Label: "Personas", Description: "Chat system prompts and the default."},
|
||||
{Path: "/settings/schedules", Label: "Schedules", Description: "Timetabled work."},
|
||||
{Path: "/settings/scheduling-policy", Label: "Scheduling policy", Description: "Work discovery and forge labels."},
|
||||
{Path: "/settings/review", Label: "Review", Description: "Pull request review: precision filter and approval."},
|
||||
|
||||
@@ -118,11 +118,9 @@ type Router struct {
|
||||
// ModelPersist persists the active model selection so it survives
|
||||
// restarts (e.g. writing back to identity config). nil = not configured.
|
||||
ModelPersist func(ctx context.Context, modelRef string) error
|
||||
// Personas holds the available personality registry for /personality.
|
||||
Personas *PersonaRegistry
|
||||
Tasks TaskCreator // nil = /spawn not configured
|
||||
Controller TaskController // nil = /approve and /cancel not configured
|
||||
Settings *messaging.SettingsCommand
|
||||
Tasks TaskCreator // nil = /spawn not configured
|
||||
Controller TaskController // nil = /approve and /cancel not configured
|
||||
Settings *messaging.SettingsCommand
|
||||
// TaskLister backs /tasks: the live work view (id, title, status,
|
||||
// workflow/stage, age). nil = /tasks not configured.
|
||||
TaskLister ChatTaskLister
|
||||
@@ -360,9 +358,6 @@ func (r *Router) dispatchLocalMisc(ctx context.Context, msg messaging.Message, p
|
||||
case "/agents":
|
||||
reply, err := r.handleAgents(ctx)
|
||||
return reply, true, err
|
||||
case "/personality":
|
||||
reply, err := r.handlePersonality(ctx, msg, rest)
|
||||
return reply, true, err
|
||||
case "/help":
|
||||
return r.helpText(), true, nil
|
||||
case "/version":
|
||||
@@ -1062,3 +1057,7 @@ func (r *Router) handleAgents(ctx context.Context) (string, error) {
|
||||
}
|
||||
return strings.TrimSpace(b.String()), nil
|
||||
}
|
||||
|
||||
func (r *Router) helpText() string {
|
||||
return "Send a message to chat with Archie. Available commands:\n" + strings.Join(LocalCommands(), " ")
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
||||
)
|
||||
|
||||
// Persona is a named communication style that modifies the system prompt.
|
||||
type Persona struct {
|
||||
Name string
|
||||
Prompt string // prepended to the system prompt
|
||||
}
|
||||
|
||||
// PersonaRegistry holds available personas and tracks the active one
|
||||
// per session. Safe for concurrent use.
|
||||
type PersonaRegistry struct {
|
||||
mu sync.RWMutex
|
||||
personas map[string]Persona
|
||||
active map[string]string // sessionKey -> persona name
|
||||
defaultName string
|
||||
}
|
||||
|
||||
// NewPersonaRegistry creates a registry pre-populated with the given
|
||||
// personas. The first persona is the default for new sessions.
|
||||
func NewPersonaRegistry(personas []Persona) *PersonaRegistry {
|
||||
r := &PersonaRegistry{
|
||||
personas: make(map[string]Persona, len(personas)),
|
||||
active: make(map[string]string),
|
||||
}
|
||||
for index, p := range personas {
|
||||
r.personas[p.Name] = p
|
||||
if index == 0 {
|
||||
r.defaultName = p.Name
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// List returns all available persona names.
|
||||
func (r *PersonaRegistry) List() []string {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
names := make([]string, 0, len(r.personas))
|
||||
for _, p := range r.personas {
|
||||
names = append(names, p.Name)
|
||||
}
|
||||
sort.Strings(names)
|
||||
return names
|
||||
}
|
||||
|
||||
// Replace atomically changes the available definitions. Sessions whose
|
||||
// selection no longer exists use the new default.
|
||||
func (r *PersonaRegistry) Replace(personas []Persona, defaultName string) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
next := make(map[string]Persona, len(personas))
|
||||
for _, persona := range personas {
|
||||
next[persona.Name] = persona
|
||||
}
|
||||
for session, name := range r.active {
|
||||
if _, exists := next[name]; !exists {
|
||||
delete(r.active, session)
|
||||
}
|
||||
}
|
||||
r.personas = next
|
||||
r.defaultName = defaultName
|
||||
}
|
||||
|
||||
// SetActive sets the active persona for a session.
|
||||
func (r *PersonaRegistry) SetActive(sessionKey, name string) bool {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
if _, ok := r.personas[name]; !ok {
|
||||
return false
|
||||
}
|
||||
r.active[sessionKey] = name
|
||||
return true
|
||||
}
|
||||
|
||||
// GetActive returns the active persona's prompt for a session, or an
|
||||
// empty string when no persona is selected.
|
||||
func (r *PersonaRegistry) GetActive(sessionKey string) string {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
name, ok := r.active[sessionKey]
|
||||
if !ok {
|
||||
name = r.defaultName
|
||||
}
|
||||
p, ok := r.personas[name]
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
if name == r.defaultName {
|
||||
return p.Prompt
|
||||
}
|
||||
if baseline, ok := r.personas[r.defaultName]; ok && baseline.Prompt != "" {
|
||||
return baseline.Prompt + "\n\n" + p.Prompt
|
||||
}
|
||||
return p.Prompt
|
||||
}
|
||||
|
||||
// ActiveName returns the selected persona name for a session, falling back to
|
||||
// the registry default. It is used by channel adapters that render a compact
|
||||
// selector summary rather than the full prompt.
|
||||
func (r *PersonaRegistry) ActiveName(sessionKey string) string {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
if name := r.active[sessionKey]; name != "" {
|
||||
return name
|
||||
}
|
||||
return r.defaultName
|
||||
}
|
||||
|
||||
// Get returns a persona by name, or false when not found.
|
||||
func (r *PersonaRegistry) Get(name string) (Persona, bool) {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
p, ok := r.personas[name]
|
||||
return p, ok
|
||||
}
|
||||
|
||||
func (r *Router) handlePersonality(ctx context.Context, msg messaging.Message, rest string) (string, error) {
|
||||
if r.Personas == nil {
|
||||
return "Personality switching is not configured.", nil
|
||||
}
|
||||
name := strings.ToLower(strings.TrimSpace(rest))
|
||||
if name == "" {
|
||||
return fmt.Sprintf("Active personality: %s\nAvailable: %s", r.Personas.ActiveName(r.sessionKey(ctx, msg)), strings.Join(r.Personas.List(), ", ")), nil
|
||||
}
|
||||
if !r.Personas.SetActive(r.sessionKey(ctx, msg), name) {
|
||||
return fmt.Sprintf("Unknown personality %q. Available: %s", name, strings.Join(r.Personas.List(), ", ")), nil
|
||||
}
|
||||
return fmt.Sprintf("Personality set to %q.", name), nil
|
||||
}
|
||||
|
||||
func (r *Router) sessionKey(ctx context.Context, msg messaging.Message) string {
|
||||
if r.sessionTracker == nil {
|
||||
return msg.ConversationID.ChannelID
|
||||
}
|
||||
key, err := r.ResolveSessionKey(ctx, Inbound{Message: msg})
|
||||
if err != nil {
|
||||
return msg.ConversationID.ChannelID
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
func (r *Router) helpText() string {
|
||||
return "Send a message to chat with Archie. Available commands:\n" + strings.Join(LocalCommands(), " ")
|
||||
}
|
||||
@@ -45,10 +45,9 @@ type SlashDenialRecorder interface {
|
||||
|
||||
// slashAdminOnly names the commands that require an admin.
|
||||
var slashAdminOnly = map[string]bool{
|
||||
"/model": true,
|
||||
"/personality": true,
|
||||
"/settings": true,
|
||||
"/update": true,
|
||||
"/model": true,
|
||||
"/settings": true,
|
||||
"/update": true,
|
||||
}
|
||||
|
||||
// SlashAccessPolicy decides which slash commands a sender may run. Deny by
|
||||
|
||||
@@ -74,14 +74,6 @@ func (c *Client) Cancel(ctx context.Context, id string) (messaging.ChatCancellat
|
||||
return messaging.ChatCancellation{Cancelled: v.Cancelled, Dropped: int(v.Dropped)}, nil
|
||||
}
|
||||
|
||||
func (c *Client) SetPersona(ctx context.Context, id, name string) (bool, error) {
|
||||
v, err := c.client.SetPersona(ctx, &pb.SetPersonaRequest{SessionId: id, Name: name})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return v.Found, nil
|
||||
}
|
||||
|
||||
func (c *Client) StopTasks(ctx context.Context, origin string, taskID int64) ([]int64, error) {
|
||||
v, err := c.client.StopTasks(ctx, &pb.StopTasksRequest{Origin: origin, TaskId: taskID})
|
||||
if err != nil {
|
||||
|
||||
@@ -86,14 +86,6 @@ func (s *server) Cancel(ctx context.Context, r *pb.CancelRequest) (*pb.CancelRes
|
||||
return &pb.CancelResponse{Cancelled: v.Cancelled, Dropped: int64(v.Dropped)}, nil
|
||||
}
|
||||
|
||||
func (s *server) SetPersona(ctx context.Context, r *pb.SetPersonaRequest) (*pb.SetPersonaResponse, error) {
|
||||
v, err := s.chat.SetPersona(ctx, r.SessionId, r.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.SetPersonaResponse{Found: v}, nil
|
||||
}
|
||||
|
||||
func (s *server) StopTasks(ctx context.Context, r *pb.StopTasksRequest) (*pb.StopTasksResponse, error) {
|
||||
stopped, err := s.chat.StopTasks(ctx, r.Origin, r.TaskId)
|
||||
if err != nil && len(stopped) == 0 {
|
||||
|
||||
@@ -257,7 +257,7 @@ func snapshotProto(v messaging.ChatSnapshot) *pb.SnapshotResponse {
|
||||
for k, list := range v.ModelsByProvider {
|
||||
groups[k] = &pb.StringList{Values: list}
|
||||
}
|
||||
return &pb.SnapshotResponse{Sessions: mapValues(v.Sessions, sessionProto), Models: v.Models, ModelsByProvider: groups, Providers: v.Providers, ActiveModel: v.ActiveModel, ActiveProvider: v.ActiveProvider, Personas: v.Personas, ActivePersonas: v.ActivePersonas, CancellationAvailable: v.CancellationAvailable, PersonasAvailable: v.PersonasAvailable, VoiceAvailable: v.VoiceAvailable, Version: v.Version}
|
||||
return &pb.SnapshotResponse{Sessions: mapValues(v.Sessions, sessionProto), Models: v.Models, ModelsByProvider: groups, Providers: v.Providers, ActiveModel: v.ActiveModel, ActiveProvider: v.ActiveProvider, CancellationAvailable: v.CancellationAvailable, VoiceAvailable: v.VoiceAvailable, Version: v.Version}
|
||||
}
|
||||
|
||||
func snapshotValue(v *pb.SnapshotResponse) messaging.ChatSnapshot {
|
||||
@@ -265,5 +265,5 @@ func snapshotValue(v *pb.SnapshotResponse) messaging.ChatSnapshot {
|
||||
for k, list := range v.ModelsByProvider {
|
||||
groups[k] = list.GetValues()
|
||||
}
|
||||
return messaging.ChatSnapshot{Sessions: mapValues(v.Sessions, sessionValue), Models: v.Models, ModelsByProvider: groups, Providers: v.Providers, ActiveModel: v.ActiveModel, ActiveProvider: v.ActiveProvider, Personas: v.Personas, ActivePersonas: v.ActivePersonas, CancellationAvailable: v.CancellationAvailable, PersonasAvailable: v.PersonasAvailable, VoiceAvailable: v.VoiceAvailable, Version: v.Version}
|
||||
return messaging.ChatSnapshot{Sessions: mapValues(v.Sessions, sessionValue), Models: v.Models, ModelsByProvider: groups, Providers: v.Providers, ActiveModel: v.ActiveModel, ActiveProvider: v.ActiveProvider, CancellationAvailable: v.CancellationAvailable, VoiceAvailable: v.VoiceAvailable, Version: v.Version}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
-- Personas are gone; SOUL is the only chat identity text.
|
||||
|
||||
-- +goose Up
|
||||
DELETE FROM apply_status WHERE kind = 'personas';
|
||||
DELETE FROM resources WHERE kind = 'personas';
|
||||
|
||||
-- +goose Down
|
||||
SELECT 1;
|
||||
@@ -109,11 +109,6 @@ func chatMediaViews(media []messaging.MediaAttachment) []chatMediaView {
|
||||
return views
|
||||
}
|
||||
|
||||
type chatPersonaRequest struct {
|
||||
SessionID string `json:"session_id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type chatCancelRequest struct {
|
||||
SessionID string `json:"session_id"`
|
||||
}
|
||||
@@ -161,13 +156,9 @@ func (s *Server) handleChatSessions(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
out := make([]messaging.SessionContext, 0, len(snapshot.Sessions))
|
||||
active := make(map[string]string)
|
||||
for _, session := range snapshot.Sessions {
|
||||
if s.ownsChatSession(r.Context(), session) {
|
||||
out = append(out, session)
|
||||
if name, ok := snapshot.ActivePersonas[session.SessionID]; ok {
|
||||
active[session.SessionID] = name
|
||||
}
|
||||
}
|
||||
}
|
||||
writeJSON(w, map[string]any{
|
||||
@@ -177,9 +168,7 @@ func (s *Server) handleChatSessions(w http.ResponseWriter, r *http.Request) {
|
||||
"providers": snapshot.Providers,
|
||||
"active_model": snapshot.ActiveModel,
|
||||
"active_provider": snapshot.ActiveProvider,
|
||||
"personas": snapshot.Personas,
|
||||
"voice_available": snapshot.VoiceAvailable,
|
||||
"active_personas": active,
|
||||
"commands": chatCommandSpecs(chat),
|
||||
})
|
||||
}
|
||||
@@ -494,44 +483,6 @@ func (s *Server) handleChatCancel(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, map[string]any{"cancelled": result.Cancelled, "dropped": result.Dropped})
|
||||
}
|
||||
|
||||
func (s *Server) handleChatPersona(w http.ResponseWriter, r *http.Request) {
|
||||
chat, ok := s.chatReady(w)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
snapshot, err := chat.Contract.Snapshot(r.Context())
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if !snapshot.PersonasAvailable {
|
||||
http.Error(w, "personality switching is not configured", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
var req chatPersonaRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil || req.SessionID == "" || req.Name == "" {
|
||||
http.Error(w, "session_id and name are required", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if session, found, err := chat.Contract.GetSession(r.Context(), req.SessionID); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
} else if !found || !s.ownsChatSession(r.Context(), session) {
|
||||
http.Error(w, "session not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
changed, err := chat.Contract.SetPersona(r.Context(), req.SessionID, strings.ToLower(req.Name))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if !changed {
|
||||
http.Error(w, fmt.Sprintf("unknown personality %q", req.Name), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
writeJSON(w, map[string]any{"ok": true, "name": strings.ToLower(req.Name)})
|
||||
}
|
||||
|
||||
// writeUpdateCheckError answers an unset check command as not configured, which
|
||||
// the dashboard shows as such rather than as a failure.
|
||||
func writeUpdateCheckError(w http.ResponseWriter, err error) {
|
||||
|
||||
@@ -99,7 +99,6 @@ func TestHTTPPolicyCannotBeBypassed(t *testing.T) {
|
||||
{"POST", "/api/chat/answer"},
|
||||
{"POST", "/api/chat/cancel"},
|
||||
{"POST", "/api/chat/message"},
|
||||
{"POST", "/api/chat/persona"},
|
||||
{"POST", "/api/chat/stream"},
|
||||
{"POST", "/api/chat/update/defer"},
|
||||
{"POST", "/api/chat/update/install"},
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
type ownedChat struct{ messaging.ChatContract }
|
||||
|
||||
func (ownedChat) Snapshot(context.Context) (messaging.ChatSnapshot, error) {
|
||||
return messaging.ChatSnapshot{CancellationAvailable: true, PersonasAvailable: true}, nil
|
||||
return messaging.ChatSnapshot{CancellationAvailable: true}, nil
|
||||
}
|
||||
|
||||
func (ownedChat) GetSession(context.Context, string) (messaging.SessionContext, bool, error) {
|
||||
@@ -32,7 +32,6 @@ func (ownedChat) RecentTurns(context.Context, string, int) ([]messaging.TurnReco
|
||||
func (ownedChat) Cancel(context.Context, string) (messaging.ChatCancellation, error) {
|
||||
return messaging.ChatCancellation{Cancelled: true}, nil
|
||||
}
|
||||
func (ownedChat) SetPersona(context.Context, string, string) (bool, error) { return true, nil }
|
||||
|
||||
func TestWebChatOwnership(t *testing.T) {
|
||||
for _, route := range []struct {
|
||||
@@ -42,7 +41,6 @@ func TestWebChatOwnership(t *testing.T) {
|
||||
{"messages", "", (*Server).handleChatMessages},
|
||||
{"turns", "", (*Server).handleChatTurns},
|
||||
{"cancel", `{"session_id":"private"}`, (*Server).handleChatCancel},
|
||||
{"persona", `{"session_id":"private","name":"archie"}`, (*Server).handleChatPersona},
|
||||
} {
|
||||
for _, user := range []string{"alice", "bob"} {
|
||||
t.Run(route.name+"/"+user, func(t *testing.T) {
|
||||
|
||||
@@ -382,7 +382,6 @@ func (s *Server) registerChatRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("POST /api/chat/cancel", s.handleChatCancel)
|
||||
mux.HandleFunc("POST /api/chat/answer", s.handleChatAnswer)
|
||||
mux.HandleFunc("GET /api/chat/file/{token}", s.handleChatFile)
|
||||
mux.HandleFunc("POST /api/chat/persona", s.handleChatPersona)
|
||||
mux.HandleFunc("GET /api/chat/update", instanceOnly(s.handleChatUpdate))
|
||||
mux.HandleFunc("POST /api/chat/update/defer", instanceOnly(s.handleChatUpdateDefer))
|
||||
mux.HandleFunc("POST /api/chat/update/install", instanceOnly(s.handleChatUpdateInstall))
|
||||
|
||||
Reference in new issue
Block a user