@@ -65,12 +65,13 @@ type GPTScript struct {
65
65
Ports string `usage:"The port range to use for ephemeral daemon ports (ex: 11000-12000)" hidden:"true"`
66
66
CredentialContext string `usage:"Context name in which to store credentials" default:"default"`
67
67
CredentialOverride string `usage:"Credentials to override (ex: --credential-override github.com/example/cred-tool:API_TOKEN=1234)"`
68
- ChatState string `usage:"The chat state to continue, or null to start a new chat and return the state"`
69
- ForceChat bool `usage:"Force an interactive chat session if even the top level tool is not a chat tool"`
70
- ForceSequential bool `usage:"Force parallel calls to run sequentially"`
68
+ ChatState string `usage:"The chat state to continue, or null to start a new chat and return the state" local:"true" `
69
+ ForceChat bool `usage:"Force an interactive chat session if even the top level tool is not a chat tool" local:"true" `
70
+ ForceSequential bool `usage:"Force parallel calls to run sequentially" local:"true" `
71
71
Workspace string `usage:"Directory to use for the workspace, if specified it will not be deleted on exit"`
72
72
UI bool `usage:"Launch the UI" local:"true" name:"ui"`
73
73
DisableTUI bool `usage:"Don't use chat TUI but instead verbose output" local:"true" name:"disable-tui"`
74
+ SaveChatStateFile string `usage:"A file to save the chat state to so that a conversation can be resumed with --chat-state" local:"true"`
74
75
75
76
readData []byte
76
77
}
@@ -425,8 +426,18 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) {
425
426
return err
426
427
}
427
428
428
- if r .ChatState != "" {
429
- resp , err := gptScript .Chat (cmd .Context (), r .ChatState , prg , gptOpt .Env , toolInput )
429
+ var chatState string
430
+ if r .ChatState != "" && r .ChatState != "null" && ! strings .HasPrefix (r .ChatState , "{" ) {
431
+ data , err := os .ReadFile (r .ChatState )
432
+ if err != nil {
433
+ return fmt .Errorf ("reading %s: %w" , r .ChatState , err )
434
+ }
435
+ chatState = string (data )
436
+ }
437
+
438
+ // This chat in a stateless mode
439
+ if r .SaveChatStateFile == "-" || r .SaveChatStateFile == "stdout" {
440
+ resp , err := gptScript .Chat (cmd .Context (), chatState , prg , gptOpt .Env , toolInput )
430
441
if err != nil {
431
442
return err
432
443
}
@@ -446,11 +457,13 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) {
446
457
CacheDir : r .CacheDir ,
447
458
SubTool : r .SubTool ,
448
459
Workspace : r .Workspace ,
460
+ SaveChatStateFile : r .SaveChatStateFile ,
461
+ ChatState : chatState ,
449
462
})
450
463
}
451
- return chat .Start (cmd .Context (), nil , gptScript , func () (types.Program , error ) {
464
+ return chat .Start (cmd .Context (), chatState , gptScript , func () (types.Program , error ) {
452
465
return r .readProgram (ctx , gptScript , args )
453
- }, gptOpt .Env , toolInput )
466
+ }, gptOpt .Env , toolInput , r . SaveChatStateFile )
454
467
}
455
468
456
469
s , err := gptScript .Run (cmd .Context (), prg , gptOpt .Env , toolInput )
0 commit comments