Skip to content
7 changes: 4 additions & 3 deletions pkg/cmd/agent/credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func TestEachRPCGetsTheCredentialTheAPITakes(t *testing.T) {
got: &agentv1.GetSessionResponse{Session: session, ViewJson: long, ViewSeq: 7},
frames: [][]*agentv1.WatchSessionResponse{{frame("idle", "c1", long)}},
whole: map[string]*agentv1.GetSessionMessageResponse{"6": {Role: "assistant", Text: "whole"}},
inputs: []*agentv1.GetSessionInputResponse{became("answered", "6")},
}
}
launch := []string{"launch", "an-agent@v1", "--source", "github:acme/lib", "--message", "hello"}
Expand All @@ -89,14 +90,14 @@ func TestEachRPCGetsTheCredentialTheAPITakes(t *testing.T) {
want map[string]string
}{
{"create", []string{"create", "hello"}, map[string]string{"CreateSession": "turn-token"}},
{"create --watch", []string{"create", "hello", "--watch"}, map[string]string{"CreateSession": "turn-token", "WatchSession": "turn-token", "GetSessionMessage": "turn-token"}},
{"create --watch", []string{"create", "hello", "--watch"}, map[string]string{"CreateSession": "turn-token", "WatchSession": "turn-token", "GetSessionInput": "turn-token", "GetSessionMessage": "turn-token"}},
{"list", []string{"list"}, map[string]string{"ListDepotAgentSessions": "turn-token"}},
{"logs", []string{"logs", "das_1"}, map[string]string{"GetSession": "turn-token", "GetSessionMessage": "turn-token"}},
{"watch", []string{"watch", "das_1", "--until-idle"}, map[string]string{"WatchSession": "turn-token", "GetSessionMessage": "turn-token"}},
{"stop", []string{"stop", "das_1"}, map[string]string{"InterruptSession": "cache-token"}},
{"stop --archive", []string{"stop", "das_1", "--archive"}, map[string]string{"ArchiveSession": "cache-token"}},
{"send", []string{"send", "das_1", "hello"}, map[string]string{"SendInput": "turn-token"}},
{"send --watch", []string{"send", "das_1", "hello", "--watch"}, map[string]string{"GetSession": "turn-token", "SendInput": "turn-token", "WatchSession": "turn-token", "GetSessionMessage": "turn-token"}},
{"send --watch", []string{"send", "das_1", "hello", "--watch"}, map[string]string{"SendInput": "turn-token", "WatchSession": "turn-token", "GetSessionInput": "turn-token", "GetSessionMessage": "turn-token"}},
{"launch", launch, map[string]string{"Launch": "turn-token"}},
{"launch --watch", append(launch, "--watch"), map[string]string{"Launch": "turn-token", "WatchSession": "turn-token", "GetSessionMessage": "turn-token"}},
} {
Expand Down Expand Up @@ -136,7 +137,7 @@ func TestAnAPIThatRefusesTheTurnTokenIsNamedAndLeavesNothingUnsaid(t *testing.T)
{"watch", []string{"watch", "das_1", "--until-idle"}, "WatchSession", "", map[string]string{"WatchSession": "turn-token"}},
{"create --watch", []string{"create", "hello", "--watch", "-o", "json"}, "WatchSession", "Session das_1 was created", map[string]string{"CreateSession": "turn-token", "WatchSession": "turn-token"}},
{"send", []string{"send", "das_1", "hello"}, "SendInput", "", map[string]string{"SendInput": "turn-token"}},
{"send --watch", []string{"send", "das_1", "hello", "--watch"}, "SendInput", "", map[string]string{"GetSession": "turn-token", "SendInput": "turn-token"}},
{"send --watch", []string{"send", "das_1", "hello", "--watch"}, "SendInput", "", map[string]string{"SendInput": "turn-token"}},
{"launch", launch, "Launch", "", map[string]string{"Launch": "turn-token"}},
{"launch --watch", append(launch, "--watch"), "Launch", "", map[string]string{"Launch": "turn-token"}},
} {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/agent/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func runLaunch(cmd *cobra.Command, o *launchOptions, agent string) error {
if err != nil || !o.watch {
return err
}
return watchAndReport(cmd, c, o.output, sessionID, watchOptions{afterInput: resp.Msg.GetInput().GetInputId(), untilIdle: true, timeout: o.timeout, url: resp.Msg.GetUrl(), base: beforeFirst(), did: "was launched"})
return watchAndReport(cmd, c, o.output, sessionID, watchOptions{afterInput: resp.Msg.GetInput().GetInputId(), untilIdle: true, timeout: o.timeout, url: resp.Msg.GetUrl(), did: "was launched"})
}

func parseSource(value string) (*agentv1.DepotAgentLaunchSource, error) {
Expand Down
21 changes: 21 additions & 0 deletions pkg/cmd/agent/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,27 @@ func (r *Renderer) fill(msg *viewMessage) error {
return nil
}

// Reply returns the whole text of the message with this id, read by the id unless a frame already read it, and
// prints it when the transcript has not shown it whole: its turn outgrew the view, or its read failed.
func (r *Renderer) Reply(id string) (string, error) {
text, held := r.full[id]
if !held {
var err error
if text, err = r.whole(id); err != nil {
return "", err
}
Comment thread
robstolarz marked this conversation as resolved.
Resolved
}
switch {
case r.once("message:" + id):
r.finishPartial(text)
case r.unread[id] > 0:
delete(r.unread, id)
r.line("(the whole reply, read on a later try)")
r.line("%s", strings.TrimSpace(text))
}
return text, nil
}

// From starts the transcript at the message of this input, leaving out the session's earlier turns.
func (r *Renderer) From(inputID string) *Renderer {
r.from = inputID
Expand Down
11 changes: 1 addition & 10 deletions pkg/cmd/agent/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ func runSend(cmd *cobra.Command, o *sendOptions, args []string) error {
if err != nil {
return err
}
var base *int64
if o.watch {
base = newestSeq(cmd.Context(), c, sessionID)
}
resp, err := c.client.SendInput(cmd.Context(), authed(c, req))
if err != nil {
if o.key != "" && connect.CodeOf(err) == connect.CodeNotFound {
Expand Down Expand Up @@ -157,12 +153,7 @@ func runSend(cmd *cobra.Command, o *sendOptions, args []string) error {
if !o.watch {
return nil
}
// A repeated client request ID returns the input of the first send. Once the session has taken that one,
// what was read just now is not from before it, so the watch finds its own base.
if status != "" && status != "pending" {
base = nil
}
wait := watchOptions{afterInput: resp.Msg.GetInput().GetInputId(), untilIdle: true, timeout: o.timeout, base: base, did: "got the message"}
wait := watchOptions{afterInput: resp.Msg.GetInput().GetInputId(), untilIdle: true, timeout: o.timeout, did: "got the message"}
if status == "cancelled" {
return report(cmd, c, o.output, sessionID, wait, watchResult{SessionID: sessionID, InputID: wait.afterInput, Status: "archived", Outcome: outcomeFailed, Error: cancelled})
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/cmd/agent/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Use ` + "`depot agent launch`" + ` to start a published agent on a repository.`,
return err
}
sessionID := resp.Msg.GetSession().GetSessionId()
wait := watchOptions{afterInput: resp.Msg.GetInput().GetInputId(), untilIdle: true, timeout: timeout, base: beforeFirst(), did: "was created"}
wait := watchOptions{afterInput: resp.Msg.GetInput().GetInputId(), untilIdle: true, timeout: timeout, did: "was created"}
if watch && f.output == "json" {
return watchAndReport(cmd, c, f.output, sessionID, wait)
}
Expand Down Expand Up @@ -278,7 +278,8 @@ reply of the agent is read whole; -o json prints the view as the API returns it.
}
if f.output == "text" {
r := NewRenderer(cmd.OutOrStdout()).Whole(func(messageID string) (string, error) {
return wholeMessage(cmd.Context(), c, args[0], messageID)
text, _, err := wholeMessage(cmd.Context(), c, args[0], messageID)
return text, err
})
_, err := r.Render(resp.Msg.GetSession(), resp.Msg.GetViewJson())
return err
Expand Down
Loading
Loading