Files

59 lines
1.9 KiB
Go

package domain
import (
"context"
"time"
)
// Clés de contexte passées aux outils lors de l'exécution : identité de
// l'appelant et modèle en cours, pour les outils qui en dépendent
// (ex. scheduler crée une tâche pour l'équipe courante).
type contextKey int
const (
contextKeyUserID contextKey = iota
contextKeyTeamID
contextKeyModelID
)
func WithToolContext(ctx context.Context, userID string, teamID string, modelID string) context.Context {
ctx = context.WithValue(ctx, contextKeyUserID, userID)
ctx = context.WithValue(ctx, contextKeyTeamID, teamID)
return context.WithValue(ctx, contextKeyModelID, modelID)
}
func UserIDFromContext(ctx context.Context) (string, bool) {
v, ok := ctx.Value(contextKeyUserID).(string)
return v, ok
}
func TeamIDFromContext(ctx context.Context) (string, bool) {
v, ok := ctx.Value(contextKeyTeamID).(string)
return v, ok
}
func ModelIDFromContext(ctx context.Context) (string, bool) {
v, ok := ctx.Value(contextKeyModelID).(string)
return v, ok
}
type Tool struct {
ID string `db:"id" json:"id"`
TeamID string `db:"team_id" json:"teamId"`
Name string `db:"name" json:"name"`
Enabled bool `db:"enabled" json:"enabled"`
Configuration string `db:"configuration" json:"configuration"`
DateCreated time.Time `db:"_date_created" json:"_date_created"`
DateUpdated *time.Time `db:"_date_updated" json:"_date_updated"`
VersionId string `db:"_version" json:"_version"`
}
type ToolRepository interface {
ListTools(userID string, teamID string) ([]*Tool, error)
GetToolByName(userID string, teamID string, name string) (*Tool, error)
GetToolByID(userID string, teamID string, id string) (*Tool, error)
CreateTool(userID string, agent *Tool) (*Tool, error)
UpdateTool(userID string, agent *Tool) (*Tool, error)
DeleteTool(userID string, teamID string, name string) error
}