Skip to content

Commit

Permalink
chore: tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Dec 12, 2024
1 parent f6d8aba commit 0c4d460
Show file tree
Hide file tree
Showing 90 changed files with 2,616 additions and 1,542 deletions.
3 changes: 3 additions & 0 deletions apiclient/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ func (c *Client) Invoke(ctx context.Context, agentID string, input string, opts
if opts.Async {
_, _ = io.Copy(io.Discard, resp.Body)
resp.Body.Close()
events := make(chan types.Progress)
close(events)
return &types.InvokeResponse{
Events: events,
ThreadID: resp.Header.Get("X-Otto-Thread-Id"),
}, nil
}
Expand Down
1 change: 1 addition & 0 deletions apiclient/types/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type AgentManifest struct {
MaxThreadTools int `json:"maxThreadTools"`
Params map[string]string `json:"params"`
Model string `json:"model"`
Env []EnvVar `json:"env"`
}

func (m AgentManifest) GetParams() *openapi3.Schema {
Expand Down
1 change: 0 additions & 1 deletion apiclient/types/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type CronJobManifest struct {
Schedule string `json:"schedule,omitempty"`
Workflow string `json:"workflow,omitempty"`
Input string `json:"input,omitempty"`
UserID string `json:"userID,omitempty"`
TaskSchedule *Schedule `json:"taskSchedule,omitempty"`
}

Expand Down
1 change: 0 additions & 1 deletion apiclient/types/emailreceiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ type EmailReceiverManifest struct {
Name string `json:"name"`
Description string `json:"description"`
User string `json:"user,omitempty"`
UserID string `json:"userID,omitempty"`
Workflow string `json:"workflow"`
AllowedSenders []string `json:"allowedSenders,omitempty"`
}
Expand Down
4 changes: 4 additions & 0 deletions apiclient/types/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ type Progress struct {
// If RunID is not populated, the event will not specify tied to any particular run
RunID string `json:"runID,omitempty"`

// ParentRunID is the parent run of the run that is specified in the RunID field
ParentRunID string `json:"parentRunID,omitempty"`

// Time is the time the event was generated
Time *Time `json:"time,omitempty"`

Expand Down Expand Up @@ -92,6 +95,7 @@ type ToolCall struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Input string `json:"input,omitempty"`
Output string `json:"output,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}

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

type Table struct {
Name string `json:"name"`
}

type TableList List[Table]

// +k8s:deepcopy-gen=false

// +k8s:openapi-gen=false
type TableRow struct {
Columns []string `json:"columns,omitempty"`
Values map[string]any `json:"values"`
}

// +k8s:deepcopy-gen=false

// +k8s:openapi-gen=false
type TableRowList List[TableRow]
1 change: 1 addition & 0 deletions apiclient/types/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type TaskIf struct {
type TaskRun struct {
Metadata
TaskID string `json:"taskID,omitempty"`
Input string `json:"input,omitempty"`
Task TaskManifest `json:"task,omitempty"`
StartTime *Time `json:"startTime,omitempty"`
EndTime *Time `json:"endTime,omitempty"`
Expand Down
23 changes: 12 additions & 11 deletions apiclient/types/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ func (in WorkflowState) IsTerminal() bool {
type Thread struct {
Metadata
ThreadManifest
AgentID string `json:"agentID,omitempty"`
WorkflowID string `json:"workflowID,omitempty"`
WebhookID string `json:"webhookID,omitempty"`
EmailReceiverID string `json:"emailReceiverID,omitempty"`
State string `json:"state,omitempty"`
LastRunID string `json:"lastRunID,omitempty"`
CurrentRunID string `json:"currentRunID,omitempty"`
ParentThreadID string `json:"parentThreadID,omitempty"`
UserID string `json:"userID,omitempty"`
AgentAlias string `json:"agentAlias,omitempty"`
Abort bool `json:"abort,omitempty"`
AgentID string `json:"agentID,omitempty"`
WorkflowID string `json:"workflowID,omitempty"`
WebhookID string `json:"webhookID,omitempty"`
EmailReceiverID string `json:"emailReceiverID,omitempty"`
State string `json:"state,omitempty"`
LastRunID string `json:"lastRunID,omitempty"`
CurrentRunID string `json:"currentRunID,omitempty"`
ParentThreadID string `json:"parentThreadID,omitempty"`
UserID string `json:"userID,omitempty"`
AgentAlias string `json:"agentAlias,omitempty"`
Abort bool `json:"abort,omitempty"`
Env []string `json:"env,omitempty"`
}

type ThreadList List[Thread]
Expand Down
1 change: 0 additions & 1 deletion apiclient/types/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type WebhookManifest struct {
Headers []string `json:"headers"`
Secret string `json:"secret"`
ValidationHeader string `json:"validationHeader"`
UserID string `json:"userID,omitempty"`
}

type WebhookList List[Webhook]
107 changes: 7 additions & 100 deletions apiclient/types/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ type WorkflowList List[Workflow]

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

type WorkflowEnv struct {
type EnvVar struct {
Name string `json:"name"`
Value string `json:"value"`
Description string `json:"description"`
Expand Down Expand Up @@ -86,15 +84,15 @@ func (s Step) Display() string {
}
if s.While != nil {
preamble.WriteString(" while ")
preamble.WriteString(oneline(s.While.Condition))
preamble.WriteString(oneLine(s.While.Condition))
}
if s.If != nil {
preamble.WriteString(" if ")
preamble.WriteString(oneline(s.If.Condition))
preamble.WriteString(oneLine(s.If.Condition))
}
if s.Step != "" {
preamble.WriteString(" ")
preamble.WriteString(oneline(s.Step))
preamble.WriteString(oneLine(s.Step))
}
return preamble.String()
}
Expand All @@ -116,105 +114,14 @@ type While struct {
Steps []Step `json:"steps,omitempty"`
}

func oneline(s string) string {
func oneLine(s string) string {
l := strings.Split(s, "\n")[0]
if len(l) > 80 {
return l[:80] + "..."
}
return l
}

func DeleteStep(manifest *WorkflowManifest, id string) *WorkflowManifest {
if manifest == nil || id == "" {
return nil
}

result := manifest.DeepCopy()
lookupID, _, _ := strings.Cut(id, "{")
result.Steps = deleteStep(manifest.Steps, lookupID)
return result
}

func deleteStep(steps []Step, id string) []Step {
newSteps := make([]Step, 0, len(steps))
for _, step := range steps {
if step.ID != id {
if step.While != nil {
step.While.Steps = deleteStep(step.While.Steps, id)
}
if step.If != nil {
step.If.Steps = deleteStep(step.If.Steps, id)
step.If.Else = deleteStep(step.If.Else, id)
}
newSteps = append(newSteps, step)
}
}
return newSteps
}

func AppendStep(manifest *WorkflowManifest, parentID string, step Step) *WorkflowManifest {
if manifest == nil {
return nil
}

parentID, addToElse := strings.CutSuffix(parentID, "::else")

result := manifest.DeepCopy()
if parentID == "" {
result.Steps = append(result.Steps, step)
return result
}

lookupID, _, _ := strings.Cut(parentID, "{")
result.Steps = appendStep(result.Steps, lookupID, addToElse, step)
return result
}

func appendStep(steps []Step, id string, addToElse bool, stepToAdd Step) []Step {
result := make([]Step, 0, len(steps))

for _, step := range steps {
if step.ID != id {
if step.If != nil {
step.If.Steps = appendStep(step.If.Steps, id, addToElse, stepToAdd)
step.If.Else = appendStep(step.If.Else, id, addToElse, stepToAdd)
}
if step.While != nil {
step.While.Steps = appendStep(step.While.Steps, id, addToElse, stepToAdd)
}
result = append(result, step)
continue
}

if step.If != nil {
if addToElse {
step.If.Else = append(step.If.Else, stepToAdd)
} else {
step.If.Steps = append(step.If.Steps, stepToAdd)
}
} else if step.While != nil {
step.While.Steps = append(step.While.Steps, stepToAdd)
}

result = append(result, step)
}

return result
}

func SetStep(manifest *WorkflowManifest, step Step) {
id := step.ID
if manifest == nil || id == "" {
return
}
lookupID, _, _ := strings.Cut(id, "{")
found, _ := findInSteps("", manifest.Steps, lookupID)
if found != nil {
*found = step
}
return
}

func FindStep(manifest *WorkflowManifest, id string) (_ *Step, parentID string) {
if manifest == nil || id == "" {
return nil, ""
Expand Down
12 changes: 12 additions & 0 deletions apiclient/types/workflowexecution.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package types

type WorkflowExecution struct {
Metadata
Workflow WorkflowManifest `json:"workflow,omitempty"`
StartTime Time `json:"startTime"`
EndTime *Time `json:"endTime"`
Input string `json:"input"`
Error string `json:"error,omitempty"`
}

type WorkflowExecutionList List[WorkflowExecution]
Loading

0 comments on commit 0c4d460

Please sign in to comment.