mirror of
https://github.com/sst/opencode.git
synced 2025-08-30 09:47:25 +00:00
wip: refactoring tui
This commit is contained in:
parent
6759674c0f
commit
fce9e79d38
5 changed files with 12 additions and 13 deletions
|
@ -25,7 +25,7 @@ type App struct {
|
|||
Events *client.Client
|
||||
State map[string]any
|
||||
Session *client.SessionInfo
|
||||
Messages []client.SessionMessage
|
||||
Messages []client.MessageInfo
|
||||
|
||||
CurrentSessionOLD *session.Session
|
||||
SessionsOLD SessionService
|
||||
|
@ -133,12 +133,12 @@ func (a *App) SendChatMessage(ctx context.Context, text string, attachments []me
|
|||
// return "", fmt.Errorf("attachments not supported yet")
|
||||
}
|
||||
|
||||
part := client.SessionMessagePart{}
|
||||
part.FromSessionMessagePartText(client.SessionMessagePartText{
|
||||
part := client.MessagePart{}
|
||||
part.FromMessagePartText(client.MessagePartText{
|
||||
Type: "text",
|
||||
Text: text,
|
||||
})
|
||||
parts := []client.SessionMessagePart{part}
|
||||
parts := []client.MessagePart{part}
|
||||
|
||||
go a.Client.PostSessionChatWithResponse(ctx, client.PostSessionChatJSONRequestBody{
|
||||
SessionID: a.Session.Id,
|
||||
|
|
|
@ -70,12 +70,12 @@ func (a *AgentServiceBridge) Run(ctx context.Context, sessionID string, text str
|
|||
// return "", fmt.Errorf("attachments not supported yet")
|
||||
}
|
||||
|
||||
part := client.SessionMessagePart{}
|
||||
part.FromSessionMessagePartText(client.SessionMessagePartText{
|
||||
part := client.MessagePart{}
|
||||
part.FromMessagePartText(client.MessagePartText{
|
||||
Type: "text",
|
||||
Text: text,
|
||||
})
|
||||
parts := []client.SessionMessagePart{part}
|
||||
parts := []client.MessagePart{part}
|
||||
|
||||
go a.client.PostSessionChatWithResponse(ctx, client.PostSessionChatJSONRequestBody{
|
||||
SessionID: sessionID,
|
||||
|
|
|
@ -76,7 +76,7 @@ func renderMessage(msg string, isUser bool, isFocused bool, width int, info ...s
|
|||
return rendered
|
||||
}
|
||||
|
||||
func renderUserMessage(msg client.SessionMessage, isFocused bool, width int, position int) uiMessage {
|
||||
func renderUserMessage(msg client.MessageInfo, isFocused bool, width int) uiMessage {
|
||||
// var styledAttachments []string
|
||||
t := theme.CurrentTheme()
|
||||
baseStyle := styles.BaseStyle()
|
||||
|
@ -118,8 +118,8 @@ func renderUserMessage(msg client.SessionMessage, isFocused bool, width int, pos
|
|||
}
|
||||
|
||||
switch part.(type) {
|
||||
case client.SessionMessagePartText:
|
||||
textPart := part.(client.SessionMessagePartText)
|
||||
case client.MessagePartText:
|
||||
textPart := part.(client.MessagePartText)
|
||||
content = renderMessage(textPart.Text, true, isFocused, width, info...)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -185,12 +185,12 @@ func formatTimeDifference(unixTime1, unixTime2 int64) string {
|
|||
|
||||
func (m *messagesCmp) renderView() {
|
||||
m.uiMessages = make([]uiMessage, 0)
|
||||
pos := 0
|
||||
baseStyle := styles.BaseStyle()
|
||||
|
||||
if m.width == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
for _, msg := range m.app.Messages {
|
||||
switch msg.Role {
|
||||
case client.User:
|
||||
|
@ -202,7 +202,6 @@ func (m *messagesCmp) renderView() {
|
|||
msg,
|
||||
msg.Id == m.currentMsgID,
|
||||
m.width,
|
||||
pos,
|
||||
)
|
||||
m.uiMessages = append(m.uiMessages, userMsg)
|
||||
m.cachedContent[msg.Id] = cacheItem{
|
||||
|
|
|
@ -292,7 +292,7 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
sessionId := parts[2]
|
||||
if sessionId == a.app.Session.Id {
|
||||
messageId := parts[3]
|
||||
var message client.SessionMessage
|
||||
var message client.MessageInfo
|
||||
bytes, _ := json.Marshal(msg.Content)
|
||||
if err := json.Unmarshal(bytes, &message); err != nil {
|
||||
status.Error(err.Error())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue