Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions console-ui/src/i18n/messages.en.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,8 @@ export const englishMessages = Object.freeze({
"聊天记录": "Chat history",
"按聊天账号和会话查看机器人和大家聊过什么(只读)。": "View conversations by account and chat (read-only).",
"按聊天账号和会话查看机器人和大家聊过什么,也可以接着聊。": "View conversations by account and chat, and pick one up again.",
"按聊天账号和会话查看机器人和大家聊过什么,可以接着聊,也可以从其他消息继续。": "View conversations by account and chat, pick one up again, or continue from another message.",
"按聊天账号和会话查看机器人和大家聊过什么,也可以从其他消息继续。": "View conversations by account and chat, and continue from another message.",
"活跃叶节点:": "Active leaf:",
"默认(最后一条)": "Default (latest message)",
"当前活跃": "Currently active",
Expand Down
2 changes: 2 additions & 0 deletions console-ui/src/pages/agent-sessions-description.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** The 聊天记录 page description for what this identity can do (Chinese source text; translate it). */
export function sessionsPageDescription(abilities: { canChat: boolean; canBranch: boolean }): string
11 changes: 11 additions & 0 deletions console-ui/src/pages/agent-sessions-description.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* 聊天记录页的页面说明(#64 `sessions-description-permission-mismatch`)。两种能力分开说:
* `canChat` 能回到会话里接着聊(endpoint.operate),`canBranch` 能从其他消息继续(POST
* /agent/sessions/<key>/leaf,按协议表查)。两样都没有时才说「只读」。返回中文原文,由页面翻译。
*/
export function sessionsPageDescription({ canChat, canBranch }) {
if (canChat && canBranch) return '按聊天账号和会话查看机器人和大家聊过什么,可以接着聊,也可以从其他消息继续。'
if (canChat) return '按聊天账号和会话查看机器人和大家聊过什么,也可以接着聊。'
if (canBranch) return '按聊天账号和会话查看机器人和大家聊过什么,也可以从其他消息继续。'
return '按聊天账号和会话查看机器人和大家聊过什么(只读)。'
}
3 changes: 2 additions & 1 deletion console-ui/src/pages/agent-sessions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { AgentSessionPicker } from '../components/AgentSessionPicker'
import { CONSOLE_REST } from '../contracts/zhin-console'
import { hasConsolePermission } from '../utils/console-access.mjs'
import { httpRouteAccess } from '../utils/http-permission.mjs'
import { sessionsPageDescription } from './agent-sessions-description.mjs'
import { permissionLabel } from './access/access-model.mjs'
import { readRecentSessions, sessionsNeedingGroupNames, summarizeRecentSessions, withGroupNames, type RecentSession, type RecentSessionSummary } from './agent-session-recent.mjs'
import { useAmbientGroupCatalog } from './AmbientGroupPicker'
Expand Down Expand Up @@ -293,7 +294,7 @@ export default function AgentSessionsPage() {
<div className="console-page console-conversations-page">
<PageHeader
title={i18n.t('聊天记录')}
description={readOnly ? i18n.t('按聊天账号和会话查看机器人和大家聊过什么(只读)。') : i18n.t('按聊天账号和会话查看机器人和大家聊过什么,也可以接着聊。')}
description={i18n.t(sessionsPageDescription({ canChat: !readOnly, canBranch: canSwitchLeaf }))}
/>

{!personal && recentResult ? (
Expand Down
12 changes: 11 additions & 1 deletion tests/conversation-page.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ts from 'typescript'
import { localeModule, isLocaleImport } from './locale-fixture.mjs'
import * as personalModels from '../console-ui/src/pages/personal-session-model.mjs'
import * as httpPermission from '../console-ui/src/utils/http-permission.mjs'
import * as sessionsDescription from '../console-ui/src/pages/agent-sessions-description.mjs'
import * as accessModel from '../console-ui/src/pages/access/access-model.mjs'
import { readRecentSessions, sessionsNeedingGroupNames, summarizeRecentSessions, withGroupNames } from '../console-ui/src/pages/agent-session-recent.mjs'
import * as recordsModel from '../console-ui/src/pages/scope/records-model.mjs'
Expand Down Expand Up @@ -52,7 +53,7 @@ function fixture(initialKey = 'icqq:bot:group:room', granted = null) {
'./SessionMessageDetails':{SessionMessageDetails:'message-details'}, './ConversationHistory':{ConversationHistory:'conversation-history'},
'./ConversationTrace':{ConversationTrace:'conversation-trace'}, './useConversationTraces':{useConversationTraces:(...args)=>{ traceReads.push(args); return {turns:[],loading:false,error:null,refresh(){}} }},
'@zhin.js/client':{cn:(...parts)=>parts.filter(Boolean).join(' ')}, '../contracts/zhin-console':{CONSOLE_REST:{AGENT_SESSIONS:'/api/agent/sessions'}},
'../utils/console-access.mjs':{hasConsolePermission:name=>!granted||granted.has(name)}, '../utils/http-permission.mjs':httpPermission, './access/access-model.mjs':accessModel, './agent-session-recent.mjs':{readRecentSessions,summarizeRecentSessions,sessionsNeedingGroupNames,withGroupNames}, './AmbientGroupPicker':{useAmbientGroupCatalog:()=>({loading:false,error:null,catalog:null,retry(){}})}, './ambient-group-picker-model.mjs':{groupNamesFromCatalog:()=>new Map()}, })
'../utils/console-access.mjs':{hasConsolePermission:name=>!granted||granted.has(name)}, '../utils/http-permission.mjs':httpPermission, './agent-sessions-description.mjs':sessionsDescription, './access/access-model.mjs':accessModel, './agent-session-recent.mjs':{readRecentSessions,summarizeRecentSessions,sessionsNeedingGroupNames,withGroupNames}, './AmbientGroupPicker':{useAmbientGroupCatalog:()=>({loading:false,error:null,catalog:null,retry(){}})}, './ambient-group-picker-model.mjs':{groupNamesFromCatalog:()=>new Map()}, })
const f = {calls,traceReads,render(){cursor=0;tree=module.default(); const run=effects;effects=[];run.forEach(fn=>fn());return tree},get tree(){return tree},setScope(value){scope=value},navigate(key){params=new URLSearchParams({sessionKey:key})},close(){slots.forEach(slot=>slot?.cleanup?.())}}
f.render();return f
}
Expand Down Expand Up @@ -300,3 +301,12 @@ test('「从这里继续」 follows the protocol (agent.configure), not endpoint
assert.doesNotMatch(text(configurer.tree), /需要「修改 AI 与 Agent 设置」权限/)
configurer.close()
})

test('the page description follows both abilities: chatting (endpoint.operate) and continuing from another message (the leaf route)', () => {
// #64 sessions-description-permission-mismatch
const description = granted => { const f = fixture('icqq:bot:group:room', granted); const value = find(f, 'page-header').props.description; f.close(); return value }
assert.equal(description(new Set()), '按聊天账号和会话查看机器人和大家聊过什么(只读)。')
assert.equal(description(new Set(['endpoint.operate'])), '按聊天账号和会话查看机器人和大家聊过什么,也可以接着聊。')
assert.equal(description(new Set(['agent.configure'])), '按聊天账号和会话查看机器人和大家聊过什么,也可以从其他消息继续。')
assert.equal(description(new Set(['endpoint.operate', 'agent.configure'])), '按聊天账号和会话查看机器人和大家聊过什么,可以接着聊,也可以从其他消息继续。')
})
32 changes: 32 additions & 0 deletions tests/sessions-description-permission-mismatch.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
import { httpRouteAccess } from '../console-ui/src/utils/http-permission.mjs'
import { sessionsPageDescription } from '../console-ui/src/pages/agent-sessions-description.mjs'
import { translate } from '../console-ui/src/i18n/locale.mjs'

// #64 `sessions-description-permission-mismatch`: the 聊天记录 description followed endpoint.operate only,
// while 「从这里继续」 follows POST /agent/sessions/<key>/leaf (agent.configure in the protocol, #215).
const canBranch = permissions => httpRouteAccess('POST', '/agent/sessions/_/leaf', name => permissions.includes(name)).allowed
const describe = permissions => sessionsPageDescription({ canChat: permissions.includes('endpoint.operate'), canBranch: canBranch(permissions) })

test('the description names each ability the identity has, and says read-only only when it has neither', () => {
assert.equal(canBranch(['agent.configure']), true, 'the protocol table maps the leaf route to agent.configure')
const none = describe([])
const chat = describe(['endpoint.operate'])
const branch = describe(['agent.configure'])
const both = describe(['endpoint.operate', 'agent.configure'])
assert.match(none, /只读/u)
for (const text of [chat, branch, both]) assert.doesNotMatch(text, /只读/u)
assert.match(chat, /接着聊/u); assert.doesNotMatch(chat, /其他消息继续/u, 'an operator has no 「从这里继续」')
assert.match(branch, /其他消息继续/u); assert.doesNotMatch(branch, /接着聊/u, 'agent.configure alone cannot chat')
assert.match(both, /接着聊/u); assert.match(both, /其他消息继续/u)
assert.equal(new Set([none, chat, branch, both]).size, 4)
for (const text of [none, chat, branch, both]) assert.notEqual(translate('en', text), text, `English for ${text}`)
})

test('the page builds its description from both abilities and keeps readOnly for the trace read', () => {
const page = readFileSync(new URL('../console-ui/src/pages/agent-sessions.tsx', import.meta.url), 'utf8')
assert.match(page, /sessionsPageDescription\(\{ canChat: !readOnly, canBranch: canSwitchLeaf \}\)/u)
assert.match(page, /useConversationTraces\(readOnly \? '' : selectedKey/u)
})