@@ -13,7 +13,7 @@ import (
1313 "time"
1414
1515 tea "github.com/charmbracelet/bubbletea"
16- "github.com/coder/agentapi/lib/httpapi "
16+ "github.com/coder/agentapi/lib/types "
1717 "github.com/spf13/cobra"
1818 sse "github.com/tmaxmax/go-sse"
1919 "golang.org/x/term"
@@ -35,27 +35,27 @@ func (c *ChannelWriter) Receive() ([]byte, bool) {
3535}
3636
3737type model struct {
38- screen string
38+ conversation string
3939}
4040
4141func (m model ) Init () tea.Cmd {
4242 // Just return `nil`, which means "no I/O right now, please."
4343 return nil
4444}
4545
46- type screenMsg struct {
47- screen string
46+ type conversationMsg struct {
47+ conversation string
4848}
4949
5050type finishMsg struct {}
5151
5252//lint:ignore U1000 The Update function is used by the Bubble Tea framework
5353func (m model ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
5454 switch msg := msg .(type ) {
55- case screenMsg :
56- m .screen = msg .screen
57- if m .screen != "" && m .screen [len (m .screen )- 1 ] != '\n' {
58- m .screen += "\n "
55+ case conversationMsg :
56+ m .conversation = msg .conversation
57+ if m .conversation != "" && m .conversation [len (m .conversation )- 1 ] != '\n' {
58+ m .conversation += "\n "
5959 }
6060 case tea.KeyMsg :
6161 if msg .String () == "ctrl+c" {
@@ -69,10 +69,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
6969}
7070
7171func (m model ) View () string {
72- return m .screen
72+ return m .conversation
7373}
7474
75- func ReadScreenOverHTTP (ctx context.Context , url string , ch chan <- httpapi .ScreenUpdateBody ) error {
75+ func ReadScreenOverHTTP (ctx context.Context , url string , ch chan <- types .ScreenUpdateBody ) error {
7676 req , _ := http .NewRequestWithContext (ctx , http .MethodGet , url , nil )
7777 req .Header .Set ("Content-Type" , "application/json" )
7878
@@ -85,25 +85,25 @@ func ReadScreenOverHTTP(ctx context.Context, url string, ch chan<- httpapi.Scree
8585 }()
8686
8787 for ev , err := range sse .Read (res .Body , & sse.ReadConfig {
88- // 256KB: screen can be big. The default terminal size is 80x1000,
88+ // 256KB: conversation can be big. The default terminal size is 80x1000,
8989 // which can be over 80000 bytes.
9090 MaxEventSize : 256 * 1024 ,
9191 }) {
9292 if err != nil {
9393 return xerrors .Errorf ("failed to read sse: %w" , err )
9494 }
95- var screen httpapi .ScreenUpdateBody
95+ var screen types .ScreenUpdateBody
9696 if err := json .Unmarshal ([]byte (ev .Data ), & screen ); err != nil {
97- return xerrors .Errorf ("failed to unmarshal screen : %w" , err )
97+ return xerrors .Errorf ("failed to unmarshal conversation : %w" , err )
9898 }
9999 ch <- screen
100100 }
101101 return nil
102102}
103103
104104func WriteRawInputOverHTTP (ctx context.Context , url string , msg string ) error {
105- messageRequest := httpapi .MessageRequestBody {
106- Type : httpapi .MessageTypeRaw ,
105+ messageRequest := types .MessageRequestBody {
106+ Type : types .MessageTypeRaw ,
107107 Content : msg ,
108108 }
109109 messageRequestBytes , err := json .Marshal (messageRequest )
@@ -145,16 +145,16 @@ func runAttach(remoteUrl string) error {
145145 }
146146 tee := io .TeeReader (os .Stdin , stdinWriter )
147147 p := tea .NewProgram (model {}, tea .WithInput (tee ), tea .WithAltScreen ())
148- screenCh := make (chan httpapi .ScreenUpdateBody , 64 )
148+ screenCh := make (chan types .ScreenUpdateBody , 64 )
149149
150150 readScreenErrCh := make (chan error , 1 )
151151 go func () {
152152 defer close (readScreenErrCh )
153- if err := ReadScreenOverHTTP (ctx , remoteUrl + "/internal/screen " , screenCh ); err != nil {
153+ if err := ReadScreenOverHTTP (ctx , remoteUrl + "/internal/conversation " , screenCh ); err != nil {
154154 if errors .Is (err , context .Canceled ) {
155155 return
156156 }
157- readScreenErrCh <- xerrors .Errorf ("failed to read screen : %w" , err )
157+ readScreenErrCh <- xerrors .Errorf ("failed to read conversation : %w" , err )
158158 }
159159 }()
160160 writeRawInputErrCh := make (chan error , 1 )
@@ -189,8 +189,8 @@ func runAttach(remoteUrl string) error {
189189 if ! ok {
190190 return
191191 }
192- p .Send (screenMsg {
193- screen : screenUpdate .Screen ,
192+ p .Send (conversationMsg {
193+ conversation : screenUpdate .Screen ,
194194 })
195195 }
196196 }
0 commit comments