Skip to content

Commit 8981e8c

Browse files
authored
Merge pull request #19 from thedadams/fix-stdout-deadlock
fix: simplify event processing
2 parents a637a38 + dae2cab commit 8981e8c

File tree

5 files changed

+91
-273
lines changed

5 files changed

+91
-273
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ None of the options is required, and the defaults will reduce the number of call
2727

2828
- `cache`: Enable or disable caching. Default (true).
2929
- `cacheDir`: Specify the cache directory.
30-
- `quiet`: No output logging
3130
- `subTool`: Use tool of this name, not the first tool
3231
- `input`: Input arguments for the tool run
3332
- `workspace`: Directory to use for the workspace, if specified it will not be deleted on exit
@@ -261,7 +260,6 @@ func streamExecTool(ctx context.Context) error {
261260
// Process event...
262261
}
263262

264-
// Wait for the output to ensure the script completes successfully.
265263
_, err = run.Text()
266264
return err
267265
}

client.go

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -165,32 +165,10 @@ func (c *client) ParseTool(ctx context.Context, toolDef string) ([]Node, error)
165165

166166
// Fmt will format the given nodes into a string.
167167
func (c *client) Fmt(ctx context.Context, nodes []Node) (string, error) {
168-
b, err := json.Marshal(Document{Nodes: nodes})
169-
if err != nil {
170-
return "", fmt.Errorf("failed to marshal nodes: %w", err)
171-
}
172-
173-
run := &runSubCommand{
174-
Run: Run{
175-
url: c.gptscriptURL,
176-
requestPath: "fmt",
177-
state: Creating,
178-
toolPath: "",
179-
content: string(b),
180-
},
181-
}
182-
183-
if err = run.request(ctx, Document{Nodes: nodes}); err != nil {
184-
return "", err
185-
}
186-
187-
out, err := run.Text()
168+
out, err := c.runBasicCommand(ctx, "fmt", Document{Nodes: nodes})
188169
if err != nil {
189170
return "", err
190171
}
191-
if run.err != nil {
192-
return run.ErrorOutput(), run.err
193-
}
194172

195173
return out, nil
196174
}
@@ -231,12 +209,11 @@ func (c *client) Confirm(ctx context.Context, resp AuthResponse) error {
231209
}
232210

233211
func (c *client) runBasicCommand(ctx context.Context, requestPath string, body any) (string, error) {
234-
run := &runSubCommand{
235-
Run: Run{
236-
url: c.gptscriptURL,
237-
requestPath: requestPath,
238-
state: Creating,
239-
},
212+
run := &Run{
213+
url: c.gptscriptURL,
214+
requestPath: requestPath,
215+
state: Creating,
216+
basicCommand: true,
240217
}
241218

242219
if err := run.request(ctx, body); err != nil {

client_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package gptscript
33
import (
44
"context"
55
"fmt"
6-
"io"
76
"os"
87
"path/filepath"
98
"runtime"
@@ -309,11 +308,6 @@ func TestStreamRun(t *testing.T) {
309308
}
310309
}
311310

312-
stdErr, err := io.ReadAll(run.stderr)
313-
if err != nil {
314-
t.Errorf("Error reading stderr: %v", err)
315-
}
316-
317311
out, err := run.Text()
318312
if err != nil {
319313
t.Errorf("Error reading output: %v", err)
@@ -327,7 +321,7 @@ func TestStreamRun(t *testing.T) {
327321
t.Errorf("Unexpected output: %s", out)
328322
}
329323

330-
if len(stdErr) != 0 {
324+
if len(run.ErrorOutput()) != 0 {
331325
t.Error("Should have no stderr output")
332326
}
333327
}

opts.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ type Options struct {
66
Input string `json:"input"`
77
DisableCache bool `json:"disableCache"`
88
CacheDir string `json:"cacheDir"`
9-
Quiet bool `json:"quiet"`
109
SubTool string `json:"subTool"`
1110
Workspace string `json:"workspace"`
1211
ChatState string `json:"chatState"`

0 commit comments

Comments
 (0)