mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-20 02:11:59 +00:00
普通用户建应用集成收尾:
- 问数据和个人应用的图放行绑定只读查询等合规工具的调用工具节点,只读和遮罩在这条路径上生效;被治理成写入的工具在只读运行里直接拒;知识库范围在工具层固定(图级默认值、参数名纠错、Agent 都改不了) - 个人应用的刷新和个人蓝图的试运行只有拥有者能读:运行、事件、证据、工件、文件、运行与审批列表、对比、可验证报告、质询、假设分析、提取工作流一并收紧;个人蓝图的试运行不论谁发起都按个人应用约束 - 共享蓝图只给拥有者、对应应用的管理者、管理员,看不到的一律 404;审核副本归审核人;管理员看别人的个人应用只有元数据、可以归档 - 记录表跨版本汇总(只读挂载旧版本、按当前列 UNION ALL、各版本各自固定高水位,缺的版本照实写进印章);停用前发起的运行可以继续写旧版本;更正沿用原提交人、更正人记审计 - 约定收口:待办种类 review、事件 file.extracted、表单错误 file、模板定义带示例与预置;前端类型一次补齐、去掉临时的局部类型;审核待办卡不再给打不开的链接;读附件事件有中文说法;检查脚本补断言
This commit is contained in:
@@ -942,6 +942,10 @@ async def run_query(
|
||||
raise SqlRejected(f"「{source.name}」只能按表名查询(如 FROM records),不能在表名前加库名「{hit}.」:"
|
||||
"这张表只给看这次运行能看的那些行")
|
||||
prelude: tuple[str, ...] = tuple(getattr(source, "prelude", None) or ())
|
||||
attach: tuple[tuple[str, str], ...] = tuple(getattr(source, "attach", None) or ())
|
||||
if attach and (kind != "sqlite" or not source.readonly):
|
||||
# 挂旧版本靠 URI 写法的 mode=ro:只有以 URI 只读打开的 SQLite 连接认它(_sqlite_url)
|
||||
raise ValueError("只有只读的 SQLite 数据源能挂其他库")
|
||||
|
||||
engine = await engines.get(source)
|
||||
started = time.perf_counter()
|
||||
@@ -950,6 +954,9 @@ async def run_query(
|
||||
return await _run_write(engine, kind, statement, limits, started)
|
||||
|
||||
async def _read(conn: AsyncConnection) -> tuple[list[str], list[list[Any]], bool, dict[str, str]]:
|
||||
# 记录表跨版本汇总:旧版本先只读挂到这条连接上(prelude 里的临时视图要引用它们)
|
||||
if prelude or attach:
|
||||
await _attach_readonly(conn, attach)
|
||||
# 连接上先执行的语句(记录表的同名临时视图)。按驱动原样执行,不经 text():视图里拼着看的人的名字,
|
||||
# 名字里的冒号不能被当成绑定参数
|
||||
for stmt in prelude:
|
||||
@@ -981,6 +988,41 @@ async def run_query(
|
||||
)
|
||||
|
||||
|
||||
#: 平台挂到查询连接上的库名只许这个样子(records/views.py 的 records_v<版本>):拼进 ATTACH / DETACH 语句
|
||||
_ATTACH_NAME = re.compile(r"^[a-z][a-z0-9_]{0,63}$")
|
||||
|
||||
|
||||
def _same_file(a: str, b: str) -> bool:
|
||||
return bool(a) and bool(b) and os.path.realpath(a) == os.path.realpath(b)
|
||||
|
||||
|
||||
async def _attach_readonly(conn: AsyncConnection, wanted: tuple[tuple[str, str], ...]) -> None:
|
||||
"""让这条连接上挂着的库正好是 wanted(库名 → 文件),一律以 URI 的 mode=ro 只读挂上。
|
||||
|
||||
连接在池子里复用,挂过的库留在连接上:已经挂好、文件对得上的不重挂;不在 wanted 里的(或文件对不上的)先摘掉——
|
||||
不然 SQL 写个库名就能读到这次没并进来的那一版。用户 SQL 里的 ATTACH / DETACH 由只读守卫拒(data/guard.py),
|
||||
挂库只有这里做;DETACH 失败(连接上还有没读完的语句)照实抛出,不带着不该挂的库查。"""
|
||||
from urllib.parse import quote
|
||||
|
||||
want = dict(wanted)
|
||||
for name in want:
|
||||
if not _ATTACH_NAME.match(name) or name in ("main", "temp"):
|
||||
raise ValueError(f"挂库的库名不合规:{name}")
|
||||
have = {str(r[1]): str(r[2] or "") for r in (await conn.exec_driver_sql("PRAGMA database_list")).fetchall()}
|
||||
for name, file in have.items():
|
||||
if name in ("main", "temp"):
|
||||
continue
|
||||
if name not in want or not _same_file(file, want[name]):
|
||||
await conn.exec_driver_sql(f'DETACH DATABASE "{name}"')
|
||||
for name, path in want.items():
|
||||
if name in have and _same_file(have[name], path):
|
||||
continue
|
||||
if not os.path.isfile(path):
|
||||
raise FileNotFoundError(f"要并进来的数据文件不在了:{os.path.basename(path)}")
|
||||
uri = f"file:{quote(os.path.realpath(path))}?mode=ro"
|
||||
await conn.exec_driver_sql(f"ATTACH DATABASE '{uri}' AS \"{name}\"")
|
||||
|
||||
|
||||
class _TypeTally:
|
||||
"""边读边记每列见过的值类型。只看驱动交回的原始值:_jsonable 之后 Decimal 就成了字符串,
|
||||
小数位为 0 的 DECIMAL("45678")和文本列的 "2026" 再也分不开。"""
|
||||
|
||||
Reference in New Issue
Block a user