Files
archie/internal/app/archiegateway/chat_task_profiles.go
T
sam f5a04ce8c5
deploy / plan (push) Successful in 7s
deploy / archied-image (push) Canceled after 0s
deploy / agent-image (push) Canceled after 0s
deploy / dist-zip (push) Canceled after 0s
deploy / gate (push) Canceled after 22s
refactor(archiegateway): own the chat task profiles; archied built a task creator it never read
2026-11-09 08:32:28 +11:00

73 lines
2.1 KiB
Go

package archiegateway
import (
"context"
"fmt"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/identity"
"github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/gateway"
)
// chatTaskWriter adapts an enqueue call returning the task to gateway.TaskWriter.
type chatTaskWriter struct {
Enqueue func(
ctx context.Context,
owner, repo, title, body, workflow, identity, origin, draft string,
inputs map[string]any,
) (*workflow.Task, error)
}
func (a chatTaskWriter) EnqueueChatTask(
ctx context.Context,
owner, repo, title, body, workflow, identity, origin string,
inputs map[string]any,
) (int64, error) {
task, err := a.Enqueue(ctx, owner, repo, title, body, workflow, identity, origin, "", inputs)
if err != nil {
return 0, err
}
if task == nil {
return 0, fmt.Errorf("enqueue chat task returned no task")
}
return task.ID, nil
}
// chatTaskProfiles returns the task profiles cfg allows and the default identity.
func chatTaskProfiles(cfg config.Config) ([]gateway.TaskProfile, string) {
if len(cfg.Identities) > 0 {
profiles := make([]gateway.TaskProfile, 0, len(cfg.Identities))
for _, identity := range cfg.Identities {
if len(identity.Repos) == 0 {
continue
}
profiles = append(profiles, newChatTaskProfile(identity.Name, identity.Repos))
}
if len(profiles) == 0 {
return nil, ""
}
return profiles, profiles[0].Identity
}
if len(cfg.Repos) == 0 {
return nil, ""
}
// Chat acts as the control-plane operator, the identity the dashboard
// stamps on the tasks it creates.
operator := string(identity.OperatorID())
return []gateway.TaskProfile{newChatTaskProfile(operator, cfg.Repos)}, operator
}
func newChatTaskProfile(identity string, repos []config.Repo) gateway.TaskProfile {
allowed := make([]string, 0, len(repos))
for _, repo := range repos {
allowed = append(allowed, repo.Owner+"/"+repo.Name)
}
return gateway.TaskProfile{
Identity: identity,
DefaultOwner: repos[0].Owner,
DefaultRepo: repos[0].Name,
Repos: allowed,
}
}