Skip to content

Commit

Permalink
bug: fix broken invoke for no name thread
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Nov 7, 2024
1 parent de427df commit 2be59ef
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
17 changes: 7 additions & 10 deletions pkg/invoke/invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 0 additions & 2 deletions ui/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
1 change: 1 addition & 0 deletions ui/user/src/lib/components/navbar/Profile.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<li>
<a
href="/admin/"
data-sveltekit-reload
class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:text-white dark:hover:bg-gray-600 dark:hover:text-white"
role="menuitem">Settings</a
>
Expand Down

0 comments on commit 2be59ef

Please sign in to comment.