From 2be59efdeea09b0b4c751441769dc0fbcfb9602a Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Thu, 7 Nov 2024 14:12:28 -0700 Subject: [PATCH] bug: fix broken invoke for no name thread --- pkg/invoke/invoker.go | 17 +++++++---------- ui/handler.go | 2 -- .../src/lib/components/navbar/Profile.svelte | 1 + 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/pkg/invoke/invoker.go b/pkg/invoke/invoker.go index 927634f44..bbdb5c355 100644 --- a/pkg/invoke/invoker.go +++ b/pkg/invoke/invoker.go @@ -26,7 +26,6 @@ import ( apierror "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" - "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/util/retry" kclient "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -181,15 +180,13 @@ func (i *Invoker) getChatState(ctx context.Context, c kclient.Client, run *v1.Ru return result, lastRun.Spec.ThreadName, err } -func getThreadForAgent(ctx context.Context, c kclient.WithWatch, agent *v1.Agent, existingThreadName string) (*v1.Thread, error) { - if existingThreadName == "" { - return nil, apierror.NewNotFound(schema.GroupResource{ - Group: v1.SchemeGroupVersion.Group, - Resource: "thread", - }, existingThreadName) +func getThreadForAgent(ctx context.Context, c kclient.WithWatch, agent *v1.Agent, opt Options) (*v1.Thread, error) { + if opt.ThreadName != "" { + var thread v1.Thread + return &thread, c.Get(ctx, router.Key(agent.Namespace, opt.ThreadName), &thread) } - var thread v1.Thread - return &thread, c.Get(ctx, router.Key(agent.Namespace, existingThreadName), &thread) + + return createThreadForAgent(ctx, c, agent, opt.ThreadName, opt.UserUID, opt.AgentRefName) } func createThreadForAgent(ctx context.Context, c kclient.WithWatch, agent *v1.Agent, threadName, userUID, agentRefName string) (*v1.Thread, error) { @@ -236,7 +233,7 @@ func (i *Invoker) updateThreadFields(ctx context.Context, c kclient.WithWatch, a } func (i *Invoker) Agent(ctx context.Context, c kclient.WithWatch, agent *v1.Agent, input string, opt Options) (_ *Response, err error) { - thread, err := getThreadForAgent(ctx, c, agent, opt.ThreadName) + thread, err := getThreadForAgent(ctx, c, agent, opt) if apierror.IsNotFound(err) && opt.CreateThread && strings.HasPrefix(opt.ThreadName, system.ThreadPrefix) { thread, err = createThreadForAgent(ctx, c, agent, opt.ThreadName, opt.UserUID, opt.AgentRefName) } diff --git a/ui/handler.go b/ui/handler.go index 37344fde6..c140a101c 100644 --- a/ui/handler.go +++ b/ui/handler.go @@ -43,8 +43,6 @@ func serve(w http.ResponseWriter, r *http.Request) { http.ServeFileFS(w, r, embedded, "user/build/index.html") } else if _, err := fs.Stat(embedded, userPath); err == nil { http.ServeFileFS(w, r, embedded, userPath) - } else if r.URL.Path == "/" { - http.Redirect(w, r, "/admin/agents", http.StatusFound) } else if _, err := fs.Stat(embedded, adminPath); err == nil { http.ServeFileFS(w, r, embedded, adminPath) } else if strings.HasPrefix(r.URL.Path, "/admin") { diff --git a/ui/user/src/lib/components/navbar/Profile.svelte b/ui/user/src/lib/components/navbar/Profile.svelte index d9cdc8091..c2fa4ce4b 100644 --- a/ui/user/src/lib/components/navbar/Profile.svelte +++ b/ui/user/src/lib/components/navbar/Profile.svelte @@ -35,6 +35,7 @@
  • Settings