feat: context usage ring and tool image previews

- the composer shows a context ring and percentage from the last
  token-bearing assistant message, toned at 75% and 90%; tapping opens a
  sheet with the model, used tokens, limits, output reserve and turn cost
- images a tool call names (read attachments as data URLs, input paths,
  and image paths in output text) get a link under the tool row; tapping
  previews it from the data URL or /api/fs/raw, allowing paths outside
  the workspace
- directory-scoped requests now send x-opencode-directory-encoding: uri,
  which scoped routes such as /api/fs/raw need to decode the header
- ocprobe gains a raw file command for checking previews

Bump version to 0.2.2 (build 16).
This commit is contained in:
blumia committed 2026-11-18 02:15:11 +08:00
1 parent dc3730eba7
commit 2fb4a8ea79
16 files changed
+884 -26

No files matched your search

+32 -2
View File
@@ -60,7 +60,9 @@ type chat struct {
permList *signal.Signal[[]ocapi.PermissionRequest]
hasPerms *signal.Signal[bool]
modelNames *signal.Signal[map[string]string]
modelNames *signal.Signal[map[string]string]
modelLimits *signal.Signal[map[string]modelLimit]
usageOpen *signal.Signal[bool]
footerOpen *signal.Signal[bool]
footerID *signal.Signal[string]
@@ -73,6 +75,13 @@ type chat struct {
lastScroll float32
imagePaths map[string][]string
previewOpen *signal.Signal[bool]
previewLoading *signal.Signal[bool]
previewPath *signal.Signal[string]
previewTitle *signal.Signal[string]
previewCache map[string]string
previewSeq int
pickerOpen *signal.Signal[bool]
pickerKind string
pickerItems *signal.Signal[[]pickerItem]
@@ -113,6 +122,8 @@ func (c *controller) openChat(s *ocapi.Session, nav *ui.Navigator) *chat {
permList: signal.NewFunc([]ocapi.PermissionRequest{}, nil),
hasPerms: signal.New(false),
modelNames: signal.NewFunc(map[string]string{}, nil),
modelLimits: signal.NewFunc(map[string]modelLimit{}, nil),
usageOpen: signal.New(false),
footerOpen: signal.New(false),
footerID: signal.New(""),
userOpen: signal.New(false),
@@ -121,6 +132,11 @@ func (c *controller) openChat(s *ocapi.Session, nav *ui.Navigator) *chat {
attaching: signal.New(false),
jumpToLatest: signal.New(false),
imagePaths: map[string][]string{},
previewOpen: signal.New(false),
previewLoading: signal.New(false),
previewPath: signal.New(""),
previewTitle: signal.New(""),
previewCache: map[string]string{},
pickerOpen: signal.New(false),
pickerItems: signal.NewFunc([]pickerItem{}, nil),
pickerFilter: signal.New(""),
@@ -150,6 +166,7 @@ func (ch *chat) loadCatalog() {
return
}
names := make(map[string]string, len(models))
limits := make(map[string]modelLimit, len(models))
for _, m := range models {
name := m.Name
if name == "" {
@@ -157,8 +174,14 @@ func (ch *chat) loadCatalog() {
}
names[m.ProviderID+"/"+m.ID] = name
names[m.ID] = name
lim := modelLimit{Context: m.Limit.Context, Output: m.Limit.Output}
limits[m.ProviderID+"/"+m.ID] = lim
limits[m.ID] = lim
}
ui.Post(func() { ch.modelNames.Set(names) })
ui.Post(func() {
ch.modelNames.Set(names)
ch.modelLimits.Set(limits)
})
}()
}
@@ -824,6 +847,8 @@ func (ch *chat) screen() ui.Node {
),
ch.footerSheet(),
ch.userSheet(),
ch.usageSheet(),
ch.previewSheet(),
ui.Sheet(ui.SheetProps{
Open: ch.pickerOpen,
Detents: ui.DetentLarge,
@@ -1115,6 +1140,7 @@ func (ch *chat) composer() ui.Node {
Multiline: true,
Style: ui.Style{Grow: 1, Lines: 5},
}),
ch.usageButton(),
ui.Show(ch.running,
func() ui.Node {
return ui.Button(ui.ButtonProps{
@@ -1481,6 +1507,10 @@ func (ch *chat) toolRow(cur chatItem) ui.Node {
}},
ui.Text(headline, ui.Style{Font: fonts.Footnote, Color: colors.SecondaryLabel, Lines: 2}),
),
ui.For(ch.toolImageAccessor(part), func(ref imageRef) string { return ref.Source },
func(ref signal.Accessor[imageRef], _ signal.Accessor[int]) ui.Node {
return ui.Dynamic(func() ui.Node { return ch.imageLinkRow(ref.Get()) })
}),
ui.Show(open, func() ui.Node {
return ui.View(ui.ViewProps{Style: ui.Style{Padding: ui.Symmetric(8, 10), CornerRadius: 8,
Background: colors.SecondaryBackground, Gap: 8}},