Skip to content

feat: add a new SDK server #387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ require (
github.com/fatih/color v1.16.0
github.com/getkin/kin-openapi v0.123.0
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/google/uuid v1.6.0
github.com/gptscript-ai/chat-completion-client v0.0.0-20240515050533-bdef9f2226a9
github.com/hexops/autogold/v2 v2.2.1
github.com/hexops/valast v1.4.4
github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056
github.com/mholt/archiver/v4 v4.0.0-alpha.8
github.com/olahol/melody v1.1.4
github.com/rs/cors v1.10.1
github.com/rs/cors v1.11.0
github.com/samber/lo v1.38.1
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hf
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
Expand Down Expand Up @@ -219,8 +221,8 @@ github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/f
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/rs/cors v1.10.1 h1:L0uuZVXIKlI1SShY2nhFfo44TYvDPQ1w4oFkUJNfhyo=
github.com/rs/cors v1.10.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/rs/cors v1.11.0 h1:0B9GE/r9Bc2UxRMMtymBkHTenPkHDv0CW4Y98GBY+po=
github.com/rs/cors v1.11.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd/go.mod h1:hPqNNc0+uJM6H+SuU8sEs5K5IQeKccPqeSjfgcKGgPk=
github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
Expand Down
51 changes: 29 additions & 22 deletions pkg/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,43 @@ import (
func Authorize(ctx engine.Context, input string) (runner.AuthorizerResponse, error) {
defer context.GetPauseFuncFromCtx(ctx.Ctx)()()

if !ctx.Tool.IsCommand() {
if IsSafe(ctx) {
return runner.AuthorizerResponse{
Accept: true,
}, nil
}

var result bool
err := survey.AskOne(&survey.Confirm{
Help: fmt.Sprintf("The full source of the tools is as follows:\n\n%s", ctx.Tool.String()),
Default: true,
Message: ConfirmMessage(ctx, input),
}, &result)
if err != nil {
return runner.AuthorizerResponse{}, err
}

return runner.AuthorizerResponse{
Accept: result,
Message: "Request denied, blocking execution.",
}, nil
}

func IsSafe(ctx engine.Context) bool {
if !ctx.Tool.IsCommand() {
return true
}

_, ok := builtin.SafeTools[strings.Split(ctx.Tool.Instructions, "\n")[0][2:]]
return ok
}

func ConfirmMessage(ctx engine.Context, input string) string {
var (
result bool
loc = ctx.Tool.Source.Location
interpreter = strings.Split(ctx.Tool.Instructions, "\n")[0][2:]
)

if _, ok := builtin.SafeTools[interpreter]; ok {
return runner.AuthorizerResponse{
Accept: true,
}, nil
}

if ctx.Tool.Source.Repo != nil {
loc = ctx.Tool.Source.Repo.Root
loc = strings.TrimPrefix(loc, "https://")
Expand All @@ -44,21 +63,9 @@ func Authorize(ctx engine.Context, input string) (runner.AuthorizerResponse, err
loc = "Builtin"
}

err := survey.AskOne(&survey.Confirm{
Help: fmt.Sprintf("The full source of the tools is as follows:\n\n%s", ctx.Tool.String()),
Default: true,
Message: fmt.Sprintf(`Description: %s
return fmt.Sprintf(`Description: %s
Interpreter: %s
Source: %s
Input: %s
Allow the above tool to execute?`, ctx.Tool.Description, interpreter, loc, strings.TrimSpace(input)),
}, &result)
if err != nil {
return runner.AuthorizerResponse{}, err
}

return runner.AuthorizerResponse{
Accept: result,
Message: "Request denied, blocking execution.",
}, nil
Allow the above tool to execute?`, ctx.Tool.Description, interpreter, loc, strings.TrimSpace(input))
}
Loading