mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-18 12:21:59 +00:00
277982ead3
- 蓝图:bp_* 操作和逐卡白名单、蓝图检查、留痕、按蓝图判权限;五个场景模板加自由形(骨架、关节、应用骨架、定时任务),实例化与骨架比对;BlueprintApplier / TemplateApplier(只收模板声明过的关节)与自查;look 新类别口径卡;蓝图对话和填关节两个流式接口,不同组的关节并行填、出错的组串行重试;模板列表 - 试运行与发布单:四种起点(对话、模板、问数据的一轮、已发布版本);试运行是探索运行,草稿应用按这次运行解析、印章写试运行,流程类派给自己、不触发升级;发布单九步、预检只读、每步留痕、停下后接着做、核对卡片指纹和应用管理权、启动时整理中断的单;白话层覆盖全部问题编号 - 记录表与文件:平台托管只追加的记录表、按高水位固定数据、连接上的临时视图做行级可见、写入走动作(records_append)、表版本在发布时切换、草稿不影响线上、记录列表遮敏感列;文件按哈希存、两步上传、提交时绑定运行、下载按读权限、清理、file_text、按配方导入一期(table_import_period) - 个人应用:存成个人应用(问数据的约束)、刷新(遮罩、只读、每日上限)、只有拥有者看得见、提交审核与共享副本、开关下发到认人接口;页面编辑的候选;隐藏组件不下发;三条新检查
108 lines
5.2 KiB
Python
108 lines
5.2 KiB
Python
"""记录的逐行查看(组件 records_list、GET /api/apps/{id}/records,docs/design/normal-user-apps.md §3.7、§4.7)。
|
||
|
||
每次打开按看的人实时过滤,不走封存(同实例列表):use 只看自己提交的,observe、manage 看全部;关登录时看全部(没填署名、
|
||
又要只看自己的,分不出谁是谁,按全部给,同实例列表)。一张记录表的各版本合在一起列:新版本在前、每个版本里新提交的
|
||
在前;被更正过的行默认不列,history 打开时列出并标 superseded。
|
||
|
||
遮罩:别人提交的行里,数据源设了遮罩的列(「填什么」里标了敏感的,加上管理员在数据页手工加的)换成「已遮罩」——和看板证据
|
||
同一套遮罩列、同一个说法(P4、P5);自己提交的行照原样给(是自己填的)。附件列遮掉之后连文件的引用也不给。
|
||
|
||
返回的形状同 frontend/src/typesBlueprint.ts 的 RecordsPage:{table, version, columns, items, mine_only},另带 next_cursor
|
||
(下一页的游标,「版本:序号」,没有下一页为空)和 state(empty:这个应用还没有记录表)。
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import asyncio
|
||
from typing import Any
|
||
|
||
from sqlalchemy.ext.asyncio import AsyncSession
|
||
|
||
from app.records import store
|
||
from app.records.access import scope_of_role
|
||
from app.records.tables import columns_of, path_of, tables_of_app, versions_of
|
||
|
||
#: 一页最多几行
|
||
PAGE_MAX = 200
|
||
|
||
|
||
async def _masked(session: AsyncSession, row: Any) -> set[str]:
|
||
"""这一版登记成的数据源设了遮罩的列(小写)。"""
|
||
from app.data.engine import masked_columns
|
||
from app.db.models import DataSource
|
||
|
||
source = await session.get(DataSource, row.source_id) if row.source_id else None
|
||
return {c.lower() for c in masked_columns(source.options if source is not None else None)}
|
||
|
||
|
||
def _shown(item: dict[str, Any], version: int, masked: set[str], viewer: str | None) -> dict[str, Any]:
|
||
"""一行交给看的人的样子:别人提交的行,遮罩列有值的换成「已遮罩」(P4)。"""
|
||
from app.api.evidence import MASKED
|
||
|
||
out = {**item, "_version": version}
|
||
if not masked or (viewer and item.get("_submitted_by") == viewer):
|
||
return out
|
||
values = item.get("values") or {}
|
||
out["values"] = {k: MASKED if k.lower() in masked and v is not None else v for k, v in values.items()}
|
||
return out
|
||
|
||
|
||
def _cursor(raw: str | None) -> tuple[int, int] | None:
|
||
if not raw:
|
||
return None
|
||
version, _, seq = str(raw).partition(":")
|
||
return (int(version), int(seq)) if version.isdigit() and seq.isdigit() else None
|
||
|
||
|
||
async def page(session: AsyncSession, app: Any, *, principal: Any, role: str | None, table: str | None = None,
|
||
who: str | None = None, cursor: str | None = None, history: bool = False,
|
||
limit: int = 50) -> dict[str, Any]:
|
||
tables = await tables_of_app(session, app.id)
|
||
current = next((t for t in tables if table in (None, "", t.table_key, t.id)), None)
|
||
if current is None and table:
|
||
# 也认数据源名(rec_…):模板里手上拿着的可能是它
|
||
from app.records.tables import find_table
|
||
|
||
found = await find_table(session, table)
|
||
current = next((t for t in tables if found is not None and t.table_key == found.table_key), None)
|
||
scope = scope_of_role(principal, role)
|
||
if who == "mine" and scope == "all":
|
||
scope = "mine"
|
||
viewer = principal.username
|
||
if scope == "mine" and not viewer and principal.mode == "off":
|
||
scope = "all"
|
||
if current is None:
|
||
return {"table": table, "version": 0, "columns": [], "items": [], "mine_only": scope == "mine",
|
||
"state": "empty", "next_cursor": None}
|
||
limit = max(1, min(int(limit), PAGE_MAX))
|
||
versions = await versions_of(session, current.table_key)
|
||
at = _cursor(cursor)
|
||
items: list[dict[str, Any]] = []
|
||
more = False
|
||
for row in versions:
|
||
if at is not None and row.version > at[0]:
|
||
continue
|
||
before = at[1] if at is not None and row.version == at[0] else None
|
||
cols = columns_of(row)
|
||
try:
|
||
got, more_here = await asyncio.to_thread(
|
||
store.rows, path_of(row), cols, scope=scope, viewer=viewer, history=history, before=before,
|
||
limit=limit - len(items))
|
||
except store.RecordsRefused:
|
||
continue
|
||
masked = await _masked(session, row)
|
||
items += [_shown(r, row.version, masked, viewer) for r in got]
|
||
if len(items) >= limit:
|
||
more = more_here or row is not versions[-1]
|
||
break
|
||
columns: list[dict[str, Any]] = []
|
||
seen: set[str] = set()
|
||
for row in versions:
|
||
for c in columns_of(row):
|
||
if c.name.lower() not in seen:
|
||
seen.add(c.name.lower())
|
||
columns.append({"name": c.name, "label": c.label or c.name, "type": c.type})
|
||
last = items[-1] if items else None
|
||
return {"table": current.table_key, "version": versions[0].version if versions else current.version,
|
||
"columns": columns, "items": items, "mine_only": scope == "mine",
|
||
"next_cursor": f"{last['_version']}:{last['_seq']}" if more and last else None}
|