Skip to content

Commit

Permalink
chore: break webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Nov 15, 2024
1 parent a082d6f commit 0b63953
Show file tree
Hide file tree
Showing 19 changed files with 363 additions and 166 deletions.
8 changes: 4 additions & 4 deletions apiclient/types/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ type AgentIcons struct {

type AgentManifest struct {
Name string `json:"name"`
Icons *AgentIcons `json:"icons,omitempty"`
Icons *AgentIcons `json:"icons"`
Description string `json:"description"`
Temperature *float32 `json:"temperature"`
Cache *bool `json:"cache"`
RefName string `json:"refName"`
Prompt string `json:"prompt"`
KnowledgeDescription string `json:"knowledgeDescription"`
Agents []string `json:"agents"`
Workflows []string `json:"workflows,omitempty"`
Workflows []string `json:"workflows"`
Tools []string `json:"tools"`
AvailableThreadTools []string `json:"availableThreadTools"`
DefaultThreadTools []string `json:"defaultThreadTools"`
OAuthApps []string `json:"oauthApps"`
MaxThreadTools int `json:"maxThreadTools"`
Params map[string]string `json:"params,omitempty"`
Model string `json:"model,omitempty"`
Params map[string]string `json:"params"`
Model string `json:"model"`
}

type AgentExternalStatus struct {
Expand Down
7 changes: 7 additions & 0 deletions apiclient/types/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ type Time struct {
Time time.Time
}

func (t *Time) GetTime() time.Time {
if t == nil {
return time.Time{}
}
return t.Time
}

// NewTimeFromPointer creates a new Time object from a pointer to a time.Time object. If the pointer is nil, the
// function returns nil.
func NewTimeFromPointer(t *time.Time) *Time {
Expand Down
13 changes: 7 additions & 6 deletions apiclient/types/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ type Webhook struct {
}

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

type WebhookExternalStatus struct {
Expand Down
14 changes: 7 additions & 7 deletions apiclient/types/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ type WorkflowList List[Workflow]

type WorkflowManifest struct {
AgentManifest `json:",inline"`
Credentials []string `json:"credentials,omitempty"`
Env []WorkflowEnv `json:"env,omitempty"`
Steps []Step `json:"steps,omitempty"`
Output string `json:"output,omitempty"`
Credentials []string `json:"credentials"`
Env []WorkflowEnv `json:"env"`
Steps []Step `json:"steps"`
Output string `json:"output"`
}

type WorkflowEnv struct {
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
Description string `json:"description,omitempty"`
Name string `json:"name"`
Value string `json:"value"`
Description string `json:"description"`
}

type Step struct {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ require (
github.com/nwaples/rardecode/v2 v2.0.0-beta.4 // indirect
github.com/ohler55/ojg v1.24.1 // indirect
github.com/olekukonko/tablewriter v0.0.6-0.20230925090304-df64c4bbad77 // indirect
github.com/otto8-ai/namegenerator v0.0.0-20241115024503-63dbbe8f03f4 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ github.com/otto8-ai/kinm v0.0.0-20241106213623-2a34e5d88241 h1:pR1P/rTKR2egA6JtU
github.com/otto8-ai/kinm v0.0.0-20241106213623-2a34e5d88241/go.mod h1:DOegE8RKFYiE0nmLdkJ3YDR668njuEmmqHE4q5qVNqU=
github.com/otto8-ai/nah v0.0.0-20241103035236-f2497c45ddb0 h1:I+4dYCCPY58dbABkbtEGtLQTx/tJvbZgkfcLj889yQM=
github.com/otto8-ai/nah v0.0.0-20241103035236-f2497c45ddb0/go.mod h1:mo2Dz5pAyZhAVvo+kQEzXZlLzb0SaNzhIate7BQs4Vg=
github.com/otto8-ai/namegenerator v0.0.0-20241115024503-63dbbe8f03f4 h1:w/VS6mtnVWy6iDxF4P8W66OuTk8dudWTJZzEtInegLU=
github.com/otto8-ai/namegenerator v0.0.0-20241115024503-63dbbe8f03f4/go.mod h1:Z4EotUCaCQ8PA+vS0ZDfTPh7JO9jTgpDoHxA3Zzwwjw=
github.com/otto8-ai/oauth2-proxy/v7 v7.0.0-20241008204315-265dabe17f43 h1:zuroXr125FGRsaj9/9brmtWfkiu3XkNoB78owd8lAo4=
github.com/otto8-ai/oauth2-proxy/v7 v7.0.0-20241008204315-265dabe17f43/go.mod h1:lxQ1wbphpjECcCoy8gfsrDHQVenNKgm+p6Oskdkl97g=
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
Expand Down
17 changes: 15 additions & 2 deletions pkg/api/handlers/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,21 @@ func convertAgent(agent v1.Agent, prefix string) *types.Agent {

func (a *AgentHandler) ByID(req api.Context) error {
var agent v1.Agent
if err := req.Get(&agent, req.PathValue("id")); err != nil {
return err
if system.IsAgentID(req.PathValue("id")) {
if err := req.Get(&agent, req.PathValue("id")); err != nil {
return err
}
} else {
var ref v1.Reference
if err := req.Get(&ref, req.PathValue("id")); err != nil {
return err
}
if ref.Spec.AgentName == "" {
return types.NewErrNotFound("reference %q is not an agent reference", ref.Name)
}
if err := req.Get(&agent, ref.Spec.AgentName); err != nil {
return err
}
}

return req.Write(convertAgent(agent, server.GetURLPrefix(req)))
Expand Down
32 changes: 21 additions & 11 deletions pkg/api/handlers/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,22 @@ func convertWebhook(webhook v1.Webhook, urlPrefix string) *types.Webhook {
}

func (a *WebhookHandler) ByID(req api.Context) error {
var wh v1.Webhook
if err := req.Get(&wh, req.PathValue("id")); err != nil {
return err
var (
wh v1.Webhook
id = req.PathValue("id")
)
if system.IsWebhookID(id) {
if err := req.Get(&wh, id); err != nil {
return err
}
} else {
var ref v1.WebhookReference
if err := req.Get(&ref, id); err != nil {
return err
}
if err := req.Get(&wh, ref.Spec.WebhookName); err != nil {
return err
}
}

return req.Write(convertWebhook(wh, server.GetURLPrefix(req)))
Expand Down Expand Up @@ -228,7 +241,7 @@ func (a *WebhookHandler) Execute(req api.Context) error {
input.WriteString(req.Request.Header.Get(k))
}

workflowID := webhook.Spec.WebhookManifest.WorkflowID
workflowID := webhook.Spec.WebhookManifest.Workflow
if !system.IsWorkflowID(workflowID) {
var ref v1.Reference
if err = req.Get(&ref, workflowID); err != nil || ref.Spec.WorkflowName == "" {
Expand Down Expand Up @@ -282,18 +295,15 @@ func validateSecretHeader(secret string, body []byte, values []string) error {

func validateManifest(req api.Context, manifest types.WebhookManifest) error {
// Ensure that the WorkflowID is set and the workflow exists
if manifest.WorkflowID == "" {
if manifest.Workflow == "" {
return apierrors.NewBadRequest("webhook manifest must have a workflow name")
}

var workflow v1.Workflow
if err := req.Get(&workflow, manifest.WorkflowID); types.IsNotFound(err) {
var ref v1.Reference
if err = req.Get(&ref, manifest.WorkflowID); err != nil || ref.Spec.WorkflowName == "" {
return apierrors.NewBadRequest(fmt.Sprintf("workflow %s does not exist", manifest.WorkflowID))
if system.IsWorkflowID(manifest.Workflow) {
if err := req.Get(&workflow, manifest.Workflow); err != nil {
return err
}
} else if err != nil {
return err
}

if (manifest.ValidationHeader != "") != (manifest.Secret != "") {
Expand Down
22 changes: 19 additions & 3 deletions pkg/api/handlers/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,25 @@ func convertWorkflow(workflow v1.Workflow, prefix string) *types.Workflow {
}

func (a *WorkflowHandler) ByID(req api.Context) error {
var workflow v1.Workflow
if err := req.Get(&workflow, req.PathValue("id")); err != nil {
return err
var (
workflow v1.Workflow
id = req.PathValue("id")
)
if system.IsWorkflowID(id) {
if err := req.Get(&workflow, id); err != nil {
return err
}
} else {
var ref v1.Reference
if err := req.Get(&ref, id); err != nil {
return err
}
if ref.Spec.WorkflowName == "" {
return types.NewErrNotFound("reference %q is not an agent reference", ref.Name)
}
if err := req.Get(&workflow, ref.Spec.WorkflowName); err != nil {
return err
}
}

return req.Write(convertWorkflow(workflow, server.GetURLPrefix(req)))
Expand Down
Loading

0 comments on commit 0b63953

Please sign in to comment.