Skip to content

Commit

Permalink
chore: rename refName to alias
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Nov 16, 2024
1 parent 71e4d50 commit 43907dc
Show file tree
Hide file tree
Showing 61 changed files with 1,397 additions and 1,553 deletions.
6 changes: 3 additions & 3 deletions apiclient/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (c *Client) CreateAgent(ctx context.Context, agent types.AgentManifest) (*t
}

type ListAgentsOptions struct {
RefName string
Alias string
}

func (c *Client) ListAgents(ctx context.Context, opts ListAgentsOptions) (result types.AgentList, err error) {
Expand All @@ -60,10 +60,10 @@ func (c *Client) ListAgents(ctx context.Context, opts ListAgentsOptions) (result
return result, err
}

if opts.RefName != "" {
if opts.Alias != "" {
var filtered types.AgentList
for _, agent := range result.Items {
if agent.RefName == opts.RefName && agent.RefNameAssigned {
if agent.Alias == opts.Alias && agent.AliasAssigned {
filtered.Items = append(filtered.Items, agent)
}
}
Expand Down
10 changes: 3 additions & 7 deletions apiclient/types/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
type Agent struct {
Metadata
AgentManifest
AgentExternalStatus
AliasAssigned bool `json:"aliasAssigned,omitempty"`
AuthStatus map[string]OAuthAppLoginAuthStatus `json:"authStatus,omitempty"`
}

type AgentList List[Agent]
Expand All @@ -29,7 +30,7 @@ type AgentManifest struct {
Description string `json:"description"`
Temperature *float32 `json:"temperature"`
Cache *bool `json:"cache"`
RefName string `json:"refName"`
Alias string `json:"alias"`
Prompt string `json:"prompt"`
KnowledgeDescription string `json:"knowledgeDescription"`
Agents []string `json:"agents"`
Expand All @@ -43,11 +44,6 @@ type AgentManifest struct {
Model string `json:"model"`
}

type AgentExternalStatus struct {
RefNameAssigned bool `json:"refNameAssigned,omitempty"`
AuthStatus map[string]OAuthAppLoginAuthStatus `json:"authStatus,omitempty"`
}

func (m AgentManifest) GetParams() *openapi3.Schema {
var args []string
for _, k := range slices.Sorted(maps.Keys(m.Params)) {
Expand Down
2 changes: 1 addition & 1 deletion apiclient/types/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type CronJob struct {
type CronJobManifest struct {
Description string `json:"description,omitempty"`
Schedule string `json:"schedule,omitempty"`
WorkflowID string `json:"workflowID,omitempty"`
Workflow string `json:"workflow,omitempty"`
Input string `json:"input,omitempty"`
}

Expand Down
17 changes: 17 additions & 0 deletions apiclient/types/emailreceiver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package types

type EmailReceiver struct {
Metadata
EmailReceiverManifest
AliasAssigned bool `json:"aliasAssigned,omitempty"`
}

type EmailReceiverManifest struct {
Name string `json:"name"`
Description string `json:"description"`
Alias string `json:"alias"`
Workflow string `json:"workflow"`
AllowedSenders []string `json:"allowedSenders,omitempty"`
}

type EmailReceiverList List[EmailReceiver]
2 changes: 1 addition & 1 deletion apiclient/types/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Thread struct {
CurrentRunID string `json:"currentRunID,omitempty"`
ParentThreadID string `json:"parentThreadID,omitempty"`
UserID string `json:"userID,omitempty"`
AgentRefName string `json:"agentRefName,omitempty"`
AgentAlias string `json:"agentAlias,omitempty"`
}

type ThreadList List[Thread]
Expand Down
9 changes: 2 additions & 7 deletions apiclient/types/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,18 @@ package types
type Webhook struct {
Metadata
WebhookManifest
RefNameAssigned bool `json:"refNameAssigned,omitempty"`
AliasAssigned bool `json:"aliasAssigned,omitempty"`
LastSuccessfulRunCompleted *Time `json:"lastSuccessfulRunCompleted,omitempty"`
}

type WebhookManifest struct {
Name string `json:"name"`
Description string `json:"description"`
RefName string `json:"refName"`
Alias string `json:"alias"`
Workflow string `json:"workflow"`
Headers []string `json:"headers"`
Secret string `json:"secret"`
ValidationHeader string `json:"validationHeader"`
}

type WebhookExternalStatus struct {
RefName string `json:"refName,omitempty"`
RefNameAssigned bool `json:"refNameAssigned,omitempty"`
}

type WebhookList List[Webhook]
8 changes: 2 additions & 6 deletions apiclient/types/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ import "strings"
type Workflow struct {
Metadata
WorkflowManifest
WorkflowExternalStatus
}

type WorkflowExternalStatus struct {
RefNameAssigned bool `json:"refNameAssigned,omitempty"`
AuthStatus map[string]OAuthAppLoginAuthStatus `json:"authStatus,omitempty"`
AliasAssigned bool `json:"aliasAssigned,omitempty"`
AuthStatus map[string]OAuthAppLoginAuthStatus `json:"authStatus,omitempty"`
}

type WorkflowList List[Workflow]
Expand Down
126 changes: 69 additions & 57 deletions apiclient/types/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions apiclient/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (c *Client) CreateWorkflow(ctx context.Context, workflow types.WorkflowMani
}

type ListWorkflowsOptions struct {
RefName string
Alias string
}

func (c *Client) ListWorkflows(ctx context.Context, opts ListWorkflowsOptions) (result types.WorkflowList, err error) {
Expand All @@ -60,10 +60,10 @@ func (c *Client) ListWorkflows(ctx context.Context, opts ListWorkflowsOptions) (
return result, err
}

if opts.RefName != "" {
if opts.Alias != "" {
var filtered types.WorkflowList
for _, workflow := range result.Items {
if workflow.RefName == opts.RefName && workflow.RefNameAssigned {
if workflow.Alias == opts.Alias && workflow.AliasAssigned {
filtered.Items = append(filtered.Items, workflow)
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/02-concepts/06-workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Another way to trigger a workflow is via a **webhook**. This feature is still un
```
curl -X POST 'http://127.0.0.1:8080/api/webhooks' -d '{ \
"description": "Webhook to respond to pagerduty events", \
"refName": "pd-hook", \
"alias": "pd-hook", \
"workflowID": "w1km9xw"}'
```
This will produce a webhook that can be called at http://localhost:8080/api/webhooks/pd-hook. When called, the body of the webhook request will be sent to the workflow as input.
Expand Down
55 changes: 55 additions & 0 deletions pkg/alias/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package alias

import (
"context"
"errors"
"strings"

"github.com/otto8-ai/nah/pkg/name"
"github.com/otto8-ai/nah/pkg/router"
v1 "github.com/otto8-ai/otto8/pkg/storage/apis/otto.otto8.ai/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
kclient "sigs.k8s.io/controller-runtime/pkg/client"
)

func Get(ctx context.Context, c kclient.Client, obj v1.Aliasable, namespace string, name string) error {
errLookup := c.Get(ctx, router.Key(namespace, name), obj.(kclient.Object))
if kclient.IgnoreNotFound(errLookup) != nil {
return errLookup
} else if errLookup == nil {
return nil
}

gvk, err := c.GroupVersionKindFor(obj.(kclient.Object))
if err != nil {
return err
}

var alias v1.Alias
if err := c.Get(ctx, router.Key(namespace, Key(gvk, obj, name)), &alias); apierrors.IsNotFound(err) {
return errLookup
} else if err != nil {
return errors.Join(errLookup, err)
} else if alias.Spec.TargetKind != gvk.Kind {
return errLookup
}

return c.Get(ctx, router.Key(alias.Spec.TargetNamespace, alias.Spec.TargetName), obj.(kclient.Object))
}

func keyFromName(scope, id string) string {
return strings.ToLower(name.SafeHashConcatName(id, scope))
}

func getScope(gvk schema.GroupVersionKind, obj v1.Aliasable) string {
if scoped, ok := obj.(v1.AliasScoped); ok && scoped.GetAliasScope() != "" {
return scoped.GetAliasScope()
}

return gvk.Kind
}

func Key(gvk schema.GroupVersionKind, obj v1.Aliasable, id string) string {
return keyFromName(getScope(gvk, obj), id)
}
Loading

0 comments on commit 43907dc

Please sign in to comment.