Skip to content

Commit 0e05bfb

Browse files
chore: bump tui to address sigint handling
1 parent 6e1dbf5 commit 0e05bfb

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
1717
github.com/google/uuid v1.6.0
1818
github.com/gptscript-ai/chat-completion-client v0.0.0-20240531200700-af8e7ecf0379
19-
github.com/gptscript-ai/tui v0.0.0-20240607210407-edb2d427695e
19+
github.com/gptscript-ai/tui v0.0.0-20240613214935-03d62e2c7822
2020
github.com/hexops/autogold/v2 v2.2.1
2121
github.com/hexops/valast v1.4.4
2222
github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056
@@ -61,7 +61,7 @@ require (
6161
github.com/google/go-cmp v0.6.0 // indirect
6262
github.com/gookit/color v1.5.4 // indirect
6363
github.com/gorilla/css v1.0.0 // indirect
64-
github.com/gptscript-ai/go-gptscript v0.0.0-20240604231423-7a845df843b1 // indirect
64+
github.com/gptscript-ai/go-gptscript v0.0.0-20240613214812-8111c2b02d71 // indirect
6565
github.com/hashicorp/errwrap v1.0.0 // indirect
6666
github.com/hashicorp/go-multierror v1.1.1 // indirect
6767
github.com/hexops/autogold v1.3.1 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
171171
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
172172
github.com/gptscript-ai/chat-completion-client v0.0.0-20240531200700-af8e7ecf0379 h1:vYnXoIyCXzaCEw0sYifQ4bDpsv3/fO/dZ2suEsTwCIo=
173173
github.com/gptscript-ai/chat-completion-client v0.0.0-20240531200700-af8e7ecf0379/go.mod h1:7P/o6/IWa1KqsntVf68hSnLKuu3+xuqm6lYhch1w4jo=
174-
github.com/gptscript-ai/go-gptscript v0.0.0-20240604231423-7a845df843b1 h1:SHoqsU8Ne2V4zfrFve9kQn4vcv4N4TItD6Oju+pzKV8=
175-
github.com/gptscript-ai/go-gptscript v0.0.0-20240604231423-7a845df843b1/go.mod h1:h1yYzC0rgB5Kk7lwdba+Xs6cWkuJfLq6sPRna45OVG0=
176-
github.com/gptscript-ai/tui v0.0.0-20240607210407-edb2d427695e h1:ETdyiFXN6i+Tb0I119XqGtMkPpDqig0m6MBrzGB7Mtc=
177-
github.com/gptscript-ai/tui v0.0.0-20240607210407-edb2d427695e/go.mod h1:At6zmCk0XrJ2J1yo95fzbEDOGwaPPEMwxxcQGJx7IGE=
174+
github.com/gptscript-ai/go-gptscript v0.0.0-20240613214812-8111c2b02d71 h1:WehkkausLuXI91ePpIVrzZ6eBmfFIU/HfNsSA1CHiwo=
175+
github.com/gptscript-ai/go-gptscript v0.0.0-20240613214812-8111c2b02d71/go.mod h1:Dh6vYRAiVcyC3ElZIGzTvNF1FxtYwA07BHfSiFKQY7s=
176+
github.com/gptscript-ai/tui v0.0.0-20240613214935-03d62e2c7822 h1:g1IR6P2F536lyDoFeGE1bLqnflXWipnUkZzIFoHIPjw=
177+
github.com/gptscript-ai/tui v0.0.0-20240613214935-03d62e2c7822/go.mod h1:ZlyM+BRiD6mV04w+Xw2mXP1VKGEUbn8BvwrosWlplUo=
178178
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
179179
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
180180
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=

pkg/cli/gptscript.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ type GPTScript struct {
5757
Assemble bool `usage:"Assemble tool to a single artifact, saved to --output" hidden:"true" local:"true"`
5858
ListModels bool `usage:"List the models available and exit" local:"true"`
5959
ListTools bool `usage:"List built-in tools and exit" local:"true"`
60-
ListenAddress string `usage:"Server listen address" default:"127.0.0.1:0"`
6160
Chdir string `usage:"Change current working directory" short:"C"`
6261
Daemon bool `usage:"Run tool as a daemon" local:"true" hidden:"true"`
6362
Ports string `usage:"The port range to use for ephemeral daemon ports (ex: 11000-12000)" hidden:"true"`
@@ -439,8 +438,12 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) {
439438

440439
if prg.IsChat() || r.ForceChat {
441440
if !r.DisableTUI && !r.Debug && !r.DebugMessages {
442-
return tui.Run(cmd.Context(), args[0], tui.RunOptions{
443-
TrustedRepoPrefixes: []string{"github.com/gptscript-ai/context"},
441+
// Don't use cmd.Context() because then sigint will cancel everything
442+
return tui.Run(context.Background(), args[0], tui.RunOptions{
443+
OpenAIAPIKey: r.OpenAIOptions.APIKey,
444+
OpenAIBaseURL: r.OpenAIOptions.BaseURL,
445+
DefaultModel: r.DefaultModel,
446+
TrustedRepoPrefixes: []string{"github.com/gptscript-ai"},
444447
DisableCache: r.DisableCache,
445448
Input: strings.Join(args[1:], " "),
446449
CacheDir: r.CacheDir,

pkg/cli/sdk_server.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package cli
22

33
import (
4+
"context"
5+
"os"
6+
47
"github.com/gptscript-ai/gptscript/pkg/sdkserver"
58
"github.com/spf13/cobra"
9+
"golang.org/x/term"
610
)
711

812
type SDKServer struct {
913
*GPTScript
14+
ListenAddress string `usage:"Server listen address" default:"127.0.0.1:0" local:"true"`
1015
}
1116

1217
func (c *SDKServer) Customize(cmd *cobra.Command) {
@@ -21,7 +26,14 @@ func (c *SDKServer) Run(cmd *cobra.Command, _ []string) error {
2126
return err
2227
}
2328

24-
return sdkserver.Start(cmd.Context(), sdkserver.Options{
29+
// Don't use cmd.Context() as we don't want to die on ctrl+c
30+
ctx := context.Background()
31+
if term.IsTerminal(int(os.Stdin.Fd())) {
32+
// Only support CTRL+C if stdin is the terminal. When ran as a SDK it will be a pipe
33+
ctx = cmd.Context()
34+
}
35+
36+
return sdkserver.Start(ctx, sdkserver.Options{
2537
Options: opts,
2638
ListenAddress: c.ListenAddress,
2739
Debug: c.Debug,

pkg/sdkserver/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type Options struct {
3030
}
3131

3232
func Start(ctx context.Context, opts Options) error {
33-
sigCtx, cancel := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGKILL)
33+
sigCtx, cancel := signal.NotifyContext(ctx, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGKILL)
3434
defer cancel()
3535
go func() {
3636
// This is a hack. This server will be run as a forked process in the SDKs. The SDKs will hold stdin open for as long

0 commit comments

Comments
 (0)