mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
refactor: bind container lifecycle to bot and improve schedule trigger flow
- Add SetupBotContainer to ContainerLifecycle interface so containers are automatically created when a bot is created, matching the existing cleanup-on-delete behavior. - Refactor schedule tools to use bot-scoped API paths and pass identity context for proper authorization. - Introduce dedicated trigger-schedule endpoint in chat resolver with explicit schedule payload instead of reusing the generic chat path. - Generate short-lived JWT tokens for schedule trigger callbacks with resolved bot owner identity. - Validate required parameters in NewLLMClient and NewOpenAIEmbedder constructors, returning errors instead of falling back to defaults. - Add unit tests for schedule token generation and chat resolver.
This commit is contained in:
@@ -112,7 +112,19 @@ func (s *Service) Create(ctx context.Context, ownerUserID string, req CreateBotR
|
||||
if err != nil {
|
||||
return Bot{}, err
|
||||
}
|
||||
return toBot(row)
|
||||
bot, err := toBot(row)
|
||||
if err != nil {
|
||||
return Bot{}, err
|
||||
}
|
||||
if s.containerLifecycle != nil {
|
||||
if err := s.containerLifecycle.SetupBotContainer(ctx, bot.ID); err != nil {
|
||||
s.logger.Error("failed to setup bot container",
|
||||
slog.String("bot_id", bot.ID),
|
||||
slog.Any("error", err),
|
||||
)
|
||||
}
|
||||
}
|
||||
return bot, nil
|
||||
}
|
||||
|
||||
func (s *Service) Get(ctx context.Context, botID string) (Bot, error) {
|
||||
|
||||
@@ -58,6 +58,7 @@ type ListMembersResponse struct {
|
||||
|
||||
// ContainerLifecycle handles container lifecycle events bound to bot operations.
|
||||
type ContainerLifecycle interface {
|
||||
SetupBotContainer(ctx context.Context, botID string) error
|
||||
CleanupBotContainer(ctx context.Context, botID string) error
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user