lemma-agent 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account-discovery.js +159 -0
- package/dist/admin.js +5 -0
- package/dist/app.js +1 -0
- package/dist/bridge.js +341 -0
- package/dist/config.js +43 -3
- package/dist/proxy.js +490 -97
- package/dist/redact.js +9 -3
- package/package.json +1 -1
- package/web/js/views.js +40 -0
package/dist/redact.js
CHANGED
|
@@ -62,9 +62,10 @@ export class Redactor {
|
|
|
62
62
|
}
|
|
63
63
|
redactText(input, outMap) {
|
|
64
64
|
if (!input || input.length > 512_000)
|
|
65
|
-
return { text: input, count: 0 };
|
|
65
|
+
return { text: input, count: 0, kinds: [] };
|
|
66
66
|
let text = input;
|
|
67
67
|
let count = 0;
|
|
68
|
+
const kinds = new Set();
|
|
68
69
|
for (const rule of this.rules) {
|
|
69
70
|
const re = new RegExp(rule.regex.source, rule.regex.flags.includes("g") ? rule.regex.flags : `${rule.regex.flags}g`);
|
|
70
71
|
text = text.replace(re, (...args) => {
|
|
@@ -76,6 +77,7 @@ export class Redactor {
|
|
|
76
77
|
if (!target || this.isExempt(target))
|
|
77
78
|
return full;
|
|
78
79
|
count++;
|
|
80
|
+
kinds.add(rule.kind);
|
|
79
81
|
const ph = this.placeholderFor(rule.kind, target);
|
|
80
82
|
outMap?.set(ph, target);
|
|
81
83
|
return `${g1}${ph}${g3}`;
|
|
@@ -83,15 +85,17 @@ export class Redactor {
|
|
|
83
85
|
if (this.isExempt(full))
|
|
84
86
|
return full;
|
|
85
87
|
count++;
|
|
88
|
+
kinds.add(rule.kind);
|
|
86
89
|
const ph = this.placeholderFor(rule.kind, full);
|
|
87
90
|
outMap?.set(ph, full);
|
|
88
91
|
return ph;
|
|
89
92
|
});
|
|
90
93
|
}
|
|
91
|
-
return { text, count };
|
|
94
|
+
return { text, count, kinds: [...kinds] };
|
|
92
95
|
}
|
|
93
96
|
redactJson(value, outMap) {
|
|
94
97
|
let total = 0;
|
|
98
|
+
const kinds = new Set();
|
|
95
99
|
const walk = (node, parentKey) => {
|
|
96
100
|
if (typeof node === "string") {
|
|
97
101
|
// 跳过图片/文件 base64 大块,避免无谓正则扫描
|
|
@@ -99,6 +103,8 @@ export class Redactor {
|
|
|
99
103
|
return node;
|
|
100
104
|
const res = this.redactText(node, outMap);
|
|
101
105
|
total += res.count;
|
|
106
|
+
for (const k of res.kinds)
|
|
107
|
+
kinds.add(k);
|
|
102
108
|
return res.text;
|
|
103
109
|
}
|
|
104
110
|
if (Array.isArray(node)) {
|
|
@@ -129,7 +135,7 @@ export class Redactor {
|
|
|
129
135
|
}
|
|
130
136
|
return node;
|
|
131
137
|
};
|
|
132
|
-
return { value: walk(value), count: total };
|
|
138
|
+
return { value: walk(value), count: total, kinds: [...kinds] };
|
|
133
139
|
}
|
|
134
140
|
restoreText(input, localMap) {
|
|
135
141
|
if (!input || !input.includes(PLACEHOLDER_PREFIX))
|
package/package.json
CHANGED
package/web/js/views.js
CHANGED
|
@@ -1345,6 +1345,45 @@ function usage() {
|
|
|
1345
1345
|
</div>
|
|
1346
1346
|
</div>
|
|
1347
1347
|
</section>`;
|
|
1348
|
+
const ps = state.proxyStatus ?? null;
|
|
1349
|
+
const psTotals = ps?.totals ?? { requests: 0, retries: 0, blocked: 0, redacted: 0 };
|
|
1350
|
+
const psCooled = ps?.pool?.cooledKeys ?? [];
|
|
1351
|
+
const psAccounts = ps?.discoveredAccounts ?? [];
|
|
1352
|
+
const psModels = ps?.models ?? [];
|
|
1353
|
+
const psRedactions = ps?.recentRedactions ?? [];
|
|
1354
|
+
const proxyCardHtml = ps
|
|
1355
|
+
? `
|
|
1356
|
+
<section class="card" data-card="proxy-status">
|
|
1357
|
+
<header class="card-head">
|
|
1358
|
+
<div class="card-heading">
|
|
1359
|
+
<h2 class="card-title">本地代理网关观测(速度 / 缓存 / 脱敏 / 本机账号)</h2>
|
|
1360
|
+
<div class="card-sub">${ps.enabled ? `运行中 · ${esc(ps.mode === "relay" ? "云端托管中转" : "本地多 Key 粘性轮转")}${ps.bridgeEnabled ? " · 已开 Claude↔OpenAI 桥接" : ""}${ps.listenUrl ? ` · ${esc(ps.listenUrl)}` : ""}` : "网关未启用(在 pi-agent.config.json 配置 proxy.enabled=true 开启)"}</div>
|
|
1361
|
+
</div>
|
|
1362
|
+
<span class="card-note">粘性会话 ${ps.pool?.activeStickyCount ?? 0}</span>
|
|
1363
|
+
</header>
|
|
1364
|
+
<div class="card-body">
|
|
1365
|
+
<div class="kpis kpis-4">
|
|
1366
|
+
<div class="kpi"><div class="kpi-top"><span class="kpi-label">网关请求</span></div><strong>${num(psTotals.requests)}</strong><span class="kpi-sub">故障切换 / 重试 ${num(psTotals.retries)} 次</span></div>
|
|
1367
|
+
<div class="kpi"><div class="kpi-top"><span class="kpi-label">隐私脱敏</span></div><strong>${num(psTotals.redacted)}</strong><span class="kpi-sub">敏感拦截 ${num(psTotals.blocked)} 次</span></div>
|
|
1368
|
+
<div class="kpi"><div class="kpi-top"><span class="kpi-label">冷却密钥</span></div><strong>${num(psCooled.length)}</strong><span class="kpi-sub">${psCooled.length ? psCooled.map((k) => `${esc(k.poolId)} (${k.remainingSec}s)`).join(" · ") : "全部 Key 健康"}</span></div>
|
|
1369
|
+
<div class="kpi"><div class="kpi-top"><span class="kpi-label">本机已发现账号</span></div><strong>${num(psAccounts.filter((a) => a.detected).length)} / ${num(psAccounts.length)}</strong><span class="kpi-sub">${psAccounts.length ? psAccounts.map((a) => `${esc(a.provider)}:${a.detected ? esc(a.authMode) : "无"}`).join(" · ") : "已关闭扫描"}</span></div>
|
|
1370
|
+
</div>
|
|
1371
|
+
${
|
|
1372
|
+
psModels.length
|
|
1373
|
+
? `<div class="table-wrap" style="margin-top:12px"><table class="table">
|
|
1374
|
+
<thead><tr><th>网关模型</th><th class="num">请求</th><th class="num">TTFT 中位</th><th class="num">TPS 中位</th><th class="num">缓存命中</th><th class="num hide-sm">输入 / 输出</th><th class="num">估算花费</th></tr></thead>
|
|
1375
|
+
<tbody>${psModels.map((m) => `<tr><td class="mono">${esc(m.model)}</td><td class="num mono">${num(m.requests)}${m.errors ? ` <span class="err-t">(${m.errors}错)</span>` : ""}</td><td class="num mono">${m.medianTtftMs == null ? "—" : `${num(m.medianTtftMs)}ms`}</td><td class="num mono">${m.medianTps == null ? "—" : `${m.medianTps} t/s`}</td><td class="num mono">${m.cacheHitRate == null ? "—" : `${m.cacheHitRate}%`}</td><td class="num mono hide-sm">${num(m.inputTokens)} / ${num(m.outputTokens)}</td><td class="num mono">${m.costUsd ? money(m.costUsd) : "—"}</td></tr>`).join("")}</tbody>
|
|
1376
|
+
</table></div>`
|
|
1377
|
+
: ""
|
|
1378
|
+
}
|
|
1379
|
+
${
|
|
1380
|
+
psRedactions.length
|
|
1381
|
+
? `<p class="footnote" style="margin-top:8px">最近脱敏审计(不含明文):${psRedactions.slice(0, 5).map((r) => `${esc(r.agent)} [${esc(r.action)}] ×${r.count} (${esc(r.kinds.join(","))})`).join(" ; ")}</p>`
|
|
1382
|
+
: ""
|
|
1383
|
+
}
|
|
1384
|
+
</div>
|
|
1385
|
+
</section>`
|
|
1386
|
+
: "";
|
|
1348
1387
|
root.innerHTML = `
|
|
1349
1388
|
<div class="kpis kpis-4">
|
|
1350
1389
|
<div class="kpi"><div class="kpi-top"><span class="kpi-label">总调度 tokens</span></div><strong>${num(input + output)}</strong><span class="kpi-sub">输入 ${num(input)} · 输出 ${num(output)}</span></div>
|
|
@@ -1353,6 +1392,7 @@ function usage() {
|
|
|
1353
1392
|
<div class="kpi"><div class="kpi-top"><span class="kpi-label">成员累计耗时</span></div><strong>${duration(t.durationMs)}</strong><span class="kpi-sub">${t.total} 次派工</span></div>
|
|
1354
1393
|
</div>
|
|
1355
1394
|
${uxCardHtml}
|
|
1395
|
+
${proxyCardHtml}
|
|
1356
1396
|
<section class="card">
|
|
1357
1397
|
<header class="card-head"><div class="card-heading"><h2 class="card-title">派工活动</h2><div class="card-sub"><span><b>${act.total}</b> 次 · ${mode === "day" ? "最近 24 小时,每小时" : "最近 14 天,每天"}</span></div></div>
|
|
1358
1398
|
<div class="act-legend">${KINDS.map((k) => `<span><i style="background:${agentColor(k)}"></i>${esc(AGENT_LABEL[k] ?? k)}</span>`).join("")}</div>
|