Skip to content

Commit df4a8c9

Browse files
committed
fix: ensure the parent call frame is of category none
Signed-off-by: Donnie Adams <[email protected]>
1 parent 3a3a70c commit df4a8c9

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

frame.go

+11
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ type RunFrame struct {
4949
Type EventType `json:"type"`
5050
}
5151

52+
type CallFrames map[string]CallFrame
53+
54+
func (c CallFrames) ParentCallFrame() CallFrame {
55+
for _, call := range c {
56+
if call.ParentID == "" && call.ToolCategory == NoCategory {
57+
return call
58+
}
59+
}
60+
return CallFrame{}
61+
}
62+
5263
type CallFrame struct {
5364
CallContext `json:",inline"`
5465

run.go

+10-18
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@ type Run struct {
3636
wait func()
3737
basicCommand bool
3838

39-
program *Program
40-
callsLock sync.RWMutex
41-
calls map[string]CallFrame
42-
parentCallFrameID string
43-
rawOutput map[string]any
44-
output, errput string
45-
events chan Frame
46-
lock sync.Mutex
47-
responseCode int
39+
program *Program
40+
callsLock sync.RWMutex
41+
calls CallFrames
42+
rawOutput map[string]any
43+
output, errput string
44+
events chan Frame
45+
lock sync.Mutex
46+
responseCode int
4847
}
4948

5049
// Text returns the text output of the gptscript. It blocks until the output is ready.
@@ -104,7 +103,7 @@ func (r *Run) RespondingTool() Tool {
104103
}
105104

106105
// Calls will return a flattened array of the calls for this run.
107-
func (r *Run) Calls() map[string]CallFrame {
106+
func (r *Run) Calls() CallFrames {
108107
r.callsLock.RLock()
109108
defer r.callsLock.RUnlock()
110109
return maps.Clone(r.calls)
@@ -115,11 +114,7 @@ func (r *Run) ParentCallFrame() (CallFrame, bool) {
115114
r.callsLock.RLock()
116115
defer r.callsLock.RUnlock()
117116

118-
if r.parentCallFrameID == "" {
119-
return CallFrame{}, false
120-
}
121-
122-
return r.calls[r.parentCallFrameID], true
117+
return r.calls.ParentCallFrame(), true
123118
}
124119

125120
// ErrorOutput returns the stderr output of the gptscript.
@@ -394,9 +389,6 @@ func (r *Run) request(ctx context.Context, payload any) (err error) {
394389
if event.Call != nil {
395390
r.callsLock.Lock()
396391
r.calls[event.Call.ID] = *event.Call
397-
if r.parentCallFrameID == "" && event.Call.ParentID == "" {
398-
r.parentCallFrameID = event.Call.ID
399-
}
400392
r.callsLock.Unlock()
401393
} else if event.Run != nil {
402394
if event.Run.Type == EventTypeRunStart {

0 commit comments

Comments
 (0)