mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-24 23:53:41 +00:00
全栈安全加固、性能提速与架构演进:连接池与沙箱止血、双路混合检索、多版本归档及前端分包治理
- 第一批(安全加固与生命周期止血):隔离测试宿主机密钥与 .env 泄漏;修复 SQLite 取消查询挂死、:memory: 连接池报错与 EngineCache 世代竞态;补齐运行与评测删除时的 Checkpointer 线程、Artifact 磁盘文件与无主附件回收;加固三套沙箱路径越界、进程组清理与 Seatbelt 数据目录隔离,封堵 SSRF IPv4-mapped IPv6 元数据绕过与响应体 OOM;修复推理模型多轮 reasoning_content、结构化输出 Token 漏计与缓存折扣计费 - 第二批(数据库/集群/问数提速与首屏分包):补齐核心表索引与 SQLite WAL 调优,列表接口按需 defer 大列,收敛启动扫描并打通跨进程 slot 槽位唤醒;优化跨源全局选表、哈希桶数字绑定、流式 CSV 导入及多方言分析算子;剥离首屏静态引入的 @xyflow/react 与全局样式(首屏主包降至 461.59 kB),补充流式 rAF 攒批、Store 精细订阅与表单无障碍绑定 - 第三批(架构演进与工程自动化闭环):记录库超挂接阈值历史版本自动增量归档至单库多表(解除 SQLite 10 库 ATTACH 硬上限);重构知识库为词面 BM25 与全集合归一化向量矩阵真·双路独立召回并支持游标分批重建;升级多方言感知 SQL 模板词法分析(E'...' / $$...$$ / q'[...]' / # / 嵌套注释)与 Decimal / bool / NaN 参数校验,消除 ledger 层对 api 路由层的反向依赖;拆分 3101 行 CaliberDrafts 页面为 7 个领域子模块,消除检查脚本本机路径硬编码并新增 GitHub Actions CI 门禁与三批回归测试套件
This commit is contained in:
@@ -47,7 +47,7 @@ from langchain_core.tracers.context import register_configure_hook
|
||||
#: 取不到模型名的调用记在这个名下
|
||||
UNKNOWN_MODEL = "unknown"
|
||||
#: 每个模型累计的几项(unreported 用量没报全的次数、unfinished 没做完的次数)
|
||||
_COUNTERS = ("input_tokens", "output_tokens", "calls", "unreported", "unfinished")
|
||||
_COUNTERS = ("input_tokens", "output_tokens", "cache_read_tokens", "cache_creation_tokens", "calls", "unreported", "unfinished")
|
||||
|
||||
|
||||
def _abandoned(error: BaseException) -> bool:
|
||||
@@ -112,6 +112,10 @@ class Meter(BaseCallbackHandler):
|
||||
if usage:
|
||||
row["input_tokens"] += int(usage.get("input_tokens") or 0)
|
||||
row["output_tokens"] += int(usage.get("output_tokens") or 0)
|
||||
details = usage.get("input_token_details") or {}
|
||||
if isinstance(details, dict):
|
||||
row["cache_read_tokens"] += int(details.get("cache_read") or 0)
|
||||
row["cache_creation_tokens"] += int(details.get("cache_creation") or 0)
|
||||
else:
|
||||
row["unreported"] += 1
|
||||
|
||||
@@ -141,6 +145,10 @@ class Meter(BaseCallbackHandler):
|
||||
reported = getattr(partial, "usage_metadata", None) or {}
|
||||
row["input_tokens"] += int(reported.get("input_tokens") or 0)
|
||||
row["output_tokens"] += int(reported.get("output_tokens") or 0)
|
||||
details = reported.get("input_token_details") or {}
|
||||
if isinstance(details, dict):
|
||||
row["cache_read_tokens"] += int(details.get("cache_read") or 0)
|
||||
row["cache_creation_tokens"] += int(details.get("cache_creation") or 0)
|
||||
|
||||
def _rows(self) -> dict[str, dict[str, int]]:
|
||||
"""累计的一份拷贝,开始了还没结束回调的调用算成没做完的(调用方持锁)。"""
|
||||
@@ -180,9 +188,21 @@ class Meter(BaseCallbackHandler):
|
||||
unpriced = row["calls"]
|
||||
else:
|
||||
unpriced = 0 if free else row["unreported"]
|
||||
cache_read = int(row.get("cache_read_tokens") or 0)
|
||||
cache_create = int(row.get("cache_creation_tokens") or 0)
|
||||
if cache_read > 0 or cache_create > 0:
|
||||
try:
|
||||
raw_cost = estimate_cost(
|
||||
model, row["input_tokens"], row["output_tokens"],
|
||||
cache_read_tokens=cache_read, cache_creation_tokens=cache_create,
|
||||
)
|
||||
except TypeError:
|
||||
raw_cost = estimate_cost(model, row["input_tokens"], row["output_tokens"])
|
||||
else:
|
||||
raw_cost = estimate_cost(model, row["input_tokens"], row["output_tokens"])
|
||||
by_model[model] = {"input_tokens": row["input_tokens"], "output_tokens": row["output_tokens"],
|
||||
"calls": row["calls"],
|
||||
"cost_usd": round(estimate_cost(model, row["input_tokens"], row["output_tokens"]), 6),
|
||||
"cost_usd": round(raw_cost, 6),
|
||||
"unpriced_calls": unpriced, "unfinished_calls": row["unfinished"]}
|
||||
total = {key: sum(r[key] for r in by_model.values())
|
||||
for key in ("input_tokens", "output_tokens", "calls", "unpriced_calls", "unfinished_calls")}
|
||||
|
||||
Reference in New Issue
Block a user