✨ feat(vscode): 代码阅读把说明里的 @param / @return / @throws 拆到参数表、输出、异常表
This commit is contained in:
1 parent
c2982537d7
commit
0958506681
43 files changed
+1300
-323
No files matched your search
@@ -0,0 +1,51 @@
|
||||
"""把对话历史转写成一段文字, 交给不共享历史、每次都从零开始的子代理.
|
||||
|
||||
更早的对话已经被压缩成摘要 (`context_compaction["summary"]`, 可能为空),
|
||||
`messages` 只剩近期窗口, 所以转写拼两段: 前情摘要 + 近期消息 (近期过长时只留尾部).
|
||||
只转写用户与助手说过的文字: 工具往来与系统消息是执行细节, 子代理要看代码自己读.
|
||||
平台注入的消息也不转写: 带 `UI_HIDDEN_KEY` 的运行通知 (任务日志 / 批准握手) 不是
|
||||
谁说过的话, 握手里的「不要再讨论计划」还会和规划任务冲突; 带 `PLATFORM_ERROR_KEY`
|
||||
的错误回复不是模型说的, 任何模型输入都不能带它.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Collection, Sequence
|
||||
from typing import Any
|
||||
|
||||
from agent_compiler_deepagents.middleware import PLATFORM_ERROR_KEY, UI_HIDDEN_KEY
|
||||
|
||||
BRIEF_MAX_LINES = 30
|
||||
|
||||
USER = "用户"
|
||||
ASSISTANT = "助手"
|
||||
_SPEAKER = {"HumanMessage": USER, "AIMessage": ASSISTANT}
|
||||
|
||||
|
||||
def render_conversation_brief(
|
||||
messages: Sequence[Any],
|
||||
summary: str | None,
|
||||
*,
|
||||
speakers: Collection[str] = (USER, ASSISTANT),
|
||||
max_lines: int = BRIEF_MAX_LINES,
|
||||
) -> str:
|
||||
"""把对话转写成「前情摘要 + 近期消息」一段文字; 什么都没有时返回空串.
|
||||
|
||||
@param messages 对话历史 (`messages` 状态).
|
||||
@param summary 更早对话的压缩摘要, 没有就传 `None`.
|
||||
@param speakers 转写谁说的话: [USER] / [ASSISTANT]; 只要用户原话时只传 [USER].
|
||||
@param max_lines 近期消息最多留几行, 多了从头丢弃并注明.
|
||||
@return 以 `[会话进展]` 开头的转写.
|
||||
"""
|
||||
lines = [t for m in messages if (t := _line_of(m, speakers))]
|
||||
truncated = len(lines) > max_lines
|
||||
if truncated:
|
||||
lines = lines[-max_lines:]
|
||||
summary_text = (summary or "").strip()
|
||||
if not summary_text and not lines:
|
||||
return ""
|
||||
parts = ["[会话进展]" + ("\n(更早对话已省略)" if truncated else "")]
|
||||
if summary_text:
|
||||
parts += ["[前情摘要]", summary_text]
|
||||
parts.extend(lines)
|
||||
return "\n".join(parts)
|
||||
@@ -0,0 +1,26 @@
|
||||
"""只放行从[桌面端](backend/src/luffy_agent/sandbox/local_runtime/visibility.py#require_desktop_client)发来、且[「我的电脑」总开关](backend/src/luffy_agent/config/services.py#get_local_runtime_enabled)开着的请求,因为网页端没有本机可用,这个功能也还没对所有人开放。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import Request
|
||||
|
||||
from luffy_agent.config.services import get_local_runtime_enabled
|
||||
from luffy_agent.core.exceptions import AppException
|
||||
from luffy_agent.sandbox.local_runtime.visibility import require_desktop_client
|
||||
|
||||
|
||||
class LocalRuntimeDisabled(AppException):
|
||||
status_code = 403
|
||||
error_code = "LOCAL_RUNTIME_DISABLED"
|
||||
message = "「我的电脑」运行时暂未开放"
|
||||
|
||||
|
||||
async def require_local_runtime_open(request: Request) -> None:
|
||||
"""只放行桌面端发来、且 [「我的电脑」总开关](backend/src/luffy_agent/config/services.py#get_local_runtime_enabled) 开着的请求,因为只有桌面端能在用户自己的电脑上跑应用,总开关让平台能把这个功能整体关掉。
|
||||
|
||||
@throws [DesktopOnly](backend/src/luffy_agent/sandbox/local_runtime/visibility.py#DesktopOnly) 请求不是桌面端发来的
|
||||
@throws [LocalRuntimeDisabled] 总开关关着
|
||||
"""
|
||||
require_desktop_client(request)
|
||||
if not await get_local_runtime_enabled():
|
||||
raise LocalRuntimeDisabled()
|
||||
Reference in new issue
Block a user