Эх сурвалжийг харах

发布 v0.4.14:统一跨端 Bot 排序并完善 iOS 消息展示

与内网主分支使用同一源码树。
Samien 2 сар өмнө
parent
commit
7a3b967134

+ 6 - 6
README.md

@@ -1,6 +1,6 @@
 # 夭夭 AI
 # 夭夭 AI
 
 
-当前 Web 与 macOS 桌面发布版本:**v0.4.13**。桌面版提供 Apple Silicon(arm64)DMG,详见 [发布说明](docs/releases/v0.4.13.md)。
+当前 Web 与 macOS 桌面发布版本:**v0.4.14**。桌面版提供 Apple Silicon(arm64)DMG,详见 [发布说明](docs/releases/v0.4.14.md)。
 
 
 夭夭 AI 为网页、iOS 和安卓提供统一的 Agent、群聊、文件库及语音配置服务。Hermes 通过标准 9119 HTTP/WebSocket 接口执行任务。
 夭夭 AI 为网页、iOS 和安卓提供统一的 Agent、群聊、文件库及语音配置服务。Hermes 通过标准 9119 HTTP/WebSocket 接口执行任务。
 
 
@@ -38,7 +38,7 @@ Web 数据默认保存在 `~/.yaoyao`,可用 `YAOYAO_HOME` 指定(兼容 `HE
 
 
 ## macOS 桌面版
 ## macOS 桌面版
 
 
-在 [v0.4.13 发布页](https://github.com/Lsamien/yaoyao/releases/tag/v0.4.13) 下载 `Yaoyao-0.4.13-arm64.dmg`,将“夭夭”拖到应用程序后打开。首次启动会核对并同步配套本机 Web 服务;普通退出保留后台运行,“停止后台服务并退出”可完整停止本应用管理的后台。详细说明见 [macOS App](docs/macos-app.md)。
+在 [v0.4.14 发布页](https://github.com/Lsamien/yaoyao/releases/tag/v0.4.14) 下载 `Yaoyao-0.4.14-arm64.dmg`,将“夭夭”拖到应用程序后打开。首次启动会核对并同步配套本机 Web 服务;普通退出保留后台运行,“停止后台服务并退出”可完整停止本应用管理的后台。详细说明见 [macOS App](docs/macos-app.md)。
 
 
 此 DMG 使用 Apple Development 开发签名,未做 Apple 公证。
 此 DMG 使用 Apple Development 开发签名,未做 Apple 公证。
 
 
@@ -48,11 +48,11 @@ Web 数据默认保存在 `~/.yaoyao`,可用 `YAOYAO_HOME` 指定(兼容 `HE
 
 
 | 镜像 | 架构 |
 | 镜像 | 架构 |
 | --- | --- |
 | --- | --- |
-| `samienluo/yaoyao:v0.4.13-amd` | AMD64 |
-| `samienluo/yaoyao:v0.4.13` | 自动匹配 AMD64 / ARM64 |
-| `samienluo/yaoyao:latest` | 最新稳定版通用镜像,当前与 `v0.4.13` 相同 |
+| `samienluo/yaoyao:v0.4.14-amd` | AMD64 |
+| `samienluo/yaoyao:v0.4.14` | 自动匹配 AMD64 / ARM64 |
+| `samienluo/yaoyao:latest` | 最新稳定版通用镜像,当前与 `v0.4.14` 相同 |
 
 
-准备好 Docker Engine/Compose 和容器可访问的 Hermes 9119 服务,在仓库目录将 `docker.env.example` 复制为 `docker.env`。配置上游地址,并设置 `HERMES_YAOYAO_IMAGE=samienluo/yaoyao:v0.4.13`(或 `samienluo/yaoyao:latest`),即可使用远程镜像:
+准备好 Docker Engine/Compose 和容器可访问的 Hermes 9119 服务,在仓库目录将 `docker.env.example` 复制为 `docker.env`。配置上游地址,并设置 `HERMES_YAOYAO_IMAGE=samienluo/yaoyao:v0.4.14`(或 `samienluo/yaoyao:latest`),即可使用远程镜像:
 
 
 ```sh
 ```sh
 docker compose --env-file docker.env pull web
 docker compose --env-file docker.env pull web

+ 1 - 1
docker.env.example

@@ -3,7 +3,7 @@ HERMES_YAOYAO_BIND_ADDRESS=127.0.0.1
 HERMES_YAOYAO_PUBLISHED_PORT=15300
 HERMES_YAOYAO_PUBLISHED_PORT=15300
 # 远程通用镜像支持 AMD64 / ARM64;每次发布更新 latest 并保留旧版本标签。
 # 远程通用镜像支持 AMD64 / ARM64;每次发布更新 latest 并保留旧版本标签。
 # HERMES_YAOYAO_IMAGE=samienluo/yaoyao:latest
 # HERMES_YAOYAO_IMAGE=samienluo/yaoyao:latest
-# 固定版本:samienluo/yaoyao:v0.4.13;仅 AMD64:samienluo/yaoyao:v0.4.13-amd。
+# 固定版本:samienluo/yaoyao:v0.4.14;仅 AMD64:samienluo/yaoyao:v0.4.14-amd。
 # 留空时使用本地构建名称 yaoyao:local。
 # 留空时使用本地构建名称 yaoyao:local。
 # YAOYAO_DESKTOP_IMAGE=hermes-yaoyao-desktop:0.4.0
 # YAOYAO_DESKTOP_IMAGE=hermes-yaoyao-desktop:0.4.0
 # Cursor Universal 兼容桌面的本地构建名称;基础镜像在 deploy/computer/Dockerfile.cursor 中固定。
 # Cursor Universal 兼容桌面的本地构建名称;基础镜像在 deploy/computer/Dockerfile.cursor 中固定。

+ 25 - 0
docs/bot-conversation-order.md

@@ -0,0 +1,25 @@
+# Bot 模式会话列表排序
+
+Web、桌面、iOS、Android 共用以下规则:
+
+1. `pinned` 为 true 的会话优先。
+2. 同一置顶分组内,按 `lastMessageAt` 倒序;缺失时使用 `createdAt`,数值 0 不算缺失。
+3. 时间相同按会话 ID 升序。服务端 UUID 使用确定性的字符顺序,不使用用户界面语言相关排序。
+
+列表时间也取相同的会话时间,不使用配置修改时间 `updatedAt`,也不使用本机当前选择的群聊任务时间。任务选择与文字预览仍可保留本地状态。
+
+## 执行位置
+
+- 服务端常规列表与首次/重连快照复用 `compareWorkspaceConversations`。
+- Web 与桌面共享 `WorkspaceTranscriptStore`,每次替换会话数组均排序;页面读取排序后的数组。
+- iOS 在快照、刷新、会话增量事件三处执行 `WebWorkspaceConversation.precedes`。
+- Android 在快照、刷新、会话增量事件三处执行 `workspaceConversationOrder`。
+- 三端刷新期间若游标已因新事件推进,丢弃旧列表响应,避免回退刚同步的置顶或时间。
+- 同步范围仍由服务端与账号决定;本次不修改账号隔离、置顶持久化或事件协议。
+
+## 验证
+
+- Web:40 项相关测试通过;服务端测试同时检查列表接口、快照接口和两个独立状态仓库接收置顶/新消息事件后的顺序。客户端覆盖反向初始数组、时间并列、空会话、时间为 0、置顶/取消置顶、新会话与重复事件。
+- iOS:51 项 WorkspaceChatTests 通过,覆盖快照与刷新一致、增量重排、新会话、旧任务时间不影响列表、旧刷新响应不能覆盖新置顶事件。
+- Android:51 项 core:model 测试通过,包含同一组跨端排序数据;app Debug Kotlin 编译通过。
+- Web 生产构建通过。以上为代码、隔离用例和构建验证,未修改线上会话,未发布新版本或安装到真实设备。

+ 7 - 7
docs/docker-install.md

@@ -12,14 +12,14 @@
 
 
 | 标签 | 架构 |
 | 标签 | 架构 |
 | --- | --- |
 | --- | --- |
-| `v0.4.13-amd` | `linux/amd64` |
-| `v0.4.13` | `linux/amd64`、`linux/arm64`,拉取时自动匹配 |
-| `latest` | 最新稳定通用镜像,当前指向与 `v0.4.13` 相同的镜像 |
+| `v0.4.14-amd` | `linux/amd64` |
+| `v0.4.14` | `linux/amd64`、`linux/arm64`,拉取时自动匹配 |
+| `latest` | 最新稳定通用镜像,当前指向与 `v0.4.14` 相同的镜像 |
 
 
 ```sh
 ```sh
-docker pull samienluo/yaoyao:v0.4.13
+docker pull samienluo/yaoyao:v0.4.14
 # 需要固定 AMD64 时:
 # 需要固定 AMD64 时:
-docker pull samienluo/yaoyao:v0.4.13-amd
+docker pull samienluo/yaoyao:v0.4.14-amd
 ```
 ```
 
 
 每次新版本发布都会更新 `latest`,旧版本标签继续保留。需要固定部署版本时使用具体版本标签。
 每次新版本发布都会更新 `latest`,旧版本标签继续保留。需要固定部署版本时使用具体版本标签。
@@ -34,7 +34,7 @@ cp docker.env.example docker.env
 
 
 | 配置 | 用途 |
 | 配置 | 用途 |
 | --- | --- |
 | --- | --- |
-| `HERMES_YAOYAO_IMAGE` | 远程镜像可设为 `samienluo/yaoyao:v0.4.13` 或 `samienluo/yaoyao:latest`;未设置时使用本地构建名称 |
+| `HERMES_YAOYAO_IMAGE` | 远程镜像可设为 `samienluo/yaoyao:v0.4.14` 或 `samienluo/yaoyao:latest`;未设置时使用本地构建名称 |
 | `HERMES_YAOYAO_UPSTREAM` | Hermes 上游地址,默认 `http://host.docker.internal:9119` |
 | `HERMES_YAOYAO_UPSTREAM` | Hermes 上游地址,默认 `http://host.docker.internal:9119` |
 | `HERMES_YAOYAO_BIND_ADDRESS` | Web 的宿主机发布地址,默认 `127.0.0.1`;局域网访问可设为 `0.0.0.0` |
 | `HERMES_YAOYAO_BIND_ADDRESS` | Web 的宿主机发布地址,默认 `127.0.0.1`;局域网访问可设为 `0.0.0.0` |
 | `HERMES_YAOYAO_PUBLISHED_PORT` | 宿主机 Web 端口,默认 `15300` |
 | `HERMES_YAOYAO_PUBLISHED_PORT` | 宿主机 Web 端口,默认 `15300` |
@@ -152,7 +152,7 @@ curl --fail http://127.0.0.1:15300/healthz
 使用 Docker Hub 发布镜像时,在 `docker.env` 设置:
 使用 Docker Hub 发布镜像时,在 `docker.env` 设置:
 
 
 ```dotenv
 ```dotenv
-HERMES_YAOYAO_IMAGE=samienluo/yaoyao:v0.4.13
+HERMES_YAOYAO_IMAGE=samienluo/yaoyao:v0.4.14
 YAOYAO_CURSOR_DESKTOP_IMAGE=samienluo/yaoyao-desktop:v0.4.12-cursor-amd
 YAOYAO_CURSOR_DESKTOP_IMAGE=samienluo/yaoyao-desktop:v0.4.12-cursor-amd
 ```
 ```
 
 

+ 38 - 0
docs/releases/v0.4.14.md

@@ -0,0 +1,38 @@
+# 夭夭 AI v0.4.14
+
+本次发布 Web、macOS Apple Silicon 桌面版、iOS 1.3(200)、Android 1.3(167)及 Docker Web 双架构镜像。
+
+## 更新内容
+
+- Bot 会话列表跨端统一为“置顶优先 → 最新消息时间倒序 → ID 兜底”,首次加载、重连快照、实时更新和刷新使用同一规则。
+- iOS 列表时间统一读取会话最新消息时间。Web、iOS、Android 在刷新期间收到新事件后,会丢弃旧列表响应,避免覆盖刚同步的置顶状态。
+- iOS Bot 恢复过程摘要时间线抽屉,思考入口放到正文前,群聊机器人名称置于气泡外,并统一回复文字与段落排版。
+- iOS 增加 OpenMausBot 同款三点输入动画,等待首字时显示,正文或思考出现、任务结束或停止后收起。
+- iOS 补回正文 Markdown 图片、文件引用和原生附件预览;图片按原比例完整缩放,文件名独立显示,修复宽图撑宽会话、后续用户消息出框的问题。
+- iOS 的 Markdown 文稿代码块默认格式化预览,可切换源码并复制原文;保留其他语言代码块的源码显示。
+
+## 下载
+
+- `Yaoyao-0.4.14-arm64.dmg`:macOS Apple Silicon,Apple Development 开发签名,未公证。
+- `Yaoyao-1.3-200-ios.ipa`:iOS 17 及以上,arm64,Apple Development 开发签名,适用于描述文件已登记设备。源码提交 `110a3e0`。
+- `Yaoyao-1.3-167-android.apk`:Android 12 及以上,正式签名。源码提交 `bcbceaa`。
+- `Yaoyao-0.4.14-source.tar.gz`:Web/桌面源码及部署配置。
+- `SHA256SUMS.txt`:全部发布附件的 SHA-256 校验值。
+
+## Docker Hub
+
+| 镜像 | 架构 |
+| --- | --- |
+| `samienluo/yaoyao:v0.4.14-amd` | `linux/amd64` |
+| `samienluo/yaoyao:v0.4.14` | `linux/amd64`、`linux/arm64` |
+| `samienluo/yaoyao:latest` | 版本镜像验证后指向同一通用镜像 |
+
+```sh
+docker pull samienluo/yaoyao:v0.4.14
+docker compose --env-file docker.env pull web
+docker compose --env-file docker.env up -d --no-build web
+```
+
+Compose 中设置 `HERMES_YAOYAO_IMAGE=samienluo/yaoyao:v0.4.14`。独立电脑镜像沿用现有版本,Cursor 继续使用 `samienluo/yaoyao-desktop:v0.4.12-cursor-amd`。保留已有数据卷、旧标签和旧发布附件。
+
+升级前备份数据与密钥。最终附件摘要、Docker manifest 摘要和运行验证记录发布在 [GitHub 发布页](https://github.com/Lsamien/yaoyao/releases/tag/v0.4.14)。模拟器验证不等同于真机帧率测试。

+ 2 - 2
package-lock.json

@@ -1,12 +1,12 @@
 {
 {
   "name": "yaoyao",
   "name": "yaoyao",
-  "version": "0.4.13",
+  "version": "0.4.14",
   "lockfileVersion": 3,
   "lockfileVersion": 3,
   "requires": true,
   "requires": true,
   "packages": {
   "packages": {
     "": {
     "": {
       "name": "yaoyao",
       "name": "yaoyao",
-      "version": "0.4.13",
+      "version": "0.4.14",
       "license": "Apache-2.0",
       "license": "Apache-2.0",
       "dependencies": {
       "dependencies": {
         "@koa/bodyparser": "^5.0.0",
         "@koa/bodyparser": "^5.0.0",

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
 {
   "name": "yaoyao",
   "name": "yaoyao",
-  "version": "0.4.13",
+  "version": "0.4.14",
   "private": true,
   "private": true,
   "license": "Apache-2.0",
   "license": "Apache-2.0",
   "description": "夭夭 AI:聊天、多 Agent 团队、文件库与电脑工作空间",
   "description": "夭夭 AI:聊天、多 Agent 团队、文件库与电脑工作空间",

+ 3 - 3
release.json

@@ -1,6 +1,6 @@
 {
 {
   "schemaVersion": 1,
   "schemaVersion": 1,
-  "releaseVersion": "0.4.13",
-  "webVersion": "0.4.13",
-  "gitTag": "v0.4.13"
+  "releaseVersion": "0.4.14",
+  "webVersion": "0.4.14",
+  "gitTag": "v0.4.14"
 }
 }

+ 6 - 1
src/client/components/workspace/transcriptStore.ts

@@ -1,4 +1,5 @@
 import type { AgentAssignment, AgentGoal } from '@shared/agentTasks'
 import type { AgentAssignment, AgentGoal } from '@shared/agentTasks'
+import { compareWorkspaceConversations } from '@shared/workspace'
 import type { WorkspaceAgent, WorkspaceConversation, WorkspaceEvent, WorkspaceInteraction, WorkspaceMessage, WorkspaceRun, WorkspaceTask } from '@shared/workspace'
 import type { WorkspaceAgent, WorkspaceConversation, WorkspaceEvent, WorkspaceInteraction, WorkspaceMessage, WorkspaceRun, WorkspaceTask } from '@shared/workspace'
 
 
 export interface WorkspaceDetail {
 export interface WorkspaceDetail {
@@ -60,7 +61,11 @@ export function foldDetail(detail: WorkspaceDetail, event: WorkspaceEvent): Work
 
 
 export class WorkspaceTranscriptStore {
 export class WorkspaceTranscriptStore {
   agents: WorkspaceAgent[] = []
   agents: WorkspaceAgent[] = []
-  conversations: WorkspaceConversation[] = []
+  private conversationRows: WorkspaceConversation[] = []
+  get conversations(): WorkspaceConversation[] { return this.conversationRows }
+  set conversations(rows: WorkspaceConversation[]) {
+    this.conversationRows = [...rows].sort(compareWorkspaceConversations)
+  }
   readonly details = new Map<string, WorkspaceDetail>()
   readonly details = new Map<string, WorkspaceDetail>()
   cursor = 0
   cursor = 0
   readonly selectedTasks = new Map<string, string>()
   readonly selectedTasks = new Map<string, string>()

+ 2 - 2
src/client/components/workspace/viewModels.ts

@@ -1,5 +1,5 @@
 import { visibleMessageText, messageReasoningText } from '@shared/messageFiles'
 import { visibleMessageText, messageReasoningText } from '@shared/messageFiles'
-import { workspaceHasUnread } from '@shared/workspace'
+import { workspaceConversationTimestamp, workspaceHasUnread } from '@shared/workspace'
 import { toolResultFailed } from '@shared/chatTools'
 import { toolResultFailed } from '@shared/chatTools'
 import { serverFilePath, serverFileUrl } from '@shared/serverFiles'
 import { serverFilePath, serverFileUrl } from '@shared/serverFiles'
 import type {
 import type {
@@ -449,7 +449,7 @@ export function workspaceConversationItem(c: import('@shared/workspace').Workspa
     id: c.id, title: c.name, subtitle: c.preview || '开始聊天', pinned: c.pinned,
     id: c.id, title: c.name, subtitle: c.preview || '开始聊天', pinned: c.pinned,
     section: c.pinned ? '已置顶' : '聊天', avatar: c.kind === 'group' ? '' : c.avatar,
     section: c.pinned ? '已置顶' : '聊天', avatar: c.kind === 'group' ? '' : c.avatar,
     avatarMembers: c.kind === 'group' ? workspaceAvatarMembers(c.memberIds, agents, c) : [],
     avatarMembers: c.kind === 'group' ? workspaceAvatarMembers(c.memberIds, agents, c) : [],
-    meta: formatConversationTime(c.lastMessageAt ?? c.createdAt),
+    meta: formatConversationTime(workspaceConversationTimestamp(c)),
     avatarKind: c.kind === 'direct' ? 'agent' : 'team',
     avatarKind: c.kind === 'direct' ? 'agent' : 'team',
     avatarState: activity ?? workspaceAvatarState(c, c.memberIds[0] || ''), avatarActivityKey: c.lastSeq,
     avatarState: activity ?? workspaceAvatarState(c, c.memberIds[0] || ''), avatarActivityKey: c.lastSeq,
     unreadDot: workspaceHasUnread(c), status: activity || c.activeRunId ? 'working' : undefined,
     unreadDot: workspaceHasUnread(c), status: activity || c.activeRunId ? 'working' : undefined,

+ 3 - 3
src/client/views/ConversationsView.vue

@@ -251,13 +251,13 @@ async function refresh() {
   if (disposed || auth.user?.id !== owner || transcriptStore.cursor !== startedAtCursor) return
   if (disposed || auth.user?.id !== owner || transcriptStore.cursor !== startedAtCursor) return
   agents.value = a.agents
   agents.value = a.agents
   const localConversations = new Map(conversations.value.map(row => [row.id, row]))
   const localConversations = new Map(conversations.value.map(row => [row.id, row]))
-  conversations.value = c.conversations.map(conversation => {
+  transcriptStore.conversations = c.conversations.map(conversation => {
     const local = localConversations.get(conversation.id)
     const local = localConversations.get(conversation.id)
     return local && local.unreadVersion === conversation.unreadVersion && [...pendingReads].some(key => key.startsWith(`${conversation.id}:`))
     return local && local.unreadVersion === conversation.unreadVersion && [...pendingReads].some(key => key.startsWith(`${conversation.id}:`))
       ? { ...conversation, unread: local.unread, unreadCount: local.unreadCount } : conversation
       ? { ...conversation, unread: local.unread, unreadCount: local.unreadCount } : conversation
   })
   })
   transcriptStore.agents = agents.value
   transcriptStore.agents = agents.value
-  transcriptStore.conversations = conversations.value
+  conversations.value = transcriptStore.conversations
   if (!cursor) { cursor = c.cursor; transcriptStore.cursor = c.cursor }
   if (!cursor) { cursor = c.cursor; transcriptStore.cursor = c.cursor }
 }
 }
 async function load(id = selected.value, append = false) {
 async function load(id = selected.value, append = false) {
@@ -458,7 +458,7 @@ async function hydrateWorkspace() {
   const snapshot = await apiRequest<WorkspaceSnapshot & { serverIdentity?: ServerIdentity }>('/api/app/workspace/snapshot')
   const snapshot = await apiRequest<WorkspaceSnapshot & { serverIdentity?: ServerIdentity }>('/api/app/workspace/snapshot')
   if (disposed || auth.user?.id !== owner) return
   if (disposed || auth.user?.id !== owner) return
   transcriptStore.hydrate(snapshot)
   transcriptStore.hydrate(snapshot)
-  agents.value = snapshot.agents; conversations.value = snapshot.conversations; cursor = snapshot.cursor
+  agents.value = snapshot.agents; conversations.value = transcriptStore.conversations; cursor = snapshot.cursor
   publishServerIdentity(snapshot.serverIdentity)
   publishServerIdentity(snapshot.serverIdentity)
 }
 }
 function connectEvents() {
 function connectEvents() {

+ 4 - 7
src/server/workspaceRoutes.ts

@@ -18,6 +18,7 @@ import { receiveGroupUploads, type UploadStore } from './uploads.js'
 import { HttpError } from './errors.js'
 import { HttpError } from './errors.js'
 import type { PushCoordinator } from './pushCoordinator.js'
 import type { PushCoordinator } from './pushCoordinator.js'
 import type { LocalAuthStore } from './localAuth.js'
 import type { LocalAuthStore } from './localAuth.js'
+import { compareWorkspaceConversations } from '../shared/workspace.js'
 import type {
 import type {
   WorkspaceMessage,
   WorkspaceMessage,
   WorkspaceAgent,
   WorkspaceAgent,
@@ -155,12 +156,7 @@ export function workspaceRouter(
       conversations: store
       conversations: store
         .list<WorkspaceConversation>(user, 'conversation')
         .list<WorkspaceConversation>(user, 'conversation')
         .map(c => store.conversationSummary(user, c))
         .map(c => store.conversationSummary(user, c))
-        .sort(
-          (a, b) =>
-            Number(b.pinned) - Number(a.pinned) ||
-            (b.lastMessageAt ?? b.createdAt) - (a.lastMessageAt ?? a.createdAt) ||
-            a.id.localeCompare(b.id),
-        ),
+        .sort(compareWorkspaceConversations),
       cursor: store.cursor(user),
       cursor: store.cursor(user),
     }
     }
   })
   })
@@ -313,7 +309,8 @@ export function workspaceRouter(
   })
   })
   router.get('/api/app/workspace/snapshot', ctx => {
   router.get('/api/app/workspace/snapshot', ctx => {
     const user = owner(ctx)
     const user = owner(ctx)
-    const conversations = store.list<WorkspaceConversation>(user, 'conversation').map(c => store.conversationSummary(user, c))
+    const conversations = store.list<WorkspaceConversation>(user, 'conversation')
+      .map(c => store.conversationSummary(user, c)).sort(compareWorkspaceConversations)
     const details = conversations.filter(c => !c.archived).map(c => workspaceDetail(store, runtime, user, c.id))
     const details = conversations.filter(c => !c.archived).map(c => workspaceDetail(store, runtime, user, c.id))
     ctx.set('Cache-Control', 'no-store')
     ctx.set('Cache-Control', 'no-store')
     ctx.body = { agents: store.list<WorkspaceAgent>(user, 'agent').map(a => store.agentSummary(a)),
     ctx.body = { agents: store.list<WorkspaceAgent>(user, 'agent').map(a => store.agentSummary(a)),

+ 10 - 0
src/shared/workspace.ts

@@ -64,6 +64,16 @@ export interface WorkspaceConversation {
   createdAt: number
   createdAt: number
   updatedAt: number
   updatedAt: number
 }
 }
+/** Shared by the HTTP lists, snapshots and Web/desktop incremental state. */
+export function workspaceConversationTimestamp(value: Pick<WorkspaceConversation, 'lastMessageAt' | 'createdAt'>): number {
+  return value.lastMessageAt ?? value.createdAt
+}
+export function compareWorkspaceConversations(a: WorkspaceConversation, b: WorkspaceConversation): number {
+  return Number(b.pinned) - Number(a.pinned)
+    || workspaceConversationTimestamp(b) - workspaceConversationTimestamp(a)
+    || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)
+}
+
 export interface WorkspaceTask {
 export interface WorkspaceTask {
   id: string
   id: string
   conversationId: string
   conversationId: string

+ 34 - 0
tests/client/workspaceTranscript.test.ts

@@ -8,6 +8,40 @@ const detail = (): WorkspaceDetail => ({ conversation, messages: [message('old',
 const event = (seq: number, value: WorkspaceMessage): WorkspaceEvent => ({ seq, type: 'message.changed', conversationId: value.conversationId, data: value })
 const event = (seq: number, value: WorkspaceMessage): WorkspaceEvent => ({ seq, type: 'message.changed', conversationId: value.conversationId, data: value })
 
 
 describe('Bot transcript cache', () => {
 describe('Bot transcript cache', () => {
+  it('keeps independent clients ordered after snapshots, pin changes and new activity', () => {
+    const rows: WorkspaceConversation[] = [
+      { ...conversation, id: 'tie-b', lastMessageAt: 200 },
+      { ...conversation, id: 'zero', lastMessageAt: 0, createdAt: 5000 },
+      { ...conversation, id: 'old', lastMessageAt: 100, updatedAt: 99999 },
+      { ...conversation, id: 'pin', pinned: true, lastMessageAt: 50 },
+      { ...conversation, id: 'new', lastMessageAt: 400 },
+      { ...conversation, id: 'tie-a', lastMessageAt: 200 },
+      { ...conversation, id: 'fallback', lastMessageAt: undefined, createdAt: 300 },
+    ]
+    const before = rows.map(c => c.id)
+    const clients = [new WorkspaceTranscriptStore(), new WorkspaceTranscriptStore()]
+    clients[0]!.hydrate({ agents: [], conversations: rows, details: [], cursor: 0 })
+    clients[1]!.hydrate({ agents: [], conversations: [...rows].reverse(), details: [], cursor: 0 })
+    const ordered = (expected: string[]) => clients.forEach(client => expect(client.conversations.map(c => c.id)).toEqual(expected))
+    ordered(['pin', 'new', 'fallback', 'tie-a', 'tie-b', 'old', 'zero'])
+    expect(rows.map(c => c.id)).toEqual(before)
+    const change = (seq: number, id: string, patch: Partial<WorkspaceConversation>) => clients.forEach(client => {
+      const current = client.conversations.find(c => c.id === id) ?? { ...conversation, id }
+      client.apply({ seq, type: 'conversation.changed', conversationId: id, data: { ...current, ...patch } })
+    })
+    change(1, 'old', { lastMessageAt: 500 })
+    ordered(['pin', 'old', 'new', 'fallback', 'tie-a', 'tie-b', 'zero'])
+    change(2, 'tie-b', { pinned: true })
+    ordered(['tie-b', 'pin', 'old', 'new', 'fallback', 'tie-a', 'zero'])
+    change(3, 'pin', { pinned: false })
+    change(4, 'new-2', { lastMessageAt: 400 })
+    ordered(['tie-b', 'old', 'new', 'new-2', 'fallback', 'tie-a', 'pin', 'zero'])
+    change(3, 'pin', { pinned: true })
+    ordered(['tie-b', 'old', 'new', 'new-2', 'fallback', 'tie-a', 'pin', 'zero'])
+    clients[0]!.conversations = [...clients[1]!.conversations].reverse()
+    ordered(['tie-b', 'old', 'new', 'new-2', 'fallback', 'tie-a', 'pin', 'zero'])
+  })
+
   it('returns a warm transcript without losing its older pages and preserves settled identities on a live update', () => {
   it('returns a warm transcript without losing its older pages and preserves settled identities on a live update', () => {
     const store = new WorkspaceTranscriptStore(), initial = detail()
     const store = new WorkspaceTranscriptStore(), initial = detail()
     store.hydrate({ agents: [], conversations: [conversation], details: [initial], cursor: 10 })
     store.hydrate({ agents: [], conversations: [conversation], details: [initial], cursor: 10 })

+ 30 - 0
tests/server/workspaceRoutes.test.ts

@@ -10,6 +10,7 @@ import { createApplication, type ApplicationRuntime } from '../../src/server/app
 import { loadServerConfig } from '../../src/server/config'
 import { loadServerConfig } from '../../src/server/config'
 import { LocalAuthStore, type LocalUser } from '../../src/server/localAuth'
 import { LocalAuthStore, type LocalUser } from '../../src/server/localAuth'
 import { WorkspaceAssets } from '../../src/server/workspaceAssets'
 import { WorkspaceAssets } from '../../src/server/workspaceAssets'
+import { WorkspaceTranscriptStore } from '../../src/client/components/workspace/transcriptStore'
 
 
 let home: string, runtime: ApplicationRuntime, cookie: string, csrf: string, upstream: string[], bridgeReady: boolean
 let home: string, runtime: ApplicationRuntime, cookie: string, csrf: string, upstream: string[], bridgeReady: boolean
 const first: LocalUser = {
 const first: LocalUser = {
@@ -95,6 +96,35 @@ afterEach(() => {
   rmSync(home, { recursive: true, force: true })
   rmSync(home, { recursive: true, force: true })
 })
 })
 describe('application workspace HTTP contract', () => {
 describe('application workspace HTTP contract', () => {
+  it('uses the same ordering for snapshots, list refreshes and pin/message events', async () => {
+    const store = runtime.workspace
+    store.createAgent('first', { name: '排序验证', profile: 'default' })
+    const base = store.list<import('../../src/shared/workspace').WorkspaceConversation>('first', 'conversation')[0]!
+    store.remove('first', 'conversation', base.id)
+    for (const item of [
+      { id: 'a-old', lastMessageAt: 100, pinned: false },
+      { id: 'b-new', lastMessageAt: 200, pinned: false },
+      { id: 'z-pin', lastMessageAt: 50, pinned: true },
+    ]) store.put('first', 'conversation', item.id, { ...base, ...item })
+    const snapshot = (await req('get', '/api/app/workspace/snapshot').expect(200)).body
+    const list = (await req('get', '/api/app/conversations').expect(200)).body.conversations
+    expect(snapshot.conversations.map((c: { id: string }) => c.id)).toEqual(['z-pin', 'b-new', 'a-old'])
+    expect(list.map((c: { id: string }) => c.id)).toEqual(snapshot.conversations.map((c: { id: string }) => c.id))
+    const clients = [new WorkspaceTranscriptStore(), new WorkspaceTranscriptStore()]
+    clients.forEach(client => client.hydrate(snapshot))
+    const stop = store.observe((owner, event) => { if (owner === 'first') clients.forEach(client => client.apply(event)) })
+    try {
+      store.saveMessage('first', { id: randomUUID(), conversationId: 'a-old', seq: 0, role: 'assistant',
+        content: '新的回复', reasoning: '', status: 'complete', attachments: [], tools: [], createdAt: 300 })
+      clients.forEach(client => expect(client.conversations.map(c => c.id)).toEqual(['z-pin', 'a-old', 'b-new']))
+      await req('patch', '/api/app/conversations/a-old').send({ pinned: true }).expect(200)
+      const expected = ['a-old', 'z-pin', 'b-new']
+      clients.forEach(client => expect(client.conversations.map(c => c.id)).toEqual(expected))
+      expect((await req('get', '/api/app/workspace/snapshot').expect(200)).body.conversations.map((c: { id: string }) => c.id)).toEqual(expected)
+      expect((await req('get', '/api/app/conversations').expect(200)).body.conversations.map((c: { id: string }) => c.id)).toEqual(expected)
+    } finally { stop() }
+  })
+
   it.each(['direct', 'group'] as const)('uses versioned unread acknowledgments for %s without recounting history', async kind => {
   it.each(['direct', 'group'] as const)('uses versioned unread acknowledgments for %s without recounting history', async kind => {
     const store = runtime.workspace
     const store = runtime.workspace
     const first = store.createAgent('first', { name: '未读甲', profile: 'default' })
     const first = store.createAgent('first', { name: '未读甲', profile: 'default' })