Skip to content

Commit 0a75894

Browse files
committed
feat: add a new SDK server
This server will be used in the SDKs for running gptscripts. This change also includes an implementation that allows the SDKs to "confirm" tools execution. Signed-off-by: Donnie Adams <[email protected]>
1 parent 9e33525 commit 0a75894

File tree

27 files changed

+1323
-298
lines changed

27 files changed

+1323
-298
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ require (
1414
github.com/fatih/color v1.16.0
1515
github.com/getkin/kin-openapi v0.123.0
1616
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
17+
github.com/google/uuid v1.6.0
1718
github.com/gptscript-ai/chat-completion-client v0.0.0-20240515050533-bdef9f2226a9
1819
github.com/hexops/autogold/v2 v2.2.1
1920
github.com/hexops/valast v1.4.4
2021
github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056
2122
github.com/mholt/archiver/v4 v4.0.0-alpha.8
2223
github.com/olahol/melody v1.1.4
23-
github.com/rs/cors v1.10.1
24+
github.com/rs/cors v1.11.0
2425
github.com/samber/lo v1.38.1
2526
github.com/sirupsen/logrus v1.9.3
2627
github.com/spf13/cobra v1.8.0

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hf
119119
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
120120
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
121121
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
122+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
123+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
122124
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
123125
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
124126
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
@@ -219,8 +221,8 @@ github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/f
219221
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
220222
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
221223
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
222-
github.com/rs/cors v1.10.1 h1:L0uuZVXIKlI1SShY2nhFfo44TYvDPQ1w4oFkUJNfhyo=
223-
github.com/rs/cors v1.10.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
224+
github.com/rs/cors v1.11.0 h1:0B9GE/r9Bc2UxRMMtymBkHTenPkHDv0CW4Y98GBY+po=
225+
github.com/rs/cors v1.11.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
224226
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
225227
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd/go.mod h1:hPqNNc0+uJM6H+SuU8sEs5K5IQeKccPqeSjfgcKGgPk=
226228
github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=

pkg/auth/auth.go

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,43 @@ import (
1515
func Authorize(ctx engine.Context, input string) (runner.AuthorizerResponse, error) {
1616
defer context.GetPauseFuncFromCtx(ctx.Ctx)()()
1717

18-
if !ctx.Tool.IsCommand() {
18+
if IsSafe(ctx) {
1919
return runner.AuthorizerResponse{
2020
Accept: true,
2121
}, nil
2222
}
2323

24+
var result bool
25+
err := survey.AskOne(&survey.Confirm{
26+
Help: fmt.Sprintf("The full source of the tools is as follows:\n\n%s", ctx.Tool.String()),
27+
Default: true,
28+
Message: ConfirmMessage(ctx, input),
29+
}, &result)
30+
if err != nil {
31+
return runner.AuthorizerResponse{}, err
32+
}
33+
34+
return runner.AuthorizerResponse{
35+
Accept: result,
36+
Message: "Request denied, blocking execution.",
37+
}, nil
38+
}
39+
40+
func IsSafe(ctx engine.Context) bool {
41+
if !ctx.Tool.IsCommand() {
42+
return true
43+
}
44+
45+
_, ok := builtin.SafeTools[strings.Split(ctx.Tool.Instructions, "\n")[0][2:]]
46+
return ok
47+
}
48+
49+
func ConfirmMessage(ctx engine.Context, input string) string {
2450
var (
25-
result bool
2651
loc = ctx.Tool.Source.Location
2752
interpreter = strings.Split(ctx.Tool.Instructions, "\n")[0][2:]
2853
)
2954

30-
if _, ok := builtin.SafeTools[interpreter]; ok {
31-
return runner.AuthorizerResponse{
32-
Accept: true,
33-
}, nil
34-
}
35-
3655
if ctx.Tool.Source.Repo != nil {
3756
loc = ctx.Tool.Source.Repo.Root
3857
loc = strings.TrimPrefix(loc, "https://")
@@ -44,21 +63,9 @@ func Authorize(ctx engine.Context, input string) (runner.AuthorizerResponse, err
4463
loc = "Builtin"
4564
}
4665

47-
err := survey.AskOne(&survey.Confirm{
48-
Help: fmt.Sprintf("The full source of the tools is as follows:\n\n%s", ctx.Tool.String()),
49-
Default: true,
50-
Message: fmt.Sprintf(`Description: %s
66+
return fmt.Sprintf(`Description: %s
5167
Interpreter: %s
5268
Source: %s
5369
Input: %s
54-
Allow the above tool to execute?`, ctx.Tool.Description, interpreter, loc, strings.TrimSpace(input)),
55-
}, &result)
56-
if err != nil {
57-
return runner.AuthorizerResponse{}, err
58-
}
59-
60-
return runner.AuthorizerResponse{
61-
Accept: result,
62-
Message: "Request denied, blocking execution.",
63-
}, nil
70+
Allow the above tool to execute?`, ctx.Tool.Description, interpreter, loc, strings.TrimSpace(input))
6471
}

0 commit comments

Comments
 (0)