feat: actions under user messages, and a dependable footer icon
Every prompt now carries a row with its time, a copy button and a menu (copy message, fork before this prompt), matching the first-party client. The turn footer's sparkles became an inline SVG: the platform symbol table left an empty square on some devices. Bump version to 0.1.10 (build 11).
This commit is contained in:
1 parent
d3e92f036a
commit
0e34d82a06
5 files changed
+135
-4
No files matched your search
+112
-1
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/egoist/asuka/colors"
|
||||
"github.com/egoist/asuka/fonts"
|
||||
"github.com/egoist/asuka/sdk/markdown"
|
||||
"github.com/egoist/asuka/sdk/svg"
|
||||
"github.com/egoist/asuka/signal"
|
||||
"github.com/egoist/asuka/ui"
|
||||
"github.com/openchamber/openchamber-native/internal/ocapi"
|
||||
@@ -62,6 +63,8 @@ type chat struct {
|
||||
|
||||
footerOpen *signal.Signal[bool]
|
||||
footerID *signal.Signal[string]
|
||||
userOpen *signal.Signal[bool]
|
||||
userID *signal.Signal[string]
|
||||
|
||||
pickerOpen *signal.Signal[bool]
|
||||
pickerKind string
|
||||
@@ -105,6 +108,8 @@ func (c *controller) openChat(s *ocapi.Session, nav *ui.Navigator) *chat {
|
||||
modelNames: signal.NewFunc(map[string]string{}, nil),
|
||||
footerOpen: signal.New(false),
|
||||
footerID: signal.New(""),
|
||||
userOpen: signal.New(false),
|
||||
userID: signal.New(""),
|
||||
pickerOpen: signal.New(false),
|
||||
pickerItems: signal.NewFunc([]pickerItem{}, nil),
|
||||
pickerFilter: signal.New(""),
|
||||
@@ -659,6 +664,7 @@ func (ch *chat) screen() ui.Node {
|
||||
ch.composer(),
|
||||
),
|
||||
ch.footerSheet(),
|
||||
ch.userSheet(),
|
||||
ui.Sheet(ui.SheetProps{
|
||||
Open: ch.pickerOpen,
|
||||
Detents: ui.DetentLarge,
|
||||
@@ -928,6 +934,7 @@ func (ch *chat) items() signal.Accessor[[]chatItem] {
|
||||
switch m.Type {
|
||||
case "user":
|
||||
out = append(out, chatItem{Key: "u/" + m.ID, Kind: "user", MsgID: m.ID})
|
||||
out = append(out, chatItem{Key: "ua/" + m.ID, Kind: "useractions", MsgID: m.ID})
|
||||
case "assistant":
|
||||
if len(m.Content) == 0 && m.Time.Completed == 0 {
|
||||
out = append(out, chatItem{Key: "a/" + m.ID, Kind: "thinking", MsgID: m.ID})
|
||||
@@ -993,6 +1000,8 @@ func (ch *chat) itemRow(it signal.Accessor[chatItem], _ signal.Accessor[int]) ui
|
||||
return ch.toolRow(cur)
|
||||
case "footer":
|
||||
return ch.footerRow(cur)
|
||||
case "useractions":
|
||||
return ch.userActionsRow(cur)
|
||||
case "shell":
|
||||
return ui.View(ui.ViewProps{Style: ui.Style{Padding: ui.Symmetric(4, 14)}},
|
||||
ui.Text(ch.shellText(cur.MsgID), ui.Style{Font: codeFont(), Color: colors.SecondaryLabel}),
|
||||
@@ -1039,13 +1048,115 @@ func (ch *chat) footerRow(cur chatItem) ui.Node {
|
||||
return strings.Join(parts, " · ")
|
||||
})
|
||||
return ui.Row(ui.Style{Padding: ui.Symmetric(6, 14), Gap: 6, Align: ui.AlignCenter},
|
||||
ui.Symbol(ui.Icon("sparkles"), ui.Style{Font: fonts.Footnote, Color: colors.SecondaryLabel}),
|
||||
svg.View(svg.Props{Icon: sparklesIcon, Color: ui.Val(colors.SecondaryLabel),
|
||||
Style: ui.Style{Width: ui.Pt(14), Height: ui.Pt(14)}}),
|
||||
ui.Text(facts, ui.Style{Font: fonts.Footnote, Color: colors.SecondaryLabel, Lines: 1, Grow: 1}),
|
||||
ui.Button(ui.ButtonProps{Icon: ui.IconMore, Label: ui.Val("更多操作"),
|
||||
OnPress: func() { ch.footerMenu(cur.MsgID) }}),
|
||||
)
|
||||
}
|
||||
|
||||
// userActionsRow is the line under a prompt: its time, copy, and a menu,
|
||||
// as the first-party client shows.
|
||||
func (ch *chat) userActionsRow(cur chatItem) ui.Node {
|
||||
stamp := signal.Func(func() string {
|
||||
m := ch.byID.Get()[cur.MsgID]
|
||||
if m.Time.Created <= 0 {
|
||||
return ""
|
||||
}
|
||||
return time.UnixMilli(m.Time.Created).Format("15:04")
|
||||
})
|
||||
return ui.Row(ui.Style{Padding: ui.Symmetric(2, 12), Gap: 10, Justify: ui.JustifyEnd, Align: ui.AlignCenter},
|
||||
ui.Row(ui.Style{Gap: 4, Align: ui.AlignCenter},
|
||||
ui.Symbol(ui.Icon("clock"), ui.Style{Font: fonts.Caption, Color: colors.SecondaryLabel}),
|
||||
ui.Text(stamp, ui.Style{Font: fonts.Caption, Color: colors.SecondaryLabel}),
|
||||
),
|
||||
ui.Button(ui.ButtonProps{Icon: "doc.on.doc", Label: ui.Val("复制消息"),
|
||||
OnPress: func() { ch.copyUserMessage(cur.MsgID) }}),
|
||||
ui.Button(ui.ButtonProps{Icon: ui.IconMore, Label: ui.Val("消息操作"),
|
||||
OnPress: func() { ch.userActionsMenu(cur.MsgID) }}),
|
||||
)
|
||||
}
|
||||
|
||||
func (ch *chat) copyUserMessage(id string) {
|
||||
m := ch.byID.Peek()[id]
|
||||
text := strings.TrimSpace(m.Text)
|
||||
if text == "" {
|
||||
ui.Snackbar(ui.SnackbarProps{Message: "没有可复制的文字"})
|
||||
return
|
||||
}
|
||||
ui.Copy(text)
|
||||
ui.Snackbar(ui.SnackbarProps{Message: "已复制消息"})
|
||||
}
|
||||
|
||||
func (ch *chat) userActionsMenu(id string) {
|
||||
ch.userID.Set(id)
|
||||
ch.userOpen.Set(true)
|
||||
}
|
||||
|
||||
func (ch *chat) userSheet() ui.Node {
|
||||
return ui.Sheet(ui.SheetProps{
|
||||
Open: ch.userOpen,
|
||||
Detents: ui.DetentMedium,
|
||||
Grabber: true,
|
||||
OnDismiss: func() { ch.userOpen.Set(false) },
|
||||
Content: func() ui.Node {
|
||||
id := ch.userID.Peek()
|
||||
m := ch.byID.Peek()[id]
|
||||
stamp := ""
|
||||
if m.Time.Created > 0 {
|
||||
stamp = time.UnixMilli(m.Time.Created).Format("2006-01-02 15:04")
|
||||
}
|
||||
act := func(f func()) func() {
|
||||
return func() {
|
||||
ch.userOpen.Set(false)
|
||||
f()
|
||||
}
|
||||
}
|
||||
return ui.SafeArea(ui.Style{Padding: ui.All(20), Gap: 4},
|
||||
ui.StaticText("更多操作", ui.Style{Font: fonts.Footnote, Color: colors.SecondaryLabel}),
|
||||
ui.Show(signal.Func(func() bool { return stamp != "" }), func() ui.Node {
|
||||
return ui.Row(ui.Style{Padding: ui.Symmetric(8, 0), Gap: 8, Align: ui.AlignCenter},
|
||||
ui.Symbol(ui.Icon("clock"), ui.Style{Font: fonts.Footnote, Color: colors.SecondaryLabel}),
|
||||
ui.StaticText(stamp, ui.Style{Font: fonts.Footnote, Color: colors.SecondaryLabel}),
|
||||
)
|
||||
}),
|
||||
sheetAction("复制消息", "doc.on.doc", act(func() { ch.copyUserMessage(id) })),
|
||||
sheetAction("从这里分叉", "", act(func() { ch.forkBefore(id) })),
|
||||
)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// forkBefore copies the transcript before a message (a prompt) into a new
|
||||
// session.
|
||||
func (ch *chat) forkBefore(id string) {
|
||||
client := ch.client()
|
||||
if client == nil {
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 25*time.Second)
|
||||
defer cancel()
|
||||
s, err := client.ForkSession(ctx, ch.id, ch.dir, id)
|
||||
ui.Post(func() {
|
||||
if err != nil {
|
||||
ch.errText.Set(friendlyError(err))
|
||||
return
|
||||
}
|
||||
ch.c.sessions.Update(func(list []ocapi.Session) []ocapi.Session {
|
||||
next := make([]ocapi.Session, 0, len(list)+1)
|
||||
next = append(next, s)
|
||||
return append(next, list...)
|
||||
})
|
||||
if ch.nav != nil {
|
||||
nc := ch.c.openChat(&s, ch.nav)
|
||||
ch.nav.Push(nc.screen, ui.ScreenOptions{Title: nc.title, Actions: chatActions(nc)})
|
||||
}
|
||||
})
|
||||
}()
|
||||
}
|
||||
|
||||
func (ch *chat) reasoningRow(cur chatItem) ui.Node {
|
||||
key := fmt.Sprintf("reason/%s/%d", cur.MsgID, cur.Part)
|
||||
open := signal.Func(func() bool { return ch.expanded.Get()[key] })
|
||||
|
||||
Reference in new issue
Block a user