Skip to content
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- 专家欢迎页:`manifest.json` 的 `quick_prompts` 写成空数组时不再回退到默认快捷卡片,与 `task_examples` 的空数组语义一致。
- 修复插件安装失败时错误正文泄漏到界面:普通请求、上传及安装 SSE 统一保留结构化错误与翻译,非 JSON 响应仅展示 HTTP 状态与请求编号,错误读取限制为 16 KiB / 2 秒。
- 插件下载、解压和依赖安装移至后台,注册和运行时刷新保留在事件循环;加入下载超时、大小及总时间预算,同插件并发冲突和取消保护,更新失败恢复旧文件与注册,禁用插件更新后保持禁用。

Expand Down
2 changes: 2 additions & 0 deletions docs/expert-package.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ ops-engineer/

不是对象的元素直接丢掉。标题和正文都空的卡片不会留在工作区清单里。

写成空数组表示这个专家没有快捷提示,欢迎页不会再补默认卡片;不写这个字段时才使用默认卡片。

建 Agent 时如果请求里另外带了 `quick_prompts`,会写进工作区 `.octop/manifest.json`,覆盖压缩包里的同名字段。

## 任务示例
Expand Down
33 changes: 23 additions & 10 deletions src/octop/api/routers/chat/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@
logger = logging.getLogger(__name__)


def workspace_welcome_payload(
manifest: dict[str, Any] | None,
catalog: Any,
) -> dict[str, Any]:
"""Quick cards for an expert's workspace manifest.

A manifest that says nothing about cards gets the catalog's defaults. One
that carries a ``quick_prompts`` list, even an empty one, is its author's
decision and is used as it stands: an expert set up with no cards keeps
showing none.
"""
if manifest is None:
return default_welcome_payload(catalog)
welcome = welcome_payload_from_manifest_data(manifest)
if welcome_payload_has_content(welcome) or isinstance(manifest.get("quick_prompts"), list):
return welcome
return default_welcome_payload(catalog)


@router.get("/agents/{agent_id}/chat/welcome", summary="Chat welcome quick cards")
async def get_chat_welcome(
agent_id: str,
Expand All @@ -50,6 +69,7 @@ async def get_chat_welcome(
Resolution order:
1. Agent row ``welcome_message`` (instance-owned; set at create/edit).
2. Agent workspace ``.octop/manifest.json`` (seeded at create; quick cards + fallback copy).
A manifest with a ``quick_prompts`` list, even an empty one, is final.
3. Default quick cards (``general-assistant`` or a small built-in set).

Team hosts keep the team intro and show members' own quick cards — the host
Expand All @@ -65,18 +85,11 @@ async def get_chat_welcome(
return {**team_payload, "task_examples": None}

workspace = registry.workspace_for_agent(agent_id)
payload: dict[str, Any] | None = None
parsed_examples = None
manifest = None
if workspace is not None:
manifest = await read_workspace_manifest_data(workspace)
if manifest is not None:
welcome = welcome_payload_from_manifest_data(manifest)
if welcome_payload_has_content(welcome):
payload = welcome
parsed_examples = parse_task_examples(manifest)

if payload is None:
payload = default_welcome_payload(catalog)
payload = workspace_welcome_payload(manifest, catalog)
parsed_examples = parse_task_examples(manifest) if manifest is not None else None

db_welcome = welcome_from_row(row) if row is not None else None
if db_welcome is not None:
Expand Down
59 changes: 59 additions & 0 deletions tests/unit/api/test_chat_welcome_cards.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""Quick cards of an expert's chat welcome screen."""

from __future__ import annotations

from pathlib import Path
from typing import Any

import pytest

from octop.api.routers.chat.routes import workspace_welcome_payload
from octop.infra.agents.experts.catalog import (
ExpertCatalog,
default_welcome_payload,
)

CARDS = [{"title": {"zh": "查资质"}, "description": {"zh": ""}, "prompt": {"zh": "查"}}]


@pytest.fixture
def catalog(tmp_path: Path) -> ExpertCatalog:
# An empty library: the default is the small built-in card set.
expert_catalog = ExpertCatalog(tmp_path / "library")
expert_catalog.refresh()
return expert_catalog


def _prompts(payload: dict[str, Any]) -> list[Any]:
return payload["quick_prompts"]


def test_manifest_without_cards_gets_the_defaults(catalog: ExpertCatalog) -> None:
assert _prompts(workspace_welcome_payload({"id": "x"}, catalog)) == _prompts(
default_welcome_payload(catalog)
)
assert _prompts(workspace_welcome_payload(None, catalog)) == _prompts(
default_welcome_payload(catalog)
)


def test_manifest_with_cards_keeps_them(catalog: ExpertCatalog) -> None:
payload = workspace_welcome_payload({"id": "x", "quick_prompts": CARDS}, catalog)
assert [card["title"] for card in _prompts(payload)] == [{"zh": "查资质", "en": "查资质"}]


def test_explicitly_empty_card_list_shows_no_cards(catalog: ExpertCatalog) -> None:
"""An expert set up with no cards must not fall back to the defaults."""
payload = workspace_welcome_payload({"id": "x", "quick_prompts": []}, catalog)
assert _prompts(payload) == []
assert payload["welcome_message"] == {"zh": "", "en": ""}


def test_non_list_card_value_still_gets_the_defaults(catalog: ExpertCatalog) -> None:
"""Only a list is the author's decision; ``null``/text is malformed, not empty."""
assert _prompts(workspace_welcome_payload({"quick_prompts": None}, catalog)) == _prompts(
default_welcome_payload(catalog)
)
assert _prompts(workspace_welcome_payload({"quick_prompts": "none"}, catalog)) == _prompts(
default_welcome_payload(catalog)
)
Loading