From 0e34d82a06f4ee23de464f9e5e305f770686214b Mon Sep 17 00:00:00 2001 From: Wang Zichong Date: Mon, 16 Nov 2026 19:55:05 +0800 Subject: [PATCH] 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). --- PLAN.md | 3 +- asuka.json | 4 +- internal/appui/chat.go | 113 +++++++++++++++++++++++++++++++++++- internal/appui/chat_test.go | 15 +++++ internal/appui/icons.go | 4 ++ 5 files changed, 135 insertions(+), 4 deletions(-) diff --git a/PLAN.md b/PLAN.md index 42e9710..4c710d5 100644 --- a/PLAN.md +++ b/PLAN.md @@ -43,7 +43,8 @@ M0 完成,并继续做到了 M3。所有验证都连的是本机正在运行 | 连接界面(对齐官方) | 首连引导 →「手动输入地址」;有保存时列表:最近使用的置顶卡片(连接/已连接)、其他服务器、添加按钮;每行「…」菜单(连接/编辑/删除,删除二次确认);密码按需弹层、失败保留并可从表单重试;连接失败时回到表单并保留输入 | | 顶栏服务器入口 | 会话页只保留一个「服务器」图标按钮,打开实例列表;点选实例即断开当前连接并连到所选实例;「断开当前连接」移入实例列表 | | 首屏无导航栏 | 未连接时直接显示服务器列表(自带标题),不再套用带「新建/刷新」的应用栏;连接后才建立导航栈与动作栏 | -| 轮次页脚 | 每个回合结束后显示「模型 · Agent · 耗时」,右侧「…」打开操作面板(时间戳、复制回答、从这里分叉);模型名由 `/api/model` 解析,耗时按 prompt→完成计算 | +| 轮次页脚 | 每个回合结束后显示「模型 · Agent · 耗时」,右侧「…」打开操作面板(时间戳、复制回答、从这里分叉);模型名由 `/api/model` 解析,耗时按 prompt→完成计算;模型图标改用内置 SVG(不依赖平台符号表) | +| 用户消息操作 | 每条用户消息下有「时间 · 复制 · …」一排;「…」面板含时间戳、复制消息、从此消息前分叉 | | Agent 选择 | 只列 `mode=primary` 的 Agent,子智能体(General/Explore)不再出现 | | 模型/Agent | 聊天页顶栏打开选择 Sheet(可搜索),切换后同步会话列表 | | 新建会话 | 会话页「新建」:标题 + 工作目录(服务端默认目录与已加载会话的目录),创建后直接进入聊天 | diff --git a/asuka.json b/asuka.json index e0e41d8..af81df9 100644 --- a/asuka.json +++ b/asuka.json @@ -1,7 +1,7 @@ { "name": "OpenChamber", "id": "com.openchamber.native", - "version": "0.1.9", - "build": 10, + "version": "0.1.10", + "build": 11, "orientations": ["portrait", "landscape"] } diff --git a/internal/appui/chat.go b/internal/appui/chat.go index cb2c74c..91af1a7 100644 --- a/internal/appui/chat.go +++ b/internal/appui/chat.go @@ -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] }) diff --git a/internal/appui/chat_test.go b/internal/appui/chat_test.go index f16d871..478f5b8 100644 --- a/internal/appui/chat_test.go +++ b/internal/appui/chat_test.go @@ -333,3 +333,18 @@ func TestForkFromTurnFooter(t *testing.T) { t.Fatal("no fork request reached the server") } } + +func TestUserMessageActions(t *testing.T) { + srv := newChatServer(t) + a := uitest.Mount(t, func() ui.Node { return rootWithStore(&memStore{}) }, uitest.Platform(ui.PlatformAndroid)) + connectViaForm(t, a, srv.URL) + a.WaitFor("First session") + a.Tap("First session") + a.WaitFor("What is this?") + + a.Expect("复制消息") + a.Tap("消息操作") + a.WaitFor("从这里分叉") + a.Expect("复制消息") + a.Back() +} diff --git a/internal/appui/icons.go b/internal/appui/icons.go index 64a0239..1fc1d19 100644 --- a/internal/appui/icons.go +++ b/internal/appui/icons.go @@ -10,6 +10,10 @@ import ( // have no server glyph on Android, and an SVG keeps it crisp at any size. var serverIcon = svg.MustParse(``) +// sparklesIcon marks the turn footer. Drawn here for the same reason as +// the server icon: not every platform's symbol set has the name. +var sparklesIcon = svg.MustParse(``) + // instancesButton opens the server list: one button, because picking a // server is also how the live one is replaced. func (c *controller) instancesButton() ui.Node {