diff options
| author | adamdotdevin <[email protected]> | 2025-07-22 09:28:13 -0500 |
|---|---|---|
| committer | adamdotdevin <[email protected]> | 2025-07-22 09:28:13 -0500 |
| commit | 99d6a28249f10ba1fcb7d61599c008154663a51f (patch) | |
| tree | 1fe754acde33b2ec258196b5a7cc019a9f6ae021 | |
| parent | 5eaf7ab586a998e729f27024bc7702c4c6bdf525 (diff) | |
| download | opencode-99d6a28249f10ba1fcb7d61599c008154663a51f.tar.gz opencode-99d6a28249f10ba1fcb7d61599c008154663a51f.zip | |
fix(tui): more defensive attachment conversion
| -rw-r--r-- | packages/tui/internal/app/prompt.go | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/packages/tui/internal/app/prompt.go b/packages/tui/internal/app/prompt.go index 158951d84..9176b7df5 100644 --- a/packages/tui/internal/app/prompt.go +++ b/packages/tui/internal/app/prompt.go @@ -41,8 +41,9 @@ func (p Prompt) ToMessage( } } for _, att := range textAttachments { - source, _ := att.GetTextSource() - text = text[:att.StartIndex] + source.Value + text[att.EndIndex:] + if source, ok := att.GetTextSource(); ok { + text = text[:att.StartIndex] + source.Value + text[att.EndIndex:] + } } parts := []opencode.PartUnion{opencode.TextPart{ @@ -58,35 +59,37 @@ func (p Prompt) ToMessage( End: int64(attachment.EndIndex), Value: attachment.Display, } - var source *opencode.FilePartSource + source := &opencode.FilePartSource{} switch attachment.Type { case "text": continue case "file": - fileSource, _ := attachment.GetFileSource() - source = &opencode.FilePartSource{ - Text: text, - Path: fileSource.Path, - Type: opencode.FilePartSourceTypeFile, + if fileSource, ok := attachment.GetFileSource(); ok { + source = &opencode.FilePartSource{ + Text: text, + Path: fileSource.Path, + Type: opencode.FilePartSourceTypeFile, + } } case "symbol": - symbolSource, _ := attachment.GetSymbolSource() - source = &opencode.FilePartSource{ - Text: text, - Path: symbolSource.Path, - Type: opencode.FilePartSourceTypeSymbol, - Kind: int64(symbolSource.Kind), - Name: symbolSource.Name, - Range: opencode.SymbolSourceRange{ - Start: opencode.SymbolSourceRangeStart{ - Line: float64(symbolSource.Range.Start.Line), - Character: float64(symbolSource.Range.Start.Char), + if symbolSource, ok := attachment.GetSymbolSource(); ok { + source = &opencode.FilePartSource{ + Text: text, + Path: symbolSource.Path, + Type: opencode.FilePartSourceTypeSymbol, + Kind: int64(symbolSource.Kind), + Name: symbolSource.Name, + Range: opencode.SymbolSourceRange{ + Start: opencode.SymbolSourceRangeStart{ + Line: float64(symbolSource.Range.Start.Line), + Character: float64(symbolSource.Range.Start.Char), + }, + End: opencode.SymbolSourceRangeEnd{ + Line: float64(symbolSource.Range.End.Line), + Character: float64(symbolSource.Range.End.Char), + }, }, - End: opencode.SymbolSourceRangeEnd{ - Line: float64(symbolSource.Range.End.Line), - Character: float64(symbolSource.Range.End.Char), - }, - }, + } } } parts = append(parts, opencode.FilePart{ |
