@@ -14,9 +14,6 @@ import (
1414 "github.com/kagent-dev/kagent/go/core/internal/service/serviceerrors"
1515 "github.com/kagent-dev/kagent/go/core/internal/utils"
1616 "github.com/kagent-dev/kagent/go/core/pkg/auth"
17- apierrors "k8s.io/apimachinery/pkg/api/errors"
18- "sigs.k8s.io/controller-runtime/pkg/client"
19- ctrllog "sigs.k8s.io/controller-runtime/pkg/log"
2017)
2118
2219type Store interface {
@@ -34,15 +31,9 @@ type Store interface {
3431 DeleteSessionShare (context.Context , string , string , string ) error
3532}
3633
37- type SandboxActorCleaner interface {
38- DeleteSandboxAgentSessionActor (context.Context , * v1alpha3.SandboxAgent , string ) (bool , error )
39- }
40-
4134type Service struct {
42- store Store
43- kube client.Client
44- actorCleaner SandboxActorCleaner
45- token func () (string , error )
35+ store Store
36+ token func () (string , error )
4637}
4738
4839type Option func (* Service )
@@ -80,13 +71,6 @@ func NewService(store Store, options ...Option) *Service {
8071 return service
8172}
8273
83- func WithSandboxLifecycle (kube client.Client , cleaner SandboxActorCleaner ) Option {
84- return func (service * Service ) {
85- service .kube = kube
86- service .actorCleaner = cleaner
87- }
88- }
89-
9074func WithShareTokenGenerator (generator func () (string , error )) Option {
9175 return func (service * Service ) {
9276 if generator != nil {
@@ -155,18 +139,12 @@ func (s *Service) Create(ctx context.Context, request CreateRequest) (*database.
155139 return nil , serviceerrors .NewInvalidArgument (fmt .Sprintf ("Agent ref is invalid, please check the agent ref %s" , request .AgentRef ), err )
156140 }
157141 if agent .WorkloadType == v1alpha3 .WorkloadModeSandbox {
158- _ , isSubstrateSandbox , err := s .lookupSubstrateSandboxAgent (ctx , request . AgentRef )
142+ existing , err := s .store . ListSessionsForAgentAllUsers (ctx , agentID )
159143 if err != nil {
160- return nil , serviceerrors .NewInternal ("Failed to inspect sandbox agent" , err )
144+ return nil , serviceerrors .NewInternal ("Failed to list sessions for agent" , err )
161145 }
162- if ! isSubstrateSandbox {
163- existing , err := s .store .ListSessionsForAgentAllUsers (ctx , agentID )
164- if err != nil {
165- return nil , serviceerrors .NewInternal ("Failed to list sessions for agent" , err )
166- }
167- if len (existing ) > 0 {
168- return nil , serviceerrors .NewAlreadyExists ("Sandbox agents support only one chat session" , fmt .Errorf ("a session already exists for this agent" ))
169- }
146+ if len (existing ) > 0 {
147+ return nil , serviceerrors .NewAlreadyExists ("Sandbox agents support only one chat session" , fmt .Errorf ("a session already exists for this agent" ))
170148 }
171149 }
172150
@@ -261,23 +239,9 @@ func (s *Service) Delete(ctx context.Context, sessionID string) error {
261239 if s .store == nil {
262240 return serviceerrors .NewInternal ("Failed to delete session" , fmt .Errorf ("database client is not configured" ))
263241 }
264-
265- var cleanup * v1alpha3.SandboxAgent
266- if s .actorCleaner != nil {
267- if session , getErr := s .store .GetSession (ctx , sessionID , userID ); getErr == nil && session != nil && session .AgentID != nil {
268- if sandboxAgent , lookupErr := s .substrateSandboxAgentForSession (ctx , session ); lookupErr == nil {
269- cleanup = sandboxAgent
270- }
271- }
272- }
273242 if err := s .store .DeleteSession (ctx , sessionID , userID ); err != nil {
274243 return serviceerrors .NewInternal ("Failed to delete session" , err )
275244 }
276- if cleanup != nil {
277- if _ , err := s .actorCleaner .DeleteSandboxAgentSessionActor (ctx , cleanup , sessionID ); err != nil {
278- ctrllog .FromContext (ctx ).Error (err , "failed to delete substrate session actor" , "sessionID" , sessionID )
279- }
280- }
281245 return nil
282246}
283247
@@ -393,47 +357,6 @@ func (s *Service) DeleteShare(ctx context.Context, sessionID, token string) erro
393357 return nil
394358}
395359
396- func (s * Service ) lookupSubstrateSandboxAgent (ctx context.Context , agentRef string ) (* v1alpha3.SandboxAgent , bool , error ) {
397- if s .kube == nil {
398- return nil , false , nil
399- }
400- ref := strings .TrimSpace (agentRef )
401- if ref == "" {
402- return nil , false , nil
403- }
404- kubernetesRef := utils .ConvertToKubernetesIdentifier (ref )
405- namespacedName , err := utils .ParseRefString (kubernetesRef , "" )
406- if err != nil {
407- return nil , false , nil
408- }
409- sandboxAgent := & v1alpha3.SandboxAgent {}
410- if err := s .kube .Get (ctx , namespacedName , sandboxAgent ); err != nil {
411- if apierrors .IsNotFound (err ) {
412- return nil , false , nil
413- }
414- return nil , false , err
415- }
416- return sandboxAgent , true , nil
417- }
418-
419- func (s * Service ) substrateSandboxAgentForSession (ctx context.Context , session * database.Session ) (* v1alpha3.SandboxAgent , error ) {
420- if session == nil || session .AgentID == nil {
421- return nil , nil
422- }
423- agent , err := s .store .GetAgent (ctx , * session .AgentID )
424- if err != nil {
425- return nil , err
426- }
427- if agent .WorkloadType != v1alpha3 .WorkloadModeSandbox {
428- return nil , nil
429- }
430- sandboxAgent , isSubstrate , err := s .lookupSubstrateSandboxAgent (ctx , * session .AgentID )
431- if err != nil || ! isSubstrate {
432- return nil , err
433- }
434- return sandboxAgent , nil
435- }
436-
437360func authenticatedPrincipal (ctx context.Context ) (auth.Principal , error ) {
438361 session , ok := auth .AuthSessionFrom (ctx )
439362 if ! ok || session == nil {
0 commit comments