feat: 智能体详情新增「最近对话」列表,完善推荐问题与任务深链配置
- 新增 AgentRecentChats 组件,在智能体详情面板底部按 agent_id 展示最近对话 - 调整问答/智能体侧边栏与最近对话列表展示逻辑 - 补充 dashboard-input、task-deeplink 相关配置与线程工具方法 - 后端推荐问题接口标签处理及 position_sync 微调,新增相关测试 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
16ba5deb0e
commit
32476c7ad4
18 files changed
+457
-60
No files matched your search
@@ -393,7 +393,10 @@ query-time type, `recommended_question`.
|
||||
Sync only ever adds/removes `origin='position'` rows, so a user's own
|
||||
favorites/subscriptions are never clobbered. Default sets (no binding for a
|
||||
type): agents = built-ins (`user_id IS NULL`); skills = empty (square stays
|
||||
full, nothing added to 我的); scheduled tasks = empty; questions = unrestricted.
|
||||
full, nothing added to 我的); scheduled tasks = empty; questions = **untagged
|
||||
only** (默认岗位 / 无标签绑定 只看到未打标的题目;打标的题目只在绑定了对应标签的
|
||||
岗位展示 — the router interprets `resolve_visible → None` as "show only untagged",
|
||||
not "show everything").
|
||||
`origin`/`position_id` columns were added to `agent_favorites` and
|
||||
`scheduled_task_subscriptions` — see migration `20260616_01` +
|
||||
`scripts/sql/column_additions_mysql.sql`. The running app also auto-adds these
|
||||
@@ -415,8 +418,12 @@ unassigned users inherit, else `null`); powers the top-bar 岗位 label
|
||||
changes: `GET /api/recommended-questions` is now
|
||||
filtered by the caller's position (`?all=1` bypasses for admin management) and
|
||||
admin can tag questions via `/api/tags/assignments/recommended_question/{id}`.
|
||||
Each listed question now carries its assigned `tags` (bulk-attached via
|
||||
`tag_store.list_assignments`), and the list accepts a repeatable `tag_ids`
|
||||
**Default-position rule**: tags are bulk-attached to **all** questions first,
|
||||
then the visibility filter applies — a position binding recommended_question 标签
|
||||
sees only those tagged questions; a 默认岗位 / 无绑定 (`resolve_visible → None`)
|
||||
sees only the **untagged** questions (打标的题目不再泄漏到默认岗位). `?all=1`
|
||||
(admin management) skips this filter and returns every question with its tags.
|
||||
The list also accepts a repeatable `tag_ids`
|
||||
OR-filter — so the 推荐问题配置 page can display per-question 标签 and search by
|
||||
them (frontend `RecommendedQuestionsPage` + `TagSearchBar`). Tests:
|
||||
`tests/test_recommended_questions_tags.py`.
|
||||
|
||||
@@ -67,24 +67,11 @@ async def list_recommended_questions(
|
||||
) -> RecommendedQuestionsListResponse:
|
||||
store = _get_store(request)
|
||||
rows = await store.list_all()
|
||||
if not all:
|
||||
# Filter by the caller's 岗位 (position) visibility. ``None`` =
|
||||
# unrestricted (no skill/question tag binding → show all default
|
||||
# questions); a set = show only the questions carrying the bound tags.
|
||||
sync = getattr(request.app.state, "position_sync", None)
|
||||
if sync is not None:
|
||||
try:
|
||||
visible = await sync.resolve_visible(_current_user_id(request), "recommended_question")
|
||||
except Exception:
|
||||
logger.debug("recommended-question visibility resolve failed", exc_info=True)
|
||||
visible = None
|
||||
if visible is not None:
|
||||
rows = [r for r in rows if r["id"] in visible]
|
||||
responses = [RecommendedQuestionResponse(**r) for r in rows]
|
||||
|
||||
# Bulk-attach the tags assigned to each question so the management list can
|
||||
# display them and filter by 标签. Best-effort: a missing/failing tag store
|
||||
# never breaks the question list.
|
||||
# display them and the 岗位 filter below can tell tagged from untagged.
|
||||
# Best-effort: a missing/failing tag store never breaks the question list.
|
||||
tag_store = getattr(request.app.state, "tag_store", None)
|
||||
if tag_store is not None and responses:
|
||||
try:
|
||||
@@ -95,6 +82,24 @@ async def list_recommended_questions(
|
||||
for resp in responses:
|
||||
resp.tags = assignments.get(resp.id, [])
|
||||
|
||||
if not all:
|
||||
# Filter by the caller's 岗位 (position) visibility:
|
||||
# * ``set`` — the position binds recommended_question 标签 → show only
|
||||
# the questions carrying those bound tags.
|
||||
# * ``None`` — 默认岗位 / 无标签绑定 → show only **untagged** questions.
|
||||
# 打标的题目只在绑定了对应标签的岗位展示,不再泄漏到默认岗位。
|
||||
sync = getattr(request.app.state, "position_sync", None)
|
||||
if sync is not None:
|
||||
try:
|
||||
visible = await sync.resolve_visible(_current_user_id(request), "recommended_question")
|
||||
except Exception:
|
||||
logger.debug("recommended-question visibility resolve failed", exc_info=True)
|
||||
visible = None
|
||||
if visible is not None:
|
||||
responses = [r for r in responses if r.id in visible]
|
||||
else:
|
||||
responses = [r for r in responses if not r.tags]
|
||||
|
||||
if tag_ids:
|
||||
wanted = set(tag_ids)
|
||||
responses = [r for r in responses if any(t.get("id") in wanted for t in r.tags)]
|
||||
|
||||
+4
-3
@@ -5,7 +5,8 @@
|
||||
随时改 ``config.yaml`` 即可(Gateway 有 mtime 热重载,无需重新构建前端)。
|
||||
|
||||
测试开关(线上接口未通时用假数据,互相独立):
|
||||
- ``test`` → 目的树查询(``purpose_detail_url``)走 ``mock.purpose_detail`` 假数据。
|
||||
- ``test`` → 目的树查询(``purpose_detail_url``)走 ``mock.purpose_detail`` 假数据;
|
||||
同时 rwfx 进入「3q 是否完成」预检(``selectSqReport``,外部接口不可用)走 ``mock.sq_report`` 假数据。
|
||||
- ``delete_test`` → 删除接口(``delete_url``)走 ``mock.delete`` 假数据(该接口尚未开发完时打开)。
|
||||
- ``action_test`` → 行动详情接口(``action_detail_url``)走 ``mock.action_detail`` 假数据。
|
||||
xdfx 深链传入的是「行动id」,需先调该接口拿 ``data.taskId`` 解析出真正的「任务id」。
|
||||
@@ -25,7 +26,7 @@ class TaskDeeplinkConfig(BaseModel):
|
||||
|
||||
test: bool = Field(
|
||||
default=False,
|
||||
description="为真时前端目的树查询走 mock.purpose_detail 假数据(不打真实接口)",
|
||||
description="为真时前端目的树查询走 mock.purpose_detail 假数据;同时 rwfx 进入「3q 是否完成」预检(selectSqReport)走 mock.sq_report 假数据(都不打真实接口)",
|
||||
)
|
||||
delete_test: bool = Field(
|
||||
default=False,
|
||||
@@ -61,5 +62,5 @@ class TaskDeeplinkConfig(BaseModel):
|
||||
)
|
||||
mock: dict[str, Any] = Field(
|
||||
default_factory=dict,
|
||||
description="test/delete_test/action_test 为真时返回的假数据:{purpose_detail: {...}, delete: {message, success}, action_detail: {state, msg, data: {taskId, ...}}}",
|
||||
description="test/delete_test/action_test 为真时返回的假数据:{purpose_detail: {...}, delete: {message, success}, action_detail: {state, msg, data: {taskId, ...}}, sq_report: {state, msg, data: [...]}}(sq_report 供 rwfx 3q 预检,test 为真时用)",
|
||||
)
|
||||
+11
-6
@@ -16,8 +16,11 @@ Resolution rule (per resource type):
|
||||
- ``scheduled_task`` → empty (no built-in tasks)
|
||||
- ``skill`` → empty (the 广场 still shows every visible skill;
|
||||
a position only *adds* its tagged skills to the member's "我的技能")
|
||||
- ``recommended_question`` → *unrestricted* (handled at query time, never
|
||||
materialized — see :meth:`resolve_visible`)
|
||||
- ``recommended_question`` → *untagged-only* (handled at query time, never
|
||||
materialized — see :meth:`resolve_visible`). The default set is the
|
||||
questions carrying **no** 标签; tagged questions surface only for a position
|
||||
that binds their tag. (The recommended-questions router interprets a
|
||||
``None`` from :meth:`resolve_visible` as "show only untagged".)
|
||||
|
||||
Materialization (``sync_user``) only ever touches rows it created itself
|
||||
(``origin='position'``), so a user's own favorites / subscriptions are never
|
||||
@@ -67,12 +70,14 @@ class PositionSyncService:
|
||||
return await self._positions.get_default_position_id()
|
||||
|
||||
async def resolve_visible(self, user_id: str, resource_type: str) -> set[str] | None:
|
||||
"""Return the set of visible ``resource_type`` ids, or ``None`` = unrestricted.
|
||||
"""Return the set of visible ``resource_type`` ids, or ``None`` = no tag binding.
|
||||
|
||||
Used by the recommended-questions filter (the only remaining query-time
|
||||
visibility type; skills are now *materialized*, not filtered). ``None``
|
||||
means "no position restriction → show everything"; a set means "restrict
|
||||
to exactly these ids".
|
||||
visibility type; skills are now *materialized*, not filtered). A set
|
||||
means "restrict to exactly these ids". ``None`` means the effective
|
||||
position binds no tag for this type — the recommended-questions router
|
||||
treats that as "默认岗位 → show only untagged questions" (see
|
||||
``app/gateway/routers/recommended_questions.py``).
|
||||
"""
|
||||
pid = await self._effective_position_id(user_id)
|
||||
if not pid:
|
||||
|
||||
@@ -77,3 +77,65 @@ async def test_list_without_tag_store_does_not_break() -> None:
|
||||
|
||||
assert [q.id for q in resp.questions] == ["q1", "q2"]
|
||||
assert all(q.tags == [] for q in resp.questions)
|
||||
|
||||
|
||||
class _FakeSync:
|
||||
"""Stub position-sync whose ``resolve_visible`` returns a fixed value.
|
||||
|
||||
``None`` mimics 默认岗位 / 无标签绑定; a set mimics a position that binds
|
||||
recommended_question 标签.
|
||||
"""
|
||||
|
||||
def __init__(self, visible: set[str] | None) -> None:
|
||||
self._visible = visible
|
||||
|
||||
async def resolve_visible(self, _user_id, _resource_type): # noqa: ANN001
|
||||
return self._visible
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_default_position_shows_only_untagged() -> None:
|
||||
"""默认岗位(resolve_visible → None)只看到未打标的题目。"""
|
||||
tag_store = MemoryTagStore()
|
||||
tag = await tag_store.create_tag(
|
||||
{"id": "t1", "name": "理赔", "tag_type": "recommended_question"}
|
||||
)
|
||||
await tag_store.set_target_tags("recommended_question", "q2", [tag["id"]])
|
||||
|
||||
req = _request(_FakeQuestionStore(_rows()), tag_store)
|
||||
req.app.state.position_sync = _FakeSync(None)
|
||||
resp = await rq_router.list_recommended_questions(req, all=False)
|
||||
|
||||
assert [q.id for q in resp.questions] == ["q1"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_bound_position_shows_only_its_tagged_questions() -> None:
|
||||
"""绑定了标签的岗位(resolve_visible → set)只看到对应打标的题目。"""
|
||||
tag_store = MemoryTagStore()
|
||||
tag = await tag_store.create_tag(
|
||||
{"id": "t1", "name": "理赔", "tag_type": "recommended_question"}
|
||||
)
|
||||
await tag_store.set_target_tags("recommended_question", "q2", [tag["id"]])
|
||||
|
||||
req = _request(_FakeQuestionStore(_rows()), tag_store)
|
||||
req.app.state.position_sync = _FakeSync({"q2"})
|
||||
resp = await rq_router.list_recommended_questions(req, all=False)
|
||||
|
||||
assert [q.id for q in resp.questions] == ["q2"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_admin_view_ignores_position_filter() -> None:
|
||||
"""``all=True`` 管理视图照旧返回全部(含打标),不受岗位过滤影响。"""
|
||||
tag_store = MemoryTagStore()
|
||||
tag = await tag_store.create_tag(
|
||||
{"id": "t1", "name": "理赔", "tag_type": "recommended_question"}
|
||||
)
|
||||
await tag_store.set_target_tags("recommended_question", "q2", [tag["id"]])
|
||||
|
||||
req = _request(_FakeQuestionStore(_rows()), tag_store)
|
||||
req.app.state.position_sync = _FakeSync(None)
|
||||
resp = await rq_router.list_recommended_questions(req, all=True)
|
||||
|
||||
assert [q.id for q in resp.questions] == ["q1", "q2"]
|
||||
@@ -331,7 +331,7 @@ summarization:
|
||||
# ?taskId= / ?id=),随时改这里即可(Gateway mtime 热重载,前端无需重建)。
|
||||
task_deeplink:
|
||||
# 线上接口未通时用假数据;三个开关互相独立。
|
||||
test: true # 目的树查询走 mock.purpose_detail 假数据
|
||||
test: true # 目的树查询走 mock.purpose_detail 假数据;同时 rwfx 进入「3q 是否完成」预检走 mock.sq_report 假数据
|
||||
delete_test: true # 删除接口走 mock.delete 假数据(该接口尚未开发完)
|
||||
action_test: true # 行动→任务解析走 mock.action_detail 假数据(xdfx 行动id→任务id)
|
||||
purpose_detail_url: "https://ch1.b.uat.4.cn/consumer/taskAnalyseSearch/getTaskPurposeDetail"
|
||||
@@ -382,3 +382,15 @@ task_deeplink:
|
||||
actionName: ""
|
||||
actionStatus: 25
|
||||
narration: ""
|
||||
# test=true 时 rwfx 进入「3q 是否完成」预检(selectSqReport,外部不可用)走这份假数据。
|
||||
# 结构同真实 GET /consumer/cop/selectSqReport?taskId= 返回;前端判定 data 为空 / 每条
|
||||
# contentJson 都是 null/空 = 「3q 未完成」→ 弹框引导去 3qfx;否则视为已完成(正常,不弹框)。
|
||||
# 默认给一条有内容的数据 = 已完成(不打扰)。要测「3q 未完成」弹框:把下面 data 改成 []。
|
||||
sq_report:
|
||||
state: "200"
|
||||
msg: "操作成功!"
|
||||
data:
|
||||
- id: "sq-mock-1"
|
||||
taskId: 3338
|
||||
categoryType: "敌情关键事件 JSON"
|
||||
contentJson: "[{\"topic\":\"示例研判事件\",\"count\":1}]"
|
||||
Reference in new issue
Block a user