Skip to content

Commit

Permalink
chore: use explicit reference to lookup workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Dec 18, 2024
1 parent 36b7486 commit 6e289c9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 deletions.
20 changes: 5 additions & 15 deletions pkg/api/handlers/tasks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handlers

import (
"fmt"
"net/http"
"slices"
"time"
Expand Down Expand Up @@ -530,20 +531,9 @@ func (t *TaskHandler) Create(req api.Context) error {
return err
}

var workspaces v1.WorkspaceList
err = req.List(&workspaces, kclient.MatchingFields{
"status.workspaceID": thread.Status.WorkspaceID,
})
if err != nil {
return err
}

if len(workspaces.Items) == 0 {
return types.NewErrBadRequest("no workspace found for the thread")
}

if len(workspaces.Items) != 1 {
return types.NewErrBadRequest("multiple workspaces found for the thread")
var workspace v1.Workspace
if err := req.Get(&workspace, thread.Status.WorkspaceName); err != nil {
return fmt.Errorf("workspace not found: %w", err)
}

workflowManifest.Alias, err = randomtoken.Generate()
Expand All @@ -561,7 +551,7 @@ func (t *TaskHandler) Create(req api.Context) error {
ThreadName: thread.Name,
Manifest: workflowManifest,
KnowledgeSetNames: thread.Status.KnowledgeSetNames,
WorkspaceName: workspaces.Items[0].Name,
WorkspaceName: workspace.Name,
},
}

Expand Down
4 changes: 1 addition & 3 deletions pkg/storage/apis/otto.otto8.ai/v1/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ func (in *Workspace) Get(field string) string {
return in.Spec.ThreadName
case "spec.knowledgeSetName":
return in.Spec.KnowledgeSetName
case "status.workspaceID":
return in.Status.WorkspaceID
}

return ""
}

func (*Workspace) FieldNames() []string {
return []string{"spec.agentName", "spec.workflowName", "spec.threadName", "spec.knowledgeSetName", "status.workspaceID"}
return []string{"spec.agentName", "spec.workflowName", "spec.threadName", "spec.knowledgeSetName"}
}

var _ fields.Fields = (*Workspace)(nil)
Expand Down
4 changes: 2 additions & 2 deletions ui/user/src/lib/components/navbar/Tables.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
{#snippet body()}
{#if !tables}
<p class="pb-3 pt-6 text-center text-sm text-gray dark:text-gray-300">Loading...</p>
{:else if tables.tables.length === 0}
<p class="pb-3 pt-6 text-center text-sm text-gray dark:text-gray-300">No files</p>
{:else if !tables.tables || tables.tables.length === 0}
<p class="pb-3 pt-6 text-center text-sm text-gray dark:text-gray-300">No tables</p>
{:else}
<ul class="space-y-4 px-3 py-6 text-sm">
{#each tables.tables as table}
Expand Down
2 changes: 1 addition & 1 deletion ui/user/src/lib/services/chat/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export interface TaskRunList {
}

export interface TableList {
tables: Table[];
tables?: Table[];
}

export interface Table {
Expand Down

0 comments on commit 6e289c9

Please sign in to comment.