correction des pb de space : le spaceId est maintenant dans l'url uniquement
This commit is contained in:
1 parent
c52460bac0
commit
0bb8d1cb46
41 files changed
+1463
-121
No files matched your search
@@ -0,0 +1,63 @@
|
||||
package turso
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
|
||||
"trankilou.fr/lassistanoque/backend/internal/adapter/database/orm"
|
||||
"trankilou.fr/lassistanoque/backend/internal/domain"
|
||||
)
|
||||
|
||||
type TursoAgentRepository struct {
|
||||
db *sql.DB
|
||||
AgentTable orm.Table[domain.Agent]
|
||||
}
|
||||
|
||||
func NewTursoAgentRepository(db *sql.DB) *TursoAgentRepository {
|
||||
dialect := orm.NewSqliteDialect()
|
||||
AgentTable, err := orm.NewTable[domain.Agent](db, dialect, "agents")
|
||||
if err != nil {
|
||||
log.Fatalf("error creating lasebuche agent table")
|
||||
}
|
||||
|
||||
return &TursoAgentRepository{
|
||||
db: db,
|
||||
AgentTable: AgentTable,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *TursoAgentRepository) ListAgents(userID string, teamID string) ([]*domain.Agent, error) {
|
||||
return r.AgentTable.Select(
|
||||
orm.WithWhere(
|
||||
"team_id=$1 and team_id in (select team_id from user_teams where user_id=$2)",
|
||||
teamID,
|
||||
userID,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
func (r *TursoAgentRepository) GetAgent(userID string, teamID string, id string) (*domain.Agent, error) {
|
||||
return r.AgentTable.SelectOne(
|
||||
"id=$1 and team_id=$2 and team_id in (select team_id from user_teams where user_id=$3)",
|
||||
id,
|
||||
teamID,
|
||||
userID,
|
||||
)
|
||||
}
|
||||
|
||||
func (r *TursoAgentRepository) CreateAgent(userID string, agent *domain.Agent) (*domain.Agent, error) {
|
||||
return r.AgentTable.Insert(agent)
|
||||
}
|
||||
|
||||
func (r *TursoAgentRepository) UpdateAgent(userID string, agent *domain.Agent) (*domain.Agent, error) {
|
||||
return r.AgentTable.Update(agent)
|
||||
}
|
||||
|
||||
func (r *TursoAgentRepository) DeleteAgent(userID string, teamID string, id string) error {
|
||||
return r.AgentTable.DeleteWhere(
|
||||
"id=$1 and team_id=$2 and team_id in (select team_id from user_teams where user_id=$3)",
|
||||
id,
|
||||
teamID,
|
||||
userID,
|
||||
)
|
||||
}
|
||||
@@ -69,5 +69,9 @@ func (db *TursoDB) FileRepository() domain.FileRepository {
|
||||
}
|
||||
|
||||
func (db *TursoDB) ProviderRepository() domain.ProviderRepository {
|
||||
return NewTursoModelRepository(db.DB)
|
||||
return NewTursoProviderRepository(db.DB)
|
||||
}
|
||||
|
||||
func (db *TursoDB) AgentRepository() domain.AgentRepository {
|
||||
return NewTursoAgentRepository(db.DB)
|
||||
}
|
||||
@@ -6,19 +6,19 @@ import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"gitea.trankilou.fr/fabien/lasebuche"
|
||||
"trankilou.fr/lassistanoque/backend/internal/adapter/database/orm"
|
||||
"trankilou.fr/lassistanoque/backend/internal/domain"
|
||||
"trankilou.fr/lassistanoque/backend/internal/utility"
|
||||
)
|
||||
|
||||
type TursoFileRepository struct {
|
||||
db *sql.DB
|
||||
FileTable lasebuche.Table[domain.File]
|
||||
FileTable orm.Table[domain.File]
|
||||
}
|
||||
|
||||
func NewTursoFileRepository(db *sql.DB) *TursoFileRepository {
|
||||
dialect := lasebuche.NewSqliteDialect()
|
||||
fileTable, err := lasebuche.NewTable[domain.File](db, dialect, "settings")
|
||||
dialect := orm.NewSqliteDialect()
|
||||
fileTable, err := orm.NewTable[domain.File](db, dialect, "settings")
|
||||
if err != nil {
|
||||
log.Fatalf("error creating lasebuche team table")
|
||||
}
|
||||
|
||||
@@ -11,3 +11,4 @@ drop table tools;
|
||||
drop table tasks;
|
||||
drop table history;
|
||||
drop table files;
|
||||
drop table agents;
|
||||
@@ -141,3 +141,24 @@ create table files (
|
||||
_date_updated numeric ,
|
||||
_version text not null
|
||||
);
|
||||
|
||||
create table agents (
|
||||
id text not null primary key,
|
||||
team_id text not null,
|
||||
name text not null default '',
|
||||
system_prompt text not null default '',
|
||||
def_provider_id text not null default '',
|
||||
def_model_id text not null default '',
|
||||
tools_policy text not null default '',
|
||||
sub_agents numeric not null default 0,
|
||||
loop_strategy text not null default '',
|
||||
max_iterations numeric not null default 1,
|
||||
stopping_criteria text not null default '',
|
||||
-- kb text not null default '',
|
||||
-- tools text not null default '',
|
||||
-- skills text not null default '',
|
||||
-- channels text not null default '',
|
||||
_date_created numeric not null default current_timestamp,
|
||||
_date_updated numeric ,
|
||||
_version text not null
|
||||
);
|
||||
@@ -4,37 +4,40 @@ import (
|
||||
"database/sql"
|
||||
"log"
|
||||
|
||||
"gitea.trankilou.fr/fabien/lasebuche"
|
||||
"trankilou.fr/lassistanoque/backend/internal/adapter/database/orm"
|
||||
"trankilou.fr/lassistanoque/backend/internal/domain"
|
||||
)
|
||||
|
||||
type TursoModelRepository struct {
|
||||
type TursoProviderRepository struct {
|
||||
db *sql.DB
|
||||
providerTable lasebuche.Table[domain.Provider]
|
||||
providerTable orm.Table[domain.Provider]
|
||||
}
|
||||
|
||||
func NewTursoModelRepository(db *sql.DB) *TursoModelRepository {
|
||||
dialect := lasebuche.NewSqliteDialect()
|
||||
providerTable, err := lasebuche.NewTable[domain.Provider](db, dialect, "providers")
|
||||
func NewTursoProviderRepository(db *sql.DB) *TursoProviderRepository {
|
||||
dialect := orm.NewSqliteDialect()
|
||||
providerTable, err := orm.NewTable[domain.Provider](db, dialect, "providers")
|
||||
if err != nil {
|
||||
log.Fatalf("error creating lasebuche team table")
|
||||
log.Fatalf("error creating lasebuche provider table")
|
||||
}
|
||||
|
||||
return &TursoModelRepository{
|
||||
return &TursoProviderRepository{
|
||||
db: db,
|
||||
providerTable: providerTable,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *TursoModelRepository) ListProviders(userID string, teamID string) ([]*domain.Provider, error) {
|
||||
return r.providerTable.SelectWhere(
|
||||
"team_id=$1 and team_id in (select team_id from user_teams where user_id=$2)",
|
||||
teamID,
|
||||
userID,
|
||||
func (r *TursoProviderRepository) ListProviders(userID string, teamID string) ([]*domain.Provider, error) {
|
||||
return r.providerTable.Select(
|
||||
orm.WithWhere(
|
||||
"team_id=$1 and team_id in (select team_id from user_teams where user_id=$2)",
|
||||
teamID,
|
||||
userID,
|
||||
),
|
||||
orm.WithOrder("name"),
|
||||
)
|
||||
}
|
||||
|
||||
func (r *TursoModelRepository) GetProvider(userID string, teamID string, id string) (*domain.Provider, error) {
|
||||
func (r *TursoProviderRepository) GetProvider(userID string, teamID string, id string) (*domain.Provider, error) {
|
||||
return r.providerTable.SelectOne(
|
||||
"id=$1 and team_id=$2 and team_id in (select team_id from user_teams where user_id=$3)",
|
||||
id,
|
||||
@@ -43,15 +46,15 @@ func (r *TursoModelRepository) GetProvider(userID string, teamID string, id stri
|
||||
)
|
||||
}
|
||||
|
||||
func (r *TursoModelRepository) CreateProvider(userID string, provider *domain.Provider) (*domain.Provider, error) {
|
||||
func (r *TursoProviderRepository) CreateProvider(userID string, provider *domain.Provider) (*domain.Provider, error) {
|
||||
return r.providerTable.Insert(provider)
|
||||
}
|
||||
|
||||
func (r *TursoModelRepository) UpdateProvider(userID string, provider *domain.Provider) (*domain.Provider, error) {
|
||||
func (r *TursoProviderRepository) UpdateProvider(userID string, provider *domain.Provider) (*domain.Provider, error) {
|
||||
return r.providerTable.Update(provider)
|
||||
}
|
||||
|
||||
func (r *TursoModelRepository) DeleteProvider(userID string, teamID string, id string) error {
|
||||
func (r *TursoProviderRepository) DeleteProvider(userID string, teamID string, id string) error {
|
||||
return r.providerTable.DeleteWhere(
|
||||
"id=$1 and team_id=$2 and team_id in (select team_id from user_teams where user_id=$3)",
|
||||
id,
|
||||
|
||||
@@ -4,18 +4,18 @@ import (
|
||||
"database/sql"
|
||||
"log"
|
||||
|
||||
"gitea.trankilou.fr/fabien/lasebuche"
|
||||
"trankilou.fr/lassistanoque/backend/internal/adapter/database/orm"
|
||||
"trankilou.fr/lassistanoque/backend/internal/domain"
|
||||
)
|
||||
|
||||
type TursoSettingsRepository struct {
|
||||
db *sql.DB
|
||||
SettingsTable lasebuche.Table[domain.Settings]
|
||||
SettingsTable orm.Table[domain.Settings]
|
||||
}
|
||||
|
||||
func NewTursoSettingsRepository(db *sql.DB) *TursoSettingsRepository {
|
||||
dialect := lasebuche.NewSqliteDialect()
|
||||
settingsTable, err := lasebuche.NewTable[domain.Settings](db, dialect, "settings")
|
||||
dialect := orm.NewSqliteDialect()
|
||||
settingsTable, err := orm.NewTable[domain.Settings](db, dialect, "settings")
|
||||
if err != nil {
|
||||
log.Fatalf("error creating lasebuche team table")
|
||||
}
|
||||
|
||||
@@ -4,34 +4,33 @@ import (
|
||||
"database/sql"
|
||||
"log"
|
||||
|
||||
"trankilou.fr/lassistanoque/backend/internal/adapter/database/orm"
|
||||
"trankilou.fr/lassistanoque/backend/internal/domain"
|
||||
|
||||
"gitea.trankilou.fr/fabien/lasebuche"
|
||||
)
|
||||
|
||||
type TursoUserRepository struct {
|
||||
DB *sql.DB
|
||||
UserTable lasebuche.Table[domain.User]
|
||||
TeamTable lasebuche.Table[domain.Team]
|
||||
UserTeamTable lasebuche.Table[domain.UserTeam]
|
||||
AddressTable lasebuche.Table[domain.UserAddress]
|
||||
UserTable orm.Table[domain.User]
|
||||
TeamTable orm.Table[domain.Team]
|
||||
UserTeamTable orm.Table[domain.UserTeam]
|
||||
AddressTable orm.Table[domain.UserAddress]
|
||||
}
|
||||
|
||||
func NewTursoUserRepository(db *sql.DB) *TursoUserRepository {
|
||||
dialect := lasebuche.NewSqliteDialect()
|
||||
userTable, err := lasebuche.NewTable[domain.User](db, dialect, "users")
|
||||
dialect := orm.NewSqliteDialect()
|
||||
userTable, err := orm.NewTable[domain.User](db, dialect, "users")
|
||||
if err != nil {
|
||||
log.Fatalf("error creating lasebuche user table")
|
||||
}
|
||||
teamTable, err := lasebuche.NewTable[domain.Team](db, dialect, "teams")
|
||||
teamTable, err := orm.NewTable[domain.Team](db, dialect, "teams")
|
||||
if err != nil {
|
||||
log.Fatalf("error creating lasebuche team table")
|
||||
}
|
||||
userTeamTable, err := lasebuche.NewTable[domain.UserTeam](db, dialect, "user_teams")
|
||||
userTeamTable, err := orm.NewTable[domain.UserTeam](db, dialect, "user_teams")
|
||||
if err != nil {
|
||||
log.Fatalf("error creating lasebuche team table")
|
||||
}
|
||||
userAddressTable, err := lasebuche.NewTable[domain.UserAddress](db, dialect, "user_addresses")
|
||||
userAddressTable, err := orm.NewTable[domain.UserAddress](db, dialect, "user_addresses")
|
||||
if err != nil {
|
||||
log.Fatalf("error creating lasebuche team table")
|
||||
}
|
||||
@@ -53,7 +52,7 @@ func (ur *TursoUserRepository) FindUserByEmail(email string) (*domain.User, erro
|
||||
}
|
||||
|
||||
func (ur *TursoUserRepository) ListUsers() ([]*domain.User, error) {
|
||||
return ur.UserTable.SelectWhere("")
|
||||
return ur.UserTable.Select()
|
||||
}
|
||||
|
||||
func (ur *TursoUserRepository) CreateUser(user *domain.User) (*domain.User, error) {
|
||||
@@ -73,7 +72,10 @@ func (ur *TursoUserRepository) FindTeam(userid string, teamid string) (*domain.T
|
||||
}
|
||||
|
||||
func (ur *TursoUserRepository) ListTeams(userid string) ([]*domain.Team, error) {
|
||||
return ur.TeamTable.SelectWhere("id in (select team_id from user_teams where user_id=$1)", userid)
|
||||
return ur.TeamTable.Select(
|
||||
orm.WithWhere("id in (select team_id from user_teams where user_id=$1)", userid),
|
||||
orm.WithOrder("label asc"),
|
||||
)
|
||||
}
|
||||
|
||||
func (ur *TursoUserRepository) CreateTeam(userid string, team *domain.Team) (*domain.Team, error) {
|
||||
@@ -108,7 +110,9 @@ func (ur *TursoUserRepository) FindUserTeam(userid string, teamid string) (*doma
|
||||
}
|
||||
|
||||
func (ur *TursoUserRepository) ListUserTeams(userid string) ([]*domain.UserTeam, error) {
|
||||
return ur.UserTeamTable.SelectWhere("user_id=$1", userid)
|
||||
return ur.UserTeamTable.Select(
|
||||
orm.WithWhere("user_id=$1", userid),
|
||||
)
|
||||
}
|
||||
|
||||
func (ur *TursoUserRepository) CreateUserTeam(userid string, team *domain.UserTeam) (*domain.UserTeam, error) {
|
||||
@@ -124,7 +128,10 @@ func (ur *TursoUserRepository) DeleteUserTeam(userid string, teamid string) erro
|
||||
}
|
||||
|
||||
func (ur *TursoUserRepository) ListUserAddresses(id string) ([]*domain.UserAddress, error) {
|
||||
return ur.AddressTable.SelectWhere("user_id=$1", id)
|
||||
return ur.AddressTable.Select(
|
||||
orm.WithWhere("user_id=$1", id),
|
||||
orm.WithOrder("type asc"),
|
||||
)
|
||||
}
|
||||
|
||||
func (ur *TursoUserRepository) GetUserAddress(addrID string) (*domain.UserAddress, error) {
|
||||
|
||||
Reference in new issue
Block a user