Skip to content

Commit

Permalink
chore: fix formatting
Browse files Browse the repository at this point in the history
There were a bunch of small formatting oddities. I switched to a new AI agent
that found and fixed them. I reviewed by hand and all look good to me.

Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams committed Feb 11, 2025
1 parent 4e0b256 commit 3e50b40
Show file tree
Hide file tree
Showing 25 changed files with 84 additions and 93 deletions.
6 changes: 3 additions & 3 deletions apiclient/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (c *Client) UpdateAgent(ctx context.Context, id string, manifest types.Agen
}

func (c *Client) GetAgent(ctx context.Context, id string) (*types.Agent, error) {
_, resp, err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/agents/"+id), nil)
_, resp, err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/agents/%s", id), nil)
if err != nil {
return nil, err
}
Expand All @@ -29,7 +29,7 @@ func (c *Client) GetAgent(ctx context.Context, id string) (*types.Agent, error)
}

func (c *Client) CreateAgent(ctx context.Context, agent types.AgentManifest) (*types.Agent, error) {
_, resp, err := c.postJSON(ctx, fmt.Sprintf("/agents"), agent)
_, resp, err := c.postJSON(ctx, "/agents", agent)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -74,7 +74,7 @@ func (c *Client) ListAgents(ctx context.Context, opts ListAgentsOptions) (result
}

func (c *Client) DeleteAgent(ctx context.Context, id string) error {
_, resp, err := c.doRequest(ctx, http.MethodDelete, fmt.Sprintf("/agents/"+id), nil)
_, resp, err := c.doRequest(ctx, http.MethodDelete, fmt.Sprintf("/agents/%s", id), nil)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions apiclient/emailreceiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func (c *Client) GetEmailReceiver(ctx context.Context, id string) (*types.EmailReceiver, error) {
_, resp, err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/email-receivers/"+id), nil)
_, resp, err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/email-receivers/%s", id), nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -41,7 +41,7 @@ func (c *Client) ListEmailReceivers(ctx context.Context) (result types.EmailRece
}

func (c *Client) DeleteEmailReceiver(ctx context.Context, id string) error {
_, resp, err := c.doRequest(ctx, http.MethodDelete, fmt.Sprintf("/email-receivers/"+id), nil)
_, resp, err := c.doRequest(ctx, http.MethodDelete, fmt.Sprintf("/email-receivers/%s", id), nil)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions apiclient/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (c *Client) StreamRuns(ctx context.Context, opts ListRunsOptions) (result <
}

func (c *Client) GetRun(ctx context.Context, id string) (result *types.Run, err error) {
_, resp, err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/runs/"+id), nil)
_, resp, err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/runs/%s", id), nil)
if err != nil {
return
}
Expand All @@ -54,7 +54,7 @@ func (c *Client) GetRun(ctx context.Context, id string) (result *types.Run, err
}

func (c *Client) DeleteRun(ctx context.Context, id string) error {
_, resp, err := c.doRequest(ctx, http.MethodDelete, fmt.Sprintf("/runs/"+id), nil)
_, resp, err := c.doRequest(ctx, http.MethodDelete, fmt.Sprintf("/runs/%s", id), nil)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions apiclient/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func (c *Client) DeleteThread(ctx context.Context, id string) error {
_, resp, err := c.doRequest(ctx, http.MethodDelete, fmt.Sprintf("/threads/"+id), nil)
_, resp, err := c.doRequest(ctx, http.MethodDelete, fmt.Sprintf("/threads/%s", id), nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -53,7 +53,7 @@ func (c *Client) UpdateThread(ctx context.Context, id string, thread types.Threa
}

func (c *Client) GetThread(ctx context.Context, threadID string) (result *types.Thread, err error) {
_, resp, err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/threads/"+threadID), nil)
_, resp, err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/threads/%s", threadID), nil)
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion apiclient/toolref.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (c *Client) DeleteToolReference(ctx context.Context, id string, toolType ty
}

func (c *Client) CreateToolReference(ctx context.Context, manifest types.ToolReferenceManifest) (*types.ToolReference, error) {
_, resp, err := c.postJSON(ctx, fmt.Sprintf("/tool-references"), &manifest)
_, resp, err := c.postJSON(ctx, "/tool-references", &manifest)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions apiclient/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ func (e *ErrHTTP) Error() string {
return fmt.Sprintf("error code %d (%s): %s", e.Code, http.StatusText(e.Code), e.Message)
}

func NewErrHttp(code int, message string) *ErrHTTP {
func NewErrHTTP(code int, message string) *ErrHTTP {
return &ErrHTTP{
Code: code,
Message: message,
}
}

func NewErrBadRequest(message string, args ...interface{}) *ErrHTTP {
return NewErrHttp(http.StatusBadRequest, fmt.Sprintf(message, args...))
return NewErrHTTP(http.StatusBadRequest, fmt.Sprintf(message, args...))
}

func NewErrNotFound(message string, args ...any) *ErrHTTP {
Expand All @@ -33,7 +33,7 @@ func NewErrNotFound(message string, args ...any) *ErrHTTP {
if len(args) > 0 {
message = fmt.Sprintf(message, args...)
}
return NewErrHttp(http.StatusNotFound, message)
return NewErrHTTP(http.StatusNotFound, message)
}

func IsNotFound(err error) bool {
Expand Down
4 changes: 2 additions & 2 deletions apiclient/types/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ func (t Time) ToUnstructured() interface{} {
return string(buf)
}

func (_ Time) OpenAPISchemaType() []string {
func (Time) OpenAPISchemaType() []string {
return []string{"string"}
}

func (_ Time) OpenAPISchemaFormat() string {
func (Time) OpenAPISchemaFormat() string {
return "date-time"
}
4 changes: 2 additions & 2 deletions apiclient/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func (c *Client) GetWebhook(ctx context.Context, id string) (result *types.Webhook, _ error) {
_, resp, err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/webhooks/"+id), nil)
_, resp, err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/webhooks/%s", id), nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -41,7 +41,7 @@ func (c *Client) ListWebhooks(ctx context.Context) (result types.WebhookList, _
}

func (c *Client) DeleteWebhook(ctx context.Context, id string) error {
_, resp, err := c.doRequest(ctx, http.MethodDelete, fmt.Sprintf("/webhooks/"+id), nil)
_, resp, err := c.doRequest(ctx, http.MethodDelete, fmt.Sprintf("/webhooks/%s", id), nil)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions apiclient/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (c *Client) UpdateWorkflow(ctx context.Context, id string, manifest types.W
}

func (c *Client) GetWorkflow(ctx context.Context, id string) (*types.Workflow, error) {
_, resp, err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/workflows/"+id), nil)
_, resp, err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/workflows/%s", id), nil)
if err != nil {
return nil, err
}
Expand All @@ -29,7 +29,7 @@ func (c *Client) GetWorkflow(ctx context.Context, id string) (*types.Workflow, e
}

func (c *Client) CreateWorkflow(ctx context.Context, workflow types.WorkflowManifest) (*types.Workflow, error) {
_, resp, err := c.postJSON(ctx, fmt.Sprintf("/workflows"), workflow)
_, resp, err := c.postJSON(ctx, "/workflows", workflow)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -106,7 +106,7 @@ func (c *Client) ListWorkflows(ctx context.Context, opts ListWorkflowsOptions) (
}

func (c *Client) DeleteWorkflow(ctx context.Context, id string) error {
_, resp, err := c.doRequest(ctx, http.MethodDelete, fmt.Sprintf("/workflows/"+id), nil)
_, resp, err := c.doRequest(ctx, http.MethodDelete, fmt.Sprintf("/workflows/%s", id), nil)
if err != nil {
return err
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/api/handlers/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func (a *AgentHandler) UploadKnowledgeFile(req api.Context) error {
}

if len(knowledgeSetNames) == 0 {
return types.NewErrHttp(http.StatusTooEarly, fmt.Sprintf("agent %q knowledge set is not created yet", agentName))
return types.NewErrHTTP(http.StatusTooEarly, fmt.Sprintf("agent %q knowledge set is not created yet", agentName))
}

ws, err := getWorkspaceFromKnowledgeSet(req, knowledgeSetNames[0])
Expand Down Expand Up @@ -493,7 +493,7 @@ func (a *AgentHandler) DeleteKnowledgeFile(req api.Context) error {
}

if len(knowledgeSetNames) == 0 {
return types.NewErrHttp(http.StatusTooEarly, fmt.Sprintf("agent %q knowledge set is not created yet", agentName))
return types.NewErrHTTP(http.StatusTooEarly, fmt.Sprintf("agent %q knowledge set is not created yet", agentName))
}
return deleteKnowledge(req, req.PathValue("file"), knowledgeSetNames[0])
}
Expand Down Expand Up @@ -552,7 +552,7 @@ func (a *AgentHandler) UpdateKnowledgeSource(req api.Context) error {
}

if len(knowledgeSetNames) == 0 {
return types.NewErrHttp(http.StatusTooEarly, fmt.Sprintf("agent %q knowledge set is not created yet", agentName))
return types.NewErrHTTP(http.StatusTooEarly, fmt.Sprintf("agent %q knowledge set is not created yet", agentName))
}

var knowledgeSource v1.KnowledgeSource
Expand Down Expand Up @@ -583,7 +583,7 @@ func (a *AgentHandler) ReIngestKnowledgeFile(req api.Context) error {
}

if len(knowledgeSetNames) == 0 {
return types.NewErrHttp(http.StatusTooEarly, fmt.Sprintf("agent %q knowledge set is not created yet", agentName))
return types.NewErrHTTP(http.StatusTooEarly, fmt.Sprintf("agent %q knowledge set is not created yet", agentName))
}

var knowledgeFile v1.KnowledgeFile
Expand Down Expand Up @@ -627,7 +627,7 @@ func (a *AgentHandler) ReSyncKnowledgeSource(req api.Context) error {
}

if len(knowledgeSetNames) == 0 {
return types.NewErrHttp(http.StatusTooEarly, fmt.Sprintf("agent %q knowledge set is not created yet", agentName))
return types.NewErrHTTP(http.StatusTooEarly, fmt.Sprintf("agent %q knowledge set is not created yet", agentName))
}

var knowledgeSource v1.KnowledgeSource
Expand Down Expand Up @@ -685,7 +685,7 @@ func (a *AgentHandler) DeleteKnowledgeSource(req api.Context) error {
}

if len(knowledgeSetNames) == 0 {
return types.NewErrHttp(http.StatusTooEarly, fmt.Sprintf("agent %q knowledge set is not created yet", agentName))
return types.NewErrHTTP(http.StatusTooEarly, fmt.Sprintf("agent %q knowledge set is not created yet", agentName))
}

var knowledgeSource v1.KnowledgeSource
Expand Down Expand Up @@ -740,7 +740,7 @@ func (a *AgentHandler) EnsureCredentialForKnowledgeSource(req api.Context) error
return fmt.Errorf("failed to get tool reference %v", ref)
}
if toolReference.Status.Tool == nil {
return types.NewErrHttp(http.StatusTooEarly, "tool reference is not ready yet")
return types.NewErrHTTP(http.StatusTooEarly, "tool reference is not ready yet")
}

if len(toolReference.Status.Tool.Credentials) == 0 {
Expand Down Expand Up @@ -940,7 +940,7 @@ func runAuthForAgent(ctx context.Context, c kclient.WithWatch, invoker *invoke.I
credentials = append(credentials, credentails...)
} else if err := c.Get(ctx, kclient.ObjectKey{Namespace: agent.Namespace, Name: tool}, &toolRef); err == nil {
if toolRef.Status.Tool == nil {
return nil, types.NewErrHttp(http.StatusTooEarly, fmt.Sprintf("tool %q is not ready", tool))
return nil, types.NewErrHTTP(http.StatusTooEarly, fmt.Sprintf("tool %q is not ready", tool))
}

credentials = append(credentials, toolRef.Status.Tool.Credentials...)
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/handlers/assistants.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func (a *AssistantHandler) UploadKnowledge(req api.Context) error {
}

if len(thread.Status.KnowledgeSetNames) == 0 {
return types.NewErrHttp(http.StatusTooEarly, "knowledge set is not available yet")
return types.NewErrHTTP(http.StatusTooEarly, "knowledge set is not available yet")
}

ws, err := getWorkspaceFromKnowledgeSet(req, thread.Status.KnowledgeSetNames[0])
Expand All @@ -424,7 +424,7 @@ func (a *AssistantHandler) DeleteKnowledge(req api.Context) error {
}

if len(thread.Status.KnowledgeSetNames) == 0 {
return types.NewErrHttp(http.StatusTooEarly, "knowledge set is not created yet")
return types.NewErrHTTP(http.StatusTooEarly, "knowledge set is not created yet")
}

return deleteKnowledge(req, req.PathValue("file"), thread.Status.KnowledgeSetNames[0])
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/handlers/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func listFiles(ctx context.Context, req api.Context, gClient *gptscript.GPTScrip

func listFileFromWorkspace(ctx context.Context, req api.Context, gClient *gptscript.GPTScript, opts gptscript.ListFilesInWorkspaceOptions) error {
if opts.WorkspaceID == "" {
return types.NewErrHttp(http.StatusTooEarly, "workspace is not available yet")
return types.NewErrHTTP(http.StatusTooEarly, "workspace is not available yet")
}
files, err := gClient.ListFilesInWorkspace(ctx, opts)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/handlers/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (a *ModelHandler) Delete(req api.Context) error {
}

if len(agents.Items) > 0 {
return types.NewErrHttp(http.StatusPreconditionFailed, fmt.Sprintf("model %q is used by %d agents", model, len(agents.Items)))
return types.NewErrHTTP(http.StatusPreconditionFailed, fmt.Sprintf("model %q is used by %d agents", model, len(agents.Items)))
}

return req.Delete(&v1.Model{
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/handlers/modelprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ func (mp *ModelProviderHandler) Validate(req api.Context) error {
ref.Name,
)
}
return types.NewErrHttp(http.StatusUnprocessableEntity, strings.Trim(err.Error(), "\"'"))
return types.NewErrHTTP(http.StatusUnprocessableEntity, strings.Trim(err.Error(), "\"'"))
}

var validationError ValidationError
if json.Unmarshal([]byte(res.Output), &validationError) == nil && validationError.Err != "" {
return types.NewErrHttp(http.StatusUnprocessableEntity, validationError.Error())
return types.NewErrHTTP(http.StatusUnprocessableEntity, validationError.Error())
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/handlers/sendgrid/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ func (h *InboundWebhookHandler) InboundWebhookHandler(req api.Context) error {
if h.username != "" && h.password != "" {
username, password, ok := req.Request.BasicAuth()
if !ok || username != h.username || password != h.password {
return types.NewErrHttp(http.StatusUnauthorized, "Invalid credentials")
return types.NewErrHTTP(http.StatusUnauthorized, "Invalid credentials")
}
}

inboundEmail, err := inbound.Parse(req.Request)
if err != nil {
return types.NewErrHttp(http.StatusBadRequest, fmt.Sprintf("Failed to parse inbound email: %v", err))
return types.NewErrHTTP(http.StatusBadRequest, fmt.Sprintf("Failed to parse inbound email: %v", err))
}

subject := inboundEmail.Headers["Subject"]
if err := h.emailTrigger.Handler(req.Context(), inboundEmail.Envelope.From, inboundEmail.Envelope.To, subject, []byte(inboundEmail.TextBody)); err != nil {
return types.NewErrHttp(http.StatusInternalServerError, fmt.Sprintf("Failed to handle inbound email: %v", err))
return types.NewErrHTTP(http.StatusInternalServerError, fmt.Sprintf("Failed to handle inbound email: %v", err))
}

req.WriteHeader(http.StatusOK)
Expand Down
10 changes: 5 additions & 5 deletions pkg/api/handlers/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (t *TaskHandler) Abort(req api.Context) error {
}

if wfe.Spec.ThreadName != userThread.Name && workflow.Name != wfe.Spec.WorkflowName {
return types.NewErrHttp(http.StatusForbidden, "task run does not belong to the thread")
return types.NewErrHTTP(http.StatusForbidden, "task run does not belong to the thread")
}

var thread v1.Thread
Expand Down Expand Up @@ -99,7 +99,7 @@ func (t *TaskHandler) Events(req api.Context) error {
}

if wfe.Spec.ThreadName != thread.Name && workflow.Name != wfe.Spec.WorkflowName {
return types.NewErrHttp(http.StatusForbidden, "task run does not belong to the user")
return types.NewErrHTTP(http.StatusForbidden, "task run does not belong to the user")
}

_, events, err := t.events.Watch(req.Context(), req.Namespace(), events.WatchOptions{
Expand Down Expand Up @@ -187,7 +187,7 @@ func (t *TaskHandler) DeleteRun(req api.Context) error {
}

if wfe.Spec.ThreadName != userThread.Name || wfe.Spec.WorkflowName != workflow.Name {
return types.NewErrHttp(http.StatusForbidden, "task run does not belong to the user")
return types.NewErrHTTP(http.StatusForbidden, "task run does not belong to the user")
}

return req.Delete(&wfe)
Expand Down Expand Up @@ -681,7 +681,7 @@ func (t *TaskHandler) getTask(req api.Context) (*v1.Workflow, *v1.Thread, error)
}

if workflow.Spec.ThreadName != thread.Name {
return nil, nil, types.NewErrHttp(http.StatusForbidden, "task does not belong to the thread")
return nil, nil, types.NewErrHTTP(http.StatusForbidden, "task does not belong to the thread")
}

return &workflow, thread, nil
Expand All @@ -707,7 +707,7 @@ func getThreadForScope(req api.Context) (*v1.Thread, error) {
return nil, err
}
if wfe.Spec.ThreadName != thread.Name {
return nil, types.NewErrHttp(http.StatusForbidden, "task run does not belong to the thread")
return nil, types.NewErrHTTP(http.StatusForbidden, "task run does not belong to the thread")
}
if wfe.Spec.WorkflowName != taskID {
return nil, types.NewErrNotFound("task run not found")
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/handlers/threads.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func (a *ThreadHandler) UploadFile(req api.Context) error {
}

if thread.Status.WorkspaceID == "" {
return types.NewErrHttp(http.StatusTooEarly, fmt.Sprintf("no workspace found for thread %s", req.PathValue("id")))
return types.NewErrHTTP(http.StatusTooEarly, fmt.Sprintf("no workspace found for thread %s", req.PathValue("id")))
}

_, err := uploadFileToWorkspace(req.Context(), req, a.gptscript, thread.Status.WorkspaceID, "files/")
Expand Down Expand Up @@ -368,7 +368,7 @@ func (a *ThreadHandler) UploadKnowledge(req api.Context) error {
}

if len(thread.Status.KnowledgeSetNames) == 0 {
return types.NewErrHttp(http.StatusTooEarly, "knowledge set is not available yet")
return types.NewErrHTTP(http.StatusTooEarly, "knowledge set is not available yet")
}

ws, err := getWorkspaceFromKnowledgeSet(req, thread.Status.KnowledgeSetNames[0])
Expand All @@ -390,7 +390,7 @@ func (a *ThreadHandler) DeleteKnowledge(req api.Context) error {
}

if len(thread.Status.KnowledgeSetNames) == 0 {
return types.NewErrHttp(http.StatusTooEarly, fmt.Sprintf("thread %q knowledge set is not created yet", thread.Name))
return types.NewErrHTTP(http.StatusTooEarly, fmt.Sprintf("thread %q knowledge set is not created yet", thread.Name))
}

return deleteKnowledge(req, req.PathValue("file"), thread.Status.KnowledgeSetNames[0])
Expand Down
Loading

0 comments on commit 3e50b40

Please sign in to comment.