page-harnessweight 0.4.0: weigh each agent harness behind the gateway (#922)
A page plugin that compares the agent harnesses behind magpie's gateway by agent: input tokens, cache hits, failures, latency and estimated tool-definition size. A local service on 127.0.0.1:3496 reads magpie's usage ledger, and a read-only gateway hook writes tool counts, sizes and names to <config>/harnessweight/tools.jsonl. Since the review at e0a0ae97 (7c6cd626a, then main merged in): - Port 3492 -> 3496 (window-warmup has 3492; 3496 is used by no other package). - Config dir: input.directory, then a cwd probe, then an absolute XDG_CONFIG_HOME, then ~/.config/magpie. A relative XDG is ignored. - tools.jsonl is append-only. Past 8 MiB it is renamed to tools.jsonl.1. Age is checked at most hourly. Appends from two hosts are serialized by a cross-process lock that is skipped after 100 ms. - MAGPIE_ADDR is honoured; the UI has English and Chinese (zh-TW and ja read English); preview PNGs dropped; /%E0 returns 400. Run at 961b20e63c7e00e1dcca723bc2aa1d302f5dd9a3, in WSL (magpie-desktop, Node 22.23.4): - node --test test/*.test.mjs in the package: 60 pass, 0 fail. - bun scripts/check.mjs: clean (registry.json ok; the package has hooks, so check skips it). - Probes against createHandler: - Origin null without the token: 403. With the token: 200. - A foreign Origin, a loopback Origin on another port, a file:// Origin, a rebound Host and a localhost Host on another port: all 403. - The index HTML carries the token and no ACAO. - ..%2f: 400. /%E0: 400. - Rollover with 40-tool rows (1306 B each), 9.5 MiB written: the file peaked at 8,388,590 B (cap 8,388,608) with one rename to .1. Append p50 was 1.35 ms, p99 9.2 ms and max 24 ms. - Portable dir: the hook's cwd probe and the service's input.directory gave the same tools.jsonl. - Broken by hand: - Size rotation turned off: two rollover tests went red. - The Host check removed: the service test "other hosts, other origins and path traversal are refused" went red. Co-authored-by: webkubor <29485642+webkubor@users.noreply.github.com>
@@ -191,6 +191,7 @@ These add a page to magpie's window, in the app and in `magpie web`, under Plugi
|
||||
| [chat](packages/chat) | Chat with magpie's models, your MCP servers, instructions and skills, by Magic_zero ([Magiczerowxy](https://github.com/Magiczerowxy)). Has a host part: a local service the page goes to | none (its service calls magpie's gateway) |
|
||||
| [window-warmup](packages/window-warmup) | Window warmup: send one fixed short message ("hi", max_tokens 16) to a provider, account and model you pick, right after its quota window resets, daily at set times or every few hours, so the next subscription window opens early, by [YangHonghang](https://github.com/YangHonghang). Has a host part: a local service on 127.0.0.1 the page goes to | none; its service calls magpie's gateway and reads magpie's providers.json (keys only as sha256 fingerprints, plus key names and account models) and model cache. Each send uses the chosen account's quota |
|
||||
| [agent-console](packages/agent-console) | Drive the Agent CLIs on this computer (Claude Code, Codex, Cursor, Copilot, OpenCode, Pi, Devin, dsh) with a timeline, Git changes, files and a terminal, by [qingnian108](https://github.com/qingnian108). Has a host part: a gate and a daemon on 127.0.0.1, started when the page opens | none (its daemon runs the Agent CLIs you pick, in the projects you open) |
|
||||
| [page-harnessweight](packages/page-harnessweight) | Compare the agent harnesses behind the gateway: tokens, cache, failures, latency and estimated tool-definition size. Has a local service and a read-only gateway hook, by [webkubor](https://github.com/webkubor) | none (the service reads the local usage ledger and the local gateway's agent names and icon keys; the hook records tool names and numerical usage metadata locally) |
|
||||
|
||||
```sh
|
||||
magpie plugin add @magpie-community/page-<name>
|
||||
@@ -216,6 +217,7 @@ Like middleware, these run on the requests agents send, but in magpie's Bun host
|
||||
| [OpenViking](https://github.com/volcengine/OpenViking/tree/main/examples/magpie-memory-plugin) | OpenViking context recall and opt-in completed-conversation capture using existing OpenViking configuration; published as `@openviking/magpie-plugin` and maintained in the OpenViking repository |
|
||||
| [@vshulcz/magpie-deja](https://github.com/vshulcz/deja-vu/tree/main/extensions/magpie) | [deja-vu](https://github.com/vshulcz/deja-vu) local cross-agent session memory: recalls project-scoped (`ctx.cwd`) history from the transcripts Claude Code, Codex, Hermes, Gemini CLI, OpenCode, Cursor and DSH write on disk, scrubs secret patterns, and attaches the recalled excerpt to the request sent to your model provider; when recalled history helped, the model is asked to end its reply with a one-line `déjà vu: … — reusing it.` note |
|
||||
| [notify](packages/notify) | A push to ntfy, Bark, Gotify, Server酱, Feishu, DingTalk, WeCom, Telegram or a webhook when an agent's turn is done or fails, after it ran `minMinutes` or longer, and when a subscription account needs signing in again |
|
||||
| [page-harnessweight](packages/page-harnessweight) | Tracks in-flight request counts in memory and records tool-definition sizes and usage metadata after responses; never modifies requests |
|
||||
|
||||
Use the same plugin management commands as middleware:
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
*.log
|
||||
data/
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 webkubor
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,39 @@
|
||||
# HarnessWeight
|
||||
|
||||
A magpie page for comparing the agents behind your gateway: requests, input and output tokens, cache reads, failures, latency and estimated tool-definition size. The dashboard groups requests by agent, not model. A read-only gateway hook records tool counts and JSON sizes after each response and observes in-flight request counts in memory.
|
||||
|
||||
[Project, screenshots and demo](https://github.com/webkubor/harnessweight)
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
magpie plugin add @magpie-community/page-harnessweight
|
||||
```
|
||||
|
||||
Open **HarnessWeight** in magpie. Usage history is read from magpie's existing local ledger; tool-size samples accumulate after installation. The service listens on loopback, port **3496** by default. Change the `port` plugin option if that port is in use.
|
||||
|
||||
## Reading the dashboard
|
||||
|
||||
- **Input** includes fresh input, cache reads and cache writes. Cache rates and input tokens are usage measurements, not a currency amount; pricing depends on the model and provider.
|
||||
- **Tool-definition tokens** are an estimate: the serialized JSON byte count divided by 3.5. They are not measured with the model's tokenizer. Tool definitions may be cached; their size is not a direct bill.
|
||||
- **In flight** is derived from hook start and response callbacks. Missing callbacks may leave counts visible until expiry (15 minutes). It does not reflect activity outside the gateway.
|
||||
- **Session duration** is the span between the first and last recorded request for a session in the chosen period, including idle time. Sessions longer than six hours are excluded from duration aggregates; a missing session ID cannot be measured.
|
||||
- Protocols are inferred from recorded endpoints for the selected period. They are not a list of the agent's current configuration.
|
||||
|
||||
## Data and security
|
||||
|
||||
The sandboxed page asks for no bridge reads; it navigates to the plugin's local service. The service reads magpie's local usage ledger and queries its local gateway for agent display names and icon keys. The hook writes request metadata, tool names, counts and sizes locally. It does not store prompts, tool arguments or credentials and does not modify the request.
|
||||
|
||||
The local service validates Host and Origin and requires a per-process random token on data APIs. No telemetry is sent by this plugin.
|
||||
|
||||
Configuration options include `port`, `usageLog`, `dataDir`, `gatewayUrl` and `agents`; see the [project documentation](https://github.com/webkubor/harnessweight) for details.
|
||||
|
||||
## Development
|
||||
|
||||
```sh
|
||||
bun test
|
||||
```
|
||||
|
||||
Agent icons are from the community page-agent-office icon collection and LobeHub; see [app/icons/NOTICE](app/icons/NOTICE). Brand marks belong to their respective owners.
|
||||
|
||||
MIT © webkubor
|
||||
@@ -0,0 +1,495 @@
|
||||
// HarnessWeight — the interface. Served by the plugin's own service, so the
|
||||
// data is a same-origin fetch away.
|
||||
|
||||
import { explainFor, COLS, CARD_SORTS } from "./explain.js"
|
||||
import { pageLanguage, languageTags, translate } from "./i18n.mjs"
|
||||
|
||||
const $ = (id) => document.getElementById(id)
|
||||
const qs = new URLSearchParams(location.search)
|
||||
// magpie's window language arrives as ?lang= (page/boot.js); opened directly,
|
||||
// the browser's own language decides
|
||||
const LANG = pageLanguage(qs.get("lang") || navigator.language || "")
|
||||
const LOCALE = languageTags[LANG] || "en"
|
||||
const T = (key, params) => translate(LANG, key, params)
|
||||
document.documentElement.lang = LOCALE
|
||||
document.title = T("app.title")
|
||||
for (const el of document.querySelectorAll("[data-t]")) el.textContent = T(el.dataset.t)
|
||||
for (const el of document.querySelectorAll("[aria-label-t]")) el.setAttribute("aria-label", T(el.getAttribute("aria-label-t")))
|
||||
// sandboxed in magpie's frame the origin is opaque and storage throws
|
||||
const store = {
|
||||
get(k) { try { return localStorage.getItem(k) } catch { return null } },
|
||||
set(k, v) { try { localStorage.setItem(k, v) } catch {} },
|
||||
}
|
||||
|
||||
const state = {
|
||||
period: store.get("al.period") || "7d",
|
||||
clients: store.get("al.clients") === "1",
|
||||
sort: { key: "prompt", dir: -1 },
|
||||
cardSort: "prompt",
|
||||
toolSort: "avgBytes",
|
||||
activeAgents: new Map(),
|
||||
activityKnown: false,
|
||||
data: null,
|
||||
openAgent: null,
|
||||
}
|
||||
|
||||
// the service writes a per-start token into this page's HTML
|
||||
const TOKEN = document.querySelector('meta[name="harnessweight-token"]')?.content || ""
|
||||
let reloaded = false
|
||||
const sessionStorageSafe = () => reloaded || location.hash === "#r"
|
||||
function markReloaded() { reloaded = true; location.hash = "r" }
|
||||
|
||||
// ---------- formatting ----------
|
||||
const esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c])
|
||||
function short(n) {
|
||||
if (n == null || !Number.isFinite(n)) return "—"
|
||||
const a = Math.abs(n)
|
||||
if (a >= 1e9) return `${(n / 1e9).toFixed(2)}B`
|
||||
if (a >= 1e6) return `${(n / 1e6).toFixed(1)}M`
|
||||
if (a >= 1e3) return `${(n / 1e3).toFixed(1)}K`
|
||||
return String(Math.round(n))
|
||||
}
|
||||
const int = (n) => (n == null ? "—" : Math.round(n).toLocaleString(LOCALE))
|
||||
const pct = (x) => (x == null || !Number.isFinite(x) ? "—" : `${(x * 100).toFixed(1)}%`)
|
||||
function secs(ms) {
|
||||
if (!ms) return "—"
|
||||
return ms < 1000 ? `${Math.round(ms)}ms` : `${(ms / 1000).toFixed(1)}s`
|
||||
}
|
||||
function dur(ms) {
|
||||
if (ms == null || !Number.isFinite(ms)) return "—"
|
||||
const m = ms / 60000
|
||||
if (m < 1) return `${Math.round(ms / 1000)}${esc(T("dur.second"))}`
|
||||
if (m < 60) return `${m.toFixed(0)}${esc(T("dur.minute"))}`
|
||||
const h = m / 60
|
||||
if (h < 24) return `${h.toFixed(1)}${esc(T("dur.hour"))}`
|
||||
return `${(h / 24).toFixed(1)}${esc(T("dur.day"))}`
|
||||
}
|
||||
function when(at) {
|
||||
if (!at) return "—"
|
||||
return new Date(at).toLocaleString(LOCALE, { month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" })
|
||||
}
|
||||
|
||||
// ---------- agent mark: magpie's own icon, else the initial ----------
|
||||
const PALETTE = ["#17A9A2", "#F26B1D", "#6D5DFC", "#2B8AE2", "#C2410C", "#0E7C77", "#8B5CF6", "#64748B"]
|
||||
function hue(s) { let h = 0; for (const c of String(s)) h = (h * 31 + c.charCodeAt(0)) >>> 0; return PALETTE[h % PALETTE.length] }
|
||||
function mark(a, size = 20) {
|
||||
const initial = esc(String(a.name || a.agent || "?").trim().charAt(0).toUpperCase())
|
||||
const letter = `<span class="mark letter" style="width:${size}px;height:${size}px;font-size:${Math.round(size * 0.58)}px;background:${hue(a.agent)}">${initial}</span>`
|
||||
if (!a.icon) return letter
|
||||
return `<span class="mark" style="width:${size}px;height:${size}px"><img src="${a.icon.startsWith("data:") ? a.icon : "icons/" + encodeURIComponent(a.icon)}" alt="" width="${size}" height="${size}"></span>`
|
||||
}
|
||||
const label = (a) => esc(a.name || a.agent)
|
||||
|
||||
// ---------- explanations ----------
|
||||
// A small "?" that shows what a number means on hover or keyboard focus. The
|
||||
// text lives in explain.js; this only renders the marker.
|
||||
// A label with a small "?" next to it that opens the explanation on hover or
|
||||
// keyboard focus. The label itself stays plain text; only the marker is a
|
||||
// button, so a label never gets squeezed by the marker.
|
||||
function tip(key, label) {
|
||||
const e = explainFor(key, LANG)
|
||||
if (!e.title || e.title.startsWith("explain.")) return label ?? ""
|
||||
return `<span class="tipwrap">${label ?? ""}<span class="tip" tabindex="0" role="button" aria-expanded="false" aria-label="${esc(e.title)}: ${esc(e.body)}"><span class="tip-body" role="tooltip"><b>${esc(e.title)}</b>${esc(e.body)}</span></span></span>`
|
||||
}
|
||||
|
||||
// Render notes outside scroll containers so table and drawer overflow never clip them.
|
||||
let activeTip = null
|
||||
function closeTip() {
|
||||
if (!activeTip) return
|
||||
activeTip.trigger.setAttribute('aria-expanded', 'false')
|
||||
activeTip.bubble.remove()
|
||||
activeTip = null
|
||||
}
|
||||
function wireTips(root) {
|
||||
for (const t of root.querySelectorAll('.tip:not([data-wired])')) {
|
||||
t.dataset.wired = '1'
|
||||
const open = () => {
|
||||
if (activeTip?.trigger === t) return
|
||||
closeTip()
|
||||
const bubble = document.createElement('div')
|
||||
bubble.className = 'floating-tip'
|
||||
bubble.setAttribute('aria-hidden', 'true') // trigger already contains the full accessible label
|
||||
bubble.innerHTML = t.querySelector('.tip-body').innerHTML
|
||||
document.body.append(bubble)
|
||||
const r = t.getBoundingClientRect(), b = bubble.getBoundingClientRect()
|
||||
const left = Math.max(8, Math.min(window.innerWidth - b.width - 8, r.left + r.width / 2 - b.width / 2))
|
||||
const top = r.top >= b.height + 10 ? r.top - b.height - 8 : Math.min(window.innerHeight - b.height - 8, r.bottom + 8)
|
||||
bubble.style.left = `${left}px`
|
||||
bubble.style.top = `${Math.max(8, top)}px`
|
||||
t.setAttribute('aria-expanded', 'true')
|
||||
activeTip = {trigger:t, bubble}
|
||||
}
|
||||
const close = () => { if (activeTip?.trigger === t) closeTip() }
|
||||
t.addEventListener('mouseenter', open)
|
||||
t.addEventListener('mouseleave', close)
|
||||
t.addEventListener('focus', open)
|
||||
t.addEventListener('blur', close)
|
||||
t.addEventListener('click', e => { e.stopPropagation(); open() })
|
||||
t.addEventListener('keydown', e => {
|
||||
e.stopPropagation()
|
||||
if (e.key === 'Escape') { close(); t.blur() }
|
||||
if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); activeTip?.trigger === t ? close() : open() }
|
||||
})
|
||||
}
|
||||
}
|
||||
document.addEventListener('scroll', closeTip, true)
|
||||
window.addEventListener('resize', closeTip)
|
||||
document.addEventListener('pointerdown', e => { if (!e.target.closest('.tip')) closeTip() })
|
||||
|
||||
// Only request-start / response-finish hook observations drive activity.
|
||||
// Completed-request timestamps must never masquerade as in-flight calls.
|
||||
function isLive(a) {
|
||||
return state.activityKnown && (state.activeAgents.get(a.agent) || 0) > 0
|
||||
}
|
||||
function activityBadge(agent) {
|
||||
const count = state.activeAgents.get(agent) || 0
|
||||
return `<span class="live-badge">${tip("live", esc(T("activity.callsInFlight", { n: count })))}</span>`
|
||||
}
|
||||
async function refreshActivity() {
|
||||
if (document.hidden) return
|
||||
try {
|
||||
const res = await fetch(`/api/activity?k=${encodeURIComponent(TOKEN)}`, {cache:'no-store', signal:AbortSignal.timeout(4000)})
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
||||
const data = await res.json()
|
||||
state.activeAgents = new Map(data.agents.map(a => [a.agent, a.count]))
|
||||
state.activityKnown = data.available === true
|
||||
if (!state.activityKnown) state.activeAgents.clear()
|
||||
} catch {
|
||||
state.activityKnown = false
|
||||
state.activeAgents.clear()
|
||||
}
|
||||
$('activityInfo').textContent = state.activityKnown
|
||||
? T("activity.liveHint")
|
||||
: T("activity.unavailableHint")
|
||||
for (const card of document.querySelectorAll('.card[data-agent]')) {
|
||||
const active = state.activityKnown && (state.activeAgents.get(card.dataset.agent) || 0) > 0
|
||||
card.classList.toggle('live', active)
|
||||
const head = card.querySelector('.card-head')
|
||||
const old = head.querySelector('.live-badge')
|
||||
const count = state.activeAgents.get(card.dataset.agent) || 0
|
||||
if (old && old.dataset.count === String(count)) continue
|
||||
old?.remove()
|
||||
if (active) {
|
||||
head.insertAdjacentHTML('beforeend', activityBadge(card.dataset.agent))
|
||||
const badge = head.querySelector('.live-badge')
|
||||
badge.dataset.count = String(count)
|
||||
wireTips(badge)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- sparkline ----------
|
||||
function spark(series, key, cls = "") {
|
||||
if (!series || series.length < 2) return ""
|
||||
const w = 240, h = cls ? 80 : 34, pad = 2
|
||||
const vals = series.map((d) => d[key])
|
||||
const max = Math.max(...vals, 1)
|
||||
const pts = vals.map((v, i) => [pad + (i * (w - pad * 2)) / (vals.length - 1), h - pad - (v / max) * (h - pad * 2)])
|
||||
const line = pts.map((p, i) => `${i ? "L" : "M"}${p[0].toFixed(1)} ${p[1].toFixed(1)}`).join(" ")
|
||||
const area = `${line} L${pts.at(-1)[0].toFixed(1)} ${h} L${pts[0][0].toFixed(1)} ${h} Z`
|
||||
return `<svg class="spark ${cls}" viewBox="0 0 ${w} ${h}" preserveAspectRatio="none" aria-hidden="true"><path class="a" d="${area}"/><path class="l" d="${line}"/></svg>`
|
||||
}
|
||||
|
||||
// ---------- paint ----------
|
||||
function paint() {
|
||||
const d = state.data
|
||||
$("state").hidden = true
|
||||
if (!d.agents.length) {
|
||||
for (const id of ["insights", "kpis", "cards", "tools"]) $(id).innerHTML = ""
|
||||
$("table").innerHTML = ""
|
||||
showState(T("state.noAgents"))
|
||||
return
|
||||
}
|
||||
paintStatus(d)
|
||||
paintInsights(d)
|
||||
paintKpis(d)
|
||||
paintCardSort()
|
||||
paintCards(d)
|
||||
paintTable(d)
|
||||
paintTools(d)
|
||||
wireTips(document)
|
||||
const s = d.sources || {}
|
||||
$("sources").textContent = T("sources.summary", { usageRows: int(s.usageRows), toolRows: int(s.toolRows), time: new Date(d.generatedAt).toLocaleTimeString(LOCALE) })
|
||||
if (state.openAgent) openDetail(state.openAgent, false)
|
||||
}
|
||||
|
||||
function ago(t) {
|
||||
if (!t) return T("time.none")
|
||||
const s = Math.max(0, (Date.now() - t) / 1000)
|
||||
if (s < 60) return T("time.secondsAgo", { n: Math.round(s) })
|
||||
if (s < 3600) return T("time.minutesAgo", { n: Math.round(s / 60) })
|
||||
if (s < 86400) return T("time.hoursAgo", { n: Math.round(s / 3600) })
|
||||
return T("time.daysAgo", { n: Math.round(s / 86400) })
|
||||
}
|
||||
function paintStatus(d) {
|
||||
const fresh = d.lastTool && Date.now() - d.lastTool < 15 * 60e3
|
||||
const el = $("status")
|
||||
el.className = "status " + (fresh ? "live" : d.lastTool ? "idle" : "wait")
|
||||
el.textContent = fresh ? T("status.collecting", { usage: ago(d.lastUsage), tool: ago(d.lastTool) })
|
||||
: d.lastTool ? T("status.stale", { tool: ago(d.lastTool) })
|
||||
: T("status.waiting")
|
||||
}
|
||||
|
||||
function paintInsights(d) {
|
||||
$("insights").innerHTML = d.insights
|
||||
.map((i) => `<div class="insight${i.kind === "volume" || i.kind === "errors" ? " hot" : ""}">${esc(i.text)}</div>`)
|
||||
.join("")
|
||||
}
|
||||
|
||||
function paintKpis(d) {
|
||||
const t = d.totals
|
||||
const items = [
|
||||
[T("kpi.inputTokens"), short(t.prompt), T("kpi.requests", { count: int(t.calls) }), "prompt"],
|
||||
[T("kpi.cacheRate"), pct(t.cacheRate), T("kpi.fullPriceOf", { value: short(t.fullPrice) }), "cacheRate"],
|
||||
[T("kpi.outputTokens"), short(t.out), T("kpi.avgPerCall", { value: short(t.calls ? t.out / t.calls : 0) }), "out"],
|
||||
[T("kpi.failed"), int(t.failed), pct(t.calls ? t.failed / t.calls : 0), "errorRate"],
|
||||
[T("kpi.agents"), int(d.agents.length), d.hiddenClients ? T("kpi.hiddenClients", { count: int(d.hiddenClients) }) : T("kpi.clients"), null],
|
||||
]
|
||||
if (t.credits > 0) items.splice(4, 0, [T("kpi.credits"), t.credits.toFixed(2), T("kpi.creditsNote")])
|
||||
$("kpis").innerHTML = items
|
||||
.map(([k, v, s, tipKey]) => `<div class="kpi"><div class="k">${tipKey ? tip(tipKey, k) : k}</div><div class="v num">${v}</div><div class="s">${esc(s)}</div></div>`)
|
||||
.join("")
|
||||
}
|
||||
|
||||
function paintCards(d) {
|
||||
const max = Math.max(...d.agents.map((a) => a.prompt), 1)
|
||||
const sorted = [...d.agents].sort((x, y) => cardVal(y, state.cardSort) - cardVal(x, state.cardSort))
|
||||
$("cards").innerHTML = sorted
|
||||
.map((a, i) => {
|
||||
const w = (a.prompt / max) * 100
|
||||
const fullW = a.prompt ? (a.fullPrice / a.prompt) * w : 0
|
||||
const top1 = a.prompt === max && d.agents.length > 1
|
||||
const live = isLive(a)
|
||||
const proto = a.protocols?.[0]?.name
|
||||
return `<div class="card${top1 ? " top1" : ""}${live ? " live" : ""}" tabindex="0" role="button" data-agent="${esc(a.agent)}" aria-label="${esc(T("card.detailsAria", { name: a.name || a.agent }))}">
|
||||
<div class="card-head"><span class="card-name">${mark(a, 22)}${label(a)}</span>${live ? activityBadge(a.agent) : ""}${top1 ? `<span class="tag">${esc(T("card.topSpender"))}</span>` : ""}</div>
|
||||
<div class="card-big num">${short(a.prompt)}<small>${esc(T("card.inputTokens"))}</small></div>
|
||||
<div class="stack" title="${esc(T("card.stackLegend"))}"><span class="cached" style="width:${(w - fullW).toFixed(2)}%"></span><span class="full" style="width:${fullW.toFixed(2)}%"></span></div>
|
||||
<div class="card-meta">
|
||||
<div><b class="num">${pct(a.cacheRate)}</b>${tip("cacheRate", esc(T("col.cacheRate")))}</div>
|
||||
<div><b class="num">${short(a.avgPrompt)}</b>${tip("avgPrompt", esc(T("col.avgPrompt")))}</div>
|
||||
<div><b class="num ${a.errorRate >= 0.03 ? "bad" : ""}">${pct(a.errorRate)}</b>${tip("errorRate", esc(T("col.errorRate")))}</div>
|
||||
</div>
|
||||
${proto ? `<div class="card-foot"><span class="proto" title="${esc(proto)}">${esc(proto)}</span>${a.session?.median ? `<span class="dur" title="${esc(T("card.sessionMedianTitle"))}">${dur(a.session.median)}</span>` : ""}</div>` : ""}
|
||||
${spark(a.series, "prompt")}
|
||||
</div>`
|
||||
})
|
||||
.join("")
|
||||
}
|
||||
|
||||
const val = (a, k) => {
|
||||
if (k === "toolTokens") return a.tools?.avgTokens ?? -1
|
||||
if (k === "agent") return a.name || a.agent
|
||||
if (k === "protocol") return a.protocols?.[0]?.name || ""
|
||||
if (k === "session") return a.session?.median ?? -1
|
||||
return a[k]
|
||||
}
|
||||
|
||||
const cardVal = (a, k) => (k === "toolTokens" ? a.tools?.avgTokens ?? -1 : a[k] ?? -1)
|
||||
|
||||
function paintCardSort() {
|
||||
const box = $("cardSort")
|
||||
if (!box) return
|
||||
box.innerHTML = CARD_SORTS.map(([k, nameKey]) =>
|
||||
`<button class="pill${state.cardSort === k ? " on" : ""}" data-sort="${k}" aria-pressed="${state.cardSort === k}">${esc(T(nameKey))}</button>`).join("")
|
||||
}
|
||||
|
||||
function paintTable(d) {
|
||||
const { key, dir } = state.sort
|
||||
const rows = [...d.agents].sort((x, y) => {
|
||||
const a = val(x, key), b = val(y, key)
|
||||
return typeof a === "string" ? a.localeCompare(b) * dir : ((a ?? 0) - (b ?? 0)) * dir
|
||||
})
|
||||
const topAgent = d.agents[0]?.agent
|
||||
const head = COLS.map(([k, nameKey, n, tipKey]) => { const name = esc(T(nameKey)); return `<th class="${n ? "n" : ""}" data-key="${k}" ${k === key ? `aria-sort="${dir < 0 ? "descending" : "ascending"}"` : ""} tabindex="0">${tipKey ? tip(tipKey, name) : name}</th>` }).join("")
|
||||
const body = rows
|
||||
.map((a) => `<tr tabindex="0" data-agent="${esc(a.agent)}">
|
||||
<td class="agent"><span class="who">${mark(a, 18)}${label(a)}${a.agent === topAgent && d.agents.length > 1 ? `<span class="dot hot" title="${esc(T("table.topSpenderTitle"))}"></span>` : ""}</span></td>
|
||||
<td class="n">${int(a.calls)}</td>
|
||||
<td class="n">${short(a.prompt)}</td>
|
||||
<td class="n">${short(a.avgPrompt)}</td>
|
||||
<td class="n">${pct(a.cacheRate)}</td>
|
||||
<td class="n">${short(a.fullPrice)}</td>
|
||||
<td class="n">${short(a.out)}</td>
|
||||
<td class="n ${a.errorRate >= 0.03 ? "bad" : ""}">${pct(a.errorRate)}</td>
|
||||
<td class="n">${secs(a.p50ttft)}</td>
|
||||
<td class="n">${secs(a.p50ms)}</td>
|
||||
<td class="n">${a.tools ? short(a.tools.avgTokens) : "—"}</td>
|
||||
<td class="n proto-cell" title="${esc(a.protocols?.map((p) => p.name).join(", ")) || ""}">${a.protocols?.length ? esc(a.protocols[0].name) : "—"}</td>
|
||||
<td class="n">${a.session?.median ? dur(a.session.median) : "—"}</td>
|
||||
</tr>`)
|
||||
.join("")
|
||||
$("table").innerHTML = `<thead><tr>${head}</tr></thead><tbody>${body}</tbody>`
|
||||
}
|
||||
|
||||
function paintTools(d) {
|
||||
const withTools = d.agents.filter((a) => a.tools)
|
||||
if (!withTools.length) {
|
||||
$("toolsHint").textContent = T("tools.hint")
|
||||
$("tools").innerHTML = `<div class="waiting">${esc(T("tools.empty"))}</div>`
|
||||
return
|
||||
}
|
||||
const sorted = [...withTools].sort((a, b) => (b.tools[state.toolSort] ?? 0) - (a.tools[state.toolSort] ?? 0))
|
||||
const max = sorted[0].tools.avgBytes || 1
|
||||
$("toolsHint").innerHTML = `${esc(T("tools.sampling", { since: when(d.toolsSince), samples: int(d.toolSamples) }))}
|
||||
<span class="sortbar inline">${[["avgBytes", T("tools.sortBytes")], ["avgTokens", T("tools.sortTokens")], ["avgCount", T("tools.sortCount")], ["shareOfPrompt", T("tools.sortShare")]]
|
||||
.map(([k, n]) => `<button class="pill${state.toolSort === k ? " on" : ""}" data-tsort="${k}" aria-pressed="${state.toolSort === k}">${n}</button>`).join("")}</span>`
|
||||
$("tools").innerHTML = `<div class="table-wrap" style="padding:4px 16px">${sorted
|
||||
.map((a, i) => `<div class="tool-row">
|
||||
<div class="agent who">${mark(a, 18)}<b>${label(a)}</b></div>
|
||||
<div class="tool-track"><div class="tool-fill${i === 0 && sorted.length > 1 ? " hot" : ""}" style="width:${((a.tools.avgBytes / max) * 100).toFixed(1)}%"></div></div>
|
||||
<div class="tool-val num">${esc(a.tools.shareOfPrompt != null ? T("tools.perAgentShare", { count: Math.round(a.tools.avgCount), tokens: short(a.tools.avgTokens), share: pct(a.tools.shareOfPrompt) }) : T("tools.perAgent", { count: Math.round(a.tools.avgCount), tokens: short(a.tools.avgTokens) }))}</div>
|
||||
</div>`)
|
||||
.join("")}</div>`
|
||||
}
|
||||
|
||||
// ---------- detail drawer ----------
|
||||
function distribution(items, total) {
|
||||
if (!items?.length) return `<p class="hint">${esc(T("detail.noRecords"))}</p>`
|
||||
return items.map(m => `<div class="dist-row"><div><span>${esc(m.label || m.name)}</span><span class="num">${esc(T("detail.countPct", { count: int(m.count), pct: pct(total ? m.count / total : 0) }))}</span></div><div class="dist-track"><span style="width:${Math.min(100, total ? m.count / total * 100 : 0)}%"></span></div></div>`).join("")
|
||||
}
|
||||
|
||||
function openDetail(agent, focus = true) {
|
||||
const a = state.data?.agents.find(x => x.agent === agent)
|
||||
if (!a) return closeDetail()
|
||||
const previousDetails = !focus ? [...$("detail").querySelectorAll('details')].map(d => d.open) : []
|
||||
const previousQuery = !focus ? $("detail").querySelector('.tool-search input')?.value || '' : ''
|
||||
state.openAgent = agent
|
||||
const modelCount = a.models.reduce((n,m) => n + m.count, 0)
|
||||
const protoNames = {anthropic:'Anthropic Messages', responses:'OpenAI Responses', chat:'OpenAI Chat Completions', gemini:'Google Gemini', other:T('detail.otherProtocol')}
|
||||
const protocolCount = a.protocols.reduce((n,p) => n + p.count, 0)
|
||||
const toolNames = a.tools?.names || []
|
||||
const cache = Math.max(0, Math.min(100, a.cacheRate * 100))
|
||||
const failure = a.calls ? a.failed / a.calls : 0
|
||||
$("detail").innerHTML = `<div class="detail detail-guide">
|
||||
<header class="detail-heading"><h3 class="who">${mark(a,32)}${label(a)}</h3><p class="hint">${when(a.first)} — ${when(a.last)} · ${esc(T('detail.selectedPeriod'))}</p></header>
|
||||
<div class="detail-summary"><strong>${esc(T('detail.summaryRequests', { calls: int(a.calls) }))}</strong><p>${esc(T('detail.summaryBody', { avg: short(a.avgPrompt), cache: pct(a.cacheRate), failed: int(a.failed), cancelled: int(a.cancelled) }))}</p><small>${esc(T('detail.summaryNote'))}</small></div>
|
||||
<section class="sec"><h4>${esc(T('detail.inputTitle'))} ${tip('prompt')}</h4>
|
||||
<div class="detail-metrics"><div><span>${esc(T('detail.totalInput'))}</span><b>${short(a.prompt)}</b></div><div><span>${esc(T('detail.avgInput'))}</span><b>${short(a.avgPrompt)}</b></div><div><span>${esc(T('detail.generatedOutput'))}</span><b>${short(a.out)}</b></div></div>
|
||||
${a.prompt ? `<div class="composition" aria-label="${esc(T('explain.cacheRate.title'))} ${pct(a.cacheRate)}"><span style="width:${cache}%"></span><span style="width:${100-cache}%"></span></div>
|
||||
<div class="composition-key"><span>● ${esc(T('detail.cacheReads'))} ${short(a.cacheRead)} · ${pct(a.cacheRate)}</span><span>● ${esc(T('detail.nonCacheReads'))} ${short(a.fullPrice)}</span></div>` : `<p class="empty-note">${esc(T('detail.noInput'))}</p>`}
|
||||
<p class="hint">${esc(T('detail.cacheNote'))}</p>
|
||||
<details><summary>${esc(T('detail.inputBreakdown'))}</summary><dl class="detail-facts"><dt>${esc(T('detail.freshInput'))}</dt><dd>${short(a.in)}</dd><dt>${esc(T('detail.cacheWrite'))}</dt><dd>${short(a.cacheWrite)}</dd>${a.credits > 0 ? `<dt>${esc(T('detail.credits'))}</dt><dd>${a.credits.toFixed(2)} credits</dd>` : ''}</dl></details>
|
||||
</section>
|
||||
<section class="sec"><h4>${esc(T('detail.latencyTitle'))}</h4><div class="detail-metrics"><div><span>${esc(T('detail.ttft'))} ${tip('p50ttft')}</span><b>${secs(a.p50ttft)}</b></div><div><span>${esc(T('detail.fullResponse'))} ${tip('p50ms')}</span><b>${secs(a.p50ms)}</b></div><div><span>${esc(T('detail.failureRate'))} ${tip('errorRate')}</span><b>${pct(failure)}</b></div></div><p class="hint">${esc(T('detail.latencyNote'))}</p></section>
|
||||
<section class="sec"><h4>${esc(T('detail.toolsTitle'))} ${tip('toolTokens')}</h4>${a.tools ? `<div class="detail-metrics"><div><span>${esc(T('detail.toolsPerRequest'))}</span><b>${esc(T('detail.toolsPerRequestValue', { count: Math.round(a.tools.avgCount) }))}</b></div><div><span>${esc(T('detail.toolSize'))}</span><b>≈${short(a.tools.avgTokens)}</b></div><div><span>${esc(T('detail.validSamples'))}</span><b>${esc(T('detail.validSamplesValue', { count: int(a.tools.samples) }))}</b></div></div><p>${esc(T('detail.toolsNote'))}</p><p class="hint">${esc(T('detail.toolsCaveat', { samples: int(a.tools.samples), calls: int(a.calls) }))}</p><details class="tool-inventory"><summary>${esc(T('detail.toolInventory'))}</summary><label class="tool-search">${esc(T('detail.toolFilter'))}<input type="search" placeholder="${esc(T('detail.toolSearchPlaceholder'))}" aria-label="${esc(T('detail.toolFilter'))}"></label><div class="chips tool-list">${toolNames.map(t=>`<span class="chip mono" data-tool-name="${esc(t.name.toLowerCase())}">${esc(t.name)}</span>`).join('')}</div><p class="hint">${esc(T('detail.toolInventoryNote'))}</p></details>` : `<p class="empty-note">${esc(T('detail.toolsEmpty'))}</p>`}</section>
|
||||
<section class="sec"><h4>${esc(T('detail.modelsTitle'))}</h4><p class="hint">${esc(T('detail.modelsNote', { count: a.models.length }))}</p>${distribution(a.models,a.calls)}${modelCount < a.calls ? `<p class="hint">${esc(T('detail.remaining', { count: int(a.calls-modelCount) }))}</p>` : ''}</section>
|
||||
<section class="sec"><h4>${esc(T('detail.protocolsTitle'))} ${tip('protocol')}</h4><p class="hint">${esc(T('detail.protocolsNote'))}</p>${distribution(a.protocols.map(p=>({...p,label:protoNames[p.name] || p.name})),a.calls)}${protocolCount < a.calls ? `<p class="hint">${esc(T('detail.remaining', { count: int(a.calls-protocolCount) }))}</p>` : ''}</section>
|
||||
<section class="sec"><h4>${esc(T('detail.sessionTitle'))} ${tip('sessionMedian')}</h4>${a.session?.measured ? `<div class="detail-metrics"><div><span>${esc(T('detail.medianSpan'))}</span><b>${dur(a.session.median)}</b></div><div><span>${esc(T('detail.p90Span'))}</span><b>${dur(a.session.p90)}</b></div><div><span>${esc(T('detail.measuredSessions'))}</span><b>${int(a.session.measured)}</b></div></div><p class="hint">${esc(T('detail.sessionNote', { open: int(a.session.open || 0) }))}</p>` : `<div class="empty-note"><strong>${esc(T('detail.sessionUnavailable'))}</strong><p>${esc(T('detail.sessionEmpty'))}</p></div>`}</section>
|
||||
<section class="sec"><h4>${esc(T('detail.trendTitle'))}</h4>${spark(a.series,'prompt','big') || `<p class="hint">${esc(T('detail.trendEmpty'))}</p>`}<p class="hint">${esc(T('detail.trendNote'))}</p></section>
|
||||
</div>`
|
||||
wireTips($("detail"))
|
||||
$("detail").querySelector('.tool-search input')?.addEventListener('input', e => {
|
||||
const term = e.target.value.trim().toLowerCase()
|
||||
for (const item of $("detail").querySelectorAll('[data-tool-name]')) item.hidden = !item.dataset.toolName.includes(term)
|
||||
})
|
||||
if (!focus) {
|
||||
$("detail").querySelectorAll('details').forEach((d,i) => { d.open = !!previousDetails[i] })
|
||||
const input = $("detail").querySelector('.tool-search input')
|
||||
if (input) { input.value = previousQuery; input.dispatchEvent(new Event('input')) }
|
||||
}
|
||||
const dr = $("drawer")
|
||||
dr.classList.add("open")
|
||||
dr.setAttribute("aria-hidden", "false")
|
||||
$("scrim").hidden = false
|
||||
if (focus) { dr.scrollTop = 0; dr.focus() }
|
||||
}
|
||||
function closeDetail() {
|
||||
state.openAgent = null
|
||||
$("drawer").classList.remove("open")
|
||||
$("drawer").setAttribute("aria-hidden", "true")
|
||||
$("scrim").hidden = true
|
||||
}
|
||||
|
||||
// ---------- loading ----------
|
||||
function showState(text, err = false) {
|
||||
$("state").hidden = false
|
||||
$("state").className = err ? "state err" : "state"
|
||||
$("state").textContent = text
|
||||
}
|
||||
|
||||
async function load() {
|
||||
if (!state.data) $("cards").innerHTML = '<div class="skeleton"></div><div class="skeleton"></div><div class="skeleton"></div>'
|
||||
try {
|
||||
const p = new URLSearchParams({ period: state.period, tz: String(new Date().getTimezoneOffset()) })
|
||||
if (state.clients) p.set("clients", "1")
|
||||
p.set("lang", LANG)
|
||||
p.set("k", TOKEN)
|
||||
const res = await fetch(`/api/summary?${p}`, { cache: "no-store" })
|
||||
if (res.status === 403 && !sessionStorageSafe("al.reloaded")) { markReloaded(); return location.reload() }
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
||||
state.data = await res.json()
|
||||
paint()
|
||||
} catch (e) {
|
||||
showState(T("state.loadError", { message: e.message }), true)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- events ----------
|
||||
function selectPeriod() {
|
||||
for (const b of $("periods").children) b.setAttribute("aria-selected", String(b.dataset.period === state.period))
|
||||
}
|
||||
$("periods").addEventListener("click", (e) => {
|
||||
const b = e.target.closest("button[data-period]")
|
||||
if (!b || b.dataset.period === state.period) return
|
||||
state.period = b.dataset.period
|
||||
store.set("al.period", state.period)
|
||||
selectPeriod()
|
||||
load()
|
||||
})
|
||||
$("clients").checked = state.clients
|
||||
$("clients").addEventListener("change", (e) => {
|
||||
state.clients = e.target.checked
|
||||
store.set("al.clients", state.clients ? "1" : "0")
|
||||
load()
|
||||
})
|
||||
const pick = (e) => e.target.closest("[data-agent]")?.dataset.agent
|
||||
$("cards").addEventListener("click", (e) => { const a = pick(e); if (a) openDetail(a) })
|
||||
$("cardSort").addEventListener("click", (e) => {
|
||||
const b = e.target.closest("button[data-sort]")
|
||||
if (!b || b.dataset.sort === state.cardSort) return
|
||||
state.cardSort = b.dataset.sort
|
||||
paintCardSort()
|
||||
paintCards(state.data)
|
||||
wireTips($("cards"))
|
||||
})
|
||||
$("toolsHint").addEventListener("click", (e) => {
|
||||
const b = e.target.closest("button[data-tsort]")
|
||||
if (!b) return
|
||||
state.toolSort = b.dataset.tsort
|
||||
paintTools(state.data)
|
||||
})
|
||||
$("table").addEventListener("click", (e) => {
|
||||
const th = e.target.closest("th[data-key]")
|
||||
if (th) {
|
||||
const k = th.dataset.key
|
||||
state.sort = { key: k, dir: state.sort.key === k ? -state.sort.dir : k === "agent" ? 1 : -1 }
|
||||
paintTable(state.data)
|
||||
wireTips($("table"))
|
||||
return
|
||||
}
|
||||
const a = pick(e)
|
||||
if (a) openDetail(a)
|
||||
})
|
||||
for (const id of ["cards", "table"]) {
|
||||
$(id).addEventListener("keydown", (e) => {
|
||||
if (e.key !== "Enter" && e.key !== " ") return
|
||||
const th = e.target.closest("th[data-key]")
|
||||
if (th) { e.preventDefault(); return th.click() }
|
||||
const a = pick(e)
|
||||
if (a) { e.preventDefault(); openDetail(a) }
|
||||
})
|
||||
}
|
||||
$("close").addEventListener("click", closeDetail)
|
||||
$("scrim").addEventListener("click", closeDetail)
|
||||
document.addEventListener("keydown", (e) => { if (e.key === "Escape" && state.openAgent) closeDetail() })
|
||||
|
||||
selectPeriod()
|
||||
await load()
|
||||
await refreshActivity()
|
||||
setInterval(load, 60_000)
|
||||
async function pollActivity() {
|
||||
await refreshActivity()
|
||||
setTimeout(pollActivity, 2000)
|
||||
}
|
||||
setTimeout(pollActivity, 2000)
|
||||
@@ -0,0 +1,50 @@
|
||||
// What every number on this page means, in one place. Each entry becomes a
|
||||
// small "?" that shows the explanation on hover or focus — so a reader who
|
||||
// does not know the term can find out without leaving the page.
|
||||
//
|
||||
// The explanations name what is measured, where the number comes from, and
|
||||
// what makes it misleading. Anything that is an estimate says so.
|
||||
//
|
||||
// The wording itself lives in i18n.mjs, beside the rest of the interface
|
||||
// text; this file only says which explanation exists and where it goes.
|
||||
|
||||
import { translate } from "./i18n.mjs"
|
||||
|
||||
// The explanation for one metric, in the page's language.
|
||||
export function explainFor(key, lang) {
|
||||
return {
|
||||
title: translate(lang, `explain.${key}.title`),
|
||||
body: translate(lang, `explain.${key}.body`),
|
||||
}
|
||||
}
|
||||
|
||||
// The order the table uses, with the tooltip key for each column.
|
||||
// [key, label key, is numeric, tooltip key]
|
||||
export const COLS = [
|
||||
["agent", "col.agent", false, null],
|
||||
["calls", "col.calls", true, "calls"],
|
||||
["prompt", "col.prompt", true, "prompt"],
|
||||
["avgPrompt", "col.avgPrompt", true, "avgPrompt"],
|
||||
["cacheRate", "col.cacheRate", true, "cacheRate"],
|
||||
["fullPrice", "col.fullPrice", true, "fullPrice"],
|
||||
["out", "col.out", true, "out"],
|
||||
["errorRate", "col.errorRate", true, "errorRate"],
|
||||
["p50ttft", "col.p50ttft", true, "p50ttft"],
|
||||
["p50ms", "col.p50ms", true, "p50ms"],
|
||||
["toolTokens", "col.toolTokens", true, "toolTokens"],
|
||||
["protocol", "col.protocol", false, "protocol"],
|
||||
["session", "col.session", true, "sessionMedian"],
|
||||
]
|
||||
|
||||
// The card order: what the cards can be sorted by.
|
||||
// [key, label key, tooltip key]
|
||||
export const CARD_SORTS = [
|
||||
["prompt", "sort.prompt", "prompt"],
|
||||
["avgPrompt", "col.avgPrompt", "avgPrompt"],
|
||||
["cacheRate", "col.cacheRate", "cacheRate"],
|
||||
["fullPrice", "col.fullPrice", "fullPrice"],
|
||||
["errorRate", "col.errorRate", "errorRate"],
|
||||
["p50ms", "col.p50ms", "p50ms"],
|
||||
["p50ttft", "col.p50ttft", "p50ttft"],
|
||||
["toolTokens", "sort.toolTokens", "toolTokens"],
|
||||
]
|
||||
@@ -0,0 +1,456 @@
|
||||
// HarnessWeight's interface text, in one place.
|
||||
//
|
||||
// The Chinese is the source of truth for the copy; every other language is a
|
||||
// table beside it. The page asks for a key, never for a language-specific
|
||||
// string, so a missing translation falls back to English instead of leaking
|
||||
// Chinese into an English UI.
|
||||
//
|
||||
// This module is shared: the browser loads it as a module (app.js imports it)
|
||||
// and the service imports the same file to write the insights sentences, so
|
||||
// both sides speak the same language and there is only one copy of the copy.
|
||||
//
|
||||
// No Node and no browser APIs here on purpose — it must load in both.
|
||||
|
||||
export const languageTags = { en: "en", zh: "zh-CN", "zh-TW": "zh-TW", ja: "ja-JP" }
|
||||
|
||||
// magpie hands the page a language tag ("zh-CN", "en-US", "ja-JP", …).
|
||||
// Anything we have no table for reads English.
|
||||
export function languageFor(value = "") {
|
||||
const tag = String(value).toLowerCase().replaceAll("_", "-")
|
||||
if (/^zh-(tw|hk|mo|hant)\b/.test(tag)) return "zh-TW"
|
||||
if (/^zh(?:-|$)/.test(tag)) return "zh"
|
||||
if (/^ja(?:-|$)/.test(tag)) return "ja"
|
||||
return "en"
|
||||
}
|
||||
|
||||
const en = {
|
||||
// ---- app shell ----
|
||||
"app.title": "HarnessWeight · agent harness token weight",
|
||||
"status.loading": "Loading…",
|
||||
"header.sub": "Behind one gateway: how many tokens each agent harness reads, how many hit the cache, how many calls fail, and how heavy the tool definitions it resends every turn are.",
|
||||
"aria.periods": "Period",
|
||||
"period.today": "Today",
|
||||
"period.7d": "7 days",
|
||||
"period.30d": "30 days",
|
||||
"clients.toggle": "Include scripts and internal requests",
|
||||
"aria.insights": "Insights",
|
||||
"aria.overview": "Overview",
|
||||
"aria.cardSort": "Sort cards",
|
||||
"aria.close": "Close",
|
||||
"footer.localOnly": "Data is read locally and never uploaded.",
|
||||
|
||||
// ---- sections ----
|
||||
"cards.title": "Where your tokens go",
|
||||
"cards.hint": "Each card is an agent. Bar length is total input tokens; the darker segment combines fresh input and cache writes. Pricing depends on the provider.",
|
||||
"activity.connecting": "Connecting to live request status…",
|
||||
"table.title": "Compare metrics",
|
||||
"table.hint": "Click a column header to sort, or a row for details.",
|
||||
"tools.title": "Tool definition weight",
|
||||
"tools.hint": "Agents resend their tool list with every request, and that counts towards input tokens too.",
|
||||
|
||||
// ---- formatting ----
|
||||
"dur.second": "s",
|
||||
"dur.minute": "m",
|
||||
"dur.hour": "h",
|
||||
"dur.day": "d",
|
||||
"unit.times": "times",
|
||||
"unit.items": "items",
|
||||
|
||||
// ---- status and sources ----
|
||||
"time.none": "not yet",
|
||||
"time.secondsAgo": "{n}s ago",
|
||||
"time.minutesAgo": "{n}m ago",
|
||||
"time.hoursAgo": "{n}h ago",
|
||||
"time.daysAgo": "{n}d ago",
|
||||
"status.collecting": "Collecting · last request {usage} · last tool sample {tool}",
|
||||
"status.stale": "No new sample in 15 minutes · last one {tool} (use an agent and it resumes)",
|
||||
"status.waiting": "Hook installed, waiting for the first request through the gateway",
|
||||
"sources.summary": "{usageRows} usage rows · {toolRows} tool samples · updated at {time}",
|
||||
"state.noAgents": "No agent requests were recorded in this period. Send a request from any agent through the gateway, then refresh.",
|
||||
"state.loadError": "Could not read the data: {message}. Make sure the magpie gateway is running, then refresh.",
|
||||
|
||||
// ---- activity ----
|
||||
"activity.callsInFlight": "{n} in flight",
|
||||
"activity.liveHint": "An animated border means the gateway observed an in-flight request for this agent.",
|
||||
"activity.unavailableHint": "Live request status is unavailable. An unlit border does not mean the agent is idle.",
|
||||
|
||||
// ---- overview tiles ----
|
||||
"kpi.inputTokens": "Input tokens",
|
||||
"kpi.cacheRate": "Cache hit rate",
|
||||
"kpi.outputTokens": "Output tokens",
|
||||
"kpi.failed": "Failed",
|
||||
"kpi.agents": "Agents",
|
||||
"kpi.credits": "credits",
|
||||
"kpi.requests": "{count} requests",
|
||||
"kpi.fullPriceOf": "{value} at full price",
|
||||
"kpi.avgPerCall": "{value} average per call",
|
||||
"kpi.hiddenClients": "{count} script/internal requests not counted",
|
||||
"kpi.clients": "Clients behind the gateway",
|
||||
"kpi.creditsNote": "Usage credits recorded by magpie",
|
||||
|
||||
// ---- cards ----
|
||||
"card.topSpender": "Top spender",
|
||||
"card.inputTokens": "input tokens",
|
||||
"card.stackLegend": "Light: cache reads; dark: billed at full price",
|
||||
"card.detailsAria": "{name} details",
|
||||
"card.sessionMedianTitle": "Median session span",
|
||||
"table.topSpenderTitle": "Top spender",
|
||||
|
||||
// ---- tools block ----
|
||||
"tools.empty": "No samples yet. The gateway hook records which tools each agent sends and how large they are (names and sizes only, never contents). Use an agent for a while, then refresh.",
|
||||
"tools.sampling": "Sampling since {since}, across {samples} requests. Token counts are estimated at about 3.5 bytes per token, the same for every agent.",
|
||||
"tools.sortBytes": "By bytes",
|
||||
"tools.sortTokens": "By tokens",
|
||||
"tools.sortCount": "By count",
|
||||
"tools.sortShare": "Share of input",
|
||||
"tools.perAgent": "{count} · ≈{tokens} tokens",
|
||||
"tools.perAgentShare": "{count} · ≈{tokens} tokens · {share} of input",
|
||||
|
||||
// ---- detail drawer ----
|
||||
"detail.noRecords": "No records to show in this period.",
|
||||
"detail.countPct": "{count} · {pct}",
|
||||
"detail.selectedPeriod": "selected period",
|
||||
"detail.summaryRequests": "In this period it sent {calls} requests to the model.",
|
||||
"detail.summaryBody": "An average of {avg} tokens read per request; {cache} of the input came from cache. {failed} failed and {cancelled} were cancelled.",
|
||||
"detail.summaryNote": "These are observed usage records. Different tasks, models, and usage frequency make this unsuitable as an agent capability ranking.",
|
||||
"detail.inputTitle": "① Where do the input tokens go?",
|
||||
"detail.totalInput": "Total input",
|
||||
"detail.avgInput": "Average per request",
|
||||
"detail.generatedOutput": "Generated output",
|
||||
"detail.inputBreakdown": "Input breakdown",
|
||||
"detail.freshInput": "Fresh input",
|
||||
"detail.cacheWrite": "Cache writes",
|
||||
"detail.credits": "Gateway credits",
|
||||
"detail.latencyTitle": "② How long does it take, and how often does it fail?",
|
||||
"detail.ttft": "Time to first token",
|
||||
"detail.fullResponse": "Full response",
|
||||
"detail.failureRate": "Failure rate",
|
||||
"detail.latencyNote": "Times are medians (p50): half of the valid records are faster. First-token and full-response samples are counted separately and may differ, so subtracting them does not give the generation time. A failure does not necessarily cost anything.",
|
||||
"detail.toolsTitle": "③ How heavy are the tool definitions?",
|
||||
"detail.toolsPerRequest": "Tools per request",
|
||||
"detail.toolsPerRequestValue": "{count}",
|
||||
"detail.toolSize": "Definition size (estimated tokens)",
|
||||
"detail.validSamples": "Valid samples",
|
||||
"detail.validSamplesValue": "{count}",
|
||||
"detail.toolsNote": "Tool definitions are the model’s instruction manuals: names, parameter schemas, and descriptions. Long manuals eat context, so fewer tools are not necessarily lighter.",
|
||||
"detail.toolsCaveat": "Estimated from JSON bytes ÷ 3.5, not from the model’s tokenizer. {samples} tool samples and {calls} usage records are not matched request by request, so no coverage rate can be derived from them. Tool definitions may hit the cache, so they are not billed at full price on every turn.",
|
||||
"detail.toolInventory": "Frequent tool names (up to 40)",
|
||||
"detail.toolFilter": "Filter tool names",
|
||||
"detail.toolSearchPlaceholder": "Search names",
|
||||
"detail.toolInventoryNote": "Shows up to the 40 names seen most often in the samples; each sample records at most 60 names. This is not a full inventory, not the current configuration, and not a count of tool calls.",
|
||||
"detail.toolsEmpty": "No tool definitions collected yet. As this agent sends new requests through the gateway, data will appear here.",
|
||||
"detail.modelsTitle": "④ Which models were used?",
|
||||
"detail.modelsNote": "Ordered by request count; percentages use this agent’s total requests as the denominator. Showing the top {count}.",
|
||||
"detail.remaining": "{count} other records.",
|
||||
"detail.protocolsTitle": "⑤ Which protocols were used?",
|
||||
"detail.protocolsNote": "A protocol is the message format between the request and the model service. These are the main protocols in the selected period, inferred from the endpoints in the logs and possibly including protocols the gateway converted; this is not the current configuration.",
|
||||
"detail.sessionTitle": "⑥ How long does a session last?",
|
||||
"detail.medianSpan": "Median span",
|
||||
"detail.p90Span": "90% of sessions below",
|
||||
"detail.measuredSessions": "Measured sessions",
|
||||
"detail.sessionNote": "Measured as the span between a session’s first and last request, including thinking and idle time, so it is not continuous work time. The current window may cut a session short; {open} sessions longer than six hours are left out of the measurement.",
|
||||
"detail.sessionUnavailable": "Session span cannot be computed",
|
||||
"detail.sessionEmpty": "No session records to measure in this period. Request counts and response times are still available; this does not mean the agent did no work.",
|
||||
"detail.otherProtocol": "Other / unknown",
|
||||
"detail.cacheReads": "Cache reads",
|
||||
"detail.nonCacheReads": "Non-cache reads",
|
||||
"detail.noInput": "No input tokens in this period, so the composition cannot be computed.",
|
||||
"detail.cacheNote": "Cache reads usually get a discount. Non-cache reads include fresh input and cache writes, and providers price them differently; token counts are not money.",
|
||||
"detail.trendTitle": "Daily input tokens",
|
||||
"detail.trendEmpty": "Not enough data to draw a trend yet.",
|
||||
"detail.trendNote": "The trend reflects how much it was used, not how well the work went.",
|
||||
|
||||
// ---- table and card columns ----
|
||||
"col.agent": "Agent",
|
||||
"col.calls": "Requests",
|
||||
"col.prompt": "Input tokens",
|
||||
"col.avgPrompt": "Input per request",
|
||||
"col.cacheRate": "Cache hit rate",
|
||||
"col.fullPrice": "At full price",
|
||||
"col.out": "Output",
|
||||
"col.errorRate": "Failure rate",
|
||||
"col.p50ttft": "First token p50",
|
||||
"col.p50ms": "Response p50",
|
||||
"col.toolTokens": "Tool tokens / request",
|
||||
"col.protocol": "Protocol",
|
||||
"col.session": "Session span",
|
||||
"sort.prompt": "Input tokens",
|
||||
"sort.toolTokens": "Tool weight",
|
||||
|
||||
// ---- explanations ----
|
||||
"explain.prompt.title": "Input tokens",
|
||||
"explain.prompt.body": "Every token read by the model in this period: fresh input, cache reads, and cache writes. Whatever context the model reads each turn lands here, and this is usually the largest part of the bill.",
|
||||
"explain.avgPrompt.title": "Input per request",
|
||||
"explain.avgPrompt.body": "Tokens read by the model per request on average. The total is multiplied by how often you called it; spread over the requests, this shows which harness is heavier per call.",
|
||||
"explain.cacheRate.title": "Cache hit rate",
|
||||
"explain.cacheRate.body": "The share of input tokens read from the prompt cache. Cache reads and writes may be priced differently by each provider. A low rate does not by itself imply a weaker model.",
|
||||
"explain.fullPrice.title": "At full price",
|
||||
"explain.fullPrice.body": "Fresh input plus cache-write tokens, excluding cache reads. This counts tokens, not money; cache-write prices also differ per model and provider.",
|
||||
"explain.out.title": "Output tokens",
|
||||
"explain.out.body": "Tokens the model generated. Input and output are usually priced differently and output can cost more; check your provider’s actual bill.",
|
||||
"explain.errorRate.title": "Failure rate",
|
||||
"explain.errorRate.body": "Share of requests that failed; deliberate cancellations are counted separately. Whether a failure burns tokens or money depends on when it happened and what the provider returned.",
|
||||
"explain.calls.title": "Requests",
|
||||
"explain.calls.body": "Requests through the gateway. Note that this only covers the harnesses you use; scripts and internal requests are hidden by default.",
|
||||
"explain.p50ttft.title": "First token p50",
|
||||
"explain.p50ttft.body": "Half of the requests were faster than this. The time to the first token decides how long you wait before anything appears, so it matters more to the feel than the total.",
|
||||
"explain.p50ms.title": "Response p50",
|
||||
"explain.p50ms.body": "Half of the requests were faster than this, measured from entering the gateway to the complete response, including reasoning and generation.",
|
||||
"explain.toolTokens.title": "Tool tokens / request",
|
||||
"explain.toolTokens.body": "Estimated from the JSON size of the tool names, parameter schemas, and descriptions sampled at the gateway: bytes ÷ 3.5. This is not an exact tokenizer count; it may hit the cache and it is not the cost.",
|
||||
"explain.toolShare.title": "Share of input",
|
||||
"explain.toolShare.body": "Tool definitions as a share of the tokens this harness reads. A 25% share means roughly one in every four input tokens describes a tool, unrelated to the conversation itself.",
|
||||
"explain.toolCount.title": "Tool count",
|
||||
"explain.toolCount.body": "How many tool definitions ride along with each request. Count is not cost: a few long descriptions can outweigh a dozen short ones. Compare their sizes.",
|
||||
"explain.sessionMedian.title": "Session span",
|
||||
"explain.sessionMedian.body": "The median span between a session’s first and last request within the selected window. It includes idle time and is not continuous work time. Sessions longer than six hours are currently left out.",
|
||||
"explain.sessionP90.title": "Session span p90",
|
||||
"explain.sessionP90.body": "90% of sessions were shorter than this. A few very long sessions (a desktop app left open) drag the average up, so this percentile is more trustworthy than the mean.",
|
||||
"explain.sessionCount.title": "Sessions",
|
||||
"explain.sessionCount.body": "The number of distinct sessions seen in this period. Session IDs are maintained by each harness, so some of them do not have the concept at all.",
|
||||
"explain.protocol.title": "Protocol",
|
||||
"explain.protocol.body": "The protocol mix in the selected period, inferred from the endpoints in the usage log. It may include the upstream protocol after the gateway converted it, so do not read it as the current client configuration.",
|
||||
"explain.live.title": "In flight",
|
||||
"explain.live.body": "Requests whose start was recorded by the gateway hook without a matching finish callback, refreshed about every two seconds. A missing finish callback is kept for up to 15 minutes. This is an observed request state, not the state of an agent’s background process.",
|
||||
"explain.fullPriceShare.title": "Full-price share",
|
||||
"explain.fullPriceShare.body": "The share of the tokens this harness reads that are billed at full price. The higher this share, the more expensive the same usage is.",
|
||||
"explain.credits.title": "credits",
|
||||
"explain.credits.body": "Usage credits recorded by magpie, which depend on how your provider prices things. This is not a token count.",
|
||||
}
|
||||
|
||||
const zh = {
|
||||
// ---- app shell ----
|
||||
"app.title": "HarnessWeight · agent harness 的 token 重量",
|
||||
"status.loading": "正在读取…",
|
||||
"header.sub": "同一个网关后面,每个 agent harness 读了多少 token、命中多少缓存、失败多少次、每轮重发多重的工具定义。",
|
||||
"aria.periods": "统计周期",
|
||||
"period.today": "今天",
|
||||
"period.7d": "7 天",
|
||||
"period.30d": "30 天",
|
||||
"clients.toggle": "含脚本和内部请求",
|
||||
"aria.insights": "结论",
|
||||
"aria.overview": "总览",
|
||||
"aria.cardSort": "卡片排序",
|
||||
"aria.close": "关闭",
|
||||
"footer.localOnly": "数据只在本机读取,不上传。",
|
||||
|
||||
// ---- sections ----
|
||||
"cards.title": "谁在花你的 token",
|
||||
"cards.hint": "每张卡是一个 Agent。条的长度是输入 token 总量,深色部分合计新鲜输入与缓存写入;价格由供应商决定。",
|
||||
"activity.connecting": "正在连接实时调用状态…",
|
||||
"table.title": "逐项对比",
|
||||
"table.hint": "点表头排序,点一行看详情。",
|
||||
"tools.title": "工具定义重量",
|
||||
"tools.hint": "Agent 每次请求都会把自己的工具清单重发一遍,这部分也按 token 计费。",
|
||||
|
||||
// ---- formatting ----
|
||||
"dur.second": "秒",
|
||||
"dur.minute": "分",
|
||||
"dur.hour": "小时",
|
||||
"dur.day": "天",
|
||||
"unit.times": "次",
|
||||
"unit.items": "个",
|
||||
|
||||
// ---- status and sources ----
|
||||
"time.none": "还没有",
|
||||
"time.secondsAgo": "{n} 秒前",
|
||||
"time.minutesAgo": "{n} 分钟前",
|
||||
"time.hoursAgo": "{n} 小时前",
|
||||
"time.daysAgo": "{n} 天前",
|
||||
"status.collecting": "采集中 · 最近一次请求 {usage} · 工具采样 {tool}",
|
||||
"status.stale": "15 分钟内没有新采样 · 上次 {tool}(用一下 Agent 就会恢复)",
|
||||
"status.waiting": "hook 已装好,等第一条请求经过网关",
|
||||
"sources.summary": "用量记录 {usageRows} 条 · 工具采样 {toolRows} 条 · 更新于 {time}",
|
||||
"state.noAgents": "这段时间网关没有记录到 Agent 的请求。用任意 Agent 走一次网关,再回来刷新。",
|
||||
"state.loadError": "读不到数据:{message}。确认 magpie 网关在运行,再刷新。",
|
||||
|
||||
// ---- activity ----
|
||||
"activity.callsInFlight": "{n} 个调用中",
|
||||
"activity.liveHint": "流光边框表示网关观察到该 Agent 有调用进行中。",
|
||||
"activity.unavailableHint": "实时调用状态暂不可用;没有流光不代表 Agent 空闲。",
|
||||
|
||||
// ---- overview tiles ----
|
||||
"kpi.inputTokens": "输入 token",
|
||||
"kpi.cacheRate": "缓存命中",
|
||||
"kpi.outputTokens": "输出 token",
|
||||
"kpi.failed": "失败",
|
||||
"kpi.agents": "Agent",
|
||||
"kpi.credits": "credits",
|
||||
"kpi.requests": "{count} 次请求",
|
||||
"kpi.fullPriceOf": "按原价算的 {value}",
|
||||
"kpi.avgPerCall": "平均 {value}/次",
|
||||
"kpi.hiddenClients": "另有 {count} 次脚本/内部请求未计",
|
||||
"kpi.clients": "网关后面的客户端",
|
||||
"kpi.creditsNote": "magpie 记账的按量额度",
|
||||
|
||||
// ---- cards ----
|
||||
"card.topSpender": "花得最多",
|
||||
"card.inputTokens": "输入 token",
|
||||
"card.stackLegend": "浅色:缓存读取;深色:按原价",
|
||||
"card.detailsAria": "{name} 详情",
|
||||
"card.sessionMedianTitle": "单次会话时长中位数",
|
||||
"table.topSpenderTitle": "花得最多",
|
||||
|
||||
// ---- tools block ----
|
||||
"tools.empty": "还没有采样。网关 hook 会从下一次请求开始记录每个 Agent 带了哪些工具、有多大(只记名字和大小,不记内容)。用一会儿 Agent 后刷新即可。",
|
||||
"tools.sampling": "从 {since} 开始采样,共 {samples} 次请求。token 数按每 token 约 3.5 字节估算,各 Agent 口径一致。",
|
||||
"tools.sortBytes": "按字节",
|
||||
"tools.sortTokens": "按 token",
|
||||
"tools.sortCount": "按个数",
|
||||
"tools.sortShare": "占输入比",
|
||||
"tools.perAgent": "{count} 个 · ≈{tokens} token",
|
||||
"tools.perAgentShare": "{count} 个 · ≈{tokens} token · 占 {share}",
|
||||
|
||||
// ---- detail drawer ----
|
||||
"detail.noRecords": "当前范围没有可展示的记录。",
|
||||
"detail.countPct": "{count} 次 · {pct}",
|
||||
"detail.selectedPeriod": "当前筛选范围",
|
||||
"detail.summaryRequests": "这段时间,它向模型发起了 {calls} 次请求。",
|
||||
"detail.summaryBody": "每次平均读入 {avg} token;输入中 {cache} 来自缓存。记录到 {failed} 次失败和 {cancelled} 次主动取消。",
|
||||
"detail.summaryNote": "这里比较的是实际使用记录;任务、模型和使用频率不同,不能直接当作 Agent 能力排名。",
|
||||
"detail.inputTitle": "① 输入都用在哪里?",
|
||||
"detail.totalInput": "累计输入",
|
||||
"detail.avgInput": "每次平均",
|
||||
"detail.generatedOutput": "生成的输出",
|
||||
"detail.inputBreakdown": "查看输入明细",
|
||||
"detail.freshInput": "新鲜输入",
|
||||
"detail.cacheWrite": "缓存写入",
|
||||
"detail.credits": "网关记录的额度",
|
||||
"detail.latencyTitle": "② 等待多久,出错多少?",
|
||||
"detail.ttft": "首字等待",
|
||||
"detail.fullResponse": "完整响应",
|
||||
"detail.failureRate": "失败率",
|
||||
"detail.latencyNote": "时间采用中位数(p50):有一半的有效记录更快。首字与完整响应各自统计,样本可能不同,不能相减当作生成耗时。失败不等于一定产生费用。",
|
||||
"detail.toolsTitle": "③ 工具说明有多重?",
|
||||
"detail.toolsPerRequest": "每次携带工具",
|
||||
"detail.toolsPerRequestValue": "{count} 个",
|
||||
"detail.toolSize": "说明体积(估算 token)",
|
||||
"detail.validSamples": "有效采样",
|
||||
"detail.validSamplesValue": "{count} 次",
|
||||
"detail.toolsNote": "工具定义是发给模型的“工具使用说明书”,包含名称、参数格式和描述。长说明书也会占上下文,工具数量少不一定更轻。",
|
||||
"detail.toolsCaveat": "以 JSON 字节数 ÷ 3.5 估算,非模型 tokenizer 的实测值。工具采样 {samples} 条,用量记录 {calls} 条;两者未逐请求关联,不能据此计算覆盖率。工具说明可能命中缓存,不代表每轮都按原价收费。",
|
||||
"detail.toolInventory": "查看高频工具名称(最多 40 项)",
|
||||
"detail.toolFilter": "筛选工具名",
|
||||
"detail.toolSearchPlaceholder": "输入名称关键词",
|
||||
"detail.toolInventoryNote": "这里最多显示采样中出现频率最高的 40 个名称;每次采样也最多记录 60 个名称。这不是完整列表、当前启用列表或工具调用次数。",
|
||||
"detail.toolsEmpty": "尚未采集到工具定义。让该 Agent 通过网关发送新请求后,这里会逐步出现数据。",
|
||||
"detail.modelsTitle": "④ 用过哪些模型?",
|
||||
"detail.modelsNote": "按请求次数排列,百分比以该 Agent 全部请求为分母。只显示前 {count} 项。",
|
||||
"detail.remaining": "其余 / 未列出的记录:{count} 次。",
|
||||
"detail.protocolsTitle": "⑤ 请求经过哪些协议?",
|
||||
"detail.protocolsNote": "协议是请求与模型服务之间使用的消息格式。下面显示所选时间范围内的主要协议,按日志中记录的端点推断,可能包含网关转换后的协议;不是当前配置清单。",
|
||||
"detail.sessionTitle": "⑥ 一次会话持续多久?",
|
||||
"detail.medianSpan": "中位时长",
|
||||
"detail.p90Span": "90% 会话短于",
|
||||
"detail.measuredSessions": "可测会话",
|
||||
"detail.sessionNote": "按同一会话首末请求的跨度计算,包含思考与闲置,不是连续工作时间。当前统计窗口可能截断会话;{open} 个超过 6 小时的会话未参与时长统计。",
|
||||
"detail.sessionUnavailable": "暂时无法计算会话时长",
|
||||
"detail.sessionEmpty": "当前范围没有可用于时长统计的会话记录。请求次数和响应耗时仍可正常查看;这不代表 Agent 没有工作。",
|
||||
"detail.otherProtocol": "其他 / 未识别",
|
||||
"detail.cacheReads": "缓存读取",
|
||||
"detail.nonCacheReads": "非缓存读取",
|
||||
"detail.noInput": "当前范围没有输入 token 记录,无法计算构成。",
|
||||
"detail.cacheNote": "缓存读取通常享有折扣。非缓存读取含新鲜输入与缓存写入,各供应商定价不同;token 数不是金额。",
|
||||
"detail.trendTitle": "每天的输入用量",
|
||||
"detail.trendEmpty": "数据不足,暂不绘制趋势。",
|
||||
"detail.trendNote": "趋势反映使用规模,不是任务完成质量。",
|
||||
|
||||
// ---- table and card columns ----
|
||||
"col.agent": "Agent",
|
||||
"col.calls": "请求",
|
||||
"col.prompt": "输入 token",
|
||||
"col.avgPrompt": "每次读",
|
||||
"col.cacheRate": "缓存命中",
|
||||
"col.fullPrice": "按原价",
|
||||
"col.out": "输出",
|
||||
"col.errorRate": "失败率",
|
||||
"col.p50ttft": "首字 p50",
|
||||
"col.p50ms": "耗时 p50",
|
||||
"col.toolTokens": "工具 token/次",
|
||||
"col.protocol": "协议",
|
||||
"col.session": "会话时长",
|
||||
"sort.prompt": "读入 token",
|
||||
"sort.toolTokens": "工具重量",
|
||||
|
||||
// ---- explanations ----
|
||||
"explain.prompt.title": "输入 token",
|
||||
"explain.prompt.body": "这段时间读进模型的所有 token:新鲜输入 + 缓存读取 + 缓存写入。模型每轮读到的上下文都算在这里,是账单里最大的一块。",
|
||||
"explain.avgPrompt.title": "每次读",
|
||||
"explain.avgPrompt.body": "平均每次请求读进模型的 token。总额会被「用了多少次」放大,摊到每次请求才能看出哪个 harness 单次更重。",
|
||||
"explain.cacheRate.title": "缓存命中",
|
||||
"explain.cacheRate.body": "读进来的 token 里,有多少是从 prompt cache 取的。命中的部分按折扣价算,没命中的按原价。命中率低不等于模型差,通常是前缀不稳定(比如工具定义变了)。",
|
||||
"explain.fullPrice.title": "按原价",
|
||||
"explain.fullPrice.body": "新鲜输入与缓存写入的 token 合计,不含缓存读取。这里统计的是数量,不是金额;不同模型、供应商的缓存写入价格也可能不同。",
|
||||
"explain.out.title": "输出 token",
|
||||
"explain.out.body": "模型生成回来的 token。输入和输出通常采用不同单价,输出单价也可能更高;请以实际供应商账单为准。",
|
||||
"explain.errorRate.title": "失败率",
|
||||
"explain.errorRate.body": "出错请求占比;主动取消单独统计。失败是否消耗 token 或收费,取决于失败发生的阶段和供应商回执。",
|
||||
"explain.calls.title": "请求",
|
||||
"explain.calls.body": "经过网关的请求数。注意这里只算你用的 harness,脚本和内部请求默认隐藏。",
|
||||
"explain.p50ttft.title": "首字 p50",
|
||||
"explain.p50ttft.body": "一半的请求比这个快。首字时间决定你等多久能看到第一个字,比总耗时更影响体感。",
|
||||
"explain.p50ms.title": "耗时 p50",
|
||||
"explain.p50ms.body": "一半的请求比这个快,指请求从进网关到拿到完整回复的总时长(含思考和生成)。",
|
||||
"explain.toolTokens.title": "工具 token/次",
|
||||
"explain.toolTokens.body": "在网关采样工具名、参数 schema 和描述的 JSON 体积,以字节数 ÷ 3.5 估算 token。不是精确 tokenizer 计数;可能命中缓存,也不等于实际费用。",
|
||||
"explain.toolShare.title": "占输入比",
|
||||
"explain.toolShare.body": "工具定义占这个 harness 自己读进的 token 的比例。25% 意味着模型读 4 个 token 就有 1 个是工具定义,跟对话内容无关。",
|
||||
"explain.toolCount.title": "工具个数",
|
||||
"explain.toolCount.body": "每次请求带了多少个工具定义。注意:个数不等于成本。有的工具描述特别长,少数几个就能顶掉一打短工具。要裁就按字节裁。",
|
||||
"explain.sessionMedian.title": "单次会话时长",
|
||||
"explain.sessionMedian.body": "所选窗口内,同一 session 首末请求的跨度中位数,包含闲置,不是持续工作时间。超过 6 小时的会话目前不参与时长统计。",
|
||||
"explain.sessionP90.title": "长会话 p90",
|
||||
"explain.sessionP90.body": "九成的会话比这个短。少数超长会话(桌面端挂着不关)会拉高平均值,所以这个数比平均更可靠。",
|
||||
"explain.sessionCount.title": "会话数",
|
||||
"explain.sessionCount.body": "这段时间内出现过的不同会话数量。会话 id 由 harness 自己维护,所以有的 harness 没有这个概念。",
|
||||
"explain.protocol.title": "接入协议",
|
||||
"explain.protocol.body": "根据用量日志端点统计所选范围内的协议分布,可能包含网关转换后的上游协议。不能当作当前客户端配置。",
|
||||
"explain.live.title": "正在使用",
|
||||
"explain.live.body": "网关 hook 已记录请求开始、尚未收到对应结束回调的数量,每约 2 秒刷新。丢失结束回调的记录最多保留 15 分钟;这是观测状态,不是 Agent 的后台进程状态。",
|
||||
"explain.fullPriceShare.title": "按原价占比",
|
||||
"explain.fullPriceShare.body": "按原价计费的 token 占它读进的总 token 的比例。这个比例越高,同样的用量越贵。",
|
||||
"explain.credits.title": "credits",
|
||||
"explain.credits.body": "magpie 记账的按量额度,取决于你走的 provider 怎么定价,不是 token 数本身。",
|
||||
}
|
||||
|
||||
export const TEXT = { en, zh }
|
||||
|
||||
// The language the page actually renders in: a recognised language with no
|
||||
// table yet (zh-TW, ja) renders English, and says so in <html lang>.
|
||||
export function pageLanguage(value = "") {
|
||||
const lang = languageFor(value)
|
||||
return TEXT[lang] ? lang : "en"
|
||||
}
|
||||
|
||||
// The insights sentences live here too: the service writes them, so they must
|
||||
// come out of the same table as the rest of the page.
|
||||
const insights = {
|
||||
en: {
|
||||
prompt: "{hi} reads an average of {avg} tokens per request, {ratio}x {lo}.",
|
||||
cache: "{hi} has the highest cache hit rate ({hiRate}); {lo} the lowest ({loRate}). Actual pricing depends on the provider and model.",
|
||||
volume: "{name} accounts for {share} of the input tokens in this period, the largest source of spend.",
|
||||
errors: "{name} has a failure rate of {rate}; failed requests may still consume tokens.",
|
||||
tools: "{hi} resends about {tokens} tokens of tool definitions per request ({count} tools), {ratio}x {lo} (about {loTokens} tokens, {loCount} tools).",
|
||||
},
|
||||
zh: {
|
||||
prompt: "{hi} 每次请求平均读 {avg} token,是 {lo} 的 {ratio} 倍。",
|
||||
cache: "缓存命中最高的是 {hi}({hiRate}),最低的是 {lo}({loRate})。实际计费取决于供应商和模型。",
|
||||
volume: "{name} 占了这段时间 {share} 的输入 token,是最大的开销来源。",
|
||||
errors: "{name} 的失败率是 {rate};失败请求也可能消耗 token。",
|
||||
tools: "{hi} 每次请求重发的工具定义约 {tokens} token({count} 个),是 {lo}(约 {loTokens} token,{loCount} 个)的 {ratio} 倍。",
|
||||
},
|
||||
}
|
||||
|
||||
// {name} placeholders are filled in; a missing one leaves the placeholder
|
||||
// visible rather than printing "undefined".
|
||||
export function translate(language, key, parameters = {}) {
|
||||
const lang = languageFor(language)
|
||||
const template = TEXT[lang]?.[key] ?? TEXT.en[key] ?? key
|
||||
return template.replace(/\{(\w+)\}/g, (match, name) => parameters[name] ?? match)
|
||||
}
|
||||
|
||||
export function insight(language, kind, parameters = {}) {
|
||||
const lang = languageFor(language)
|
||||
const template = insights[lang]?.[kind] ?? insights.en[kind] ?? kind
|
||||
return template.replace(/\{(\w+)\}/g, (match, name) => parameters[name] ?? match)
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
These agent icons are the same files magpie shows for each agent. They were
|
||||
copied from the community plugin @magpie-community/page-agent-office
|
||||
(packages/agent-office/page/icons, MIT), whose SVG brand marks come from
|
||||
@lobehub/icons (https://github.com/lobehub/lobe-icons, MIT, Copyright (c) 2023
|
||||
LobeHub). Each mark remains the trademark of its owner; it is shown only to
|
||||
name the agent it belongs to.
|
||||
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" height="1em" style="flex:none;line-height:1" viewBox="0 0 80 80" width="1em" xmlns="http://www.w3.org/2000/svg"><title>AionUi</title><path d="M40 20Q38 22 25 40Q23 42 26 42L30 42Q32 40 40 30Q48 40 50 42L54 42Q57 42 55 40Q42 22 40 20Z"></path><circle cx="40" cy="46" r="3"></circle><path d="M18 50Q40 70 62 50" fill="none" stroke="currentColor" stroke-linecap="round" stroke-width="3.5"></path></svg>
|
||||
|
After Width: | Height: | Size: 425 B |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 7.5 KiB |
@@ -0,0 +1,28 @@
|
||||
<svg width="64" height="64" viewBox="0 0 64 64" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g clip-path="url(#clip0_3720_17128)">
|
||||
<path d="M56.9375 31.6738C56.9388 31.7823 56.9404 31.8911 56.9404 32C56.9404 32.0644 56.9389 32.1291 56.9385 32.1934C56.8345 45.8783 45.7094 56.9395 32 56.9395C30.6085 56.9395 29.2434 56.8256 27.9141 56.6064C27.3793 56.518 27.2976 55.8201 27.7266 55.542C27.7811 55.5724 27.8436 55.5948 27.9141 55.6064C29.2434 55.8256 30.6085 55.9395 32 55.9395C45.6095 55.9395 56.6693 45.0389 56.9316 31.4922C56.9328 31.5525 56.9367 31.6134 56.9375 31.6738Z" fill="#000"/>
|
||||
<path d="M38.3145 39.5625C38.4856 39.6394 38.5389 39.859 38.4209 40.0049C34.4382 44.9261 30.045 48.5593 26.0938 50.6084C22.5921 52.4242 20.0866 52.7156 18.4785 52.3613C17.4846 52.1422 16.6878 51.4063 16.2383 50.4932C15.6369 49.2714 15.2416 47.5446 15.3105 45.2578C15.3665 47.0556 15.728 48.4563 16.2383 49.4932C16.6878 50.4063 17.4846 51.1422 18.4785 51.3613C20.0866 51.7156 22.5921 51.4242 26.0938 49.6084C29.9246 47.6218 34.168 44.144 38.0527 39.4492C38.139 39.4867 38.2269 39.5231 38.3145 39.5625Z" fill="#000"/>
|
||||
<path d="M18.4385 24.8818C18.5499 24.977 18.5727 25.1403 18.4922 25.2627C17.7302 26.4181 17.0255 27.5814 16.3799 28.7441C13.4388 33.9918 11.6671 39.2061 11.1826 43.6816C11.121 44.2476 10.3717 44.44 10.0986 43.9404C8.19024 40.4472 7.09384 36.4468 7.06152 32.1934C7.06107 32.1291 7.05957 32.0644 7.05957 32C7.05957 31.8911 7.06023 31.7823 7.06152 31.6738C7.0625 31.598 7.06574 31.5219 7.06738 31.4463C7.14038 35.6053 8.22812 39.5165 10.0986 42.9404C10.3717 43.44 11.121 43.2476 11.1826 42.6816C11.6671 38.2061 13.4388 32.9918 16.3799 27.7441C16.9457 26.725 17.5585 25.7066 18.2139 24.6924C18.289 24.7563 18.3645 24.8187 18.4385 24.8818Z" fill="#000"/>
|
||||
<path d="M45.8057 39.1992C46.9619 40.1962 48.2518 41.281 49.6797 42.4785C49.8546 42.6252 49.8869 42.8825 49.7529 43.0674L49.5391 43.3604C48.0723 42.1301 46.7519 41.0208 45.5752 40.002C45.4638 39.9055 45.4435 39.7401 45.5264 39.6182C45.6209 39.479 45.7128 39.3386 45.8057 39.1992Z" fill="#000"/>
|
||||
<path d="M25.6172 34.2979C25.7798 36.4917 24.8232 38.9809 22.7842 42.542L22.6963 42.4785C22.5152 42.3468 22.4666 42.095 22.5791 41.9014C24.4462 38.6877 25.4669 36.3316 25.6172 34.2979Z" fill="#000"/>
|
||||
<path d="M48.2588 16.5908C48.2898 17.673 48.2144 18.9446 48.0137 20.4385C47.2724 24.9108 45.1103 30.3267 41.5459 35.7334C41.4431 35.8894 41.2184 35.9059 41.0928 35.7676C38.9435 33.4009 37.9884 31.4093 38.1523 29.04C38.2891 30.9892 39.2524 32.741 41.0928 34.7676C41.2184 34.9059 41.4431 34.8894 41.5459 34.7334C45.1103 29.3267 47.2724 23.9108 48.0137 19.4385C48.1556 18.382 48.2352 17.4366 48.2588 16.5908Z" fill="#000"/>
|
||||
<path d="M32 1.12988C48.0163 1.12988 61 14.5033 61 31C61 31.1667 60.9958 31.333 60.9932 31.499C60.7335 15.2333 47.8538 2.12988 32 2.12988C16.1462 2.12989 3.26551 15.2333 3.00586 31.499C3.00322 31.333 3 31.1667 3 31C3 14.5033 15.9837 1.12989 32 1.12988Z" fill="#000"/>
|
||||
<path d="M39.3936 18.7578C39.543 18.5909 39.7983 18.5597 39.9795 18.6914L41.1709 19.5576C41.3519 19.6893 41.4014 19.9402 41.2891 20.1338C41.2189 20.2546 41.1499 20.3746 41.082 20.4932L39.9795 19.6914C39.7983 19.5597 39.543 19.5909 39.3936 19.7578C33.7757 26.0312 31.0071 26.8222 25.0586 23.7402C24.8966 23.6561 24.8507 23.4426 24.9668 23.3018C25.0854 23.158 25.2066 23.0168 25.3262 22.875C31.0923 25.7954 33.8602 24.9368 39.3936 18.7578Z" fill="#000"/>
|
||||
<path d="M36.5615 7.50586C36.9481 7.7182 36.9404 8.33763 36.4873 8.54883C31.6315 10.8118 26.3765 15.0772 21.7588 20.8066C21.6218 20.9752 21.4853 21.1451 21.3496 21.3164C21.2583 21.4316 21.0951 21.4616 20.9697 21.3848C19.4694 20.4652 17.7925 19.4036 15.8906 18.2129C15.6971 18.0918 15.443 18.1407 15.3086 18.3252L13.9873 20.1436C13.9407 20.1045 13.8936 20.0657 13.8467 20.0264C13.6715 19.8796 13.6401 19.6224 13.7744 19.4375L15.3086 17.3252C15.443 17.1407 15.6971 17.0918 15.8906 17.2129C17.7925 18.4036 19.4694 19.4652 20.9697 20.3848C21.0951 20.4616 21.2583 20.4316 21.3496 20.3164C21.4853 20.1451 21.6218 19.9752 21.7588 19.8066C26.3765 14.0772 31.6315 9.81182 36.4873 7.54883C36.5138 7.53646 36.538 7.52087 36.5615 7.50586Z" fill="#000"/>
|
||||
<path d="M61 33C60.9999 49.4967 48.0162 62.8701 32 62.8701C15.9838 62.8701 3.00006 49.4967 3 33C3 32.8327 3.0032 32.6657 3.00586 32.499C3.26462 48.7655 16.1456 61.8701 32 61.8701C47.8544 61.8701 60.7344 48.7655 60.9932 32.499C60.9958 32.6657 61 32.8327 61 33Z" fill="#000"/>
|
||||
<path d="M43.3584 42.5928C43.4489 42.477 43.6115 42.4456 43.7373 42.5215C45.1138 43.3522 46.6296 44.2992 48.3174 45.3545C48.5111 45.4756 48.7661 45.4261 48.9004 45.2412L49.5391 44.3604C49.5858 44.3996 49.6326 44.439 49.6797 44.4785C49.8546 44.6252 49.8869 44.8825 49.7529 45.0674L48.9004 46.2412C48.7661 46.4261 48.5111 46.4756 48.3174 46.3545C46.6296 45.2992 45.1138 44.3522 43.7373 43.5215C43.6115 43.4456 43.4489 43.477 43.3584 43.5928C38.5834 49.7097 33.0004 54.2085 27.8174 56.4932C27.7849 56.5075 27.7546 56.5238 27.7266 56.542C27.3397 56.3262 27.3543 55.6974 27.8174 55.4932C33.0004 53.2085 38.5834 48.7097 43.3584 42.5928Z" fill="#000"/>
|
||||
<path d="M21.5029 28.0957C21.6014 27.9422 21.8185 27.9207 21.9482 28.0488C24.6046 30.6719 25.8071 32.7273 25.6172 35.2979C25.4596 33.1711 24.2515 31.3232 21.9482 29.0488C21.8185 28.9207 21.6014 28.9422 21.5029 29.0957C20.9328 29.9845 20.4005 30.8726 19.9062 31.7559C17.5103 36.0815 16.0483 40.3126 15.5186 43.9463C15.3981 44.7727 15.3321 45.5427 15.3105 46.2578C15.2799 45.2747 15.3398 44.1727 15.5186 42.9463C16.0483 39.3126 17.5103 35.0815 19.9062 30.7559C20.4005 29.8726 20.9328 28.9845 21.5029 28.0957Z" fill="#000"/>
|
||||
<path d="M24.4736 44.2783C29.8543 38.2684 32.7749 37.0727 38.3145 39.5625C38.4856 39.6394 38.5389 39.859 38.4209 40.0049C38.2995 40.1549 38.1749 40.3016 38.0527 40.4492C32.681 38.1138 29.7693 39.3634 24.4736 45.2783C24.3243 45.4451 24.0699 45.4761 23.8887 45.3447L22.6963 44.4785C22.5152 44.3468 22.4666 44.095 22.5791 43.9014C22.6492 43.7807 22.7165 43.6603 22.7842 43.542L23.8887 44.3447C24.0699 44.4761 24.3243 44.4451 24.4736 44.2783Z" fill="#000"/>
|
||||
<path d="M53.0791 20.8086C53.1398 20.2357 53.902 20.048 54.167 20.5596C55.8921 23.8955 56.8861 27.6714 56.9375 31.6738C56.9388 31.7823 56.9404 31.8911 56.9404 32C56.9404 32.0644 56.9389 32.1291 56.9385 32.1934C56.9377 32.2931 56.9336 32.3927 56.9316 32.4922C56.853 28.557 55.866 24.8451 54.167 21.5596C53.902 21.048 53.1398 21.2357 53.0791 21.8086C52.4968 27.3425 50.01 33.89 45.8057 40.1992C45.7286 40.1327 45.6511 40.0677 45.5752 40.002C45.4638 39.9055 45.4435 39.7401 45.5264 39.6182C49.9012 33.181 52.4839 26.4647 53.0791 20.8086Z" fill="#000"/>
|
||||
<path d="M32 7.05957C33.4955 7.05957 34.9607 7.19106 36.3838 7.44336C36.9135 7.53751 36.9932 8.23002 36.5615 8.50586C36.5093 8.47719 36.4502 8.45517 36.3838 8.44336C34.9607 8.19106 33.4955 8.05957 32 8.05957C18.411 8.05957 7.36181 18.928 7.06738 32.4463C7.0659 32.3621 7.06216 32.2778 7.06152 32.1934C7.06107 32.1291 7.05957 32.0644 7.05957 32C7.05957 31.8911 7.06023 31.7823 7.06152 31.6738C7.23633 18.0503 18.335 7.05957 32 7.05957Z" fill="#000"/>
|
||||
<path d="M41.1709 21.5576C41.3519 21.6893 41.4014 21.9402 41.2891 22.1338C39.3629 25.4482 38.3005 27.8985 38.1523 30.04C37.9904 27.7304 38.9905 25.1439 41.082 21.4932L41.1709 21.5576Z" fill="#000"/>
|
||||
<path d="M13.9873 21.1436C15.6527 22.5379 17.1354 23.769 18.4385 24.8818C18.5499 24.977 18.5727 25.1403 18.4922 25.2627C18.3981 25.4054 18.3062 25.5495 18.2139 25.6924C16.9284 24.5984 15.4742 23.3896 13.8467 22.0264C13.6715 21.8796 13.6401 21.6224 13.7744 21.4375L13.9873 21.1436Z" fill="#000"/>
|
||||
<path d="M37.3555 12.8906C40.9317 11.1236 43.5958 10.8706 45.3682 11.3281C46.4364 11.604 47.2999 12.4117 47.7061 13.4375C48.1054 14.4465 48.3088 15.7939 48.2588 17.5908C48.2213 16.2817 48.0276 15.2499 47.7061 14.4375C47.2999 13.4117 46.4364 12.604 45.3682 12.3281C43.5958 11.8706 40.9317 12.1236 37.3555 13.8906C33.5314 15.7802 29.1715 19.3163 25.3262 23.875C25.2381 23.8304 25.1481 23.7866 25.0586 23.7402C24.8966 23.6561 24.8507 23.4426 24.9668 23.3018C28.8975 18.5362 33.4125 14.8389 37.3555 12.8906Z" fill="#000"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M32 2.12988C48.0163 2.12988 61 15.5031 61 31.9999C61 48.4966 48.0163 61.8699 32 61.8699C15.9837 61.8699 3 48.4966 3 31.9999C3 15.5031 15.9837 2.12988 32 2.12988ZM54.1672 20.5599C53.9023 20.0478 53.1393 20.2356 53.079 20.809C52.4838 26.4652 49.901 33.181 45.5262 39.6182C45.4433 39.7401 45.4638 39.9052 45.5752 40.0017C46.7896 41.0531 48.1568 42.2012 49.6801 43.4788C49.8552 43.6256 49.8869 43.8829 49.7526 44.0678L48.9002 45.241C48.7659 45.4259 48.5114 45.4753 48.3176 45.3541C46.6298 44.2989 45.1138 43.3523 43.7373 42.5216C43.6113 42.4456 43.4484 42.4768 43.3579 42.5927C38.5829 48.7096 33.0007 53.2087 27.8177 55.4933C27.289 55.7263 27.3443 56.5125 27.9144 56.6066C29.2437 56.8258 30.6086 56.9399 32 56.9399C45.7095 56.9399 56.8351 45.8781 56.9389 32.193C56.9393 32.1287 56.94 32.0643 56.94 31.9999C56.94 31.8909 56.9392 31.782 56.9379 31.6734C56.8865 27.6709 55.8923 23.8958 54.1672 20.5599ZM21.9484 28.0484C21.8186 27.9203 21.6017 27.942 21.5033 28.0955C20.9329 28.9845 20.4005 29.8729 19.9061 30.7563C17.5102 35.082 16.0482 39.3126 15.5184 42.9463C15.0127 46.4154 15.4486 48.889 16.238 50.4929C16.6876 51.4063 17.4848 52.1422 18.4789 52.3612C20.087 52.7155 22.5924 52.4244 26.0942 50.6085C30.0455 48.5594 34.4382 44.9263 38.4209 40.005C38.539 39.8592 38.4857 39.6399 38.3145 39.563C32.7748 37.073 29.8542 38.2682 24.4733 44.2784C24.3239 44.4453 24.0697 44.4759 23.8885 44.3443L22.6967 43.4784C22.5155 43.3468 22.4664 43.0951 22.5789 42.9014C26.8059 35.6256 26.7065 32.7469 21.9484 28.0484ZM32 7.05988C18.335 7.05988 7.23679 18.0499 7.06198 31.6734C7.06069 31.782 7.06 31.8909 7.06 31.9999C7.06 32.0643 7.06068 32.1287 7.06113 32.193C7.0934 36.4466 8.19033 40.4468 10.0988 43.9402C10.3719 44.44 11.1217 44.2476 11.183 43.6813C11.6675 39.2057 13.4387 33.9916 16.3798 28.7439C17.0254 27.5811 17.7299 26.4183 18.4919 25.2628C18.5726 25.1404 18.5502 24.977 18.4387 24.8818C17.0991 23.7378 15.5692 22.4693 13.8466 21.0263C13.6714 20.8795 13.6396 20.6221 13.774 20.4372L15.3083 18.3256C15.4426 18.1407 15.6972 18.0914 15.8909 18.2126C17.7928 19.4034 19.4698 20.4649 20.9701 21.3845C21.0955 21.4614 21.2582 21.4318 21.3495 21.3166C21.4854 21.1452 21.6218 20.975 21.759 20.8063C26.3767 15.0768 31.6318 10.8118 36.4876 8.54883C37.002 8.30908 36.9422 7.54283 36.3834 7.44377C34.9603 7.19147 33.4955 7.05988 32 7.05988ZM45.3678 11.3285C43.5954 10.8709 40.9315 11.1233 37.3552 12.8903C33.4122 14.8386 28.8977 18.5361 24.967 23.3017C24.8507 23.4426 24.8966 23.6564 25.0588 23.7404C31.0074 26.8224 33.7759 26.0313 39.3938 19.7578C39.5432 19.5909 39.7978 19.5598 39.979 19.6915L41.1708 20.5573C41.352 20.689 41.4014 20.9402 41.2888 21.1339C37.2317 28.1154 37.0009 31.2617 41.0932 35.7678C41.2188 35.9061 41.4426 35.8898 41.5454 35.7338C45.11 30.327 47.2726 24.9111 48.0139 20.4387C48.4575 17.1374 48.2936 14.9211 47.7062 13.4372C47.3 12.4113 46.4361 11.6043 45.3678 11.3285Z" fill="#000"/>
|
||||
</g>
|
||||
<defs>
|
||||
<clipPath id="clip0_3720_17128">
|
||||
<rect width="64" height="64" fill="#000"/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 11 KiB |
@@ -0,0 +1 @@
|
||||
<svg height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>AstrBot</title><g fill="#2f86bd" transform="matrix(0.048 0 0 0.048 1.8384 1.7392)"><path d="m246.3 328.1-17.8 41.2c-6.4 14.8-26.9 14.8-33.3 0l-17.8-41.2c-14.9-34.2-41.8-61.4-75.3-76.3l-48.8-21.6c-14.7-6.5-14.7-27.9 0-34.4l47.2-21c34.4-15.3 61.7-43.5 76.4-78.8l18-43.7c6.3-15.2 27.3-15.2 33.6 0l18 43.7c14.7 35.3 42 63.6 76.4 78.8l47.2 21c14.7 6.5 14.7 27.9 0 34.4l-48.8 21.6c-33.5 14.8-60.4 42.1-75.3 76.2z" transform="translate(0 35)"/><path d="m402.2 449.3-5.3 12.2c-3.5 7.9-14.4 7.9-17.9 0l-5.3-12.2c-8.4-19.3-23.6-34.6-42.4-43l-15.4-6.9c-7.9-3.5-7.9-14.9 0-18.4l14.5-6.5c19.4-8.6 34.8-24.5 43.1-44.5l5.4-13.1c3.4-8.1 14.6-8.1 18 0l5.4 13.1c8.3 19.9 23.7 35.8 43.1 44.5l14.5 6.5c7.9 3.5 7.9 14.9 0 18.4l-15.4 6.9c-19 8.3-34.1 23.7-42.5 43z" transform="matrix(0.95 0 0 0.95 22 -278)"/></g></svg>
|
||||
|
After Width: | Height: | Size: 922 B |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 7.9 KiB |
@@ -0,0 +1 @@
|
||||
<svg height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Claude</title><path d="M4.709 15.955l4.72-2.647.08-.23-.08-.128H9.2l-.79-.048-2.698-.073-2.339-.097-2.266-.122-.571-.121L0 11.784l.055-.352.48-.321.686.06 1.52.103 2.278.158 1.652.097 2.449.255h.389l.055-.157-.134-.098-.103-.097-2.358-1.596-2.552-1.688-1.336-.972-.724-.491-.364-.462-.158-1.008.656-.722.881.06.225.061.893.686 1.908 1.476 2.491 1.833.365.304.145-.103.019-.073-.164-.274-1.355-2.446-1.446-2.49-.644-1.032-.17-.619a2.97 2.97 0 01-.104-.729L6.283.134 6.696 0l.996.134.42.364.62 1.414 1.002 2.229 1.555 3.03.456.898.243.832.091.255h.158V9.01l.128-1.706.237-2.095.23-2.695.08-.76.376-.91.747-.492.584.28.48.685-.067.444-.286 1.851-.559 2.903-.364 1.942h.212l.243-.242.985-1.306 1.652-2.064.73-.82.85-.904.547-.431h1.033l.76 1.129-.34 1.166-1.064 1.347-.881 1.142-1.264 1.7-.79 1.36.073.11.188-.02 2.856-.606 1.543-.28 1.841-.315.833.388.091.395-.328.807-1.969.486-2.309.462-3.439.813-.042.03.049.061 1.549.146.662.036h1.622l3.02.225.79.522.474.638-.079.485-1.215.62-1.64-.389-3.829-.91-1.312-.329h-.182v.11l1.093 1.068 2.006 1.81 2.509 2.33.127.578-.322.455-.34-.049-2.205-1.657-.851-.747-1.926-1.62h-.128v.17l.444.649 2.345 3.521.122 1.08-.17.353-.608.213-.668-.122-1.374-1.925-1.415-2.167-1.143-1.943-.14.08-.674 7.254-.316.37-.729.28-.607-.461-.322-.747.322-1.476.389-1.924.315-1.53.286-1.9.17-.632-.012-.042-.14.018-1.434 1.967-2.18 2.945-1.726 1.845-.414.164-.717-.37.067-.662.401-.589 2.388-3.036 1.44-1.882.93-1.086-.006-.158h-.055L4.132 18.56l-1.13.146-.487-.456.061-.746.231-.243 1.908-1.312-.006.006z" fill="#D97757" fill-rule="nonzero"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.7 KiB |
@@ -0,0 +1 @@
|
||||
<svg height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Claude Code</title><path clip-rule="evenodd" d="M20.998 10.949H24v3.102h-3v3.028h-1.487V20H18v-2.921h-1.487V20H15v-2.921H9V20H7.488v-2.921H6V20H4.487v-2.921H3V14.05H0V10.95h3V5h17.998v5.949zM6 10.949h1.488V8.102H6v2.847zm10.51 0H18V8.102h-1.49v2.847z" fill="#D97757" fill-rule="evenodd"></path></svg>
|
||||
|
After Width: | Height: | Size: 424 B |
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Cline</title><path d="M17.035 3.991c2.75 0 4.98 2.24 4.98 5.003v1.667l1.45 2.896a1.01 1.01 0 01-.002.909l-1.448 2.864v1.668c0 2.762-2.23 5.002-4.98 5.002H7.074c-2.751 0-4.98-2.24-4.98-5.002V17.33l-1.48-2.855a1.01 1.01 0 01-.003-.927l1.482-2.887V8.994c0-2.763 2.23-5.003 4.98-5.003h9.962zM8.265 9.6a2.274 2.274 0 00-2.274 2.274v4.042a2.274 2.274 0 004.547 0v-4.042A2.274 2.274 0 008.265 9.6zm7.326 0a2.274 2.274 0 00-2.274 2.274v4.042a2.274 2.274 0 104.548 0v-4.042A2.274 2.274 0 0015.59 9.6z"></path><path d="M12.054 5.558a2.779 2.779 0 100-5.558 2.779 2.779 0 000 5.558z"></path></svg>
|
||||
|
After Width: | Height: | Size: 750 B |
@@ -0,0 +1 @@
|
||||
<svg height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>CodeBuddy</title><path d="M18.821 0H5.18A5.179 5.179 0 000 5.179V18.82A5.179 5.179 0 005.179 24H18.82A5.179 5.179 0 0024 18.821V5.18A5.179 5.179 0 0018.821 0z" fill="url(#lobe-icons-code-buddy-_R_0_)"></path><path d="M18.777 1.647c.28-.02.536.114.972.51 1.018.926 2.437 2.828 3.318 4.452l.34.631.482.24.11.06v3.638a5.206 5.206 0 00-5.32-1.23c-.491.166-1.021.471-2.08 1.082l-6.09 3.516c-1.057.61-1.586.916-1.975 1.259a5.208 5.208 0 00-1.493 5.572c.165.49.471 1.02 1.082 2.08l.315.543h-3.26c-.685 0-1.34-.135-1.939-.377-.169-.956-.009-1.789.469-2.335.158-.18.164-.189.13-.493a11.846 11.846 0 01-.057-1.711l.02-.444-.667-1.18C2.1 15.622 1.445 14.078 1.192 12.9c-.133-.647-.125-.934.04-1.146.1-.128.427-.261.822-.334.994-.175 3.162-.017 5.575.41l.25.043.551-.487c.915-.81 1.522-1.264 2.641-1.962 1.167-.73 2.484-1.331 3.967-1.807l.476-.152.261-.688c.937-2.471 1.896-4.293 2.58-4.9.235-.21.25-.22.422-.23z" fill="#fff"></path><path d="M12.139 18.2a1.203 1.203 0 011.642.44l1.296 2.243a1.204 1.204 0 01-2.083 1.203l-1.296-2.243a1.203 1.203 0 01.44-1.644zM18.629 14.452a1.203 1.203 0 011.642.44l1.295 2.244a1.203 1.203 0 11-2.083 1.203l-1.295-2.243a1.203 1.203 0 01.44-1.644z" fill="#fff"></path><defs><radialGradient cx="0" cy="0" gradientTransform="matrix(-9.00009 -16 16 -9.00009 21 24.5)" gradientUnits="userSpaceOnUse" id="lobe-icons-code-buddy-_R_0_" r="1"><stop stop-color="#2EA99D"></stop><stop offset="1" stop-color="#6C4DFF"></stop></radialGradient></defs></svg>
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
@@ -0,0 +1 @@
|
||||
<svg height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Codex</title><path d="M19.503 0H4.496A4.496 4.496 0 000 4.496v15.007A4.496 4.496 0 004.496 24h15.007A4.496 4.496 0 0024 19.503V4.496A4.496 4.496 0 0019.503 0z" fill="#fff"></path><path d="M9.064 3.344a4.578 4.578 0 012.285-.312c1 .115 1.891.54 2.673 1.275.01.01.024.017.037.021a.09.09 0 00.043 0 4.55 4.55 0 013.046.275l.047.022.116.057a4.581 4.581 0 012.188 2.399c.209.51.313 1.041.315 1.595a4.24 4.24 0 01-.134 1.223.123.123 0 00.03.115c.594.607.988 1.33 1.183 2.17.289 1.425-.007 2.71-.887 3.854l-.136.166a4.548 4.548 0 01-2.201 1.388.123.123 0 00-.081.076c-.191.551-.383 1.023-.74 1.494-.9 1.187-2.222 1.846-3.711 1.838-1.187-.006-2.239-.44-3.157-1.302a.107.107 0 00-.105-.024c-.388.125-.78.143-1.204.138a4.441 4.441 0 01-1.945-.466 4.544 4.544 0 01-1.61-1.335c-.152-.202-.303-.392-.414-.617a5.81 5.81 0 01-.37-.961 4.582 4.582 0 01-.014-2.298.124.124 0 00.006-.056.085.085 0 00-.027-.048 4.467 4.467 0 01-1.034-1.651 3.896 3.896 0 01-.251-1.192 5.189 5.189 0 01.141-1.6c.337-1.112.982-1.985 1.933-2.618.212-.141.413-.251.601-.33.215-.089.43-.164.646-.227a.098.098 0 00.065-.066 4.51 4.51 0 01.829-1.615 4.535 4.535 0 011.837-1.388zm3.482 10.565a.637.637 0 000 1.272h3.636a.637.637 0 100-1.272h-3.636zM8.462 9.23a.637.637 0 00-1.106.631l1.272 2.224-1.266 2.136a.636.636 0 101.095.649l1.454-2.455a.636.636 0 00.005-.64L8.462 9.23z" fill="url(#lobe-icons-codex-_R_0_)"></path><defs><linearGradient gradientUnits="userSpaceOnUse" id="lobe-icons-codex-_R_0_" x1="12" x2="12" y1="3" y2="21"><stop stop-color="#B1A7FF"></stop><stop offset=".5" stop-color="#7A9DFF"></stop><stop offset="1" stop-color="#3941FF"></stop></linearGradient></defs></svg>
|
||||
|
After Width: | Height: | Size: 1.7 KiB |
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 144 144" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Command Code</title><path fill-rule="evenodd" clip-rule="evenodd" d="M73.1399 5.87207H70.4648C53.6901 5.87207 41.6998 5.88454 32.5877 7.10962C23.6446 8.312 18.3583 10.5847 14.4715 14.4715C10.5847 18.3583 8.312 23.6446 7.10962 32.5877C5.88454 41.6998 5.87207 53.6901 5.87207 70.4648V73.1398C5.87207 89.9145 5.88454 101.905 7.10962 111.017C8.312 119.96 10.5847 125.246 14.4715 129.133C18.3583 133.02 23.6446 135.293 32.5877 136.495C41.6998 137.72 53.6901 137.733 70.4648 137.733H73.1398C89.9145 137.733 101.905 137.72 111.017 136.495C119.96 135.293 125.246 133.02 129.133 129.133C133.02 125.246 135.293 119.96 136.495 111.017C137.72 101.905 137.733 89.9146 137.733 73.1399V70.4648C137.733 53.6901 137.72 41.6998 136.495 32.5877C135.293 23.6446 133.02 18.3583 129.133 14.4715C125.246 10.5847 119.96 8.312 111.017 7.10962C101.905 5.88454 89.9146 5.87207 73.1399 5.87207ZM10.3193 10.3193C0 20.6387 0 37.2474 0 70.4648V73.1398C0 106.357 0 122.966 10.3193 133.285C20.6387 143.605 37.2474 143.605 70.4648 143.605H73.1398C106.357 143.605 122.966 143.605 133.285 133.285C143.605 122.966 143.605 106.357 143.605 73.1399V70.4648C143.605 37.2474 143.605 20.6387 133.285 10.3193C122.966 0 106.357 0 73.1399 0H70.4648C37.2474 0 20.6387 0 10.3193 10.3193Z"/><path d="M98.8049 27.6163C89.3295 27.6163 81.6214 35.3243 81.6214 44.7997V52.1641H61.9832V44.7997C61.9832 35.3243 54.2752 27.6163 44.7997 27.6163C35.3243 27.6163 27.6163 35.3243 27.6163 44.7997C27.6163 54.2752 35.3243 61.9832 44.7997 61.9832H52.1641V81.6214H44.7997C35.3243 81.6214 27.6163 89.3295 27.6163 98.8049C27.6163 108.28 35.3243 115.988 44.7997 115.988C54.2752 115.988 61.9832 108.28 61.9832 98.8049V91.4406H81.6214V98.8049C81.6214 108.28 89.3295 115.988 98.8049 115.988C108.28 115.988 115.988 108.28 115.988 98.8049C115.988 89.3295 108.28 81.6214 98.8049 81.6214H91.4406V61.9832H98.8049C108.28 61.9832 115.988 54.2752 115.988 44.7997C115.988 35.3243 108.28 27.6163 98.8049 27.6163ZM91.4406 52.1641V44.7997C91.4406 40.7248 94.73 37.4354 98.8049 37.4354C102.88 37.4354 106.169 40.7248 106.169 44.7997C106.169 48.8747 102.88 52.1641 98.8049 52.1641H91.4406ZM44.7997 52.1641C40.7248 52.1641 37.4354 48.8747 37.4354 44.7997C37.4354 40.7248 40.7248 37.4354 44.7997 37.4354C48.8747 37.4354 52.1641 40.7248 52.1641 44.7997V52.1641H44.7997ZM61.9832 81.6214V61.9832H81.6214V81.6214H61.9832ZM98.8049 106.169C94.73 106.169 91.4406 102.88 91.4406 98.8049V91.4406H98.8049C102.88 91.4406 106.169 94.73 106.169 98.8049C106.169 102.88 102.88 106.169 98.8049 106.169ZM44.7997 106.169C40.7248 106.169 37.4354 102.88 37.4354 98.8049C37.4354 94.73 40.7248 91.4406 44.7997 91.4406H52.1641V98.8049C52.1641 102.88 48.8747 106.169 44.7997 106.169Z"/></svg>
|
||||
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 16 KiB |
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Cursor</title><path d="M22.106 5.68L12.5.135a.998.998 0 00-.998 0L1.893 5.68a.84.84 0 00-.419.726v11.186c0 .3.16.577.42.727l9.607 5.547a.999.999 0 00.998 0l9.608-5.547a.84.84 0 00.42-.727V6.407a.84.84 0 00-.42-.726zm-.603 1.176L12.228 22.92c-.063.108-.228.064-.228-.061V12.34a.59.59 0 00-.295-.51l-9.11-5.26c-.107-.062-.063-.228.062-.228h18.55c.264 0 .428.286.296.514z"></path></svg>
|
||||
|
After Width: | Height: | Size: 547 B |
@@ -0,0 +1 @@
|
||||
<svg height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>DeepSeek</title><path d="M23.748 4.482c-.254-.124-.364.113-.512.234-.051.039-.094.09-.137.136-.372.397-.806.657-1.373.626-.829-.046-1.537.214-2.163.848-.133-.782-.575-1.248-1.247-1.548-.352-.156-.708-.311-.955-.65-.172-.241-.219-.51-.305-.774-.055-.16-.11-.323-.293-.35-.2-.031-.278.136-.356.276-.313.572-.434 1.202-.422 1.84.027 1.436.633 2.58 1.838 3.393.137.093.172.187.129.323-.082.28-.18.552-.266.833-.055.179-.137.217-.329.14a5.526 5.526 0 01-1.736-1.18c-.857-.828-1.631-1.742-2.597-2.458a11.365 11.365 0 00-.689-.471c-.985-.957.13-1.743.388-1.836.27-.098.093-.432-.779-.428-.872.004-1.67.295-2.687.684a3.055 3.055 0 01-.465.137 9.597 9.597 0 00-2.883-.102c-1.885.21-3.39 1.102-4.497 2.623C.082 8.606-.231 10.684.152 12.85c.403 2.284 1.569 4.175 3.36 5.653 1.858 1.533 3.997 2.284 6.438 2.14 1.482-.085 3.133-.284 4.994-1.86.47.234.962.327 1.78.397.63.059 1.236-.03 1.705-.128.735-.156.684-.837.419-.961-2.155-1.004-1.682-.595-2.113-.926 1.096-1.296 2.746-2.642 3.392-7.003.05-.347.007-.565 0-.845-.004-.17.035-.237.23-.256a4.173 4.173 0 001.545-.475c1.396-.763 1.96-2.015 2.093-3.517.02-.23-.004-.467-.247-.588zM11.581 18c-2.089-1.642-3.102-2.183-3.52-2.16-.392.024-.321.471-.235.763.09.288.207.486.371.739.114.167.192.416-.113.603-.673.416-1.842-.14-1.897-.167-1.361-.802-2.5-1.86-3.301-3.307-.774-1.393-1.224-2.887-1.298-4.482-.02-.386.093-.522.477-.592a4.696 4.696 0 011.529-.039c2.132.312 3.946 1.265 5.468 2.774.868.86 1.525 1.887 2.202 2.891.72 1.066 1.494 2.082 2.48 2.914.348.292.625.514.891.677-.802.09-2.14.11-3.054-.614zm1-6.44a.306.306 0 01.415-.287.302.302 0 01.2.288.306.306 0 01-.31.307.303.303 0 01-.304-.308zm3.11 1.596c-.2.081-.399.151-.59.16a1.245 1.245 0 01-.798-.254c-.274-.23-.47-.358-.552-.758a1.73 1.73 0 01.016-.588c.07-.327-.008-.537-.239-.727-.187-.156-.426-.199-.688-.199a.559.559 0 01-.254-.078c-.11-.054-.2-.19-.114-.358.028-.054.16-.186.192-.21.356-.202.767-.136 1.146.016.352.144.618.408 1.001.782.391.451.462.576.685.914.176.265.336.537.445.848.067.195-.019.354-.25.452z" fill="#4D6BFE"></path></svg>
|
||||
|
After Width: | Height: | Size: 2.1 KiB |
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Devin</title><path d="M2.033 9.867l2.554 1.483a.589.589 0 00.592 0l2.554-1.483.01-.008a.608.608 0 00.11-.084l.013-.015a.631.631 0 00.076-.1c.003-.005.008-.01.01-.016a.558.558 0 00.052-.125l.007-.028a.611.611 0 00.019-.14V7.868c0-.572.307-1.105.8-1.392a1.595 1.595 0 011.598 0l1.277.742a.54.54 0 00.129.053l.028.01c.044.01.088.015.133.016h.006l.013-.002a.587.587 0 00.27-.074l.011-.004 2.554-1.483a.596.596 0 00.297-.516V2.253a.595.595 0 00-.297-.516L12.293.257a.587.587 0 00-.591 0L9.148 1.737l-.01.01a.609.609 0 00-.109.083l-.014.015a.632.632 0 00-.076.1c-.003.005-.008.01-.01.016a.57.57 0 00-.052.124l-.007.028a.612.612 0 00-.018.14v1.483c0 .572-.307 1.105-.8 1.393a1.597 1.597 0 01-1.599 0l-1.276-.742a.603.603 0 00-.13-.053l-.028-.008a.658.658 0 00-.133-.018h-.02a.57.57 0 00-.269.074c-.003.002-.008.002-.012.005L2.033 5.872a.596.596 0 00-.297.515v2.966c0 .213.113.41.297.515z"></path><path d="M15.943 10.607a1.596 1.596 0 011.599 0l1.276.74c.041.025.085.04.13.055l.028.008c.043.01.088.016.133.018h.005c.005 0 .01-.002.014-.003a.474.474 0 00.122-.016l.021-.005a.616.616 0 00.126-.052c.004-.002.009-.002.013-.005l2.554-1.482a.597.597 0 00.297-.516V6.383a.596.596 0 00-.297-.515l-2.552-1.483a.587.587 0 00-.592 0l-2.553 1.482-.011.008a.61.61 0 00-.108.084l-.014.016a.637.637 0 00-.076.1c-.003.005-.008.01-.01.016a.57.57 0 00-.052.124l-.007.029a.612.612 0 00-.018.14v1.482c0 .572-.307 1.105-.8 1.393a1.597 1.597 0 01-1.599 0l-1.276-.742a.584.584 0 00-.13-.053l-.028-.008a.62.62 0 00-.133-.018h-.02a.587.587 0 00-.269.074l-.012.004L9.15 10a.596.596 0 00-.296.516v2.966c0 .212.112.409.296.515l2.554 1.483s.008.002.012.005c.04.022.082.04.126.052l.02.004a.57.57 0 00.123.017l.014.002h.006c.054 0 .108-.01.16-.025a.587.587 0 00.13-.054l1.277-.741a1.597 1.597 0 012.398 1.392v1.482c0 .049.007.095.019.14l.007.028a.619.619 0 00.051.125c.004.006.008.01.01.016a.6.6 0 00.076.1l.014.015c.033.032.069.06.108.084.004.002.006.006.011.008l2.554 1.483a.59.59 0 00.593 0l2.554-1.483a.597.597 0 00.296-.516v-2.965a.595.595 0 00-.296-.516l-2.554-1.483s-.008-.002-.012-.005a.54.54 0 00-.126-.051c-.007-.003-.013-.003-.02-.005a.635.635 0 00-.125-.017h-.018a.557.557 0 00-.16.026.588.588 0 00-.13.053l-1.276.742a1.595 1.595 0 01-1.598 0 1.615 1.615 0 010-2.785l-.005-.001z"></path><path d="M14.848 18.265l-2.554-1.482-.012-.005a.526.526 0 00-.126-.052c-.007-.002-.014-.002-.02-.005a.64.64 0 00-.124-.017h-.02a.56.56 0 00-.16.026.588.588 0 00-.13.053l-1.276.742a1.594 1.594 0 01-1.598 0c-.493-.286-.8-.82-.8-1.393V14.65a.563.563 0 00-.018-.14l-.008-.028a.604.604 0 00-.051-.124l-.01-.017a.603.603 0 00-.076-.1l-.014-.015a.596.596 0 00-.109-.084c-.003-.002-.005-.006-.01-.008L5.178 12.65a.587.587 0 00-.591 0l-2.554 1.483a.596.596 0 00-.297.516v2.965c0 .213.113.41.297.516l2.554 1.483.012.004a.618.618 0 00.267.074l.016.002h.007a.55.55 0 00.16-.026.584.584 0 00.129-.053l1.277-.742a1.597 1.597 0 012.398 1.393v1.482c0 .05.007.095.019.14l.007.028c.013.044.03.085.051.125l.01.016c.022.036.047.07.076.1l.014.015c.032.032.069.06.109.084l.01.008 2.554 1.483a.587.587 0 00.593 0l2.554-1.483a.596.596 0 00.296-.515v-2.966a.596.596 0 00-.296-.516h-.002z"></path></svg>
|
||||
|
After Width: | Height: | Size: 3.2 KiB |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 192 192" width="192" height="192" role="img" aria-label="Empryo"><g transform="translate(16 16)"><defs><mask id="mote-small-cutout" maskUnits="userSpaceOnUse" x="0" y="0" width="160" height="160" style="mask-type:luminance"><g style="transform-origin:34px 40px"><path d="M34 40L26 30" fill="none" stroke="#fff" stroke-width="4.5" stroke-linecap="round"/></g><g style="transform-origin:79px 24px"><path d="M79 24L82 11" fill="none" stroke="#fff" stroke-width="4.5" stroke-linecap="round"/></g><g style="transform-origin:130px 51px"><path d="M130 51L144 48" fill="none" stroke="#fff" stroke-width="4.5" stroke-linecap="round"/></g><g style="transform-origin:120px 113px"><path d="M120 113L130 126" fill="none" stroke="#fff" stroke-width="4.5" stroke-linecap="round"/></g><g style="transform-origin:57px 127px"><path d="M57 127L49 142" fill="none" stroke="#fff" stroke-width="4.5" stroke-linecap="round"/></g><g style="transform-origin:24px 76px"><path d="M24 76L9 73" fill="none" stroke="#fff" stroke-width="4.5" stroke-linecap="round"/></g><path d="M37 38C50 18 86 15 110 29C135 33 144 63 136 88C137 114 111 136 82 132C55 142 29 119 27 97C14 77 20 49 37 38Z" fill="#fff"/><path d="M44 43C56 29 85 26 105 38C125 40 134 64 127 86C128 107 107 126 83 122C61 132 38 112 36 93C26 75 30 53 44 43Z" fill="#000"/><circle cx="99" cy="66" r="25" fill="#fff"/><circle cx="99" cy="66" r="10" fill="#000"/><circle cx="104" cy="60" r="3" fill="#fff"/></mask></defs><g id="empryo-mark" mask="url(#mote-small-cutout)"><g data-cilium="0" style="transform-origin:34px 40px"><path d="M34 40L26 30" fill="none" stroke="#31697e" stroke-width="4.5" stroke-linecap="round"/></g><g data-cilium="2" style="transform-origin:79px 24px"><path d="M79 24L82 11" fill="none" stroke="#31697e" stroke-width="4.5" stroke-linecap="round"/></g><g data-cilium="4" style="transform-origin:130px 51px"><path d="M130 51L144 48" fill="none" stroke="#31697e" stroke-width="4.5" stroke-linecap="round"/></g><g data-cilium="6" style="transform-origin:120px 113px"><path d="M120 113L130 126" fill="none" stroke="#31697e" stroke-width="4.5" stroke-linecap="round"/></g><g data-cilium="8" style="transform-origin:57px 127px"><path d="M57 127L49 142" fill="none" stroke="#31697e" stroke-width="4.5" stroke-linecap="round"/></g><g data-cilium="10" style="transform-origin:24px 76px"><path d="M24 76L9 73" fill="none" stroke="#31697e" stroke-width="4.5" stroke-linecap="round"/></g><path data-motion="membrane" d="M37 38C50 18 86 15 110 29C135 33 144 63 136 88C137 114 111 136 82 132C55 142 29 119 27 97C14 77 20 49 37 38Z" fill="#31697e"/><path d="M44 43C56 29 85 26 105 38C125 40 134 64 127 86C128 107 107 126 83 122C61 132 38 112 36 93C26 75 30 53 44 43Z" fill="#000"/><circle cx="99" cy="66" r="25" fill="#a34170"/><circle cx="99" cy="66" r="10" fill="#000"/><circle cx="104" cy="60" r="3" fill="#a34170"/></g></g></svg>
|
||||
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 5.9 KiB |
@@ -0,0 +1 @@
|
||||
<svg height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Gemini CLI</title><path d="M0 4.391A4.391 4.391 0 014.391 0h15.217A4.391 4.391 0 0124 4.391v15.217A4.391 4.391 0 0119.608 24H4.391A4.391 4.391 0 010 19.608V4.391z" fill="url(#lobe-icons-gemini-cli-_R_0_)"></path><path clip-rule="evenodd" d="M19.74 1.444a2.816 2.816 0 012.816 2.816v15.48a2.816 2.816 0 01-2.816 2.816H4.26a2.816 2.816 0 01-2.816-2.816V4.26A2.816 2.816 0 014.26 1.444h15.48zM7.236 8.564l7.752 3.728-7.752 3.727v2.802l9.557-4.596v-3.866L7.236 5.763v2.801z" fill="#1E1E2E" fill-rule="evenodd"></path><defs><linearGradient gradientUnits="userSpaceOnUse" id="lobe-icons-gemini-cli-_R_0_" x1="24" x2="0" y1="6.587" y2="16.494"><stop stop-color="#EE4D5D"></stop><stop offset=".328" stop-color="#B381DD"></stop><stop offset=".476" stop-color="#207CFE"></stop></linearGradient></defs></svg>
|
||||
|
After Width: | Height: | Size: 921 B |
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>GithubCopilot</title><path d="M19.245 5.364c1.322 1.36 1.877 3.216 2.11 5.817.622 0 1.2.135 1.592.654l.73.964c.21.278.323.61.323.955v2.62c0 .339-.173.669-.453.868C20.239 19.602 16.157 21.5 12 21.5c-4.6 0-9.205-2.583-11.547-4.258-.28-.2-.452-.53-.453-.868v-2.62c0-.345.113-.679.321-.956l.73-.963c.392-.517.974-.654 1.593-.654l.029-.297c.25-2.446.81-4.213 2.082-5.52 2.461-2.54 5.71-2.851 7.146-2.864h.198c1.436.013 4.685.323 7.146 2.864zm-7.244 4.328c-.284 0-.613.016-.962.05-.123.447-.305.85-.57 1.108-1.05 1.023-2.316 1.18-2.994 1.18-.638 0-1.306-.13-1.851-.464-.516.165-1.012.403-1.044.996a65.882 65.882 0 00-.063 2.884l-.002.48c-.002.563-.005 1.126-.013 1.69.002.326.204.63.51.765 2.482 1.102 4.83 1.657 6.99 1.657 2.156 0 4.504-.555 6.985-1.657a.854.854 0 00.51-.766c.03-1.682.006-3.372-.076-5.053-.031-.596-.528-.83-1.046-.996-.546.333-1.212.464-1.85.464-.677 0-1.942-.157-2.993-1.18-.266-.258-.447-.661-.57-1.108-.32-.032-.64-.049-.96-.05zm-2.525 4.013c.539 0 .976.426.976.95v1.753c0 .525-.437.95-.976.95a.964.964 0 01-.976-.95v-1.752c0-.525.437-.951.976-.951zm5 0c.539 0 .976.426.976.95v1.753c0 .525-.437.95-.976.95a.964.964 0 01-.976-.95v-1.752c0-.525.437-.951.976-.951zM7.635 5.087c-1.05.102-1.935.438-2.385.906-.975 1.037-.765 3.668-.21 4.224.405.394 1.17.657 1.995.657h.09c.649-.013 1.785-.176 2.73-1.11.435-.41.705-1.433.675-2.47-.03-.834-.27-1.52-.63-1.813-.39-.336-1.275-.482-2.265-.394zm6.465.394c-.36.292-.6.98-.63 1.813-.03 1.037.24 2.06.675 2.47.968.957 2.136 1.104 2.776 1.11h.044c.825 0 1.59-.263 1.995-.657.555-.556.765-3.187-.21-4.224-.45-.468-1.335-.804-2.385-.906-.99-.088-1.875.058-2.265.394zM12 7.615c-.24 0-.525.015-.84.044.03.16.045.336.06.526l-.001.159a2.94 2.94 0 01-.014.25c.225-.022.425-.027.612-.028h.366c.187 0 .387.006.612.028-.015-.146-.015-.277-.015-.409.015-.19.03-.365.06-.526a9.29 9.29 0 00-.84-.044z"></path></svg>
|
||||
|
After Width: | Height: | Size: 2.0 KiB |
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Goose</title><path d="M21.595 23.61c1.167-.254 2.405-.944 2.405-.944l-2.167-1.784a12.124 12.124 0 01-2.695-3.131 12.127 12.127 0 00-3.97-4.049l-.794-.462a1.115 1.115 0 01-.488-.815.844.844 0 01.154-.575c.413-.582 2.548-3.115 2.94-3.44.503-.416 1.065-.762 1.586-1.159.074-.056.148-.112.221-.17.003-.002.007-.004.009-.007.167-.131.325-.272.45-.438.453-.524.563-.988.59-1.193-.061-.197-.244-.639-.753-1.148.319.02.705.272 1.056.569.235-.376.481-.773.727-1.171.165-.266-.08-.465-.086-.471h-.001V3.22c-.007-.007-.206-.25-.471-.086-.567.35-1.134.702-1.639 1.021 0 0-.597-.012-1.305.599a2.464 2.464 0 00-.438.45l-.007.009c-.058.072-.114.147-.17.221-.397.521-.743 1.083-1.16 1.587-.323.391-2.857 2.526-3.44 2.94a.842.842 0 01-.574.153 1.115 1.115 0 01-.815-.488l-.462-.794a12.123 12.123 0 00-4.049-3.97 12.133 12.133 0 01-3.13-2.695L1.332 0S.643 1.238.39 2.405c.352.428 1.27 1.49 2.34 2.302C1.58 4.167.73 3.75.06 3.4c-.103.765-.063 1.92.043 2.816.726.317 1.961.806 3.219 1.066-1.006.236-2.11.278-2.961.262.15.554.358 1.119.64 1.688.119.263.25.52.39.77.452.125 2.222.383 3.164.171l-2.51.897a27.776 27.776 0 002.544 2.726c2.031-1.092 2.494-1.241 4.018-2.238-2.467 2.008-3.108 2.828-3.8 3.67l-.483.678c-.25.351-.469.725-.65 1.117-.61 1.31-1.47 4.1-1.47 4.1-.154.486.202.842.674.674 0 0 2.79-.861 4.1-1.47.392-.182.766-.4 1.118-.65l.677-.483c.227-.187.453-.37.701-.586 0 0 1.705 2.02 3.458 3.349l.896-2.511c-.211.942.046 2.712.17 3.163.252.142.509.272.772.392.569.28 1.134.49 1.688.64-.016-.853.026-1.956.261-2.962.26 1.258.75 2.493 1.067 3.219.895.106 2.051.146 2.816.043a73.87 73.87 0 01-1.308-2.67c.811 1.07 1.874 1.988 2.302 2.34h-.001z"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.8 KiB |
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Grok</title><path d="M9.27 15.29l7.978-5.897c.391-.29.95-.177 1.137.272.98 2.369.542 5.215-1.41 7.169-1.951 1.954-4.667 2.382-7.149 1.406l-2.711 1.257c3.889 2.661 8.611 2.003 11.562-.953 2.341-2.344 3.066-5.539 2.388-8.42l.006.007c-.983-4.232.242-5.924 2.75-9.383.06-.082.12-.164.179-.248l-3.301 3.305v-.01L9.267 15.292M7.623 16.723c-2.792-2.67-2.31-6.801.071-9.184 1.761-1.763 4.647-2.483 7.166-1.425l2.705-1.25a7.808 7.808 0 00-1.829-1A8.975 8.975 0 005.984 5.83c-2.533 2.536-3.33 6.436-1.962 9.764 1.022 2.487-.653 4.246-2.34 6.022-.599.63-1.199 1.259-1.682 1.925l7.62-6.815"></path></svg>
|
||||
|
After Width: | Height: | Size: 756 B |
|
After Width: | Height: | Size: 21 KiB |
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="12 16 40 40" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Hermes Agent</title><path d="M21 20h7v14h8V20h7v32h-7V40h-8v12h-7zM13 21l7 3v6l-7-3zM51 21l-7 3v6l7-3z"></path></svg>
|
||||
|
After Width: | Height: | Size: 284 B |
|
After Width: | Height: | Size: 12 KiB |
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Kilo Code</title><path d="M0 0v24h24V0H0zm22.222 22.222H1.778V1.778h20.444v20.444zm-7.555-4.964h2.222v1.778h-2.794L12.89 17.83v-2.794h1.778v2.222zm4 0h-1.778v-2.222h-2.222v-1.778h2.793l1.207 1.207v2.793zm-7.556-2.591H9.333v-1.778h1.778v1.778zm-5.778-1.778h1.778v4h4v1.778H6.54L5.333 17.46V12.89zm13.334-3.556v1.778h-5.778V9.333h1.987V7.111h-1.987V5.333h2.558l1.206 1.207v2.793h2.014zm-11.556-2h2.222l1.778 1.778v2H9.333v-2H7.111v2H5.333V5.333h1.778v2zm4 0H9.333v-2h1.778v2z"></path></svg>
|
||||
|
After Width: | Height: | Size: 652 B |
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Kimi</title><path d="M21.846 0a1.923 1.923 0 110 3.846H20.15a.226.226 0 01-.227-.226V1.923C19.923.861 20.784 0 21.846 0z"></path><path d="M11.065 11.199l7.257-7.2c.137-.136.06-.41-.116-.41H14.3a.164.164 0 00-.117.051l-7.82 7.756c-.122.12-.302.013-.302-.179V3.82c0-.127-.083-.23-.185-.23H3.186c-.103 0-.186.103-.186.23V19.77c0 .128.083.23.186.23h2.69c.103 0 .186-.102.186-.23v-3.25c0-.069.025-.135.069-.178l2.424-2.406a.158.158 0 01.205-.023l6.484 4.772a7.677 7.677 0 003.453 1.283c.108.012.2-.095.2-.23v-3.06c0-.117-.07-.212-.164-.227a5.028 5.028 0 01-2.027-.807l-5.613-4.064c-.117-.078-.132-.279-.028-.381z"></path></svg>
|
||||
|
After Width: | Height: | Size: 786 B |
@@ -0,0 +1 @@
|
||||
<svg height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Kiro</title><path d="M18.8 0H5.2A5.2 5.2 0 000 5.2v13.6A5.2 5.2 0 005.2 24h13.6a5.2 5.2 0 005.2-5.2V5.2A5.2 5.2 0 0018.8 0z" fill="#9046FF"></path><path d="M7.97 16.376c-1.644 3.642 1.86 4.556 4.443 2.424.76 2.39 3.608.607 4.631-1.247 2.251-4.084 1.342-8.249 1.108-9.108-1.6-5.859-9.6-5.869-10.976.03-.323 1.033-.328 2.206-.507 3.423-.09.617-.16 1.009-.393 1.655-.139.373-.323.7-.62 1.257-.458.865-.264 2.53 2.101 1.665l.224-.1h-.01l-.001.001z" fill="#fff"></path><path d="M12.722 10.985c-.656 0-.755-.785-.755-1.252 0-.423.074-.756.218-.97a.61.61 0 01.537-.283c.229 0 .428.095.567.289.159.218.243.55.243.964 0 .785-.303 1.252-.805 1.252h-.005zm2.703 0c-.656 0-.755-.785-.755-1.252 0-.423.074-.756.219-.97a.61.61 0 01.536-.283c.229 0 .428.095.567.289.159.218.243.55.243.964 0 .785-.303 1.252-.805 1.252h-.005z" fill="#000"></path></svg>
|
||||
|
After Width: | Height: | Size: 960 B |
|
After Width: | Height: | Size: 5.9 KiB |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -25 150 150" width="1em" height="1em"><title>Meta</title><defs><linearGradient gradientUnits="userSpaceOnUse" id="meta-a" x1="124.599" x2="159.703" y1="96.689" y2="57.25"><stop offset="0.21" stop-color="#0278F1"></stop><stop offset="0.533" stop-color="#0180FA"></stop></linearGradient><linearGradient gradientUnits="userSpaceOnUse" id="meta-b" x1="43.859" x2="0" y1="4.984" y2="63.795"><stop offset="0.427" stop-color="#0165E0"></stop><stop offset="0.917" stop-color="#0180FA"></stop></linearGradient><linearGradient gradientUnits="userSpaceOnUse" id="meta-c" x1="28.409" x2="134.567" y1="28.907" y2="71.769"><stop stop-color="#0064E0"></stop><stop offset="0.656" stop-color="#0066E2"></stop><stop offset="1" stop-color="#0278F1"></stop></linearGradient></defs><path d="M107.654 0c-12.3 0-21.915 9.264-30.618 21.032C65.076 5.802 55.073 0 43.103 0 18.698 0 0 31.76 0 65.376 0 86.41 10.177 99.679 27.223 99.679c12.268 0 21.092-5.784 36.778-33.203 0 0 6.539-11.547 11.037-19.501a514.1 514.1 0 0 1 4.98 8.227l7.356 12.374c14.329 23.977 22.312 32.103 36.778 32.103C140.758 99.68 150 86.23 150 64.757 150 29.56 130.88 0 107.654 0ZM52.039 59.051C39.322 78.987 34.922 83.455 27.841 83.455c-7.287 0-11.617-6.397-11.617-17.804 0-24.404 12.167-49.359 26.672-49.359 7.855 0 14.42 4.537 24.474 18.93-9.547 14.645-15.33 23.83-15.33 23.83Zm47.999-2.51-8.795-14.667c-2.38-3.87-4.66-7.428-6.862-10.689 7.927-12.234 14.465-18.33 22.241-18.33 16.155 0 29.079 23.786 29.079 53.002 0 11.137-3.647 17.599-11.205 17.599-7.244 0-10.704-4.785-24.458-26.914Z" fill="#0180FA"></path><path d="M145.119 34.888h-14.878c3.44 8.718 5.46 19.42 5.46 30.969 0 11.137-3.647 17.599-11.205 17.599-1.403 0-2.663-.18-3.884-.63V99.5a33.48 33.48 0 0 0 3.54.18C140.758 99.68 150 86.23 150 64.756c0-10.702-1.768-20.882-4.881-29.868Z" fill="url(#meta-a)"></path><path d="M43.103 0c.253 0 .505.003.756.008v16.308c-.319-.016-.64-.024-.962-.024-14.138 0-26.055 23.706-26.65 47.503H.014C.588 30.77 19.08 0 43.103 0Z" fill="url(#meta-b)"></path><path d="M43.103 0c11.115 0 20.534 5.004 31.4 17.913 3.055 3.817 6.74 8.777 10.682 14.511l.017.025.024-.003c1.939 2.912 3.94 6.05 6.017 9.428l8.795 14.668c13.754 22.13 17.214 26.913 24.458 26.913h.103v16.22c-.148.003-.297.004-.447.004-14.466 0-22.449-8.126-36.778-32.103l-7.356-12.374a587.065 587.065 0 0 0-2.287-3.822l.019-.045c-5.483-8.971-8.971-14.454-11.962-18.44l-.05.037c-9.15-12.59-15.42-16.64-22.842-16.64h-.034V.001l.24-.001Z" fill="url(#meta-c)"></path></svg>
|
||||
|
After Width: | Height: | Size: 2.5 KiB |
@@ -0,0 +1,11 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="1em" height="1em" role="img" aria-label="MiMo Code">
|
||||
<title>MiMo Code</title>
|
||||
<defs>
|
||||
<linearGradient id="mimoG" x1="0" y1="0" x2="1" y2="1">
|
||||
<stop offset="0" stop-color="#7FD4FF"/><stop offset="1" stop-color="#2B6FF3"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<circle cx="9" cy="9" r="6.2" fill="none" stroke="url(#mimoG)" stroke-width="2"/>
|
||||
<circle cx="15" cy="15" r="6.2" fill="none" stroke="url(#mimoG)" stroke-width="2" opacity=".75"/>
|
||||
<circle cx="15" cy="15" r="1.7" fill="#2B6FF3"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 575 B |
@@ -0,0 +1 @@
|
||||
<svg height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Minimax</title><defs><linearGradient id="lobe-icons-minimax-_R_0_" x1="0%" x2="100.182%" y1="50.057%" y2="50.057%"><stop offset="0%" stop-color="#E2167E"></stop><stop offset="100%" stop-color="#FE603C"></stop></linearGradient></defs><path d="M16.278 2c1.156 0 2.093.927 2.093 2.07v12.501a.74.74 0 00.744.709.74.74 0 00.743-.709V9.099a2.06 2.06 0 012.071-2.049A2.06 2.06 0 0124 9.1v6.561a.649.649 0 01-.652.645.649.649 0 01-.653-.645V9.1a.762.762 0 00-.766-.758.762.762 0 00-.766.758v7.472a2.037 2.037 0 01-2.048 2.026 2.037 2.037 0 01-2.048-2.026v-12.5a.785.785 0 00-.788-.753.785.785 0 00-.789.752l-.001 15.904A2.037 2.037 0 0113.441 22a2.037 2.037 0 01-2.048-2.026V18.04c0-.356.292-.645.652-.645.36 0 .652.289.652.645v1.934c0 .263.142.506.372.638.23.131.514.131.744 0a.734.734 0 00.372-.638V4.07c0-1.143.937-2.07 2.093-2.07zm-5.674 0c1.156 0 2.093.927 2.093 2.07v11.523a.648.648 0 01-.652.645.648.648 0 01-.652-.645V4.07a.785.785 0 00-.789-.78.785.785 0 00-.789.78v14.013a2.06 2.06 0 01-2.07 2.048 2.06 2.06 0 01-2.071-2.048V9.1a.762.762 0 00-.766-.758.762.762 0 00-.766.758v3.8a2.06 2.06 0 01-2.071 2.049A2.06 2.06 0 010 12.9v-1.378c0-.357.292-.646.652-.646.36 0 .653.29.653.646V12.9c0 .418.343.757.766.757s.766-.339.766-.757V9.099a2.06 2.06 0 012.07-2.048 2.06 2.06 0 012.071 2.048v8.984c0 .419.343.758.767.758.423 0 .766-.339.766-.758V4.07c0-1.143.937-2.07 2.093-2.07z" fill="url(#lobe-icons-minimax-_R_0_)" fill-rule="nonzero"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 10 KiB |
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="12 16 40 40" width="1em" xmlns="http://www.w3.org/2000/svg"><title>omp</title><path d="M14 16h36v8H40v32h-8V24h-6v22h-8V24h-4z"></path></svg>
|
||||
|
After Width: | Height: | Size: 240 B |
@@ -0,0 +1,11 @@
|
||||
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
||||
<!-- OpenChamber's logo (github.com/openchamber/openchamber, MIT: packages/web/public/favicon.svg) -->
|
||||
<g transform="translate(16, 16) scale(0.48)">
|
||||
<path d="M0 0 L-26 -15 L-26 15 L0 30 Z" fill="#000" fill-opacity="0.25" stroke="#000" stroke-width="4" stroke-linejoin="round"/>
|
||||
<path d="M0 0 L26 -15 L26 15 L0 30 Z" fill="#000" fill-opacity="0.4" stroke="#000" stroke-width="4" stroke-linejoin="round"/>
|
||||
<path d="M0 -30 L-26 -15 L0 0 L26 -15 Z" fill="none" stroke="#000" stroke-width="4" stroke-linejoin="round"/>
|
||||
<g transform="matrix(0.866, 0.5, -0.866, 0.5, 0, -15) scale(0.55)">
|
||||
<rect x="-12" y="-14" width="24" height="28" fill="#000" fill-opacity="0.4" stroke="#000" stroke-width="8"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 824 B |
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>opencode</title><path d="M16 6H8v12h8V6zm4 16H4V2h16v20z"></path></svg>
|
||||
|
After Width: | Height: | Size: 235 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="139 129 954 954"><defs><clipPath id="rounded"><rect x="139" y="129" width="954" height="954" rx="230"/></clipPath><linearGradient id="a" x1="432" x2="978" y1="304" y2="884" gradientUnits="userSpaceOnUse"><stop stop-color="#111b2a"/><stop offset="1" stop-color="#091423"/></linearGradient><linearGradient id="b"><stop stop-color="#0e1928"/><stop offset=".4" stop-color="#0b2963"/><stop offset=".7" stop-color="#054ac8"/><stop offset=".82" stop-color="#0258f4"/><stop offset="1" stop-color="#015dfc"/></linearGradient><linearGradient xlink:href="#b" id="c" x1="964" x2="1065" y1="451" y2="423" gradientUnits="userSpaceOnUse"/><linearGradient xlink:href="#b" id="d" x1="365" x2="260" y1="800" y2="860" gradientUnits="userSpaceOnUse"/><linearGradient xlink:href="#b" id="e" x1="442" x2="350" y1="836" y2="905" gradientUnits="userSpaceOnUse"/></defs><g clip-path="url(#rounded)"><path fill="#fefefe" d="M0 0h1254v1254H0Z"/><path fill="#015dfc" d="M475 558v3c-1 0-3 1-4 1-16 4-31 9-47 14-1 0-2 1-4 1-76 26-179 67-217 143-7 15-9 29-4 45 2 5 4 10 8 14s4 4 4 6c1 1 3 1 4 2s2 1 3 2c9 6 18 10 29 14 4 1 4 1 8 3v2c-23 4-48-1-67-14-12-9-19-19-22-34-2-28 8-50 27-71 1-2 3-4 5-6s4-4 5-6l3-3h2c1-1 1-3 2-4 20-19 44-35 69-48 1-1 3-2 4-2 14-8 29-15 44-21l9-3c36-15 74-26 112-34 1 0 2 0 3-1 17-3 17-3 24-3m571 110c-7 13-22 25-33 35l-3 3c-7 6-15 12-23 18-1 1-2 2-3 2-71 54-153 93-236 122-1 0-2 1-3 1-31 11-63 20-95 27-1 0-1 0-4 1-65 14-132 17-198 8 0-1-1-1-1-2 4-1 7-2 11-2 141-16 278-54 423-118 1 0 2-1 3-1 26-12 51-24 75-38 1 0 1 0 5-3 14-8 27-16 40-24 1-1 2-1 4-2 11-8 21-16 32-24 4-3 4-3 6-3"/><path fill="url(#a)" d="M532 329c35 18 68 41 97 68l9 6 12 12c3 3 6 6 10 9 3 3 6 5 8 8 36 34 36 34 56 42l-3-3-17-17c1-5 2-8 5-13 0-1 0-1 2-4 1-2 1-4 2-5 1-2 2-3 2-5 13-26 25-51 45-72 0-1 0-1 2-3 24-26 60-37 94-39 20-1 39 1 58 6 19 6 39 8 58 2-1 6-3 10-7 14-3 2-6 4-9 5 1 1 2 1 3 2 16 11 26 24 30 44 3 18 3 18 0 24h3c50-4 50-4 71 10 2 2 2 2 3 7-5 5-10 6-16 8-31 9-53 23-72 49-1 1-2 2-3 4-24 33-41 70-57 108-17 42-39 80-68 114-1 1-1 2-2 2-10 12-22 24-34 34-2 1-4 3-6 5-12 10-24 18-37 26-1 1-3 2-4 3-73 47-165 69-251 56-21-3-38 2-58 8-1 0-1 0-4 1-2 1-3 1-4 2-2 0-3 0-4 1-6 2-8 7-11 13-4 7-8 14-13 20l-3 3c-9 11-19 23-34 26-6 0-7 0-11-4-2-3-1-6-1-10v-3c-1 1-3 2-4 3-7 4-12 6-20 5-4-2-5-3-6-7 0-8 3-13 8-18h-3c-4-1-4-1-6-3-2-4-2-5-1-9 17-29 46-44 77-53-17-3-37-6-53 2-2 2-4 5-6 7-4 6-9 11-14 16l-3 3c-12 12-27 25-45 29-5 0-6 0-10-4-2-2-2-2-2-6 1-5 2-7 4-11-10 3-10 3-13 4-5 1-8 1-13 0-4-4-4-4-5-8 1-7 6-11 11-16-2-1-3-1-5-2l-2-2c1-11 11-18 19-25 18-16 40-27 63-35 5-2 9-4 13-8l4-4c-2 0-3-1-5-1-18-4-34-10-50-21v-3h3c33-3 64-17 86-42 3-3 6-7 8-11 3-3 6-7 10-10 2-3 4-5 6-8 6-7 13-14 19-21 2-1 3-2 4-3 7-7 14-14 22-20 2-2 4-4 6-5 32-27 68-49 104-69l3 3c9 7 20 10 32 12-2-1-3-2-5-3-24-15-41-37-55-62 0-1 0-1-3-5-5-8-9-16-14-25-15-27-32-52-51-76-1-1-2-3-3-4-6-8-13-15-19-23-4-4-8-9-12-14-1-1-2-2-3-4-12-15-12-15-12-23 1-4 1-4 3-6 25-15 74 11 97 22m288 38-3 3c-16 14-26 35-27 56 0 15 1 27 8 40 1 1 1 2 2 3 10 18 25 29 44 38 2 0 3 1 5 1v2l-3 1c-43 10-81 41-108 76-2 2-4 5-6 7-4 5-8 11-12 16-5 7-11 14-17 21-2 3-5 7-8 10-47 58-107 90-180 104-30 6-56 19-81 38-2 2-4 3-6 4-2 2-3 3-5 4 3 3 9 4 13 6 7 2 14 4 21 7 27 10 54 17 83 20h4c80 7 163-20 228-65 1-1 2-2 4-3 25-17 50-37 69-61 2-2 3-5 5-7 28-32 46-71 62-109 17-40 36-78 63-112-3-2-6-3-10-4-15-4-26-12-37-23 1-2 2-3 3-5 7-10 9-21 7-33-4-19-12-32-29-43-29-16-64-13-89 8"/><path fill="url(#c)" d="M985 405h3c0 2 1 4 1 6h4c49-5 49-5 67 7 4 4 4 4 6 7-1 2-1 3-2 5-1 0-2 1-4 1-3 1-6 2-10 3l-9 3c-19 6-35 15-49 30l-3 3-5 5-6 6c-3-1-5-3-8-4 1-5 2-7 6-11l-12-3c0-1-1-3-1-4 1-1 1-2 2-3 3-5 5-9 6-14 1-2 1-3 2-5 2-6 2-6 2-8l3-3c1-3 1-5 2-8 1-5 2-8 5-13"/><path fill="url(#d)" d="M308 782c1 0 1 1 2 1v4c1 1 3 1 4 2v2c2 0 3-1 5-1l2 2c8 8 15 11 26 11 3 1 7 3 10 4h5l3 1c-2 8-8 14-14 20-2 3-3 5-5 7-13 14-31 31-51 32-5 0-5 0-9-3-2-6 0-11 3-17q-4.5 0-9 3c-5 2-10 2-15 1-3-1-3-1-6-4-1-5 0-8 3-12 2-3 4-5 7-8l-6-3c0-2-1-4-1-6 10-12 21-23 35-31h3v-2c3-1 5-2 8-3"/><path fill="url(#e)" d="M393 824c1 1 2 1 3 2h4c6 1 7 3 11 6 3 1 7 2 10 3 1 1 2 1 4 2 3 1 3 1 8 2 6 1 7 2 10 7l-1 3h-2c-1 2-1 3-2 5-9 19-25 45-45 53-6 2-10 4-16 2-4-4-4-5-4-10 0-2 1-4 1-6-1 0-2 1-3 1-1 1-2 2-3 2-1 1-3 2-4 2-5 3-9 3-15 3-3-2-5-3-6-7 0-7 3-13 8-18-1 0-3-1-4-1-4-1-4-1-6-3-1-5 0-7 2-11 1-2 2-3 3-4s1-2 2-3l8-8c0-1 0-1 3-3 23-22 23-22 34-19"/><path fill="#0e1827" d="M880 387c10 6 19 13 23 25 1 7 1 12-2 18-4 5-8 8-15 8-8 0-11-2-16-7-4-9-3-17 0-25 2-4 2-4 6-8h2c-4-6-10-8-17-10h-15c2-4 2-4 5-6 10-3 20 1 29 5m-3 16c-2 2-2 2-2 6s0 4 4 8c5-3 5-3 6-6 0-3 0-3-3-8Z"/></g></svg>
|
||||
|
After Width: | Height: | Size: 4.5 KiB |
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Pi</title><path clip-rule="evenodd" d="M1 1h16.5v11H12v5.5H6.5V23H1V1zm5.5 5.5V12H12V6.5H6.5z"></path><path d="M17.5 12H23v11h-5.5V12z"></path></svg>
|
||||
|
After Width: | Height: | Size: 313 B |
|
After Width: | Height: | Size: 6.1 KiB |
@@ -0,0 +1 @@
|
||||
<svg height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Qwen</title><path d="M12.604 1.34c.393.69.784 1.382 1.174 2.075a.18.18 0 00.157.091h5.552c.174 0 .322.11.446.327l1.454 2.57c.19.337.24.478.024.837-.26.43-.513.864-.76 1.3l-.367.658c-.106.196-.223.28-.04.512l2.652 4.637c.172.301.111.494-.043.77-.437.785-.882 1.564-1.335 2.34-.159.272-.352.375-.68.37-.777-.016-1.552-.01-2.327.016a.099.099 0 00-.081.05 575.097 575.097 0 01-2.705 4.74c-.169.293-.38.363-.725.364-.997.003-2.002.004-3.017.002a.537.537 0 01-.465-.271l-1.335-2.323a.09.09 0 00-.083-.049H4.982c-.285.03-.553-.001-.805-.092l-1.603-2.77a.543.543 0 01-.002-.54l1.207-2.12a.198.198 0 000-.197 550.951 550.951 0 01-1.875-3.272l-.79-1.395c-.16-.31-.173-.496.095-.965.465-.813.927-1.625 1.387-2.436.132-.234.304-.334.584-.335a338.3 338.3 0 012.589-.001.124.124 0 00.107-.063l2.806-4.895a.488.488 0 01.422-.246c.524-.001 1.053 0 1.583-.006L11.704 1c.341-.003.724.032.9.34zm-3.432.403a.06.06 0 00-.052.03L6.254 6.788a.157.157 0 01-.135.078H3.253c-.056 0-.07.025-.041.074l5.81 10.156c.025.042.013.062-.034.063l-2.795.015a.218.218 0 00-.2.116l-1.32 2.31c-.044.078-.021.118.068.118l5.716.008c.046 0 .08.02.104.061l1.403 2.454c.046.081.092.082.139 0l5.006-8.76.783-1.382a.055.055 0 01.096 0l1.424 2.53a.122.122 0 00.107.062l2.763-.02a.04.04 0 00.035-.02.041.041 0 000-.04l-2.9-5.086a.108.108 0 010-.113l.293-.507 1.12-1.977c.024-.041.012-.062-.035-.062H9.2c-.059 0-.073-.026-.043-.077l1.434-2.505a.107.107 0 000-.114L9.225 1.774a.06.06 0 00-.053-.031zm6.29 8.02c.046 0 .058.02.034.06l-.832 1.465-2.613 4.585a.056.056 0 01-.05.029.058.058 0 01-.05-.029L8.498 9.841c-.02-.034-.01-.052.028-.054l.216-.012 6.722-.012z" fill="url(#lobe-icons-qwen-_R_0_)" fill-rule="nonzero"></path><defs><linearGradient id="lobe-icons-qwen-_R_0_" x1="0%" x2="100%" y1="0%" y2="0%"><stop offset="0%" stop-color="#6336E7" stop-opacity=".84"></stop><stop offset="100%" stop-color="#6F69F7" stop-opacity=".84"></stop></linearGradient></defs></svg>
|
||||
|
After Width: | Height: | Size: 2.0 KiB |
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Raycast</title><path d="M6.004 15.492v2.504L0 11.992l1.258-1.249Zm2.504 2.504H6.004L12.008 24l1.253-1.253zm14.24-4.747L24 11.997 12.003 0 10.75 1.251 15.491 6h-2.865L9.317 2.692 8.065 3.944l2.06 2.06H8.691v9.31H18v-1.432l2.06 2.06 1.252-1.252-3.312-3.32V8.506ZM6.63 5.372 5.38 6.625l1.342 1.343 1.251-1.253Zm10.655 10.655-1.247 1.251 1.342 1.343 1.253-1.251zM3.944 8.059 2.692 9.31l3.312 3.314v-2.506zm9.936 9.937h-2.504l3.314 3.312 1.25-1.252z"/></svg>
|
||||
|
After Width: | Height: | Size: 617 B |
@@ -0,0 +1,48 @@
|
||||
<!--
|
||||
Reasonix Studio app icon, from esengine/DeepSeek-Reasonix/desktop/electron/assets/icon.svg.
|
||||
MIT License
|
||||
Copyright (c) 2026 Reasonix Contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
-->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
|
||||
<defs>
|
||||
<linearGradient id="tile" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0" stop-color="#23211d"/>
|
||||
<stop offset="1" stop-color="#0b0a09"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="gold" x1="0" y1="0" x2="1" y2="1">
|
||||
<stop offset="0" stop-color="#f6dc9a"/>
|
||||
<stop offset=".48" stop-color="#d4a652"/>
|
||||
<stop offset="1" stop-color="#9a6b25"/>
|
||||
</linearGradient>
|
||||
<linearGradient id="rim" x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0" stop-color="#e2bd6e" stop-opacity=".55"/>
|
||||
<stop offset="1" stop-color="#e2bd6e" stop-opacity=".08"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect x="103" y="103" width="818" height="818" rx="190" fill="url(#tile)"/>
|
||||
<rect x="106" y="106" width="812" height="812" rx="187" fill="none" stroke="url(#rim)" stroke-width="6"/>
|
||||
<g fill="url(#gold)" transform="translate(512 512) scale(1.9) translate(-359.74 -192.62)">
|
||||
<path d="M369.75,185.3c2.09,1.76,4.98,2.41,7.95,1.06,1.18-.54,1.96-1.91,1.47-3.25-3.92-10.71-14.97-18.54-19.38-12.48-.54.74-.52,1.7-.11,2.29.32.47.97.57,1.82.4,2.68-.56,6.02,1.31,5.7,4.3-.33,3.12.3,5.79,2.56,7.69Z"/>
|
||||
<path d="M434.28,204.78c10.12-11.32,16.46-25.01,18.67-40.07,5.04-32.93-11.31-63.01-42.11-75.75-10.83-4.35-21.95-6.2-33.76-6.09l-114.5.03v219.42s56.29-.04,56.29-.04v-77.17c-1.86-.69-3.15-1.27-3.15-1.27-12.24-5.59-21.6-15.29-26.74-27.44-6.56-15.51-4.54-32.9,5.78-46.12,10.28-12.84,24.31-16.92,40.41-14.67,5.95.83,12.3-6.15,24.4-4.81.81.09,1.63.7,1.71,1.18.28,1.65-4.4,2.54-4.4,7.05,0,1.9.85,4.1,2.65,5.36,6.17,4.33,11.51,9.19,17.1,14.22,2.72,2.44,11.93,9.31,14.27,3.72,1.37-3.26,2.27-6.68,3.18-10.15.45-1.72-.5-2.74-1.89-3.56-9.5-5.63-13.08-17.35-9.37-27.74.36-1,1.29-1.49,2.08-1.52,3.19-.14,1.49,5.78,9.38,8.21,7.49,2.31,7.71,8.53,11.35,6.05,8.48-5.78,11.54-1.05,19.41-8.46.81-.76,2.2-.82,3.04-.23.52.36.97,1.29.93,2.38-.23,6.26-2.67,12.24-6.95,16.84-8.09,8.69-14.89,4.53-15.33,10.62-1.29,17.86-7.13,35.69-19.81,48.66-.41.42-.65,1.01-.58,1.41.07.42.57.83,1.12,1.01l10.68,3.63c1.51.51,2.6,1.87,2.41,3.31-.17,1.26-1.17,2.37-2.61,2.85-7.84,2.59-16.26,2.14-24.24-.27-10.56,8.89-23.54,13.48-37.68,12.93l20.53,28.34,33.49,45.73,66.85-.09-56.68-76.53c13.19-3.89,24.78-10.87,34.07-20.94Z"/>
|
||||
<circle cx="362.14" cy="177.19" r="1.58"/>
|
||||
<path d="M300.31,167.85c-3.53.43-5.65,2.96-5.31,6.74,2.39,26.35,26.7,47.92,53.94,42.72,5.8-1.11,11.08-3.41,15.36-7.74-9.27-7.98-13.79-16.12-21.41-24.13-10.91-11.47-26.43-19.54-42.58-17.59Z"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 6.2 KiB |
@@ -0,0 +1 @@
|
||||
<svg height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Stepfun</title><path d="M22.012 0h1.032v.927H24v.968h-.956V3.78h-1.032V1.896h-1.878v-.97h1.878V0zM2.6 12.371V1.87h.969v10.502h-.97zm10.423.66h10.95v.918h-6.208v9.579h-4.742V13.03zM5.629 3.333v12.356H0v4.51h10.386V8L20.859 8l-.003-4.668-15.227.001z" fill="url(#lobe-icons-stepfun-_R_0_)" fill-rule="evenodd"></path><defs><linearGradient gradientUnits="userSpaceOnUse" id="lobe-icons-stepfun-_R_0_" x1="1.646" x2="18.342" y1="1.916" y2="22.091"><stop stop-color="#01A9FF"></stop><stop offset="1" stop-color="#0160FF"></stop></linearGradient></defs></svg>
|
||||
|
After Width: | Height: | Size: 676 B |
@@ -0,0 +1,4 @@
|
||||
<svg width="128" height="128" viewBox="0 0 128 128" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<!-- T3 Code's T3 mark (github.com/pingdotgg/t3code, assets/prod/logo.svg, MIT), its letters alone so it draws as a mask -->
|
||||
<path d="M33.4509 93V47.56H15.5309V37H64.3309V47.56H46.4109V93H33.4509ZM86.7253 93.96C82.832 93.96 78.9653 93.4533 75.1253 92.44C71.2853 91.3733 68.032 89.88 65.3653 87.96L70.4053 78.04C72.5386 79.5867 75.0186 80.8133 77.8453 81.72C80.672 82.6267 83.5253 83.08 86.4053 83.08C89.6586 83.08 92.2186 82.44 94.0853 81.16C95.952 79.88 96.8853 78.12 96.8853 75.88C96.8853 73.7467 96.0586 72.0667 94.4053 70.84C92.752 69.6133 90.0853 69 86.4053 69H80.4853V60.44L96.0853 42.76L97.5253 47.4H68.1653V37H107.365V45.4L91.8453 63.08L85.2853 59.32H89.0453C95.9253 59.32 101.125 60.8667 104.645 63.96C108.165 67.0533 109.925 71.0267 109.925 75.88C109.925 79.0267 109.099 81.9867 107.445 84.76C105.792 87.48 103.259 89.6933 99.8453 91.4C96.432 93.1067 92.0586 93.96 86.7253 93.96Z" fill="black"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1013 B |
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>TRAE</title><path d="M24 20.541H3.428v-3.426H0V3.4h24V20.54zM3.428 17.115h17.144V6.827H3.428v10.288zm8.573-5.196l-2.425 2.424-2.424-2.424 2.424-2.424 2.425 2.424zm6.857-.001l-2.424 2.423-2.425-2.423 2.425-2.425 2.424 2.425z"></path></svg>
|
||||
|
After Width: | Height: | Size: 402 B |
@@ -0,0 +1 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="64.0003" height="64"><defs><linearGradient id="gradient_0" gradientTransform="matrix(3.91889e-15 64 -64.0003 3.91887e-15 32.0002 -1.95943e-15)" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="1" y2="0"><stop offset="0" stop-color="#0EC7A8"/><stop offset="1" stop-color="#00C885"/></linearGradient></defs><rect fill="url(#gradient_0)" width="64.0003" height="64" rx="13.8106" ry="13.8106"/><defs><filter id="filter_0" x="-3" y="13" width="78" height="69" filterUnits="userSpaceOnUse"><feGaussianBlur stdDeviation="4.4002" result="blur"/></filter></defs><g transform="matrix(1 0 0 1 18 18)" filter="url(#filter_0)"><clipPath id="clip_0"><path d="M63.9867 13.197Q63.9935 13.3503 63.9969 13.5037Q64.0003 13.6571 64.0003 13.8106L64.0003 50.1894Q64.0003 55.91 59.9553 59.955Q55.9103 64 50.1898 64L13.8106 64Q8.09 64 4.045 59.955Q0 55.91 0 50.1894L0 13.8106Q0 13.6571 0.0034 13.5037Q0.0068 13.3503 0.0136 13.197L63.9867 13.197Z" clip-rule="evenodd"/></clipPath><g clip-path="url(#clip_0)"><circle fill="#FFE255" fill-opacity="0.49" transform="matrix(1 0 0 1 14.7525 31.197)" cx="20.5928" cy="20.5928" r="20.5928"/></g></g><clipPath id="clip_1"><rect width="64.0003" height="64" rx="13.8106" ry="13.8106"/></clipPath><g clip-path="url(#clip_1)"><defs><linearGradient id="gradient_1" gradientTransform="matrix(4.35136e-15 60.044 78.3872 0 39.1936 -2.86512e-06)" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="1" y2="0"><stop offset="0" stop-color="#FFF" stop-opacity="0.8"/><stop offset="0.4377" stop-color="#FFF"/><stop offset="1" stop-color="#FFF"/></linearGradient></defs><path fill="url(#gradient_1)" fill-opacity="1" transform="matrix(0.866025 -0.5 0.5 0.866025 -7.25994 37.2434)" d="M10.4632 2.7569C11.0168 1.0854 11.4183 0.4342 12.0804 0.1628C12.482 0 13.4155 0.1302 14.4249 0.4884C16.9539 1.411 21.7513 4.6672 26.755 8.8677L27.276 9.3018L29.1971 8.9111C32.3882 8.2598 34.3961 8.0211 37.9128 7.9017C41.5815 7.7714 45.4237 8.1405 49.4831 9.0196L50.7856 9.3018L52.3051 8.0645C57.7647 3.6035 62.4102 0.6729 64.798 0.1845C65.6229 0.0109 65.6663 0.0109 66.0788 0.2171C66.7517 0.5427 67.1642 1.1939 67.6418 2.6918C68.7597 6.1867 69.4978 12.4712 69.3675 17.3989L69.3133 19.3092L70.1056 20.5031C70.8654 21.6645 71.9833 23.7918 72.3741 24.8121C72.5477 25.2788 72.5912 25.3114 73.0145 25.3765C74.9248 25.6696 76.694 27.7644 77.5731 30.7926C78.3655 33.517 78.3872 37.4027 77.6382 40.203C77.508 40.648 77.1498 41.5597 76.835 42.211C75.7171 44.4903 74.0022 45.8362 72.1896 45.8471C71.8205 45.847 71.7771 45.8796 71.3864 46.5743C70.0538 48.9871 68.2229 51.1078 65.931 52.9197L65.931 18.983L12.3947 18.983L12.3947 53.6887C12.3876 53.6834 12.3806 53.6781 12.3735 53.6727C9.8011 51.7407 7.2938 48.8536 6.165 46.5308C5.872 45.9122 5.8069 45.847 5.3727 45.7385C3.0608 45.1632 1.1397 42.4932 0.3473 38.7703C0.0326 37.2833 0 34.0597 0.2822 32.5075C0.9551 28.8823 2.7352 26.2882 5.0905 25.4851C5.6983 25.2788 5.72 25.268 6.0456 24.5191C6.5775 23.2926 7.5001 21.5559 8.1947 20.4922L8.8351 19.4937L8.8677 15.8793C8.9328 10.257 9.4755 5.8177 10.4632 2.7569ZM12.5027 53.7693C16.8022 56.9564 22.7683 58.8585 31.0748 59.6967C34.5807 60.044 42.7971 60.0114 46.4874 59.6207C53.3471 58.9152 59.0672 57.2654 63.1482 54.8341C63.7166 54.4938 64.2642 54.1388 64.7905 53.7693L12.5027 53.7693Z" fill-rule="evenodd"/><path fill="#FFF" transform="matrix(0.866025 -0.5 0.5 0.866025 29.5937 50.1354)" d="M6.4145 3.2072L6.4145 10.1152Q6.4145 11.4436 5.4751 12.383Q4.5357 13.3224 3.2072 13.3224L3.2072 13.3224Q1.8788 13.3224 0.9394 12.383Q0 11.4436 0 10.1152L0 3.2072Q0 1.8788 0.9394 0.9394Q1.8788 0 3.2072 0L3.2072 0Q4.5357 0 5.4751 0.9394Q6.4145 1.8788 6.4145 3.2072Z"/><path fill="#FFF" transform="matrix(0.866025 -0.5 0.5 0.866025 46.9001 40.1434)" d="M6.4145 3.2072L6.4145 10.1152Q6.4145 11.4436 5.4751 12.383Q4.5357 13.3224 3.2072 13.3224L3.2072 13.3224Q1.8788 13.3224 0.9394 12.383Q0 11.4436 0 10.1152L0 3.2072Q0 1.8788 0.9394 0.9394Q1.8788 0 3.2072 0L3.2072 0Q4.5357 0 5.4751 0.9394Q6.4145 1.8788 6.4145 3.2072Z"/></g></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Grok</title><path d="M6.469 8.776L16.512 23h-4.464L2.005 8.776H6.47zm-.004 7.9l2.233 3.164L6.467 23H2l4.465-6.324zM22 2.582V23h-3.659V7.764L22 2.582zM22 1l-9.952 14.095-2.233-3.163L17.533 1H22z"></path></svg>
|
||||
|
After Width: | Height: | Size: 372 B |
|
After Width: | Height: | Size: 8.0 KiB |
@@ -0,0 +1 @@
|
||||
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 96 96" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Zed</title><path clip-rule="evenodd" d="M9 6C7.34315 6 6 7.34315 6 9V75H0V9C0 4.02944 4.02944 0 9 0H89.3787C93.3878 0 95.3955 4.84715 92.5607 7.68198L43.0551 57.1875H57V51H63V58.6875C63 61.1728 60.9853 63.1875 58.5 63.1875H37.0551L26.7426 73.5H73.5V36H79.5V73.5C79.5 76.8137 76.8137 79.5 73.5 79.5H20.7426L10.2426 90H87C88.6569 90 90 88.6569 90 87V21H96V87C96 91.9706 91.9706 96 87 96H6.62132C2.61224 96 0.604504 91.1529 3.43934 88.318L52.7574 39H39V45H33V37.5C33 35.0147 35.0147 33 37.5 33H58.7574L69.2574 22.5H22.5V60H16.5V22.5C16.5 19.1863 19.1863 16.5 22.5 16.5H75.2574L85.7574 6H9Z"/></svg>
|
||||
|
After Width: | Height: | Size: 760 B |
|
After Width: | Height: | Size: 18 KiB |
@@ -0,0 +1,80 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>HarnessWeight · agent harness token weight</title>
|
||||
<link rel="icon" href="logo.svg" type="image/svg+xml">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<script>
|
||||
// theme before first paint: ?theme= from magpie, else the system's
|
||||
(() => { const t = new URLSearchParams(location.search).get("theme"); if (t === "dark" || t === "light") document.documentElement.dataset.theme = t })()
|
||||
</script>
|
||||
<script src="app.js" type="module"></script>
|
||||
</head>
|
||||
<body>
|
||||
<header class="top">
|
||||
<div class="brand">
|
||||
<img class="logo on-light" src="logo.svg" alt="" width="34" height="34"><img class="logo on-dark" src="logo-dark.svg" alt="" width="34" height="34">
|
||||
<div>
|
||||
<h1>HarnessWeight</h1>
|
||||
<p class="status wait" id="status" role="status" data-t="status.loading">正在读取…</p>
|
||||
<p class="sub" data-t="header.sub">同一个网关后面,每个 agent harness 读了多少 token、命中多少缓存、失败多少次、每轮重发多重的工具定义。</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<div class="seg" role="tablist" aria-label="统计周期" aria-label-t="aria.periods" id="periods">
|
||||
<button role="tab" data-period="today" data-t="period.today">今天</button>
|
||||
<button role="tab" data-period="7d" data-t="period.7d">7 天</button>
|
||||
<button role="tab" data-period="30d" data-t="period.30d">30 天</button>
|
||||
</div>
|
||||
<label class="toggle"><input type="checkbox" id="clients"><span data-t="clients.toggle">含脚本和内部请求</span></label>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<section class="insights" id="insights" aria-label="结论" aria-label-t="aria.insights"></section>
|
||||
<section class="kpis" id="kpis" aria-label="总览" aria-label-t="aria.overview"></section>
|
||||
|
||||
<section class="block">
|
||||
<div class="block-head">
|
||||
<h2 data-t="cards.title">谁在花你的 token</h2>
|
||||
<p class="hint" data-t="cards.hint">每张卡是一个 Agent。条的长度是这段时间读进模型的总 token,深色部分是按原价算的(没命中缓存)。</p>
|
||||
<div class="sortbar" id="cardSort" role="group" aria-label="卡片排序" aria-label-t="aria.cardSort"></div>
|
||||
<p class="hint" id="activityInfo" role="status" data-t="activity.connecting">正在连接实时调用状态…</p>
|
||||
</div>
|
||||
<div class="cards" id="cards"></div>
|
||||
</section>
|
||||
|
||||
<section class="block">
|
||||
<div class="block-head">
|
||||
<h2 data-t="table.title">逐项对比</h2>
|
||||
<p class="hint" data-t="table.hint">点表头排序,点一行看详情。</p>
|
||||
</div>
|
||||
<div class="table-wrap"><table id="table"></table></div>
|
||||
</section>
|
||||
|
||||
<section class="block" id="toolsBlock">
|
||||
<div class="block-head">
|
||||
<h2 data-t="tools.title">工具定义重量</h2>
|
||||
<p class="hint" id="toolsHint" data-t="tools.hint">Agent 每次请求都会把自己的工具清单重发一遍,这部分也按 token 计费。</p>
|
||||
</div>
|
||||
<div id="tools"></div>
|
||||
</section>
|
||||
|
||||
<p class="state" id="state" hidden></p>
|
||||
</main>
|
||||
|
||||
<aside class="drawer" id="drawer" aria-hidden="true" tabindex="-1">
|
||||
<button class="close" id="close" aria-label="关闭" aria-label-t="aria.close">×</button>
|
||||
<div id="detail"></div>
|
||||
</aside>
|
||||
<div class="scrim" id="scrim" hidden></div>
|
||||
|
||||
<footer class="foot">
|
||||
<span data-t="footer.localOnly">数据只在本机读取,不上传。</span>
|
||||
<span id="sources"></span>
|
||||
<a href="https://github.com/webkubor/harnessweight" target="_blank" rel="noopener">GitHub</a>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,17 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" role="img" aria-label="HarnessWeight">
|
||||
<title>HarnessWeight</title>
|
||||
<defs>
|
||||
<linearGradient id="t" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#5EE0D2"/><stop offset="1" stop-color="#17A9A2"/></linearGradient>
|
||||
<linearGradient id="o" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#FFA23A"/><stop offset="1" stop-color="#F26B1D"/></linearGradient>
|
||||
<linearGradient id="y" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#FFE27A"/><stop offset="1" stop-color="#FFB547"/></linearGradient>
|
||||
<clipPath id="cg"><rect x="36" y="48" width="104" height="104" rx="28" fill="#000" /></clipPath>
|
||||
<clipPath id="ct"><rect x="76" y="76" width="104" height="104" rx="28" fill="#000" /></clipPath>
|
||||
</defs>
|
||||
<g transform="skewY(-7) translate(0 16)">
|
||||
<rect x="36" y="48" width="104" height="104" rx="28" fill="#3A414D" stroke="#6B7484" stroke-width="2"/>
|
||||
<rect x="76" y="76" width="104" height="104" rx="28" fill="url(#t)" />
|
||||
<g clip-path="url(#cg)"><rect x="76" y="76" width="104" height="104" rx="28" fill="#1E6F6B" /></g>
|
||||
<rect x="116" y="104" width="104" height="104" rx="28" fill="url(#o)" />
|
||||
<g clip-path="url(#ct)"><rect x="116" y="104" width="104" height="104" rx="28" fill="url(#y)" /></g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,17 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" role="img" aria-label="HarnessWeight">
|
||||
<title>HarnessWeight</title>
|
||||
<defs>
|
||||
<linearGradient id="t" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#5EE0D2"/><stop offset="1" stop-color="#17A9A2"/></linearGradient>
|
||||
<linearGradient id="o" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#FFA23A"/><stop offset="1" stop-color="#F26B1D"/></linearGradient>
|
||||
<linearGradient id="y" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#FFE27A"/><stop offset="1" stop-color="#FFB547"/></linearGradient>
|
||||
<clipPath id="cg"><rect x="36" y="48" width="104" height="104" rx="28" fill="#000" /></clipPath>
|
||||
<clipPath id="ct"><rect x="76" y="76" width="104" height="104" rx="28" fill="#000" /></clipPath>
|
||||
</defs>
|
||||
<g transform="skewY(-7) translate(0 16)">
|
||||
<rect x="36" y="48" width="104" height="104" rx="28" fill="#2B2F36" />
|
||||
<rect x="76" y="76" width="104" height="104" rx="28" fill="url(#t)" />
|
||||
<g clip-path="url(#cg)"><rect x="76" y="76" width="104" height="104" rx="28" fill="#1E6F6B" /></g>
|
||||
<rect x="116" y="104" width="104" height="104" rx="28" fill="url(#o)" />
|
||||
<g clip-path="url(#ct)"><rect x="116" y="104" width="104" height="104" rx="28" fill="url(#y)" /></g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,310 @@
|
||||
/* HarnessWeight — brand v2: teal #17A9A2, orange #F26B1D, warm yellow #FFB547, graphite #2B2F36.
|
||||
Orange marks "the most expensive one" only; it is never decoration. */
|
||||
:root {
|
||||
--bg: #F6F7F8; --panel: #FFFFFF; --panel-2: #F1F3F5; --fg: #1B1E23; --muted: #646B76; --line: #E4E7EB;
|
||||
--teal: #17A9A2; --teal-2: #5EE0D2; --teal-ink: #0E7C77; --teal-soft: #E3F6F4;
|
||||
--orange: #F26B1D; --orange-2: #FFA23A; --orange-soft: #FFF0E5; --yellow: #FFB547;
|
||||
--ink: #2B2F36; --bar: #E6E9ED; --danger: #C2410C;
|
||||
--radius: 14px; --shadow: 0 1px 2px rgba(16,24,40,.04), 0 4px 16px rgba(16,24,40,.05);
|
||||
--tip-bg: #1B1E23; --tip-fg: #F2F4F7; --teal-glow: rgba(23,169,162,.30); --chip-bg: #F1F3F5;
|
||||
--mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
|
||||
color-scheme: light;
|
||||
}
|
||||
:root[data-theme="dark"] {
|
||||
--bg: #0D1117; --panel: #151B23; --panel-2: #1B222C; --fg: #E6EAF0; --muted: #8B94A3; --line: #252D38;
|
||||
--teal: #2CC5BC; --teal-ink: #5EE0D2; --teal-soft: #0F2A2A; --orange-soft: #2E1C10;
|
||||
--ink: #3A414D; --bar: #232B36; --danger: #FF8A4C;
|
||||
--tip-bg: #E9EDF2; --tip-fg: #1B1E23; --teal-glow: rgba(44,197,188,.34); --chip-bg: #1B222C;
|
||||
--shadow: none; color-scheme: dark;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root:not([data-theme="light"]) {
|
||||
--bg: #0D1117; --panel: #151B23; --panel-2: #1B222C; --fg: #E6EAF0; --muted: #8B94A3; --line: #252D38;
|
||||
--teal: #2CC5BC; --teal-ink: #5EE0D2; --teal-soft: #0F2A2A; --orange-soft: #2E1C10;
|
||||
--ink: #3A414D; --bar: #232B36; --danger: #FF8A4C; --shadow: none; color-scheme: dark;
|
||||
--tip-bg: #E9EDF2; --tip-fg: #1B1E23; --teal-glow: rgba(44,197,188,.34); --chip-bg: #1B222C;
|
||||
}
|
||||
}
|
||||
.logo.on-dark { display: none; }
|
||||
:root[data-theme="dark"] .logo.on-dark { display: block; } :root[data-theme="dark"] .logo.on-light { display: none; }
|
||||
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .logo.on-dark { display: block; } :root:not([data-theme="light"]) .logo.on-light { display: none; } }
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
body { margin: 0; background: var(--bg); color: var(--fg);
|
||||
font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
|
||||
-webkit-font-smoothing: antialiased; }
|
||||
.num, td.n, th.n { font-variant-numeric: tabular-nums; }
|
||||
|
||||
.top, main, .foot { max-width: 1120px; margin: 0 auto; padding-left: 24px; padding-right: 24px; }
|
||||
.top { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between; padding-top: 28px; padding-bottom: 20px; }
|
||||
.brand { display: flex; gap: 12px; align-items: center; }
|
||||
.logo { display: block; }
|
||||
h1 { margin: 0; font-size: 22px; font-weight: 680; letter-spacing: -.01em; }
|
||||
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
|
||||
.controls { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
|
||||
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; }
|
||||
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px; padding: 5px 13px; border-radius: 7px; cursor: pointer; }
|
||||
.seg button:hover { color: var(--fg); }
|
||||
.seg button[aria-selected="true"] { background: var(--panel); color: var(--fg); box-shadow: var(--shadow); font-weight: 600; }
|
||||
.seg button:focus-visible, .toggle input:focus-visible, button:focus-visible, tr:focus-visible, .card:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
|
||||
.toggle { color: var(--muted); font-size: 13px; display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
|
||||
.toggle input { accent-color: var(--teal); }
|
||||
|
||||
.insights { display: grid; gap: 8px; margin-bottom: 18px; }
|
||||
.insight { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: 12px; background: var(--teal-soft); color: var(--fg); font-size: 13.5px; }
|
||||
.insight::before { content: ""; flex: none; width: 6px; height: 6px; margin-top: 8px; border-radius: 50%; background: var(--teal); }
|
||||
.insight.hot { background: var(--orange-soft); } .insight.hot::before { background: var(--orange); }
|
||||
|
||||
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 26px; }
|
||||
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
|
||||
.kpi .k { color: var(--muted); font-size: 12px; }
|
||||
.kpi .v { font-size: 24px; font-weight: 680; letter-spacing: -.01em; margin-top: 2px; }
|
||||
.kpi .s { color: var(--muted); font-size: 12px; margin-top: 2px; }
|
||||
|
||||
.block { margin-bottom: 30px; }
|
||||
.block-head { margin-bottom: 12px; }
|
||||
h2 { margin: 0; font-size: 16px; font-weight: 650; }
|
||||
.hint { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }
|
||||
|
||||
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
|
||||
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); cursor: pointer; transition: border-color .15s, transform .15s; }
|
||||
.card:hover { border-color: color-mix(in srgb, var(--teal) 45%, var(--line)); transform: translateY(-1px); }
|
||||
.card:active { transform: translateY(0) scale(.995); }
|
||||
.card.top1 { border-color: color-mix(in srgb, var(--orange) 55%, var(--line)); }
|
||||
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
|
||||
.card-name { font-weight: 650; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.tag { font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--orange); color: #fff; font-weight: 600; white-space: nowrap; }
|
||||
.card-big { margin-top: 10px; font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
|
||||
.card-big small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 4px; }
|
||||
.stack { margin-top: 8px; height: 8px; border-radius: 4px; background: var(--bar); overflow: hidden; display: flex; }
|
||||
.stack .cached { background: linear-gradient(90deg, var(--teal-2), var(--teal)); }
|
||||
.stack .full { background: var(--ink); }
|
||||
.card.top1 .stack .full { background: linear-gradient(90deg, var(--orange-2), var(--orange)); }
|
||||
.card-meta { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-top: 12px; }
|
||||
.card-meta > div { font-size: 12px; color: var(--muted); min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 1px; }
|
||||
.card-meta b { color: var(--fg); font-size: 13.5px; font-weight: 600; }
|
||||
/* the label under the number wraps as a word, never one character per line */
|
||||
/* labels may be longer than the column (English); wrap, never spill into the next one */
|
||||
.card-meta .tipwrap { display: inline; white-space: normal; max-width: 100%; line-height: 1.35; }
|
||||
.card-meta .tipwrap .tip { margin-left: 3px; vertical-align: 1px; }
|
||||
.spark { display: block; width: 100%; height: 34px; margin-top: 10px; }
|
||||
.spark path.l { fill: none; stroke: var(--teal); stroke-width: 1.6; }
|
||||
.spark path.a { fill: color-mix(in srgb, var(--teal) 14%, transparent); }
|
||||
|
||||
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
|
||||
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
|
||||
table th, table td { padding: 9px 9px; }
|
||||
table th .tip { margin-left: 2px; }
|
||||
table td.n, table th.n { padding-left: 7px; padding-right: 7px; }
|
||||
table .proto-cell { max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 11px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none; }
|
||||
th:hover { color: var(--fg); }
|
||||
th[aria-sort] { color: var(--fg); }
|
||||
th[aria-sort="descending"]::after { content: " ↓"; } th[aria-sort="ascending"]::after { content: " ↑"; }
|
||||
th.n, td.n { text-align: right; }
|
||||
td { padding: 11px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
|
||||
tbody tr { cursor: pointer; }
|
||||
tbody tr:hover td { background: var(--panel-2); }
|
||||
tbody tr:last-child td { border-bottom: 0; }
|
||||
td.agent { font-weight: 600; }
|
||||
.bad { color: var(--danger); font-weight: 600; }
|
||||
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 8px; background: var(--teal); vertical-align: 0; }
|
||||
.dot.hot { background: var(--orange); }
|
||||
|
||||
.tool-row { display: grid; grid-template-columns: 190px 1fr 190px; gap: 12px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); }
|
||||
.tool-row:last-child { border-bottom: 0; }
|
||||
.tool-track { height: 10px; background: var(--bar); border-radius: 5px; overflow: hidden; }
|
||||
.tool-fill { height: 100%; background: linear-gradient(90deg, var(--teal-2), var(--teal)); border-radius: 5px; }
|
||||
.tool-fill.hot { background: linear-gradient(90deg, var(--orange-2), var(--orange)); }
|
||||
.tool-val { text-align: right; color: var(--muted); font-size: 12.5px; }
|
||||
.waiting { background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); padding: 18px; color: var(--muted); font-size: 13px; }
|
||||
|
||||
.state { text-align: center; color: var(--muted); padding: 40px 0; }
|
||||
.state.err { color: var(--danger); }
|
||||
.skeleton { background: linear-gradient(90deg, var(--panel-2), var(--line), var(--panel-2)); background-size: 200% 100%; animation: sk 1.2s linear infinite; border-radius: var(--radius); min-height: 86px; }
|
||||
@keyframes sk { to { background-position: -200% 0; } }
|
||||
|
||||
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(580px, 100vw); background: var(--panel); border-left: 1px solid var(--line); box-shadow: -12px 0 40px rgba(0,0,0,.12); padding: 22px 22px 40px; overflow-y: auto; transform: translateX(100%); transition: transform .22s cubic-bezier(.2,.8,.2,1); z-index: 20; }
|
||||
.drawer.open { transform: none; }
|
||||
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 10; }
|
||||
.close { position: absolute; top: 14px; right: 14px; border: 0; background: var(--panel-2); color: var(--fg); width: 30px; height: 30px; border-radius: 8px; font-size: 18px; cursor: pointer; }
|
||||
.detail h3 { margin: 0 0 4px; font-size: 18px; }
|
||||
.detail .sec { margin-top: 20px; }
|
||||
.detail .sec h4 { margin: 0 0 8px; font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
|
||||
.dl { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
|
||||
.dl div { font-size: 12px; color: var(--muted); }
|
||||
.dl b { display: block; font-size: 14px; color: var(--fg); font-weight: 600; }
|
||||
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
|
||||
.chip { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); }
|
||||
.chip.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; border-radius: 6px; }
|
||||
.spark.big { height: 80px; }
|
||||
|
||||
.foot { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); font-size: 12px; padding-top: 10px; padding-bottom: 36px; }
|
||||
.foot a { color: var(--teal-ink); text-decoration: none; margin-left: auto; }
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.top, main, .foot { padding-left: 14px; padding-right: 14px; }
|
||||
.tool-row { grid-template-columns: 96px 1fr 104px; gap: 8px; }
|
||||
.card-big { font-size: 22px; }
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) { .card, .drawer { transition: none; } .skeleton { animation: none; } }
|
||||
|
||||
.status { display: inline-flex; align-items: center; gap: 6px; margin: 4px 0 2px; font-size: 12px; color: var(--muted); }
|
||||
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
|
||||
.status.live { color: var(--teal-ink); } .status.live::before { background: var(--teal); box-shadow: 0 0 0 3px var(--teal-soft); animation: pulse 2s ease-in-out infinite; }
|
||||
.status.idle::before { background: var(--yellow); }
|
||||
@keyframes pulse { 50% { box-shadow: 0 0 0 5px transparent; } }
|
||||
@media (prefers-reduced-motion: reduce) { .status.live::before { animation: none; } }
|
||||
|
||||
.mark { display: inline-flex; flex: none; align-items: center; justify-content: center; border-radius: 6px; overflow: hidden; vertical-align: middle; }
|
||||
.mark img { display: block; width: 100%; height: 100%; object-fit: contain; }
|
||||
.mark.letter { color: #fff; font-weight: 700; line-height: 1; }
|
||||
.who { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
|
||||
.card-name { display: inline-flex; align-items: center; gap: 9px; }
|
||||
.who .dot { margin: 0 0 0 2px; }
|
||||
:root[data-theme="dark"] .mark img { background: #fff; border-radius: 5px; padding: 1px; }
|
||||
|
||||
.tool-row .who { overflow: hidden; } .tool-row .who b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
|
||||
/* ---------- explanations: a small "?" that opens the note ---------- */
|
||||
.tipwrap { display: inline-flex; align-items: baseline; gap: 4px; }
|
||||
.tip {
|
||||
position: relative; display: inline-flex; align-items: center; justify-content: center; flex: none;
|
||||
width: 14px; height: 14px; border-radius: 50%;
|
||||
border: 1px solid var(--line); color: var(--muted); font-size: 9px; line-height: 1;
|
||||
cursor: help; vertical-align: middle; outline: none;
|
||||
}
|
||||
.tip::before { content: "?"; }
|
||||
.tip:hover, .tip:focus { border-color: var(--teal); color: var(--teal-ink); background: var(--teal-soft); }
|
||||
.tip-body {
|
||||
position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%) translateY(4px);
|
||||
width: max-content; max-width: 280px; padding: 9px 11px; border-radius: 8px;
|
||||
white-space: normal; font-weight: 400;
|
||||
background: var(--tip-bg); color: var(--tip-fg); border: 1px solid var(--line);
|
||||
box-shadow: 0 8px 28px rgba(0,0,0,.18); font-size: 12px; line-height: 1.55; font-weight: 400;
|
||||
opacity: 0; pointer-events: none; transition: opacity .14s ease, transform .14s ease; z-index: 40; text-align: left;
|
||||
}
|
||||
.tip-body::after {
|
||||
content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
|
||||
border: 6px solid transparent; border-top-color: var(--tip-bg);
|
||||
}
|
||||
.tip.open .tip-body, .tip:hover .tip-body, .tip:focus-within .tip-body { opacity: 1; transform: translateX(-50%) translateY(0); }
|
||||
.tip-body { display: none; }
|
||||
.floating-tip { position: fixed; z-index: 100; width: max-content; max-width: min(280px, calc(100vw - 16px)); padding: 10px 12px; border-radius: 8px; background: var(--tip-bg); color: var(--tip-fg); border: 1px solid var(--line); box-shadow: 0 8px 28px rgba(0,0,0,.25); font-size: 12px; line-height: 1.55; white-space: normal; text-align: left; pointer-events: none; }
|
||||
.floating-tip b { display: block; font-weight: 700; margin-bottom: 3px; }
|
||||
/* near the top of the page the note would go off-screen: open downwards */
|
||||
.tip.flip .tip-body { bottom: auto; top: calc(100% + 8px); transform: translateX(-50%) translateY(-4px); }
|
||||
.tip.flip.open .tip-body, .tip.flip:hover .tip-body, .tip.flip:focus-within .tip-body { transform: translateX(-50%) translateY(0); }
|
||||
.tip.flip .tip-body::after { top: auto; bottom: 100%; border-top-color: transparent; border-bottom-color: var(--tip-bg); }
|
||||
|
||||
/* ---------- sorting pills ---------- */
|
||||
.sortbar { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 2px; }
|
||||
.sortbar.inline { display: inline-flex; margin: 6px 0 0; vertical-align: middle; }
|
||||
.pill {
|
||||
border: 1px solid var(--line); background: transparent; color: var(--muted);
|
||||
border-radius: 999px; padding: 4px 11px; font-size: 12px; cursor: pointer; line-height: 1.4;
|
||||
transition: background .12s ease, color .12s ease, border-color .12s ease;
|
||||
}
|
||||
.pill:hover { border-color: var(--teal); color: var(--teal-ink); }
|
||||
.pill.on { background: var(--teal-soft); border-color: var(--teal); color: var(--teal-ink); font-weight: 600; }
|
||||
.pill:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
|
||||
|
||||
/* ---------- an agent in use right now ---------- */
|
||||
@property --flow-angle { syntax: '<angle>'; inherits: false; initial-value: 0deg; }
|
||||
.card.live { position: relative; border-color: rgba(70,210,220,.38); box-shadow: 0 0 14px rgba(50,200,220,.16), var(--shadow); }
|
||||
.card.live::before {
|
||||
content: ""; position: absolute; inset: -1px; border-radius: inherit; pointer-events: none;
|
||||
padding: 2px;
|
||||
background: conic-gradient(from var(--flow-angle), transparent 0deg, rgba(50,190,225,.18) 145deg, #91fcff 195deg, #2cc8e4 215deg, transparent 265deg);
|
||||
-webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
|
||||
-webkit-mask-composite: xor;
|
||||
mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
|
||||
mask-composite: exclude;
|
||||
animation: flow-border 3s linear infinite;
|
||||
}
|
||||
@keyframes flow-border { to { --flow-angle: 360deg; } }
|
||||
.live-badge {
|
||||
display: inline-flex; align-items: center; gap: 5px; color: var(--teal-ink);
|
||||
background: var(--teal-soft); border-radius: 999px; padding: 2px 8px 2px 6px; font-size: 11px; font-weight: 600;
|
||||
}
|
||||
.live-badge::before {
|
||||
content: ""; width: 16px; height: 12px; flex: none;
|
||||
background: linear-gradient(var(--teal),var(--teal)) left bottom / 3px 40% no-repeat,
|
||||
linear-gradient(var(--teal),var(--teal)) center bottom / 3px 100% no-repeat,
|
||||
linear-gradient(var(--teal),var(--teal)) right bottom / 3px 60% no-repeat;
|
||||
animation: activity-bars .9s ease-in-out infinite alternate;
|
||||
}
|
||||
.live-badge .tip { margin-left: 2px; }
|
||||
@keyframes activity-bars {
|
||||
0% { background-size: 3px 30%, 3px 90%, 3px 50%; }
|
||||
50% { background-size: 3px 95%, 3px 40%, 3px 75%; }
|
||||
100% { background-size: 3px 50%, 3px 65%, 3px 100%; }
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.card.live::before, .live-badge::before { animation: none; }
|
||||
.card.live { border-width: 2px; }
|
||||
}
|
||||
|
||||
/* ---------- small bits on the card ---------- */
|
||||
.card-foot { display: flex; gap: 8px; margin-top: 8px; font-size: 11px; color: var(--muted); }
|
||||
.card-foot .proto, .card-foot .dur {
|
||||
background: var(--chip-bg); border-radius: 5px; padding: 1px 6px; white-space: nowrap;
|
||||
}
|
||||
.proto-cell { font-family: var(--mono); font-size: 11px; color: var(--muted); }
|
||||
|
||||
/* a label followed by a tip marker must not wrap */
|
||||
.kpi .k, th { white-space: nowrap; }
|
||||
.card-meta .tipwrap { gap: 3px; align-items: center; }
|
||||
.kpi .k { display: flex; align-items: center; gap: 2px; }
|
||||
.kpi .k .tipwrap { gap: 3px; }
|
||||
.live-badge { flex: none; white-space: nowrap; align-self: center; }
|
||||
.live-badge .tipwrap { gap: 2px; }
|
||||
.live-badge .tip { width: 13px; height: 13px; font-size: 9px; }
|
||||
/* the live badge sits on one line with the name */
|
||||
.card-head { flex-wrap: wrap; row-gap: 4px; }
|
||||
.card-name { min-width: 0; flex: 1 1 auto; }
|
||||
/* the badge and the "most expensive" tag go to the next line on narrow cards */
|
||||
.card-head .live-badge, .card-head .tag { order: 2; }
|
||||
/* the table header must breathe: many columns now carry a tip marker */
|
||||
th .tip { margin-left: 3px; }
|
||||
|
||||
.detail-guide { font-size: 14px; line-height: 1.65; }
|
||||
.detail-guide .sec { padding: 22px 0; border-top: 1px solid var(--line); margin-top: 0; }
|
||||
.detail.detail-guide .sec h4 { font-size: 15px; color: var(--fg); margin: 0 0 12px; }
|
||||
.detail-guide .detail-metrics b { white-space: nowrap; font-size: clamp(16px,2vw,22px); }
|
||||
.drawer { overflow-x: hidden; }
|
||||
.detail-guide .tip-body { left:auto; right:-12px; transform:translateY(4px); max-width:min(280px,75vw); }
|
||||
.detail-guide .tip.open .tip-body, .detail-guide .tip:hover .tip-body { transform:translateY(0); }
|
||||
.detail-guide .tip-body::after { left:auto; right:12px; transform:none; }
|
||||
.detail-summary { padding: 16px; border-radius: 12px; background: var(--teal-soft); margin: 16px 0 24px; }
|
||||
.detail-summary strong { color: var(--teal-ink); }
|
||||
.detail-summary p { margin: 8px 0; }
|
||||
.detail-summary small { color: var(--muted); }
|
||||
.detail-metrics { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 10px; margin: 14px 0; }
|
||||
.detail-metrics > div { padding: 12px; background: var(--panel-2); border-radius: 9px; }
|
||||
.detail-metrics span { color: var(--muted); font-size: 11px; }
|
||||
.detail-metrics b { display: block; font-size: 22px; color: var(--fg); font-variant-numeric: tabular-nums; }
|
||||
.composition { display: flex; height: 16px; border-radius: 5px; overflow: hidden; }
|
||||
.composition > span:first-child { background: var(--teal); }
|
||||
.composition > span:last-child { background: var(--orange); }
|
||||
.composition-key { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 8px 0; font-size: 12px; }
|
||||
.composition-key span:first-child { color: var(--teal-ink); }
|
||||
.composition-key span:last-child { color: var(--orange); }
|
||||
.dist-row { margin: 12px 0; }
|
||||
.dist-row > div:first-child { display:flex; justify-content:space-between; gap:12px; font-size:12px; }
|
||||
.dist-row > div:first-child > span:first-child { overflow-wrap: anywhere; }
|
||||
.dist-row .num { color:var(--muted); flex-shrink:0; }
|
||||
.dist-track { background:var(--bar); height:7px; border-radius:4px; overflow:hidden; margin-top:5px; }
|
||||
.dist-track span { background:var(--teal); display:block; height:100%; }
|
||||
.detail-guide details { padding:12px; background:var(--panel-2); border-radius:9px; }
|
||||
.detail-guide summary { cursor:pointer; font-weight:600; }
|
||||
.detail-facts { display:grid; grid-template-columns:1fr auto; gap:8px; }
|
||||
.detail-facts dd { margin:0; font-variant-numeric:tabular-nums; }
|
||||
.tool-search { display:block; font-size:12px; margin:12px 0; color:var(--muted); }
|
||||
.tool-search input { display:block; width:100%; margin-top:5px; padding:9px; border:1px solid var(--line); border-radius:7px; background:var(--panel); color:var(--fg); }
|
||||
.tool-list { max-height:240px; overflow:auto; }
|
||||
.tool-list [hidden] { display:none; }
|
||||
.empty-note { padding:14px; background:var(--panel-2); border-radius:9px; color:var(--muted); }
|
||||
.empty-note strong { color:var(--fg); }
|
||||
.empty-note p { margin-bottom:0; }
|
||||
@media(max-width:500px) { .detail-metrics { gap:5px; } .detail-metrics > div { padding:8px; } .detail-metrics b { font-size:18px; } }
|
||||
@@ -0,0 +1,17 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" role="img" aria-label="HarnessWeight">
|
||||
<title>HarnessWeight</title>
|
||||
<defs>
|
||||
<linearGradient id="t" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#5EE0D2"/><stop offset="1" stop-color="#17A9A2"/></linearGradient>
|
||||
<linearGradient id="o" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#FFA23A"/><stop offset="1" stop-color="#F26B1D"/></linearGradient>
|
||||
<linearGradient id="y" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#FFE27A"/><stop offset="1" stop-color="#FFB547"/></linearGradient>
|
||||
<clipPath id="cg"><rect x="36" y="48" width="104" height="104" rx="28" fill="#000" /></clipPath>
|
||||
<clipPath id="ct"><rect x="76" y="76" width="104" height="104" rx="28" fill="#000" /></clipPath>
|
||||
</defs>
|
||||
<g transform="skewY(-7) translate(0 16)">
|
||||
<rect x="36" y="48" width="104" height="104" rx="28" fill="#3A414D" stroke="#6B7484" stroke-width="2"/>
|
||||
<rect x="76" y="76" width="104" height="104" rx="28" fill="url(#t)" />
|
||||
<g clip-path="url(#cg)"><rect x="76" y="76" width="104" height="104" rx="28" fill="#1E6F6B" /></g>
|
||||
<rect x="116" y="104" width="104" height="104" rx="28" fill="url(#o)" />
|
||||
<g clip-path="url(#ct)"><rect x="116" y="104" width="104" height="104" rx="28" fill="url(#y)" /></g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,17 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" role="img" aria-label="HarnessWeight">
|
||||
<title>HarnessWeight</title>
|
||||
<defs>
|
||||
<linearGradient id="t" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#5EE0D2"/><stop offset="1" stop-color="#17A9A2"/></linearGradient>
|
||||
<linearGradient id="o" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#FFA23A"/><stop offset="1" stop-color="#F26B1D"/></linearGradient>
|
||||
<linearGradient id="y" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#FFE27A"/><stop offset="1" stop-color="#FFB547"/></linearGradient>
|
||||
<clipPath id="cg"><rect x="36" y="48" width="104" height="104" rx="28" fill="#000" /></clipPath>
|
||||
<clipPath id="ct"><rect x="76" y="76" width="104" height="104" rx="28" fill="#000" /></clipPath>
|
||||
</defs>
|
||||
<g transform="skewY(-7) translate(0 16)">
|
||||
<rect x="36" y="48" width="104" height="104" rx="28" fill="#2B2F36" />
|
||||
<rect x="76" y="76" width="104" height="104" rx="28" fill="url(#t)" />
|
||||
<g clip-path="url(#cg)"><rect x="76" y="76" width="104" height="104" rx="28" fill="#1E6F6B" /></g>
|
||||
<rect x="116" y="104" width="104" height="104" rx="28" fill="url(#o)" />
|
||||
<g clip-path="url(#ct)"><rect x="116" y="104" width="104" height="104" rx="28" fill="url(#y)" /></g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,403 @@
|
||||
// HarnessWeight — the gateway hook that watches what each agent behind the
|
||||
// gateway costs you.
|
||||
//
|
||||
// {"port": 3496, "dataDir": "", "gatewayTimeoutMs": 2000, "agents": []}
|
||||
//
|
||||
// One magpie request is one model request: the gateway routes it, the client
|
||||
// (the agent) has already assembled the body, and the tool declarations in
|
||||
// that body are what the agent re-sends on every turn. Their size is the
|
||||
// part of the input the user pays for again and again, and no upstream
|
||||
// usage page counts it per agent.
|
||||
//
|
||||
// What this hook records, per request, by agent:
|
||||
// - the tokens the upstream reported (input, output, cache read, cache write)
|
||||
// - the tool declarations' size: how many, how many bytes, and their names
|
||||
// - the outcome (the request succeeded or not)
|
||||
//
|
||||
// What it never records: the conversation, the prompt, the user's words, the
|
||||
// tool arguments, the credentials. Only names, counts and numbers, so the
|
||||
// file it writes is safe to keep and to show.
|
||||
//
|
||||
// The rows go to ~/.config/magpie/harnessweight/tools.jsonl (or dataDir). The page (a
|
||||
// local service next to it) reads that file and draws the comparison.
|
||||
//
|
||||
// The gateway's contract for this file:
|
||||
// export async function onRequest(body, ctx) — before routing. Returning
|
||||
// undefined leaves the request as it was; returning a body that changed
|
||||
// the tools, the model or the streaming rolls the whole request back.
|
||||
// This hook only reads, so it returns undefined.
|
||||
// export async function onResponse(reply, ctx) — after the reply is whole.
|
||||
// ctx.request is the accepted request, ctx.success says whether it
|
||||
// worked. This is best-effort: a notification may be lost, and that is
|
||||
// fine, a missing row is not a wrong row.
|
||||
|
||||
import { appendFile, mkdir, open, readFile, rename, stat, unlink } from "node:fs/promises"
|
||||
import { randomUUID } from "node:crypto"
|
||||
import { basename, dirname } from "node:path"
|
||||
import { measureTools } from "./lib/measure.mjs"
|
||||
import { toolsLog } from "./lib/paths.mjs"
|
||||
import { activity } from "./lib/activity.mjs"
|
||||
|
||||
|
||||
// Rows older than this are dropped when a generation is retired: the file is
|
||||
// a rolling window of the recent past, not a ledger of all time.
|
||||
const MAX_AGE_MS = 30 * 24 * 60 * 60 * 1000
|
||||
// One generation is rewritten when it passes this size. The previous
|
||||
// generation is kept beside it as tools.jsonl.1, so two generations hold at
|
||||
// most about 16 MiB; the next rollover retires the older one.
|
||||
export const MAX_FILE_BYTES = 8 * 1024 * 1024
|
||||
// How often the age of the rows is checked. The check reads the file, so it
|
||||
// runs on an hourly cadence rather than on every request.
|
||||
export const AGE_CHECK_MS = 60 * 60 * 1000
|
||||
// The longest a response waits for the lock. The hook runs on the response
|
||||
// path, so contention must cost the user almost nothing: past this window
|
||||
// the sample is skipped (and a throttled warning printed) instead of
|
||||
// waiting. An uncontended critical section takes a few milliseconds.
|
||||
export const LOCK_TIMEOUT_MS = 100
|
||||
// How long to wait between attempts to take a lock (doubles up to the max).
|
||||
const LOCK_RETRY_MS = 10
|
||||
const LOCK_RETRY_MAX_MS = 200
|
||||
// A skipped-sample warning is printed at most this often per file.
|
||||
const WARN_EVERY_MS = 60 * 1000
|
||||
const append = createToolsWriter()
|
||||
|
||||
// Two plugin hosts can run at once (the host may keep the old one alive
|
||||
// during a restart) and share a dataDir. The in-process queue cannot stop
|
||||
// host B from renaming over the generation host A just moved aside, so the
|
||||
// whole critical section (stat, age check, rename, append) also runs under a
|
||||
// cross-process lock.
|
||||
//
|
||||
// A lock is a small file holding the owner's pid and a token, created with
|
||||
// an exclusive open ("wx"), so exactly one host can hold it. Two layers:
|
||||
// - the main lock (<file>.lock) guards the critical section;
|
||||
// - the reaper lock (<file>.reaper.lock) is held only while reclaiming a
|
||||
// dead main lock. The reaper re-reads the main lock inside it, so two
|
||||
// reclaimers cannot both unlink, and a slow one cannot delete the fresh
|
||||
// lock a live host took in the meantime.
|
||||
//
|
||||
// A main lock is reclaimed only when its pid is provably dead (kill(pid, 0)
|
||||
// reports ESRCH). Everything else fails closed — the sample is skipped and a
|
||||
// warning printed, rather than a live host's lock removed:
|
||||
// - a lock from a live pid, or a pid we cannot signal (EPERM, other user);
|
||||
// - an empty or corrupt lock (a host died between creating it and writing
|
||||
// its pid): remove <file>.lock by hand once no host is running;
|
||||
// - a leftover reaper lock (a host died while reclaiming): remove
|
||||
// <file>.reaper.lock by hand once no host is running.
|
||||
// A reused pid makes a dead lock look alive: that also fails closed.
|
||||
//
|
||||
// Limits: local filesystems only (O_EXCL is not reliable over NFS and pids
|
||||
// mean nothing across machines or pid namespaces). Normal exits, thrown
|
||||
// errors and failed writes release the lock in finally; only a hard crash
|
||||
// leaves one behind, and a dead holder's lock is then reclaimed.
|
||||
function lockPath(file) { return file + ".lock" }
|
||||
function reaperPath(file) { return file + ".reaper.lock" }
|
||||
|
||||
// Create a lock file exclusively and write its owner. Returns the token, or
|
||||
// null if the file already exists. A failed write removes our own empty
|
||||
// file: nobody else can have replaced it, since it exists and is unreadable.
|
||||
async function createLock(path) {
|
||||
let handle
|
||||
try {
|
||||
handle = await open(path, "wx")
|
||||
} catch (error) {
|
||||
if (error.code === "EEXIST") return null
|
||||
throw error
|
||||
}
|
||||
const token = randomUUID()
|
||||
let closed = false
|
||||
try {
|
||||
await handle.writeFile(JSON.stringify({ pid: process.pid, token, at: Date.now() }))
|
||||
closed = true
|
||||
await handle.close()
|
||||
} catch (error) {
|
||||
// A failed write or close must not leave a lock naming this live pid:
|
||||
// nobody could ever reclaim it. The file is ours (it exists, so no one
|
||||
// else can have created it), so remove it.
|
||||
if (!closed) await handle.close().catch(() => {})
|
||||
await unlink(path).catch(() => {})
|
||||
throw error
|
||||
}
|
||||
return token
|
||||
}
|
||||
|
||||
// Release a lock we hold. Unconditional: while we are alive nobody else
|
||||
// removes it (a main lock is only reclaimed for a dead pid, a reaper lock
|
||||
// never), so it cannot have been replaced. Re-reading it first would keep a
|
||||
// live pid's lock forever whenever that read failed (EMFILE, EIO...).
|
||||
// A failed unlink would leave this live host's lock in place and block every
|
||||
// writer, this one included, until the host exits: say so (throttled, file
|
||||
// name and error code only).
|
||||
async function removeLock(path) {
|
||||
await unlink(path).catch((error) => {
|
||||
if (error.code === "ENOENT") return
|
||||
const key = `${path}:release:${error.code}`
|
||||
const at = Date.now()
|
||||
if (at - (warnedAt.get(key) ?? -Infinity) < WARN_EVERY_MS) return
|
||||
warnedAt.set(key, at)
|
||||
console.warn(`[harnessweight] could not release ${basename(path)} (${error.code ?? "error"}); samples are skipped until it is removed or this host exits`)
|
||||
})
|
||||
}
|
||||
|
||||
function alive(pid) {
|
||||
if (!Number.isInteger(pid) || pid <= 0) return null
|
||||
try {
|
||||
process.kill(pid, 0)
|
||||
return true
|
||||
} catch (error) {
|
||||
// ESRCH: no such process, the owner is gone.
|
||||
if (error.code === "ESRCH") return false
|
||||
// EPERM: the process exists but belongs to another user.
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
// The lock's owner: undefined when there is no lock, null when it cannot be
|
||||
// identified (empty, truncated, corrupt — including the instant between a
|
||||
// live host creating it and writing its pid).
|
||||
async function readLock(path) {
|
||||
let text
|
||||
try {
|
||||
text = await readFile(path, "utf8")
|
||||
} catch (error) {
|
||||
if (error.code === "ENOENT") return undefined
|
||||
return null
|
||||
}
|
||||
try {
|
||||
const parsed = JSON.parse(text)
|
||||
const pid = Number(parsed?.pid)
|
||||
const token = typeof parsed?.token === "string" ? parsed.token : ""
|
||||
if (!Number.isInteger(pid) || pid <= 0 || !token) return null
|
||||
return { pid, token }
|
||||
} catch {
|
||||
// Empty, truncated or corrupt: the owner cannot be identified.
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
// Take the main lock, reclaiming it first if its owner is provably dead.
|
||||
// The deadline is absolute, fixed when the request was queued. One attempt
|
||||
// is always made, so a free lock is taken even late; a held one fails at
|
||||
// once. Throws a coded error when it cannot be taken in time.
|
||||
async function acquireLock(file, deadline) {
|
||||
const path = lockPath(file)
|
||||
let wait = LOCK_RETRY_MS
|
||||
let reason = "held"
|
||||
for (;;) {
|
||||
const token = await createLock(path)
|
||||
if (token) return { path, token }
|
||||
const outcome = await reclaimDeadLock(file)
|
||||
reason = outcome
|
||||
// Checked on every path, "reclaimed" included: hosts that keep
|
||||
// reclaiming and losing the race must still give up on time.
|
||||
if (Date.now() >= deadline) {
|
||||
const error = new Error(`tools log lock not acquired (${reason})`)
|
||||
error.code = "HW_LOCK_TIMEOUT"
|
||||
error.reason = reason
|
||||
throw error
|
||||
}
|
||||
if (outcome === "reclaimed") continue
|
||||
// Never sleep past the deadline: the wait bound is what keeps the
|
||||
// response path fast.
|
||||
await sleep(Math.min(wait, Math.max(0, deadline - Date.now())))
|
||||
wait = Math.min(wait * 2, LOCK_RETRY_MAX_MS)
|
||||
}
|
||||
}
|
||||
|
||||
// Reclaim a main lock whose owner is provably dead. Only one host reclaims
|
||||
// at a time (the reaper lock), and it re-reads the main lock inside the
|
||||
// reaper lock, so it can only unlink the lock it judged dead. Returns
|
||||
// "reclaimed", or why not: "held" (live or unprovable owner), "unreadable"
|
||||
// (empty/corrupt lock), "reaper" (another reaper, or a leftover one).
|
||||
async function reclaimDeadLock(file) {
|
||||
const main = lockPath(file)
|
||||
const reaper = reaperPath(file)
|
||||
const reaperToken = await createLock(reaper)
|
||||
// Never remove a reaper lock we did not create: it may belong to a live
|
||||
// host. A leftover one blocks reclaiming until removed by hand.
|
||||
if (!reaperToken) return "reaper"
|
||||
try {
|
||||
const current = await readLock(main)
|
||||
if (current === undefined) return "reclaimed" // gone already: try again
|
||||
if (current === null) return "unreadable"
|
||||
if (alive(current.pid) !== false) return "held"
|
||||
await unlink(main).catch((error) => { if (error.code !== "ENOENT") throw error })
|
||||
return "reclaimed"
|
||||
} finally {
|
||||
await removeLock(reaper)
|
||||
}
|
||||
}
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms))
|
||||
}
|
||||
|
||||
// The hook's own options, filled in by the gateway before the first call.
|
||||
let OPTIONS = {
|
||||
port: 3496,
|
||||
dataDir: "",
|
||||
gatewayTimeoutMs: 2000,
|
||||
agents: [],
|
||||
}
|
||||
|
||||
function dataPath() {
|
||||
return toolsLog(OPTIONS)
|
||||
}
|
||||
|
||||
// The agent names this hook watches; empty means all of them.
|
||||
function wanted(agent) {
|
||||
if (!agent) return false
|
||||
if (!Array.isArray(OPTIONS.agents) || OPTIONS.agents.length === 0) return true
|
||||
return OPTIONS.agents.some((a) => String(a).trim().toLowerCase() === String(agent).toLowerCase())
|
||||
}
|
||||
|
||||
// The tokens a reply reports, in the shapes the four protocols use.
|
||||
function usageOf(reply) {
|
||||
const u = reply?.usage ?? reply?.usage_metadata ?? reply?.usageMetadata
|
||||
if (!u || typeof u !== "object") return null
|
||||
return {
|
||||
in: num(u.input_tokens ?? u.prompt_tokens ?? u.promptTokenCount ?? u.input),
|
||||
out: num(u.output_tokens ?? u.completion_tokens ?? u.candidatesTokenCount ?? u.output),
|
||||
cacheRead: num(u.cache_read_input_tokens ?? u.cached_content_token_count ?? u.cacheRead),
|
||||
cacheWrite: num(u.cache_creation_input_tokens ?? u.cacheWrite),
|
||||
}
|
||||
}
|
||||
|
||||
function num(v) {
|
||||
return typeof v === "number" && Number.isFinite(v) ? v : 0
|
||||
}
|
||||
|
||||
// The row this hook writes. Everything in it is a number or a name.
|
||||
function row(ctx, body, reply, success) {
|
||||
const tools = measureTools(body)
|
||||
const r = {
|
||||
t: Date.now(),
|
||||
agent: ctx?.agent ?? "unknown",
|
||||
model: ctx?.model ?? body?.model ?? "unknown",
|
||||
protocol: ctx?.protocol ?? "unknown",
|
||||
path: ctx?.path ?? "",
|
||||
tools: tools.count,
|
||||
toolBytes: tools.bytes,
|
||||
toolNames: tools.names.slice(0, 60),
|
||||
ok: success !== false,
|
||||
}
|
||||
const u = usageOf(reply)
|
||||
if (u) {
|
||||
r.in = u.in
|
||||
r.out = u.out
|
||||
r.cacheRead = u.cacheRead
|
||||
r.cacheWrite = u.cacheWrite
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// The hook's entry point: called before the request goes to the model.
|
||||
// This hook only reads, so it returns undefined and the request goes on
|
||||
// exactly as it came.
|
||||
export async function onRequest(body, ctx) {
|
||||
OPTIONS = { ...OPTIONS, ...(ctx?.options ?? {}) }
|
||||
const agent = ctx?.agent ?? "unknown"
|
||||
// ctx.state survives until onResponse. ctx.signal does NOT: the host
|
||||
// aborts it when this hook returns, even while the model is still running.
|
||||
try {
|
||||
if (wanted(agent)) activity.start(dataPath(), ctx, agent)
|
||||
} catch { /* Tracking must never interrupt the user's request. */ }
|
||||
return undefined
|
||||
}
|
||||
|
||||
// The hook's other entry point: called after the model replied. This is
|
||||
// where the row is written.
|
||||
export async function onResponse(reply, ctx) {
|
||||
// Clear before any filtering or disk work, including failed responses.
|
||||
try { activity.finish(ctx) } catch { /* best-effort telemetry */ }
|
||||
OPTIONS = { ...OPTIONS, ...(ctx?.options ?? {}) }
|
||||
const agent = ctx?.agent ?? "unknown"
|
||||
if (!wanted(agent)) return
|
||||
|
||||
try {
|
||||
// ctx.request is the request the gateway accepted; it carries the tool
|
||||
// declarations, which the reply knows nothing about.
|
||||
const body = ctx?.request
|
||||
await append(dataPath(), row(ctx, body, reply, ctx?.success !== false))
|
||||
} catch {
|
||||
// A hook that fails leaves the request as it was. Never let a write
|
||||
// error touch the user's request.
|
||||
}
|
||||
}
|
||||
|
||||
// A skipped sample is reported, at most once a minute per file and code,
|
||||
// with no sample content: only the file name and the reason.
|
||||
const warnedAt = new Map()
|
||||
function warnSkipped(error, file) {
|
||||
const code = error?.code ?? error?.name ?? "error"
|
||||
const key = `${file}:${code}:${error?.reason ?? ""}`
|
||||
const at = Date.now()
|
||||
if (at - (warnedAt.get(key) ?? -Infinity) < WARN_EVERY_MS) return
|
||||
warnedAt.set(key, at)
|
||||
const why = error?.reason === "unreadable" ? `${basename(file)}.lock is empty or corrupt; remove it once no host is running`
|
||||
: error?.reason === "reaper" ? `${basename(file)}.reaper.lock is held or left over; remove it once no host is running`
|
||||
: error?.reason === "reclaimed" ? `${basename(file)}.lock was contended past the wait budget`
|
||||
: error?.code === "HW_LOCK_TIMEOUT" ? `${basename(file)}.lock is held by another host`
|
||||
: `${code}`
|
||||
console.warn(`[harnessweight] tool sample skipped: ${why}`)
|
||||
}
|
||||
|
||||
// Append one row to the data file. The log is append-only: rows are never
|
||||
// rewritten in place. When a generation grows past the size limit, or holds
|
||||
// rows older than the window, it is renamed aside (tools.jsonl.1) and a new
|
||||
// generation starts. The whole stat → age check → rename → append runs under
|
||||
// the in-process queue and the cross-process lock, so no host can rename a
|
||||
// generation another host just moved aside.
|
||||
export function createToolsWriter({
|
||||
now = Date.now,
|
||||
maxBytes = MAX_FILE_BYTES,
|
||||
lockTimeoutMs = LOCK_TIMEOUT_MS,
|
||||
warn = warnSkipped,
|
||||
} = {}) {
|
||||
const states = new Map()
|
||||
return function append(file, row) {
|
||||
const line = JSON.stringify(row) + "\n"
|
||||
const bytes = Buffer.byteLength(line)
|
||||
// Refuse an oversized sample rather than allow unbounded telemetry.
|
||||
if (bytes > maxBytes) return Promise.reject(new RangeError(`Tool sample exceeds ${maxBytes} bytes`))
|
||||
let state = states.get(file)
|
||||
if (!state) { state = { tail: Promise.resolve(), checkedAt: -Infinity }; states.set(file, state) }
|
||||
// The wait budget starts now, not when this row reaches the head of the
|
||||
// queue: N queued requests behind a held lock all give up about
|
||||
// lockTimeoutMs after they arrived, instead of N × lockTimeoutMs.
|
||||
const deadline = Date.now() + lockTimeoutMs
|
||||
const pending = state.tail.then(async () => {
|
||||
await mkdir(dirname(file), { recursive: true })
|
||||
const lock = await acquireLock(file, deadline)
|
||||
try {
|
||||
let st
|
||||
try { st = await stat(file) } catch (error) { if (error.code !== "ENOENT") throw error }
|
||||
const time = now()
|
||||
let rotate = Boolean(st) && st.size + bytes > maxBytes
|
||||
if (!rotate && time - state.checkedAt >= AGE_CHECK_MS) {
|
||||
if (st?.size) {
|
||||
const text = await readFile(file, "utf8")
|
||||
rotate = text.split("\n").some((line) => {
|
||||
try { const r = JSON.parse(line); return Number.isFinite(r?.t) && r.t < time - MAX_AGE_MS }
|
||||
catch { return false }
|
||||
})
|
||||
}
|
||||
state.checkedAt = time
|
||||
}
|
||||
if (rotate) {
|
||||
// The old generation moves aside whole; nothing is rewritten.
|
||||
await rename(file, file + ".1")
|
||||
state.checkedAt = time
|
||||
}
|
||||
await appendFile(file, line, "utf8")
|
||||
} finally {
|
||||
await removeLock(lock.path)
|
||||
}
|
||||
}).catch((error) => {
|
||||
try { warn(error, file) } catch { /* reporting must not mask the error */ }
|
||||
throw error
|
||||
})
|
||||
// A failed sample must not poison later requests.
|
||||
state.tail = pending.catch(() => {})
|
||||
return pending
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// HarnessWeight as an OpenCode v1 plugin: magpie's Bun host loads it and calls
|
||||
// server(), which starts the local service the page navigates to. It adds no
|
||||
// provider. Importing this module alone binds no port.
|
||||
import { serve } from "./service.mjs"
|
||||
|
||||
let started = null
|
||||
function start(options) {
|
||||
if (!started) {
|
||||
started = serve(options || {})
|
||||
started.ready.then((p) => p && console.log(`[harnessweight] listening on http://127.0.0.1:${p}`))
|
||||
}
|
||||
return started
|
||||
}
|
||||
|
||||
export default {
|
||||
id: "harnessweight",
|
||||
server: async (input, options) => {
|
||||
start({ ...options, directory: input?.directory })
|
||||
return {}
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// Hook and service run in the same plugin-host process. Never infer active
|
||||
// requests from completed usage rows. State is intentionally not persisted.
|
||||
export const MAX_ACTIVITY_AGE_MS = 15 * 60 * 1000
|
||||
const REQUEST = Symbol("harnessweight.request")
|
||||
|
||||
export function createActivityTracker({ now = Date.now, maxAgeMs = MAX_ACTIVITY_AGE_MS } = {}) {
|
||||
const scopes = new Map()
|
||||
function scope(key) {
|
||||
if (!scopes.has(key)) scopes.set(key, { requests: new Map(), observed: false, expired: 0 })
|
||||
return scopes.get(key)
|
||||
}
|
||||
function expire(s, time) {
|
||||
for (const [id, request] of s.requests) {
|
||||
if (time - request.startedAt >= maxAgeMs) {
|
||||
s.requests.delete(id)
|
||||
s.expired++
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
start(key, ctx, agent) {
|
||||
if (!ctx?.state || typeof ctx.state !== "object") return
|
||||
const s = scope(key)
|
||||
s.observed = true
|
||||
const time = now()
|
||||
expire(s, time)
|
||||
if (ctx.state[REQUEST]) return
|
||||
const id = Symbol()
|
||||
ctx.state[REQUEST] = { key, id }
|
||||
s.requests.set(id, { agent, startedAt: time })
|
||||
},
|
||||
finish(ctx) {
|
||||
const request = ctx?.state?.[REQUEST]
|
||||
if (!request) return
|
||||
scopes.get(request.key)?.requests.delete(request.id)
|
||||
delete ctx.state[REQUEST]
|
||||
},
|
||||
snapshot(key) {
|
||||
const s = scope(key)
|
||||
const observedAt = now()
|
||||
expire(s, observedAt)
|
||||
const counts = new Map()
|
||||
for (const { agent } of s.requests.values()) counts.set(agent, (counts.get(agent) || 0) + 1)
|
||||
return {
|
||||
agents: [...counts].map(([agent, count]) => ({ agent, count })).sort((a, b) => a.agent.localeCompare(b.agent)),
|
||||
total: s.requests.size, observedAt, tracking: "hooks", available: s.observed,
|
||||
maxAgeMs, expired: s.expired,
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export const activity = createActivityTracker()
|
||||
@@ -0,0 +1,90 @@
|
||||
// Each agent's display name and icon, exactly as magpie shows them. magpie's
|
||||
// gateway already knows both: GET /v1/magpie/usage lists every agent with a
|
||||
// name ("Claude Code") and an icon key ("claudecode-color"). The icon files
|
||||
// live in app/icons/, named by that key; a key with no file falls back to the
|
||||
// agent's initial in the page.
|
||||
import { readFile, readdir } from "node:fs/promises"
|
||||
import { dirname, join } from "node:path"
|
||||
import { fileURLToPath } from "node:url"
|
||||
|
||||
const ICONS = join(dirname(fileURLToPath(import.meta.url)), "..", "app", "icons")
|
||||
const TTL_MS = 10 * 60e3
|
||||
|
||||
export function gatewayUrl(options = {}) {
|
||||
const explicit = options.gatewayUrl || process.env.MAGPIE_GATEWAY_URL
|
||||
if (explicit) return String(explicit).trim().replace(/\/+$/, "")
|
||||
// MAGPIE_ADDR is the host's host:port, not a URL. Only wildcard bind
|
||||
// addresses become IPv4 loopback; an explicit IPv6 listener stays IPv6.
|
||||
const addr = String(process.env.MAGPIE_ADDR || "").trim().replace(/^(0\.0\.0\.0|\[::\])(:|$)/, "127.0.0.1$2")
|
||||
if (/^(\[[0-9a-f:.]+\]|[\w.-]+):\d+$/i.test(addr)) return `http://${addr}`
|
||||
return "http://127.0.0.1:3425"
|
||||
}
|
||||
|
||||
export function createBrands(options = {}, fetchImpl = globalThis.fetch) {
|
||||
let at = 0
|
||||
let map = new Map()
|
||||
let files = null
|
||||
let pending = null
|
||||
|
||||
async function iconFiles() {
|
||||
if (!files) {
|
||||
files = new Map()
|
||||
for (const f of await readdir(ICONS).catch(() => [])) {
|
||||
const dot = f.lastIndexOf(".")
|
||||
if (dot > 0 && /\.(svg|png|webp)$/i.test(f)) files.set(f.slice(0, dot), f)
|
||||
}
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
if (Date.now() - at < TTL_MS) return
|
||||
if (pending) return pending
|
||||
pending = (async () => {
|
||||
const have = await iconFiles()
|
||||
try {
|
||||
const res = await fetchImpl(`${gatewayUrl(options)}/v1/magpie/usage?period=30d`, { signal: AbortSignal.timeout(3000) })
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
||||
const body = await res.json()
|
||||
const next = new Map()
|
||||
for (const g of body.agents || []) {
|
||||
if (!g || !g.id) continue
|
||||
const key = typeof g.icon === "string" && g.icon !== "generic" ? g.icon : ""
|
||||
next.set(String(g.id), { name: String(g.name || g.id), icon: have.get(key) || null })
|
||||
}
|
||||
map = next
|
||||
} catch {
|
||||
// the gateway is down or older: keep what we had, retry sooner
|
||||
at = Date.now() - TTL_MS + 30e3
|
||||
return
|
||||
}
|
||||
at = Date.now()
|
||||
})().finally(() => { pending = null })
|
||||
return pending
|
||||
}
|
||||
|
||||
// the brand for an agent id: magpie's, else the id itself and an icon file
|
||||
// whose name is the id, else no icon
|
||||
function of(agent) {
|
||||
const b = map.get(agent)
|
||||
if (b) return b
|
||||
const f = files?.get(String(agent).toLowerCase()) || files?.get(`${String(agent).toLowerCase()}-color`)
|
||||
return { name: agent, icon: f || null }
|
||||
}
|
||||
|
||||
// an icon as a data: URI, so the page needs no request for it (in magpie's
|
||||
// sandboxed frame, images the script adds after load do not show)
|
||||
const uris = new Map()
|
||||
const TYPES = { svg: "image/svg+xml", png: "image/png", webp: "image/webp" }
|
||||
async function dataUri(file) {
|
||||
if (!file) return null
|
||||
if (!uris.has(file)) {
|
||||
const buf = await readFile(join(ICONS, file)).catch(() => null)
|
||||
const ext = file.slice(file.lastIndexOf(".") + 1).toLowerCase()
|
||||
uris.set(file, buf ? `data:${TYPES[ext]};base64,${buf.toString("base64")}` : null)
|
||||
}
|
||||
return uris.get(file)
|
||||
}
|
||||
|
||||
return { refresh, of, dataUri }
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
// Tool-declaration measurement, shared by the hook and the tests.
|
||||
|
||||
// The size of a tool declaration, per protocol. magpie speaks four shapes
|
||||
// to four families of models, and the tools live in a different place in
|
||||
// each:
|
||||
//
|
||||
// anthropic (/v1/messages): tools: [{ name, description, input_schema }]
|
||||
// chat (/v1/chat/completions): tools: [{ type, function: {...} }]
|
||||
// responses (/v1/responses): tools: [{ type, name, parameters }]
|
||||
// gemini (…/streamGenerateContent): tools: [{ functionDeclarations: [...] }]
|
||||
//
|
||||
// The numbers that matter for a cost comparison are the count and the
|
||||
// bytes: the bytes are what the model reads again on every turn.
|
||||
export function measureTools(body) {
|
||||
const out = { count: 0, bytes: 0, names: [] }
|
||||
if (!body || typeof body !== "object") return out
|
||||
|
||||
const tools = Array.isArray(body.tools) ? body.tools : null
|
||||
if (!tools) return out
|
||||
|
||||
for (const t of tools) {
|
||||
if (!t || typeof t !== "object") continue
|
||||
// A namespace's tools are its own tools (OpenAI responses).
|
||||
if (Array.isArray(t.tools)) {
|
||||
const inner = measureTools({ tools: t.tools })
|
||||
out.count += inner.count
|
||||
out.bytes += inner.bytes
|
||||
out.names.push(...inner.names)
|
||||
continue
|
||||
}
|
||||
// Gemini puts them one level deeper, under functionDeclarations.
|
||||
if (Array.isArray(t.functionDeclarations)) {
|
||||
for (const fd of t.functionDeclarations) {
|
||||
out.count++
|
||||
out.bytes += sizeOf(fd)
|
||||
if (fd && typeof fd.name === "string") out.names.push(fd.name)
|
||||
}
|
||||
continue
|
||||
}
|
||||
// OpenAI chat wraps them in a function object.
|
||||
if (t.function && typeof t.function === "object") {
|
||||
out.count++
|
||||
out.bytes += sizeOf(t.function)
|
||||
if (typeof t.function.name === "string") out.names.push(t.function.name)
|
||||
continue
|
||||
}
|
||||
// Anthropic and OpenAI responses keep them flat.
|
||||
out.count++
|
||||
out.bytes += sizeOf(t)
|
||||
if (typeof t.name === "string") out.names.push(t.name)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// The size of one declaration, in bytes of JSON. This is a proxy for the
|
||||
// tokens the model reads, not a token count: JSON is not BPE, and no
|
||||
// tokenizer is exact for every provider. It is the same measure for every
|
||||
// agent, which is what a comparison needs.
|
||||
export function sizeOf(value) {
|
||||
try {
|
||||
return Buffer.byteLength(JSON.stringify(value) ?? "", "utf8")
|
||||
} catch {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// Where HarnessWeight reads and writes. Both the hook and the service resolve
|
||||
// paths here, so they always agree.
|
||||
import { homedir } from "node:os"
|
||||
import { existsSync, realpathSync, renameSync } from "node:fs"
|
||||
import { dirname, isAbsolute, join, parse, resolve } from "node:path"
|
||||
import { fileURLToPath } from "node:url"
|
||||
|
||||
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..")
|
||||
|
||||
// One directory, one string. The host may name the config dir through
|
||||
// input.directory while the hook sees it as its cwd; a symlinked path
|
||||
// (/var -> /private/var on macOS) would otherwise give the two different
|
||||
// spellings of the same disk directory. Resolve symlinks as far as the
|
||||
// directory exists, so both sides name it identically.
|
||||
function canonical(dir) {
|
||||
const path = resolve(dir)
|
||||
try {
|
||||
return realpathSync(path)
|
||||
} catch { /* not created yet: canonicalize the nearest existing parent */ }
|
||||
const parts = []
|
||||
let current = path
|
||||
for (;;) {
|
||||
const parent = dirname(current)
|
||||
if (parent === current) return path
|
||||
parts.unshift(parse(current).base)
|
||||
try {
|
||||
return join(realpathSync(parent), ...parts)
|
||||
} catch { /* keep walking up */ }
|
||||
current = parent
|
||||
}
|
||||
}
|
||||
|
||||
// The host passes its config directory to server() and also starts the hook
|
||||
// there. Probe cwd for the hook; standalone launches fall back to XDG/home.
|
||||
export function magpieDir(options = {}) {
|
||||
if (options.directory) return canonical(options.directory)
|
||||
try {
|
||||
const cwd = process.cwd()
|
||||
if (cwd !== ROOT && ["usage.jsonl", "plugins.json", "providers.json"].some((f) => existsSync(join(cwd, f)))) return canonical(cwd)
|
||||
} catch { /* cwd may have been removed */ }
|
||||
const xdg = process.env.XDG_CONFIG_HOME
|
||||
return canonical(xdg && isAbsolute(xdg) ? join(xdg, "magpie") : join(homedir(), ".config", "magpie"))
|
||||
}
|
||||
|
||||
// magpie's own usage ledger: one JSON line per gateway request.
|
||||
export function usageLog(options = {}) {
|
||||
return options.usageLog ? resolve(options.usageLog) : join(magpieDir(options), "usage.jsonl")
|
||||
}
|
||||
|
||||
// The tool-weight samples the hook writes. Kept outside the plugin's folder
|
||||
// so a reinstall or an update does not wipe them.
|
||||
export function toolsLog(options = {}) {
|
||||
if (options.dataDir) return join(canonical(options.dataDir), "tools.jsonl")
|
||||
const dir = join(magpieDir(options), "harnessweight")
|
||||
// the plugin was called Agent Lens until 0.4.0: carry its samples over once
|
||||
const old = join(magpieDir(options), "agent-lens")
|
||||
if (!existsSync(dir) && existsSync(old)) {
|
||||
try { renameSync(old, dir) } catch {
|
||||
// Another host may have completed the same migration concurrently.
|
||||
if (!existsSync(dir) && existsSync(old)) return join(old, "tools.jsonl")
|
||||
}
|
||||
}
|
||||
return join(dir, "tools.jsonl")
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
// The comparison: magpie's usage rows and the hook's tool samples, grouped by
|
||||
// agent. Everything here is plain arithmetic over numbers already recorded;
|
||||
// nothing is estimated except the tool tokens, which say so.
|
||||
import { kindOf } from "./usage.mjs"
|
||||
// the insight sentences live in the shared table, so the page and the service
|
||||
// say the same thing in the same language
|
||||
import { insight } from "../app/i18n.mjs"
|
||||
|
||||
export const PERIODS = { today: 24 * 3600e3, "7d": 7 * 24 * 3600e3, "30d": 30 * 24 * 3600e3 }
|
||||
|
||||
// JSON bytes per token of a tool declaration, roughly. JSON is dense (short
|
||||
// ASCII keys), about 3.5 bytes a token. The same estimate for every agent.
|
||||
export const BYTES_PER_TOKEN = 3.5
|
||||
|
||||
function median(xs) {
|
||||
if (!xs.length) return 0
|
||||
const s = [...xs].sort((a, b) => a - b)
|
||||
const m = s.length >> 1
|
||||
return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2
|
||||
}
|
||||
|
||||
function bump(map, key, n = 1) { map.set(key, (map.get(key) || 0) + n) }
|
||||
function top(map, n) {
|
||||
return [...map.entries()].sort((a, b) => b[1] - a[1]).slice(0, n).map(([name, count]) => ({ name, count }))
|
||||
}
|
||||
|
||||
function dayKey(t, tzOffsetMin) {
|
||||
return new Date(t - tzOffsetMin * 60e3).toISOString().slice(0, 10)
|
||||
}
|
||||
|
||||
export function summarize({ usage = [], tools = [], period = "7d", now = Date.now(), showClients = false, tzOffsetMin = 0, nameOf = (a) => a, lang = "zh" }) {
|
||||
const span = PERIODS[period] ?? PERIODS["7d"]
|
||||
const since = now - span
|
||||
const by = new Map()
|
||||
const get = (agent) => {
|
||||
let a = by.get(agent)
|
||||
if (!a) {
|
||||
a = {
|
||||
agent, kind: kindOf(agent), calls: 0, failed: 0, cancelled: 0,
|
||||
in: 0, out: 0, cacheRead: 0, cacheWrite: 0, credits: 0,
|
||||
ms: [], ttft: [], models: new Map(), protocols: new Map(), days: new Map(),
|
||||
sessions: new Map(),
|
||||
first: Infinity, last: 0,
|
||||
tool: { samples: 0, count: 0, bytes: 0, names: new Map(), first: Infinity },
|
||||
}
|
||||
by.set(agent, a)
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
let hidden = 0
|
||||
for (const r of usage) {
|
||||
if (r.t < since) continue
|
||||
if (!showClients && kindOf(r.agent) === "client") { hidden++; continue }
|
||||
const a = get(r.agent)
|
||||
a.calls++
|
||||
if (r.failed) a.failed++
|
||||
if (r.cancelled) a.cancelled++
|
||||
a.in += r.in; a.out += r.out; a.cacheRead += r.cacheRead; a.cacheWrite += r.cacheWrite
|
||||
a.credits += r.credits
|
||||
if (r.ms > 0 && !r.failed) a.ms.push(r.ms)
|
||||
if (r.ttft > 0 && !r.failed) a.ttft.push(r.ttft)
|
||||
bump(a.models, r.model)
|
||||
bump(a.protocols, r.protocol)
|
||||
if (r.session) {
|
||||
let s = a.sessions.get(r.session)
|
||||
if (!s) { s = { first: r.t, last: r.t, calls: 0 }; a.sessions.set(r.session, s) }
|
||||
if (r.t < s.first) s.first = r.t
|
||||
if (r.t > s.last) s.last = r.t
|
||||
s.calls++
|
||||
}
|
||||
const prompt = r.in + r.cacheRead + r.cacheWrite
|
||||
const d = dayKey(r.t, tzOffsetMin)
|
||||
const day = a.days.get(d) || { day: d, calls: 0, prompt: 0, out: 0 }
|
||||
day.calls++; day.prompt += prompt; day.out += r.out
|
||||
a.days.set(d, day)
|
||||
if (r.t < a.first) a.first = r.t
|
||||
if (r.t > a.last) a.last = r.t
|
||||
}
|
||||
|
||||
let toolSamples = 0
|
||||
let toolsSince = Infinity
|
||||
for (const r of tools) {
|
||||
if (r.t < since) continue
|
||||
if (!showClients && kindOf(r.agent) === "client") continue
|
||||
const a = get(r.agent)
|
||||
toolSamples++
|
||||
a.tool.samples++
|
||||
a.tool.count += r.tools || 0
|
||||
a.tool.bytes += r.toolBytes || 0
|
||||
for (const n of r.toolNames || []) bump(a.tool.names, n)
|
||||
if (r.t < a.tool.first) a.tool.first = r.t
|
||||
if (r.t < toolsSince) toolsSince = r.t
|
||||
}
|
||||
|
||||
const agents = [...by.values()].filter((a) => a.calls > 0 || a.tool.samples > 0).map((a) => {
|
||||
const prompt = a.in + a.cacheRead + a.cacheWrite
|
||||
const avgPrompt = a.calls ? prompt / a.calls : 0
|
||||
const tb = a.tool.samples ? a.tool.bytes / a.tool.samples : 0
|
||||
const toolTokens = tb / BYTES_PER_TOKEN
|
||||
return {
|
||||
agent: a.agent, kind: a.kind,
|
||||
calls: a.calls, failed: a.failed, cancelled: a.cancelled,
|
||||
errorRate: a.calls ? a.failed / a.calls : 0,
|
||||
prompt, avgPrompt, out: a.out, avgOut: a.calls ? a.out / a.calls : 0,
|
||||
in: a.in, cacheRead: a.cacheRead, cacheWrite: a.cacheWrite,
|
||||
// share of what the model read that came from the cache (billed cheap)
|
||||
cacheRate: prompt ? a.cacheRead / prompt : 0,
|
||||
// what was read at full price: fresh input plus cache writes
|
||||
fullPrice: a.in + a.cacheWrite,
|
||||
credits: a.credits,
|
||||
p50ms: median(a.ms), p50ttft: median(a.ttft),
|
||||
models: top(a.models, 8), protocols: top(a.protocols, 4),
|
||||
session: sessionStats(a.sessions),
|
||||
series: [...a.days.values()].sort((x, y) => (x.day < y.day ? -1 : 1)),
|
||||
first: Number.isFinite(a.first) ? a.first : null, last: a.last || null,
|
||||
tools: a.tool.samples ? {
|
||||
samples: a.tool.samples,
|
||||
avgCount: a.tool.count / a.tool.samples,
|
||||
avgBytes: tb,
|
||||
avgTokens: toolTokens,
|
||||
shareOfPrompt: avgPrompt ? Math.min(1, toolTokens / avgPrompt) : null,
|
||||
names: top(a.tool.names, 40),
|
||||
since: a.tool.first,
|
||||
} : null,
|
||||
}
|
||||
}).sort((x, y) => y.prompt - x.prompt)
|
||||
|
||||
const totals = agents.reduce((t, a) => {
|
||||
t.calls += a.calls; t.failed += a.failed; t.prompt += a.prompt; t.out += a.out
|
||||
t.cacheRead += a.cacheRead; t.fullPrice += a.fullPrice; t.credits += a.credits
|
||||
return t
|
||||
}, { calls: 0, failed: 0, prompt: 0, out: 0, cacheRead: 0, fullPrice: 0, credits: 0 })
|
||||
totals.cacheRate = totals.prompt ? totals.cacheRead / totals.prompt : 0
|
||||
|
||||
let lastUsage = 0, lastTool = 0
|
||||
for (let i = usage.length - 1; i >= 0 && i >= usage.length - 50; i--) if (usage[i].t > lastUsage) lastUsage = usage[i].t
|
||||
for (const r of tools) if (r.t > lastTool) lastTool = r.t
|
||||
return {
|
||||
lastUsage: lastUsage || null, lastTool: lastTool || null,
|
||||
period, since, generatedAt: now, agents, totals, hiddenClients: hidden,
|
||||
toolSamples, toolsSince: Number.isFinite(toolsSince) ? toolsSince : null,
|
||||
insights: insights(agents, nameOf, lang),
|
||||
}
|
||||
}
|
||||
|
||||
// The few sentences a reader takes away. Only about agents with enough calls
|
||||
// to say anything, and only when there is something to compare.
|
||||
// How long one conversation lasts. A harness that keeps a session id gives us
|
||||
// the span from a session's first request to its last. Sessions that stay open
|
||||
// for days (a desktop app left running overnight) would skew the average, so
|
||||
// anything longer than MAX_SESSION_MS is counted but not measured.
|
||||
const MAX_SESSION_MS = 6 * 3600e3
|
||||
|
||||
function sessionStats(sessions) {
|
||||
const spans = []
|
||||
let open = 0
|
||||
for (const s of sessions.values()) {
|
||||
const span = s.last - s.first
|
||||
if (span <= MAX_SESSION_MS) spans.push(span)
|
||||
else open++
|
||||
}
|
||||
if (!spans.length) return { count: sessions.size, measured: 0, median: null, p90: null, longest: null }
|
||||
spans.sort((a, b) => a - b)
|
||||
return {
|
||||
count: sessions.size,
|
||||
measured: spans.length,
|
||||
median: spans[spans.length >> 1],
|
||||
p90: spans[Math.min(spans.length - 1, Math.floor(spans.length * 0.9))],
|
||||
longest: spans[spans.length - 1],
|
||||
open,
|
||||
}
|
||||
}
|
||||
|
||||
export function insights(agents, nameOf = (a) => a, lang = "zh") {
|
||||
const N = (a) => nameOf(a.agent)
|
||||
// only agents a person works in; scripts and probes never make a takeaway
|
||||
agents = agents.filter((a) => a.kind === "agent")
|
||||
const out = []
|
||||
const real = agents.filter((a) => a.calls >= 20)
|
||||
if (real.length >= 2) {
|
||||
const byPrompt = [...real].sort((a, b) => b.avgPrompt - a.avgPrompt)
|
||||
const hi = byPrompt[0], lo = byPrompt[byPrompt.length - 1]
|
||||
if (lo.avgPrompt > 0 && hi.avgPrompt / lo.avgPrompt >= 1.5) {
|
||||
out.push({ kind: "prompt", agents: [hi.agent, lo.agent], ratio: hi.avgPrompt / lo.avgPrompt,
|
||||
text: insight(lang, "prompt", { hi: N(hi), lo: N(lo), avg: fmt(hi.avgPrompt), ratio: (hi.avgPrompt / lo.avgPrompt).toFixed(1) }) })
|
||||
}
|
||||
const byCache = [...real].sort((a, b) => b.cacheRate - a.cacheRate)
|
||||
const c1 = byCache[0], c2 = byCache[byCache.length - 1]
|
||||
if (c1.cacheRate - c2.cacheRate >= 0.05) {
|
||||
out.push({ kind: "cache", agents: [c1.agent, c2.agent],
|
||||
text: insight(lang, "cache", { hi: N(c1), lo: N(c2), hiRate: pct(c1.cacheRate), loRate: pct(c2.cacheRate) }) })
|
||||
}
|
||||
const share = [...real].sort((a, b) => b.prompt - a.prompt)[0]
|
||||
const total = real.reduce((n, a) => n + a.prompt, 0)
|
||||
if (total) out.push({ kind: "volume", agents: [share.agent],
|
||||
text: insight(lang, "volume", { name: N(share), share: pct(share.prompt / total) }) })
|
||||
}
|
||||
const shaky = agents.filter((a) => a.calls >= 20 && a.errorRate >= 0.03).sort((a, b) => b.errorRate - a.errorRate)[0]
|
||||
if (shaky) out.push({ kind: "errors", agents: [shaky.agent],
|
||||
text: insight(lang, "errors", { name: N(shaky), rate: pct(shaky.errorRate) }) })
|
||||
const withTools = agents.filter((a) => a.tools && a.tools.samples >= 3 && a.tools.avgCount > 0).sort((a, b) => b.tools.avgBytes - a.tools.avgBytes)
|
||||
if (withTools.length >= 2) {
|
||||
const h = withTools[0], l = withTools[withTools.length - 1]
|
||||
out.push({ kind: "tools", agents: [h.agent, l.agent],
|
||||
text: insight(lang, "tools", { hi: N(h), lo: N(l), tokens: fmt(h.tools.avgTokens), count: Math.round(h.tools.avgCount), loTokens: fmt(l.tools.avgTokens), loCount: Math.round(l.tools.avgCount), ratio: (h.tools.avgTokens / Math.max(1, l.tools.avgTokens)).toFixed(1) }) })
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
function fmt(n) {
|
||||
if (n >= 1e6) return `${(n / 1e6).toFixed(1)}M`
|
||||
if (n >= 1e3) return `${(n / 1e3).toFixed(1)}K`
|
||||
return String(Math.round(n))
|
||||
}
|
||||
function pct(x) { return `${(x * 100).toFixed(1)}%` }
|
||||
@@ -0,0 +1,51 @@
|
||||
// Both bounded generations belong to the rolling sample window. Cache by
|
||||
// inode as well as size/mtime so a rename cannot masquerade as an append.
|
||||
import { readFile, stat } from "node:fs/promises"
|
||||
|
||||
const MAX_AGE_MS = 30 * 24 * 60 * 60 * 1000
|
||||
export function createToolsReader(file, { now = Date.now } = {}) {
|
||||
const files = [file + ".1", file]
|
||||
let key = ""
|
||||
let rows = []
|
||||
let reading
|
||||
async function signature() {
|
||||
return (await Promise.all(files.map(async (path) => {
|
||||
try { const s = await stat(path); return `${s.dev}:${s.ino}:${s.size}:${s.mtimeMs}:${s.ctimeMs}` }
|
||||
catch (error) { if (error.code === "ENOENT") return "missing"; throw error }
|
||||
}))).join("|")
|
||||
}
|
||||
async function refresh() {
|
||||
if (reading) return reading
|
||||
reading = (async () => {
|
||||
// Retention advances even if neither file has changed.
|
||||
rows = rows.filter((r) => r.t >= now() - MAX_AGE_MS)
|
||||
for (let attempt = 0; attempt < 3; attempt++) {
|
||||
const before = await signature()
|
||||
if (before === key) return
|
||||
const texts = await Promise.all(files.map(async (path) => {
|
||||
try { return await readFile(path, "utf8") }
|
||||
catch (error) { if (error.code === "ENOENT") return ""; throw error }
|
||||
}))
|
||||
// Retry a rotation/append during the read rather than publish duplicate
|
||||
// generations or a missing history. Under sustained writes retry later.
|
||||
if (before !== await signature()) continue
|
||||
const out = []
|
||||
for (const text of texts) {
|
||||
const lines = text.split("\n")
|
||||
lines.pop() // only complete, newline-terminated records
|
||||
for (const line of lines) {
|
||||
try {
|
||||
const r = JSON.parse(line)
|
||||
if (Number.isFinite(r?.t) && r.t >= now() - MAX_AGE_MS && r.agent) out.push(r)
|
||||
} catch { /* malformed line */ }
|
||||
}
|
||||
}
|
||||
rows = out
|
||||
key = before
|
||||
return
|
||||
}
|
||||
})().finally(() => { reading = null })
|
||||
return reading
|
||||
}
|
||||
return { refresh, rows: () => rows, file }
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
// Reads magpie's usage ledger incrementally. The file is large (hundreds of
|
||||
// MB) and only ever appended to, so the reader remembers how far it got and
|
||||
// reads only what is new; when the file shrinks (rotated), it starts over.
|
||||
import { createReadStream } from "node:fs"
|
||||
import { open, stat } from "node:fs/promises"
|
||||
import { createInterface } from "node:readline"
|
||||
|
||||
// Rows older than this are not kept in memory: the page offers 30 days.
|
||||
export const KEEP_MS = 31 * 24 * 60 * 60 * 1000
|
||||
|
||||
// Clients that are scripts, SDKs or magpie's own probes rather than agents a
|
||||
// person works in. They are hidden by default and can be shown.
|
||||
const CLIENTS = new Set([
|
||||
"gateway-probe", "python-urllib", "curl", "go-http-client", "openai", "node",
|
||||
"asyncopenai", "bun", "anthropic", "magpie", "ai", "vercel-ai", "langchain", "litellm", "axios", "python-requests", "httpx", "wget",
|
||||
])
|
||||
export function kindOf(agent) {
|
||||
const a = String(agent || "").toLowerCase()
|
||||
if (!a || a === "unknown") return "client"
|
||||
if (CLIENTS.has(a) || a.startsWith("local-agent-mode")) return "client"
|
||||
return "agent"
|
||||
}
|
||||
|
||||
// The request family, from magpie's endpoint note ("/v1/chat/completions → /v1/messages").
|
||||
export function protocolOf(ep) {
|
||||
const e = String(ep || "")
|
||||
const last = e.split("→").pop()
|
||||
if (last.includes("streamGenerateContent") || last.includes("generateContent")) return "gemini"
|
||||
if (last.includes("/messages")) return "anthropic"
|
||||
if (last.includes("/responses")) return "responses"
|
||||
if (last.includes("/chat/completions")) return "chat"
|
||||
return "other"
|
||||
}
|
||||
|
||||
// One ledger line → a compact row, or null when it is not a model request.
|
||||
export function parseUsageLine(line) {
|
||||
let d
|
||||
try { d = JSON.parse(line) } catch { return null }
|
||||
if (!d || typeof d !== "object") return null
|
||||
const t = typeof d.t === "number" ? d.t : Date.parse(d.t)
|
||||
if (!Number.isFinite(t)) return null
|
||||
const status = Number(d.status) || 0
|
||||
const cancelled = status === 499
|
||||
const failed = !cancelled && (status === 0 || status >= 400 || Boolean(d.err))
|
||||
return {
|
||||
t,
|
||||
agent: intern(String(d.agent || "unknown")),
|
||||
// the conversation this request belongs to; harnesses that keep a session
|
||||
// id let us measure how long one session actually lasts
|
||||
session: d.session ? intern(String(d.session)) : "",
|
||||
model: intern(String(d.model || "unknown")),
|
||||
protocol: protocolOf(d.ep),
|
||||
in: num(d.in), out: num(d.out),
|
||||
cacheRead: num(d.cache_read), cacheWrite: num(d.cache_write),
|
||||
credits: num(d.credits),
|
||||
ms: num(d.ms), ttft: num(d.ttft_ms),
|
||||
failed, cancelled,
|
||||
}
|
||||
}
|
||||
|
||||
// Ledger strings repeat endlessly (a few agents, a few dozen models): keep one copy.
|
||||
const pool = new Map()
|
||||
function intern(s) {
|
||||
let v = pool.get(s)
|
||||
if (v === undefined) { v = s; pool.set(s, s) }
|
||||
return v
|
||||
}
|
||||
|
||||
function num(v) { return typeof v === "number" && Number.isFinite(v) ? v : 0 }
|
||||
|
||||
export function createUsageReader(file) {
|
||||
let offset = 0
|
||||
let rows = []
|
||||
let reading = null
|
||||
|
||||
async function refresh() {
|
||||
if (reading) return reading
|
||||
reading = (async () => {
|
||||
let st
|
||||
try { st = await stat(file) } catch { rows = []; offset = 0; return }
|
||||
if (st.size < offset) { rows = []; offset = 0 }
|
||||
if (st.size === offset) return
|
||||
// a last line still being written has no newline yet: stop before it
|
||||
const end = await lastNewline(file, offset, st.size)
|
||||
if (end < offset) return
|
||||
const cutoff = Date.now() - KEEP_MS
|
||||
const fresh = []
|
||||
const stream = createReadStream(file, { start: offset, end, encoding: "utf8" })
|
||||
const rl = createInterface({ input: stream, crlfDelay: Infinity })
|
||||
for await (const line of rl) {
|
||||
if (!line) continue
|
||||
const r = parseUsageLine(line)
|
||||
if (r && r.t >= cutoff) fresh.push(r)
|
||||
}
|
||||
offset = end + 1
|
||||
const keepFrom = Date.now() - KEEP_MS
|
||||
rows = rows.length && rows[0].t < keepFrom ? rows.filter((r) => r.t >= keepFrom) : rows
|
||||
for (const r of fresh) rows.push(r)
|
||||
})().finally(() => { reading = null })
|
||||
return reading
|
||||
}
|
||||
|
||||
return { refresh, rows: () => rows, file }
|
||||
}
|
||||
|
||||
// The position of the last newline in [from, size), or from-1 when none.
|
||||
async function lastNewline(file, from, size) {
|
||||
const fh = await open(file, "r")
|
||||
try {
|
||||
const step = 64 * 1024
|
||||
let pos = size
|
||||
while (pos > from) {
|
||||
const start = Math.max(from, pos - step)
|
||||
const buf = Buffer.alloc(pos - start)
|
||||
await fh.read(buf, 0, buf.length, start)
|
||||
const i = buf.lastIndexOf(10)
|
||||
if (i >= 0) return start + i
|
||||
pos = start
|
||||
}
|
||||
return from - 1
|
||||
} finally {
|
||||
await fh.close()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
{
|
||||
"name": "@magpie-community/page-harnessweight",
|
||||
"version": "0.4.0",
|
||||
"description": "HarnessWeight: a magpie page that weighs every agent harness behind your gateway, by agent rather than by model: input tokens, cache hit rate, tokens at full price, failures, latency, and the tool definitions each harness re-sends every turn",
|
||||
"type": "module",
|
||||
"files": [
|
||||
"index.mjs",
|
||||
"harnessweight.hooks.mjs",
|
||||
"service.mjs",
|
||||
"lib",
|
||||
"page",
|
||||
"app",
|
||||
"brand/assets",
|
||||
"README.md",
|
||||
"LICENSE"
|
||||
],
|
||||
"keywords": [
|
||||
"magpie",
|
||||
"magpie-plugin",
|
||||
"agent-harness",
|
||||
"harness",
|
||||
"token-usage",
|
||||
"claude-code",
|
||||
"codex",
|
||||
"cost",
|
||||
"llm-gateway"
|
||||
],
|
||||
"license": "MIT",
|
||||
"magpie": {
|
||||
"hooks": "./harnessweight.hooks.mjs",
|
||||
"page": {
|
||||
"title": "HarnessWeight",
|
||||
"titles": {
|
||||
"zh": "HarnessWeight",
|
||||
"zh-TW": "HarnessWeight",
|
||||
"ja": "HarnessWeight"
|
||||
},
|
||||
"file": "page/index.html",
|
||||
"icon": "page/icon.svg",
|
||||
"service": {
|
||||
"port": 3496,
|
||||
"option": "port"
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"port": 3496,
|
||||
"dataDir": "",
|
||||
"usageLog": "",
|
||||
"agents": [],
|
||||
"gatewayTimeoutMs": 2000,
|
||||
"gatewayUrl": ""
|
||||
},
|
||||
"permissions": [],
|
||||
"summary": {
|
||||
"en": "Compare agent harnesses behind your gateway by input tokens, cache, failures, latency and estimated tool-definition size. Its local service reads this machine's usage ledger; a read-only hook samples tool sizes and tracks in-flight requests.",
|
||||
"zh": "按 Agent 对比网关后面的输入 token、缓存、失败率、延迟与工具定义体积估算。本机服务读取用量记录,只读 hook 采样工具大小并追踪进行中的请求。"
|
||||
}
|
||||
},
|
||||
"main": "./index.mjs",
|
||||
"scripts": {
|
||||
"test": "node --test test/*.test.mjs",
|
||||
"dev": "node service.mjs"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/magpie-community/plugins.git",
|
||||
"directory": "packages/page-harnessweight"
|
||||
},
|
||||
"homepage": "https://github.com/webkubor/harnessweight",
|
||||
"author": "webkubor"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// The page in magpie's window is sandboxed (connect-src 'none'): it cannot
|
||||
// fetch, so it cannot even check whether the service is up. The one thing it
|
||||
// may do is navigate itself, so it goes straight to the plugin's service,
|
||||
// carrying the window's theme and language.
|
||||
(async () => {
|
||||
let port = 3496, dark = null, lang = "", service = ""
|
||||
try {
|
||||
const t = await window.magpie?.ready
|
||||
if (t && typeof t.dark === "boolean") dark = t.dark
|
||||
if (t && t.lang) lang = String(t.lang)
|
||||
} catch {}
|
||||
try {
|
||||
const s = window.magpie?.service
|
||||
if (typeof s === "string" && /^https?:\/\//.test(s)) service = s
|
||||
} catch {}
|
||||
try {
|
||||
const o = await window.magpie?.options?.get?.()
|
||||
if (o && Number(o.port) > 0) port = Number(o.port)
|
||||
} catch {}
|
||||
const q = new URLSearchParams()
|
||||
if (dark !== null) q.set("theme", dark ? "dark" : "light")
|
||||
if (lang) q.set("lang", lang)
|
||||
q.set("embed", "1")
|
||||
const base = service ? service.replace(/\/?$/, "/") : `http://127.0.0.1:${port}/`
|
||||
location.replace(base + "?" + q.toString())
|
||||
})()
|
||||
@@ -0,0 +1,17 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" role="img" aria-label="HarnessWeight">
|
||||
<title>HarnessWeight</title>
|
||||
<defs>
|
||||
<linearGradient id="t" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#5EE0D2"/><stop offset="1" stop-color="#17A9A2"/></linearGradient>
|
||||
<linearGradient id="o" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#FFA23A"/><stop offset="1" stop-color="#F26B1D"/></linearGradient>
|
||||
<linearGradient id="y" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#FFE27A"/><stop offset="1" stop-color="#FFB547"/></linearGradient>
|
||||
<clipPath id="cg"><rect x="36" y="48" width="104" height="104" rx="28" fill="#000" /></clipPath>
|
||||
<clipPath id="ct"><rect x="76" y="76" width="104" height="104" rx="28" fill="#000" /></clipPath>
|
||||
</defs>
|
||||
<g transform="skewY(-7) translate(0 16)">
|
||||
<rect x="36" y="48" width="104" height="104" rx="28" fill="#2B2F36" />
|
||||
<rect x="76" y="76" width="104" height="104" rx="28" fill="url(#t)" />
|
||||
<g clip-path="url(#cg)"><rect x="76" y="76" width="104" height="104" rx="28" fill="#1E6F6B" /></g>
|
||||
<rect x="116" y="104" width="104" height="104" rx="28" fill="url(#o)" />
|
||||
<g clip-path="url(#ct)"><rect x="116" y="104" width="104" height="104" rx="28" fill="url(#y)" /></g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,31 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>HarnessWeight</title>
|
||||
<script src="_magpie/bridge.js"></script>
|
||||
<script src="boot.js"></script>
|
||||
<style>
|
||||
body { margin: 0; display: grid; place-items: center; min-height: 100vh; font: 14px/1.5 system-ui, sans-serif; color: var(--magpie-fg, #444); background: var(--magpie-bg, transparent); }
|
||||
.wait { text-align: center; opacity: .8; }
|
||||
.wait img { width: 48px; height: 48px; animation: p 1.4s ease-in-out infinite; }
|
||||
@keyframes p { 50% { opacity: .45; transform: scale(.94); } }
|
||||
@media (prefers-reduced-motion: reduce) { .wait img { animation: none; } }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="wait"><img src="icon.svg" alt=""><p id="msg">Opening HarnessWeight…</p></div>
|
||||
<script>
|
||||
// the window's language, from magpie's bridge; only Simplified Chinese has its own line
|
||||
(async () => {
|
||||
try {
|
||||
const l = String((await window.magpie?.ready)?.lang || navigator.language || "").toLowerCase()
|
||||
const zh = /^zh(?:-|$)/.test(l) && !/^zh-(tw|hk|mo|hant)\b/.test(l)
|
||||
document.documentElement.lang = zh ? "zh-CN" : "en"
|
||||
if (zh) document.getElementById("msg").textContent = "正在打开 HarnessWeight…"
|
||||
} catch {}
|
||||
})()
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,172 @@
|
||||
// HarnessWeight — the local service. magpie's plugin page is sandboxed with
|
||||
// connect-src 'none' and cannot fetch anything, so the page navigates its
|
||||
// frame here, and this serves the real interface and the data behind it.
|
||||
//
|
||||
// GET / the interface (app/)
|
||||
// GET /api/summary ?period=today|7d|30d&clients=1&tz=<minutes>
|
||||
// GET /api/health
|
||||
//
|
||||
// Loopback only: the data is the user's own usage.
|
||||
import { createServer } from "node:http"
|
||||
import { randomBytes, timingSafeEqual } from "node:crypto"
|
||||
import { readFile } from "node:fs/promises"
|
||||
import { dirname, join, normalize, sep } from "node:path"
|
||||
import { fileURLToPath } from "node:url"
|
||||
import { toolsLog, usageLog } from "./lib/paths.mjs"
|
||||
import { createToolsReader } from "./lib/tools.mjs"
|
||||
import { createUsageReader } from "./lib/usage.mjs"
|
||||
import { PERIODS, summarize } from "./lib/summarize.mjs"
|
||||
import { createBrands } from "./lib/brands.mjs"
|
||||
import { activity } from "./lib/activity.mjs"
|
||||
// the same table the page imports, so both sides speak one language
|
||||
import { pageLanguage, languageTags } from "./app/i18n.mjs"
|
||||
|
||||
const HERE = dirname(fileURLToPath(import.meta.url))
|
||||
const APP = join(HERE, "app")
|
||||
const MIME = {
|
||||
".html": "text/html; charset=utf-8", ".js": "text/javascript; charset=utf-8",
|
||||
// app/i18n.mjs is a module both sides import, so the browser must get a
|
||||
// JavaScript media type for it.
|
||||
".mjs": "text/javascript; charset=utf-8",
|
||||
".css": "text/css; charset=utf-8", ".svg": "image/svg+xml", ".png": "image/png", ".webp": "image/webp",
|
||||
}
|
||||
|
||||
// Guards, as magpie's chat page does them. The page frame is sandboxed, so its
|
||||
// Origin is the literal "null" — and so is any other site's sandboxed frame.
|
||||
// Origin alone proves nothing, so every /api/ route also needs a token that
|
||||
// lives only in this process and is written into the interface's HTML when
|
||||
// this service serves it (that HTML carries no CORS header, so no other page
|
||||
// can read it). Host must be this service itself, against DNS rebinding.
|
||||
export const TOKEN_HEADER = "x-harnessweight-token"
|
||||
|
||||
export function createHandler(options = {}) {
|
||||
const port = Number(options.port) > 0 ? Number(options.port) : 3496
|
||||
const token = options.token || randomBytes(32).toString("hex")
|
||||
const own = new Set([`http://127.0.0.1:${port}`, `http://localhost:${port}`])
|
||||
const hosts = new Set([`127.0.0.1:${port}`, `localhost:${port}`])
|
||||
const hostOK = (req) => hosts.has(String(req.headers.host || "").toLowerCase())
|
||||
const originOK = (req) => { const o = req.headers.origin; return o === undefined || o === "null" || own.has(o) }
|
||||
const tokenOK = (req) => {
|
||||
// a query param, not only a header: a custom header makes the sandboxed
|
||||
// frame's fetch a preflighted request, which Chrome's private-network
|
||||
// checks block from an opaque origin; a plain GET goes through
|
||||
const q = new URL(req.url ?? "/", "http://127.0.0.1").searchParams.get("k")
|
||||
const got = Buffer.from(String(req.headers[TOKEN_HEADER] || q || ""))
|
||||
const want = Buffer.from(token)
|
||||
return got.length === want.length && timingSafeEqual(got, want)
|
||||
}
|
||||
|
||||
const usage = createUsageReader(usageLog(options))
|
||||
const tools = createToolsReader(toolsLog(options))
|
||||
const brands = createBrands(options)
|
||||
|
||||
return async function handle(req, res) {
|
||||
const url = new URL(req.url ?? "/", "http://127.0.0.1")
|
||||
res.setHeader("Cache-Control", "no-store")
|
||||
res.setHeader("X-Content-Type-Options", "nosniff")
|
||||
res.setHeader("Referrer-Policy", "no-referrer")
|
||||
if (!hostOK(req) || !originOK(req)) return text(res, 403, "HarnessWeight only serves its own page in magpie")
|
||||
// after the sandboxed frame navigates here its origin is opaque ("null"), so
|
||||
// even its own module script is cross-origin: allow that, nothing else
|
||||
const cors = () => { if (req.headers.origin) res.setHeader("Access-Control-Allow-Origin", req.headers.origin === "null" ? "null" : req.headers.origin) }
|
||||
if (req.method === "OPTIONS") {
|
||||
cors()
|
||||
res.setHeader("Access-Control-Allow-Headers", TOKEN_HEADER)
|
||||
res.setHeader("Access-Control-Allow-Private-Network", "true")
|
||||
res.writeHead(204); return res.end()
|
||||
}
|
||||
if (req.method !== "GET" && req.method !== "HEAD") return text(res, 405, "method not allowed")
|
||||
try {
|
||||
if (url.pathname.startsWith("/api/") && url.pathname !== "/api/health" && !tokenOK(req)) {
|
||||
cors()
|
||||
// the service restarted and the token changed: the page reloads once
|
||||
return json(res, 403, { error: "stale token", reload: true })
|
||||
}
|
||||
if (url.pathname === "/api/activity") {
|
||||
cors()
|
||||
return json(res, 200, activity.snapshot(tools.file))
|
||||
}
|
||||
if (url.pathname === "/api/summary") {
|
||||
await Promise.all([usage.refresh(), tools.refresh(), brands.refresh()])
|
||||
const period = PERIODS[url.searchParams.get("period")] ? url.searchParams.get("period") : "7d"
|
||||
const tz = Number(url.searchParams.get("tz"))
|
||||
// the page sends the language it rendered in, so the insights it gets
|
||||
// back are in the same language as the rest of the page
|
||||
const lang = pageLanguage(url.searchParams.get("lang"))
|
||||
const body = summarize({
|
||||
usage: usage.rows(), tools: tools.rows(), period,
|
||||
showClients: url.searchParams.get("clients") === "1",
|
||||
tzOffsetMin: Number.isFinite(tz) ? tz : 0,
|
||||
nameOf: (a) => brands.of(a).name,
|
||||
lang,
|
||||
})
|
||||
for (const a of body.agents) {
|
||||
const b = brands.of(a.agent)
|
||||
Object.assign(a, { name: b.name, icon: await brands.dataUri(b.icon) })
|
||||
}
|
||||
body.sources = { usageLog: usage.file, toolsLog: tools.file, usageRows: usage.rows().length, toolRows: tools.rows().length }
|
||||
cors()
|
||||
return json(res, 200, body)
|
||||
}
|
||||
if (url.pathname === "/api/health") {
|
||||
return json(res, 200, { ok: true, service: "harnessweight" })
|
||||
}
|
||||
let rel
|
||||
try { rel = url.pathname === "/" ? "index.html" : decodeURIComponent(url.pathname.slice(1)) }
|
||||
catch { return text(res, 400, "bad path") }
|
||||
const full = normalize(join(APP, rel))
|
||||
if (!full.startsWith(APP + sep)) return text(res, 400, "bad path")
|
||||
const content = await readFile(full).catch(() => null)
|
||||
if (!content) return text(res, 404, "not found")
|
||||
const ext = full.slice(full.lastIndexOf("."))
|
||||
if (full === join(APP, "index.html")) {
|
||||
// the token goes into the HTML, which gets no CORS header
|
||||
// the lang attribute follows the same ?lang= the page reads, so the
|
||||
// document says what language it is before anything paints
|
||||
const lang = pageLanguage(url.searchParams.get("lang"))
|
||||
const html = content.toString("utf8")
|
||||
.replace("<head>", `<head>\n<meta name="harnessweight-token" content="${token}">`)
|
||||
.replace('<html lang="zh-CN">', `<html lang="${languageTags[lang]}">`)
|
||||
res.writeHead(200, { "Content-Type": MIME[".html"] })
|
||||
return res.end(html)
|
||||
}
|
||||
cors()
|
||||
res.writeHead(200, { "Content-Type": MIME[ext] ?? "application/octet-stream" })
|
||||
res.end(content)
|
||||
} catch (e) {
|
||||
json(res, 500, { error: String(e?.message || e) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function json(res, code, body) {
|
||||
res.writeHead(code, { "Content-Type": "application/json; charset=utf-8" })
|
||||
res.end(JSON.stringify(body))
|
||||
}
|
||||
function text(res, code, body) {
|
||||
res.writeHead(code, { "Content-Type": "text/plain; charset=utf-8" })
|
||||
res.end(body)
|
||||
}
|
||||
|
||||
// Start listening. A port still held by a previous host is retried in the
|
||||
// background instead of failing the host's start.
|
||||
export function serve(options = {}) {
|
||||
const port = Number(options.port) > 0 ? Number(options.port) : 3496
|
||||
const server = createServer(createHandler({ ...options, port }))
|
||||
const ready = new Promise((resolve) => {
|
||||
let tries = 0
|
||||
const attempt = () => server.listen(port, "127.0.0.1")
|
||||
server.on("listening", () => resolve(port))
|
||||
server.on("error", (e) => {
|
||||
if (e.code === "EADDRINUSE" && tries++ < 30) setTimeout(attempt, 2000)
|
||||
else { console.error("[harnessweight] could not listen:", e.message); resolve(null) }
|
||||
})
|
||||
attempt()
|
||||
})
|
||||
return { server, port, ready }
|
||||
}
|
||||
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
const s = serve({ port: process.env.HARNESSWEIGHT_PORT })
|
||||
s.ready.then((p) => p && console.log(`harnessweight on http://127.0.0.1:${p}/`))
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { test } from "node:test"
|
||||
import assert from "node:assert/strict"
|
||||
import { createServer } from "node:http"
|
||||
import { mkdtemp } from "node:fs/promises"
|
||||
import { tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
import { createActivityTracker } from "../lib/activity.mjs"
|
||||
import { onRequest, onResponse } from "../harnessweight.hooks.mjs"
|
||||
import { createHandler } from "../service.mjs"
|
||||
|
||||
test("overlapping requests finish independently and duplicate finishes are harmless", () => {
|
||||
const tracker = createActivityTracker()
|
||||
const a = { state: {} }, b = { state: {} }, c = { state: {} }
|
||||
tracker.start("one", a, "dsh")
|
||||
tracker.start("one", a, "dsh")
|
||||
tracker.start("one", b, "dsh")
|
||||
tracker.start("two", c, "claude")
|
||||
assert.deepEqual(tracker.snapshot("one").agents, [{ agent: "dsh", count: 2 }])
|
||||
tracker.finish(b)
|
||||
tracker.finish(b)
|
||||
assert.equal(tracker.snapshot("one").total, 1)
|
||||
assert.equal(tracker.snapshot("two").total, 1)
|
||||
tracker.finish(a)
|
||||
assert.equal(tracker.snapshot("one").total, 0)
|
||||
})
|
||||
|
||||
test("unknown tracking is distinct from idle; unmatched requests expire explicitly", () => {
|
||||
let now = 0
|
||||
const tracker = createActivityTracker({ now: () => now, maxAgeMs: 100 })
|
||||
assert.equal(tracker.snapshot("one").available, false)
|
||||
tracker.start("one", {}, "untrackable")
|
||||
assert.equal(tracker.snapshot("one").available, false)
|
||||
const a = { state: {} }
|
||||
tracker.start("one", a, "dsh")
|
||||
now = 99
|
||||
assert.equal(tracker.snapshot("one").total, 1)
|
||||
now = 100
|
||||
const result = tracker.snapshot("one")
|
||||
assert.equal(result.total, 0)
|
||||
assert.equal(result.expired, 1)
|
||||
assert.equal(result.available, true)
|
||||
tracker.finish(a)
|
||||
assert.equal(tracker.snapshot("one").expired, 1)
|
||||
})
|
||||
|
||||
test("hook lifecycle reaches authenticated service, including failures and hook-signal abort", async (t) => {
|
||||
const dataDir = await mkdtemp(join(tmpdir(), "hw-activity-"))
|
||||
const server = createServer()
|
||||
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve))
|
||||
t.after(() => { server.closeAllConnections(); server.close() })
|
||||
const port = server.address().port
|
||||
server.on("request", createHandler({ port, token: "test", dataDir }))
|
||||
const url = `http://127.0.0.1:${port}/api/activity`
|
||||
assert.equal((await fetch(url)).status, 403)
|
||||
const get = async () => (await fetch(url + "?k=test")).json()
|
||||
assert.equal((await get()).available, false)
|
||||
const controller = new AbortController()
|
||||
const ctx = { state: {}, agent: "dsh", options: { dataDir }, signal: controller.signal }
|
||||
const second = { state: {}, agent: "dsh", options: { dataDir } }
|
||||
assert.equal(await onRequest({}, ctx), undefined)
|
||||
await onRequest({}, second)
|
||||
controller.abort() // Host does this after onRequest, not after the request.
|
||||
assert.deepEqual((await get()).agents, [{ agent: "dsh", count: 2 }])
|
||||
await onResponse(null, { ...ctx, success: false })
|
||||
assert.equal((await get()).total, 1)
|
||||
await onResponse({}, { ...second, success: true })
|
||||
assert.equal((await get()).total, 0)
|
||||
})
|
||||
@@ -0,0 +1,276 @@
|
||||
import { test } from "node:test"
|
||||
import assert from "node:assert/strict"
|
||||
import { spawn } from "node:child_process"
|
||||
import { chmod, mkdtemp, mkdir, open, readFile, rm, stat, writeFile } from "node:fs/promises"
|
||||
import { chmodSync, writeFileSync } from "node:fs"
|
||||
import { tmpdir } from "node:os"
|
||||
import { dirname, join } from "node:path"
|
||||
import { fileURLToPath } from "node:url"
|
||||
import { createToolsWriter, LOCK_TIMEOUT_MS } from "../harnessweight.hooks.mjs"
|
||||
|
||||
const CHILD = fileURLToPath(new URL("./fixtures/append-child.mjs", import.meta.url))
|
||||
|
||||
async function fixture(t) {
|
||||
const dir = await mkdtemp(join(tmpdir(), "hw-xproc-"))
|
||||
t.after(() => rm(dir, { recursive: true, force: true }))
|
||||
return join(dir, "tools.jsonl")
|
||||
}
|
||||
const exists = (path) => stat(path).then(() => true, () => false)
|
||||
// Resolves with the exit code, even if the child already exited before the
|
||||
// listener was attached ("exit" fires only once).
|
||||
const exited = (child) => new Promise((resolve) => {
|
||||
if (child.exitCode !== null || child.signalCode !== null) resolve(child.exitCode)
|
||||
else child.once("exit", (code) => resolve(code))
|
||||
})
|
||||
async function ids(file) {
|
||||
const out = []
|
||||
for (const path of [file + ".1", file]) {
|
||||
const text = await readFile(path, "utf8").catch(() => "")
|
||||
for (const line of text.split("\n").filter(Boolean)) out.push(JSON.parse(line).id)
|
||||
}
|
||||
return out
|
||||
}
|
||||
// A child that holds the main lock until killed.
|
||||
async function holder(t, file) {
|
||||
const child = spawn(process.execPath, [CHILD, "--hold", file], { stdio: ["ignore", "pipe", "inherit"] })
|
||||
t.after(() => { if (child.exitCode === null) child.kill("SIGKILL") })
|
||||
await new Promise((resolve, reject) => {
|
||||
child.stdout.on("data", (d) => { if (String(d).includes("LOCKED")) resolve() })
|
||||
child.on("exit", () => reject(new Error("holder exited early")))
|
||||
})
|
||||
return child
|
||||
}
|
||||
// A pid that certainly belonged to a process that has exited.
|
||||
async function deadPid() {
|
||||
const child = spawn(process.execPath, ["-e", ""])
|
||||
await exited(child)
|
||||
return child.pid
|
||||
}
|
||||
|
||||
test("two host processes rotating the same log concurrently lose no row", async (t) => {
|
||||
// 64 KiB generations, ~5.9 KB rows: 20 rows fill one generation and part
|
||||
// of the next, so exactly one rotation happens and every row must survive.
|
||||
for (let round = 0; round < 5; round++) {
|
||||
const file = await fixture(t)
|
||||
const kids = ["a", "b"].map((tag) =>
|
||||
spawn(process.execPath, [CHILD, file, `${tag}${round}`, "10", String(64 * 1024), "5800"], { stdio: "inherit" }))
|
||||
const codes = await Promise.all(kids.map(exited))
|
||||
assert.deepEqual(codes, [0, 0], "both writers exit cleanly (no ENOENT on rename)")
|
||||
const seen = await ids(file)
|
||||
assert.equal(seen.length, 20, `round ${round}: every row is present`)
|
||||
assert.equal(new Set(seen).size, 20, `round ${round}: no row is duplicated`)
|
||||
assert.ok(await exists(file + ".1"), "the boundary was crossed")
|
||||
assert.ok(!(await exists(file + ".lock")), "no lock is left behind")
|
||||
}
|
||||
})
|
||||
|
||||
test("a crashed holder's lock is reclaimed once its pid is gone", async (t) => {
|
||||
const file = await fixture(t)
|
||||
const child = await holder(t, file)
|
||||
child.kill("SIGKILL")
|
||||
await exited(child)
|
||||
const append = createToolsWriter({ lockTimeoutMs: 2000, warn: () => {} })
|
||||
await append(file, { t: Date.now(), agent: "a", id: "after-crash" })
|
||||
assert.deepEqual(await ids(file), ["after-crash"])
|
||||
assert.ok(!(await exists(file + ".lock")))
|
||||
assert.ok(!(await exists(file + ".reaper.lock")))
|
||||
})
|
||||
|
||||
test("a live holder's lock is never removed; the sample fails closed", async (t) => {
|
||||
const file = await fixture(t)
|
||||
await writeFile(file, JSON.stringify({ t: Date.now(), agent: "a", id: "old" }) + "\n")
|
||||
await holder(t, file)
|
||||
const append = createToolsWriter({ lockTimeoutMs: 300, warn: () => {} })
|
||||
await assert.rejects(append(file, { t: Date.now(), agent: "a", id: "new" }),
|
||||
(e) => e.code === "HW_LOCK_TIMEOUT" && e.reason === "held")
|
||||
assert.ok(await exists(file + ".lock"), "the live lock is still there")
|
||||
assert.deepEqual(await ids(file), ["old"], "existing data untouched")
|
||||
})
|
||||
|
||||
test("by default a held lock delays a response by about 100 ms, then skips the sample", async (t) => {
|
||||
const file = await fixture(t)
|
||||
await holder(t, file)
|
||||
const append = createToolsWriter({ warn: () => {} }) // default LOCK_TIMEOUT_MS
|
||||
const started = performance.now()
|
||||
await assert.rejects(append(file, { t: Date.now(), agent: "a", id: "x" }), { code: "HW_LOCK_TIMEOUT" })
|
||||
const waited = performance.now() - started
|
||||
assert.equal(LOCK_TIMEOUT_MS, 100)
|
||||
assert.ok(waited >= 90 && waited < 1500, `waited ${waited.toFixed(0)} ms`)
|
||||
assert.ok(!(await exists(file)), "no row written while another host holds the lock")
|
||||
})
|
||||
|
||||
test("queued requests behind a held lock do not add up their waits", async (t) => {
|
||||
const file = await fixture(t)
|
||||
await holder(t, file)
|
||||
const lines = []
|
||||
const original = console.warn
|
||||
console.warn = (msg) => lines.push(String(msg))
|
||||
t.after(() => { console.warn = original })
|
||||
const append = createToolsWriter() // default 100 ms, default throttled warning
|
||||
const started = performance.now()
|
||||
const results = await Promise.allSettled(Array.from({ length: 30 }, (_, i) =>
|
||||
append(file, { t: Date.now(), agent: "a", id: `q${i}` })))
|
||||
const elapsed = performance.now() - started
|
||||
assert.ok(results.every((r) => r.status === "rejected" && r.reason.code === "HW_LOCK_TIMEOUT"))
|
||||
// 30 × 100 ms would be 3 s; the shared budget keeps it near 100 ms.
|
||||
assert.ok(elapsed < 1500, `30 queued requests took ${elapsed.toFixed(0)} ms`)
|
||||
t.diagnostic(`30 queued requests behind a held lock: ${elapsed.toFixed(0)} ms in total`)
|
||||
assert.equal(lines.length, 1, "one warning for 30 skipped samples")
|
||||
assert.match(lines[0], /tool sample skipped: tools\.jsonl\.lock is held by another host/)
|
||||
})
|
||||
|
||||
test("under a concurrent peak from two hosts, every accepted row is kept and latency stays bounded", async (t) => {
|
||||
const file = await fixture(t)
|
||||
// The other host writes 200 rows continuously while this one takes a burst.
|
||||
const other = spawn(process.execPath, [CHILD, file, "other", "200", String(1 << 20), "200"], { stdio: "inherit" })
|
||||
const append = createToolsWriter({ maxBytes: 1 << 20, warn: () => {} }) // default 100 ms
|
||||
await new Promise((r) => setTimeout(r, 20))
|
||||
const latencies = []
|
||||
const results = await Promise.allSettled(Array.from({ length: 100 }, async (_, i) => {
|
||||
const started = performance.now()
|
||||
try { await append(file, { t: Date.now(), agent: "peak", id: `peak-${i}` }) }
|
||||
finally { latencies.push(performance.now() - started) }
|
||||
}))
|
||||
assert.equal(await exited(other), 0)
|
||||
const kept = new Set(await ids(file))
|
||||
const accepted = results.map((r, i) => r.status === "fulfilled" && `peak-${i}`).filter(Boolean)
|
||||
const skipped = results.filter((r) => r.status === "rejected")
|
||||
assert.ok(skipped.every((r) => r.reason.code === "HW_LOCK_TIMEOUT"), "only lock timeouts skip")
|
||||
for (const id of accepted) assert.ok(kept.has(id), `accepted ${id} is in the log`)
|
||||
for (let i = 0; i < 100; i++) if (results[i].status === "rejected") assert.ok(!kept.has(`peak-${i}`))
|
||||
for (let i = 0; i < 200; i++) assert.ok(kept.has(`other-${i}`), `other host row ${i} kept`)
|
||||
const worst = Math.max(...latencies)
|
||||
assert.ok(worst < 1500, `worst response delay ${worst.toFixed(0)} ms`)
|
||||
t.diagnostic(`peak: ${accepted.length}/100 kept, ${skipped.length} skipped, worst delay ${worst.toFixed(0)} ms`)
|
||||
})
|
||||
|
||||
test("an uncontended append takes the lock without waiting", async (t) => {
|
||||
const file = await fixture(t)
|
||||
const append = createToolsWriter({ warn: () => {} })
|
||||
await append(file, { t: Date.now(), agent: "a", id: "warm" })
|
||||
const started = performance.now()
|
||||
for (let i = 0; i < 20; i++) await append(file, { t: Date.now(), agent: "a", id: `n${i}` })
|
||||
const each = (performance.now() - started) / 20
|
||||
assert.ok(each < 100, `per append ${each.toFixed(2)} ms`)
|
||||
})
|
||||
|
||||
test("an empty or corrupt lock is not reclaimed", async (t) => {
|
||||
for (const content of ["", "{not json", JSON.stringify({ token: "x" })]) {
|
||||
const file = await fixture(t)
|
||||
await writeFile(file + ".lock", content)
|
||||
const append = createToolsWriter({ lockTimeoutMs: 150, warn: () => {} })
|
||||
await assert.rejects(append(file, { t: Date.now(), agent: "a", id: "x" }),
|
||||
(e) => e.code === "HW_LOCK_TIMEOUT" && e.reason === "unreadable")
|
||||
assert.equal(await readFile(file + ".lock", "utf8"), content)
|
||||
assert.ok(!(await exists(file)))
|
||||
}
|
||||
})
|
||||
|
||||
test("a leftover reaper lock blocks reclaiming instead of being removed", async (t) => {
|
||||
const file = await fixture(t)
|
||||
await writeFile(file + ".lock", JSON.stringify({ pid: await deadPid(), token: "dead" }))
|
||||
await writeFile(file + ".reaper.lock", "")
|
||||
const append = createToolsWriter({ lockTimeoutMs: 150, warn: () => {} })
|
||||
await assert.rejects(append(file, { t: Date.now(), agent: "a", id: "x" }),
|
||||
(e) => e.code === "HW_LOCK_TIMEOUT" && e.reason === "reaper")
|
||||
assert.ok(await exists(file + ".lock"))
|
||||
assert.ok(await exists(file + ".reaper.lock"))
|
||||
})
|
||||
|
||||
test("an error inside the critical section releases the lock", async (t) => {
|
||||
const file = await fixture(t)
|
||||
await mkdir(file) // appendFile on a directory fails with EISDIR
|
||||
const append = createToolsWriter({ lockTimeoutMs: 1000, warn: () => {} })
|
||||
await assert.rejects(append(file, { t: Date.now(), agent: "a", id: "fail" }), { code: "EISDIR" })
|
||||
assert.ok(!(await exists(file + ".lock")), "lock released in finally")
|
||||
await rm(file, { recursive: true })
|
||||
await append(file, { t: Date.now(), agent: "a", id: "ok" })
|
||||
assert.deepEqual(await ids(file), ["ok"])
|
||||
})
|
||||
|
||||
test("the holder releases its lock even when the lock can no longer be read", async (t) => {
|
||||
const file = await fixture(t)
|
||||
// now() runs inside the critical section: make the held lock unreadable
|
||||
// there, as a failed read (EMFILE, EIO) at release time would.
|
||||
const append = createToolsWriter({ warn: () => {}, now: () => { writeFileSync(file + ".lock", ""); return Date.now() } })
|
||||
await append(file, { t: Date.now(), agent: "a", id: "one" })
|
||||
assert.ok(!(await exists(file + ".lock")), "a live holder never leaves its lock behind")
|
||||
await append(file, { t: Date.now(), agent: "a", id: "two" })
|
||||
assert.deepEqual(await ids(file), ["one", "two"])
|
||||
})
|
||||
|
||||
test("a failed release is reported, throttled and without sample content", async (t) => {
|
||||
const file = await fixture(t)
|
||||
const dir = dirname(file)
|
||||
const lines = []
|
||||
const original = console.warn
|
||||
console.warn = (msg) => lines.push(String(msg))
|
||||
t.after(async () => { console.warn = original; await chmod(dir, 0o755).catch(() => {}) })
|
||||
// Inside the critical section, make the directory read-only: the append
|
||||
// still works (the file is open for append) but unlinking the lock fails.
|
||||
await writeFile(file, "")
|
||||
const append = createToolsWriter({ warn: () => {}, now: () => { chmodSync(dir, 0o555); return Date.now() } })
|
||||
await append(file, { t: Date.now(), agent: "a", id: "SECRET" })
|
||||
await chmod(dir, 0o755)
|
||||
assert.ok(await exists(file + ".lock"), "the release really failed")
|
||||
await rm(file + ".lock")
|
||||
await append(file, { t: Date.now(), agent: "a", id: "SECRET2" })
|
||||
await chmod(dir, 0o755)
|
||||
await rm(file + ".lock", { force: true })
|
||||
assert.equal(lines.length, 1, "one warning per minute")
|
||||
assert.match(lines[0], /could not release tools\.jsonl\.lock \(EACCES\)/)
|
||||
assert.ok(!lines[0].includes("SECRET") && !lines[0].includes(dir))
|
||||
})
|
||||
|
||||
test("a lock whose close fails is removed, not left naming a live pid", async (t) => {
|
||||
const file = await fixture(t)
|
||||
const probe = await open(file + ".probe", "w")
|
||||
const proto = Object.getPrototypeOf(probe)
|
||||
await probe.close()
|
||||
// Node defines close per handle, so hook writeFile (shared) and make the
|
||||
// close of that one handle — the lock file's — fail after really closing.
|
||||
const writeFileOrig = proto.writeFile
|
||||
let failNext = true
|
||||
proto.writeFile = async function (...args) {
|
||||
const result = await writeFileOrig.apply(this, args)
|
||||
if (failNext) {
|
||||
failNext = false
|
||||
const close = this.close
|
||||
this.close = async () => { await close.call(this); throw Object.assign(new Error("close failed"), { code: "EIO" }) }
|
||||
}
|
||||
return result
|
||||
}
|
||||
t.after(() => { proto.writeFile = writeFileOrig })
|
||||
const append = createToolsWriter({ warn: () => {} })
|
||||
// The first handle.writeFile in append is the lock file's owner record.
|
||||
await assert.rejects(append(file, { t: Date.now(), agent: "a", id: "x" }), { code: "EIO" })
|
||||
assert.ok(!(await exists(file + ".lock")), "no orphaned lock")
|
||||
await append(file, { t: Date.now(), agent: "a", id: "ok" })
|
||||
assert.deepEqual(await ids(file), ["ok"])
|
||||
})
|
||||
|
||||
test("reclaiming a dead lock still respects the deadline", async (t) => {
|
||||
const file = await fixture(t)
|
||||
await writeFile(file + ".lock", JSON.stringify({ pid: await deadPid(), token: "dead" }))
|
||||
// A deadline already passed: reclaiming must not loop on past it.
|
||||
const append = createToolsWriter({ lockTimeoutMs: -1, warn: () => {} })
|
||||
await assert.rejects(append(file, { t: Date.now(), agent: "a", id: "late" }),
|
||||
(e) => e.code === "HW_LOCK_TIMEOUT" && e.reason === "reclaimed")
|
||||
assert.ok(!(await exists(file + ".lock")), "the dead lock was still reclaimed")
|
||||
await createToolsWriter({ warn: () => {} })(file, { t: Date.now(), agent: "a", id: "next" })
|
||||
assert.deepEqual(await ids(file), ["next"])
|
||||
})
|
||||
|
||||
test("skipped samples warn at most once a minute and name no sample content", async (t) => {
|
||||
const file = await fixture(t)
|
||||
await writeFile(file + ".lock", "")
|
||||
const lines = []
|
||||
const original = console.warn
|
||||
console.warn = (msg) => lines.push(String(msg))
|
||||
t.after(() => { console.warn = original })
|
||||
const append = createToolsWriter({ lockTimeoutMs: 50 })
|
||||
for (let i = 0; i < 3; i++) await append(file, { t: Date.now(), agent: "secret-agent", id: "SECRET" }).catch(() => {})
|
||||
assert.equal(lines.length, 1)
|
||||
assert.match(lines[0], /tools\.jsonl\.lock is empty or corrupt/)
|
||||
assert.ok(!lines[0].includes("SECRET") && !lines[0].includes(file))
|
||||
})
|
||||
@@ -0,0 +1,23 @@
|
||||
// A second plugin host in miniature: appends rows to a shared tools log.
|
||||
// node append-child.mjs <file> <tag> <count> <maxBytes> <padBytes>
|
||||
// node append-child.mjs --hold <file> take the lock, print LOCKED, wait
|
||||
import { createToolsWriter } from "../../harnessweight.hooks.mjs"
|
||||
import { open } from "node:fs/promises"
|
||||
|
||||
const args = process.argv.slice(2)
|
||||
if (args[0] === "--hold") {
|
||||
// Take the main lock the way the writer does and keep it until killed.
|
||||
const handle = await open(args[1] + ".lock", "wx")
|
||||
await handle.writeFile(JSON.stringify({ pid: process.pid, token: "held-by-child", at: Date.now() }))
|
||||
await handle.close()
|
||||
process.stdout.write("LOCKED\n")
|
||||
setInterval(() => {}, 1 << 30)
|
||||
} else {
|
||||
const [file, tag, count, maxBytes, pad] = args
|
||||
// A longer wait than the 100 ms default: this test checks that no row is
|
||||
// lost under contention, not that contention skips samples.
|
||||
const append = createToolsWriter({ maxBytes: Number(maxBytes), lockTimeoutMs: 5000, warn: () => {} })
|
||||
for (let i = 0; i < Number(count); i++) {
|
||||
await append(file, { t: Date.now(), agent: tag, id: `${tag}-${i}`, pad: "x".repeat(Number(pad)) })
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
import { test } from "node:test"
|
||||
import assert from "node:assert/strict"
|
||||
import { mkdtemp, readFile, writeFile, appendFile } from "node:fs/promises"
|
||||
import { tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
import { measureTools } from "../lib/measure.mjs"
|
||||
import { parseUsageLine, protocolOf, kindOf, createUsageReader } from "../lib/usage.mjs"
|
||||
import { summarize } from "../lib/summarize.mjs"
|
||||
import { onRequest, onResponse } from "../harnessweight.hooks.mjs"
|
||||
|
||||
const schema = { type: "object", properties: { path: { type: "string" } } }
|
||||
|
||||
test("measureTools reads all four protocol shapes", () => {
|
||||
assert.equal(measureTools({ tools: [{ name: "Read", description: "d", input_schema: schema }] }).count, 1) // anthropic
|
||||
assert.deepEqual(measureTools({ tools: [{ type: "function", function: { name: "shell", parameters: schema } }] }).names, ["shell"]) // chat
|
||||
assert.deepEqual(measureTools({ tools: [{ type: "namespace", tools: [{ type: "function", name: "a" }, { type: "function", name: "b" }] }] }).names, ["a", "b"]) // responses namespace
|
||||
assert.deepEqual(measureTools({ tools: [{ functionDeclarations: [{ name: "g1" }, { name: "g2" }] }] }).names, ["g1", "g2"]) // gemini
|
||||
assert.equal(measureTools({}).count, 0)
|
||||
assert.ok(measureTools({ tools: [{ name: "x", input_schema: schema }] }).bytes > 0)
|
||||
})
|
||||
|
||||
test("usage lines: protocol, failure, cancel, clients", () => {
|
||||
assert.equal(protocolOf("/v1/chat/completions → /v1/messages"), "anthropic")
|
||||
assert.equal(protocolOf("/v1/chat/completions → /v1internal:streamGenerateContent?alt=sse"), "gemini")
|
||||
const ok = parseUsageLine(JSON.stringify({ t: "2026-11-09T10:00:00+08:00", agent: "dsh", model: "m", status: 200, in: 10, cache_read: 90, out: 5 }))
|
||||
assert.equal(ok.failed, false); assert.equal(ok.cacheRead, 90)
|
||||
assert.equal(parseUsageLine(JSON.stringify({ t: 1, agent: "a", status: 502 })).failed, true)
|
||||
const c = parseUsageLine(JSON.stringify({ t: 1, agent: "a", status: 499 }))
|
||||
assert.equal(c.failed, false); assert.equal(c.cancelled, true)
|
||||
assert.equal(parseUsageLine("{broken"), null)
|
||||
assert.equal(kindOf("curl"), "client"); assert.equal(kindOf("ai"), "client"); assert.equal(kindOf("magpie"), "client"); assert.equal(kindOf("dsh"), "agent")
|
||||
})
|
||||
|
||||
test("summarize groups by agent, hides clients, computes cache rate", () => {
|
||||
const now = Date.now()
|
||||
const r = (agent, inp, cr, failed = false) => ({ t: now - 1000, agent, model: "m", protocol: "anthropic", in: inp, out: 1, cacheRead: cr, cacheWrite: 0, credits: 0, ms: 100, ttft: 10, failed, cancelled: false })
|
||||
const usage = [...Array(30)].map(() => r("a", 10, 90)).concat([...Array(30)].map(() => r("b", 50, 50)), [r("curl", 1, 0)])
|
||||
const s = summarize({ usage, period: "7d", now })
|
||||
assert.deepEqual(s.agents.map((x) => x.agent).sort(), ["a", "b"])
|
||||
assert.equal(s.hiddenClients, 1)
|
||||
const a = s.agents.find((x) => x.agent === "a")
|
||||
assert.equal(a.cacheRate, 0.9)
|
||||
assert.ok(s.insights.some((i) => i.kind === "cache"))
|
||||
assert.equal(summarize({ usage, period: "7d", now, showClients: true }).agents.length, 3)
|
||||
})
|
||||
|
||||
test("usage reader is incremental and skips a half-written last line", async () => {
|
||||
const dir = await mkdtemp(join(tmpdir(), "al-"))
|
||||
const f = join(dir, "usage.jsonl")
|
||||
const line = (n) => JSON.stringify({ t: new Date().toISOString(), agent: "x" + n, status: 200, in: 1 }) + "\n"
|
||||
await writeFile(f, line(1) + line(2) + '{"t":"half')
|
||||
const r = createUsageReader(f)
|
||||
await r.refresh(); assert.equal(r.rows().length, 2)
|
||||
await appendFile(f, '-written"}\n' + line(3))
|
||||
await r.refresh(); assert.equal(r.rows().length, 3)
|
||||
})
|
||||
|
||||
test("hook never changes the request and writes only names and numbers", async () => {
|
||||
const dir = await mkdtemp(join(tmpdir(), "al-"))
|
||||
const body = { model: "m", messages: [{ role: "user", content: "SECRET PROMPT" }], tools: [{ name: "Read", input_schema: schema }] }
|
||||
const ctx = { agent: "dsh", protocol: "anthropic", model: "m", options: { dataDir: dir } }
|
||||
assert.equal(await onRequest(structuredClone(body), ctx), undefined)
|
||||
await onResponse({ usage: { input_tokens: 3, output_tokens: 4, cache_read_input_tokens: 5 } }, { ...ctx, request: body, success: true })
|
||||
const text = await readFile(join(dir, "tools.jsonl"), "utf8")
|
||||
const row = JSON.parse(text.trim())
|
||||
assert.equal(row.agent, "dsh"); assert.equal(row.tools, 1); assert.deepEqual(row.toolNames, ["Read"]); assert.equal(row.cacheRead, 5)
|
||||
assert.ok(!text.includes("SECRET"))
|
||||
})
|
||||
|
||||
test("insights ignore clients and use display names", () => {
|
||||
const now = Date.now()
|
||||
const r = (agent, inp, cr) => ({ t: now - 1000, agent, model: "m", protocol: "chat", in: inp, out: 1, cacheRead: cr, cacheWrite: 0, credits: 0, ms: 1, ttft: 1, failed: false, cancelled: false })
|
||||
const usage = [...Array(30)].flatMap(() => [r("a", 10, 90), r("b", 50, 50), r("curl", 1, 0)])
|
||||
const s = summarize({ usage, period: "7d", now, showClients: true, nameOf: (x) => ({ a: "Agent A" })[x] || x })
|
||||
assert.ok(s.insights.every((i) => !i.text.includes("curl")))
|
||||
assert.ok(s.insights.some((i) => i.text.includes("Agent A")))
|
||||
})
|
||||
|
||||
test("brands come from the gateway and fall back softly", async () => {
|
||||
const { createBrands } = await import("../lib/brands.mjs")
|
||||
const ok = createBrands({}, async () => ({ ok: true, json: async () => ({ agents: [{ id: "claude", name: "Claude Code", icon: "claudecode-color" }, { id: "x", name: "X", icon: "generic" }] }) }))
|
||||
await ok.refresh()
|
||||
assert.deepEqual(ok.of("claude"), { name: "Claude Code", icon: "claudecode-color.svg" })
|
||||
assert.equal(ok.of("x").icon, null)
|
||||
assert.match(await ok.dataUri("claudecode-color.svg"), /^data:image\/svg\+xml;base64,/)
|
||||
const down = createBrands({}, async () => { throw new Error("down") })
|
||||
await down.refresh()
|
||||
assert.equal(down.of("codex").name, "codex")
|
||||
})
|
||||
|
||||
test("session length is measured, and runaway sessions are counted not measured", () => {
|
||||
const now = Date.now()
|
||||
const r = (agent, session, t) => ({ t, agent, model: "m", protocol: "chat", in: 1, out: 1, cacheRead: 0, cacheWrite: 0, ms: 1, ttft: 1, failed: false, cancelled: false, session })
|
||||
const usage = [
|
||||
r("a", "s1", now - 600e3), r("a", "s1", now - 300e3), // 5 minutes
|
||||
r("a", "s2", now - 20_000e3), r("a", "s2", now - 10_000e3), // 10 seconds
|
||||
r("a", "s3", now - 30 * 3600e3), r("a", "s3", now - 10e3), // open for a day: not measured
|
||||
]
|
||||
const s = summarize({ usage, period: "7d", now, showClients: true })
|
||||
const a = s.agents.find((x) => x.agent === "a")
|
||||
assert.equal(a.session.count, 3)
|
||||
assert.equal(a.session.measured, 2)
|
||||
assert.equal(a.session.open, 1)
|
||||
assert.equal(a.session.median, 10_000_000)
|
||||
assert.ok(a.session.longest <= 6 * 3600e3)
|
||||
})
|
||||
|
||||
test("agents without a session id report no session length", () => {
|
||||
const now = Date.now()
|
||||
const usage = [{ t: now, agent: "a", model: "m", protocol: "chat", in: 1, out: 1, cacheRead: 0, cacheWrite: 0, ms: 1, ttft: 1, failed: false, cancelled: false }]
|
||||
const s = summarize({ usage, period: "7d", now, showClients: true })
|
||||
const a = s.agents.find((x) => x.agent === "a")
|
||||
assert.equal(a.session.count, 0)
|
||||
assert.equal(a.session.median, null)
|
||||
})
|
||||
|
||||
test("the protocol each agent speaks is reported", () => {
|
||||
const now = Date.now()
|
||||
const usage = [
|
||||
{ t: new Date(now).toISOString(), agent: "a", model: "m", ep: "/v1/messages", status: 200, in: 1, out: 1, cache_read: 0, cache_write: 0, ms: 1, ttft_ms: 1 },
|
||||
{ t: new Date(now).toISOString(), agent: "a", model: "m", ep: "/v1/messages", status: 200, in: 1, out: 1, cache_read: 0, cache_write: 0, ms: 1, ttft_ms: 1 },
|
||||
{ t: new Date(now).toISOString(), agent: "a", model: "m", ep: "/v1/responses", status: 200, in: 1, out: 1, cache_read: 0, cache_write: 0, ms: 1, ttft_ms: 1 },
|
||||
].map((d) => parseUsageLine(JSON.stringify(d)))
|
||||
const s = summarize({ usage, period: "7d", now, showClients: true })
|
||||
const a = s.agents.find((x) => x.agent === "a")
|
||||
assert.deepEqual(a.protocols.map((p) => p.name), ["anthropic", "responses"])
|
||||
})
|
||||
@@ -0,0 +1,103 @@
|
||||
import { test } from "node:test"
|
||||
import assert from "node:assert/strict"
|
||||
import { createServer } from "node:http"
|
||||
import { mkdtemp, readFile, writeFile } from "node:fs/promises"
|
||||
import { tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
import { TEXT, languageFor, pageLanguage, languageTags, translate, insight } from "../app/i18n.mjs"
|
||||
import { insights } from "../lib/summarize.mjs"
|
||||
import { createHandler } from "../service.mjs"
|
||||
|
||||
const CJK = /[\u4e00-\u9fff]/
|
||||
|
||||
test("English and Chinese tables have the same keys and no empty strings", () => {
|
||||
assert.deepEqual(Object.keys(TEXT.en).sort(), Object.keys(TEXT.zh).sort())
|
||||
for (const lang of ["en", "zh"]) for (const [k, v] of Object.entries(TEXT[lang])) assert.ok(v.trim(), `${lang} ${k}`)
|
||||
for (const [k, v] of Object.entries(TEXT.en)) assert.doesNotMatch(v, CJK, `en ${k} still Chinese`)
|
||||
})
|
||||
|
||||
test("placeholders match between languages", () => {
|
||||
const names = (s) => [...s.matchAll(/\{(\w+)\}/g)].map((m) => m[1]).sort()
|
||||
for (const k of Object.keys(TEXT.en)) assert.deepEqual(names(TEXT.en[k]), names(TEXT.zh[k]), k)
|
||||
})
|
||||
|
||||
test("languageFor follows magpie's tags; untranslated languages read English", () => {
|
||||
assert.equal(languageFor("zh-CN"), "zh")
|
||||
assert.equal(languageFor("zh_Hans"), "zh")
|
||||
assert.equal(languageFor("zh-Hant-TW"), "zh-TW")
|
||||
assert.equal(languageFor("ja-JP"), "ja")
|
||||
assert.equal(languageFor("en-US"), "en")
|
||||
assert.equal(languageFor(""), "en")
|
||||
assert.equal(languageTags.zh, "zh-CN")
|
||||
assert.equal(pageLanguage("zh-TW"), "en")
|
||||
assert.equal(pageLanguage("ja-JP"), "en")
|
||||
assert.equal(pageLanguage("zh-CN"), "zh")
|
||||
// zh-TW and ja have no table yet: they must fall back to English, never Simplified Chinese
|
||||
assert.equal(translate("zh-TW", "status.loading"), TEXT.en["status.loading"])
|
||||
assert.equal(translate("ja", "status.loading"), TEXT.en["status.loading"])
|
||||
assert.equal(translate("zh", "status.loading"), "正在读取…")
|
||||
assert.equal(translate("en", "kpi.requests", { count: "1,234" }), "1,234 requests")
|
||||
assert.equal(translate("en", "kpi.requests"), "{count} requests")
|
||||
assert.equal(translate("en", "no.such.key"), "no.such.key")
|
||||
})
|
||||
|
||||
test("insights speak the requested language with the same numbers and real Chinese names", () => {
|
||||
const mk = (agent, avgPrompt, cacheRate, prompt, errorRate) => ({ agent, kind: "agent", calls: 50, avgPrompt, cacheRate, prompt, errorRate })
|
||||
const agents = [mk("a", 30000, 0.9, 1.5e6, 0.0), mk("b", 6000, 0.4, 3e5, 0.1)]
|
||||
const names = { a: "克劳德<b>", b: "代码助手" }
|
||||
const zh = insights(agents, (a) => names[a], "zh")
|
||||
const en = insights(agents, (a) => names[a], "en")
|
||||
assert.deepEqual(zh.map((i) => i.kind), en.map((i) => i.kind))
|
||||
const zp = zh.find((i) => i.kind === "prompt").text, ep = en.find((i) => i.kind === "prompt").text
|
||||
assert.equal(zp, "克劳德<b> 每次请求平均读 30.0K token,是 代码助手 的 5.0 倍。")
|
||||
assert.equal(ep, "克劳德<b> reads an average of 30.0K tokens per request, 5.0x 代码助手.")
|
||||
// apart from user-supplied agent names, the English sentences carry no Chinese
|
||||
for (const i of en) assert.doesNotMatch(i.text.replaceAll(names.a, "").replaceAll(names.b, ""), CJK, i.kind)
|
||||
// default stays Chinese for existing callers
|
||||
assert.equal(insights(agents, (a) => names[a])[0].text, zh[0].text)
|
||||
assert.equal(insight("ja", "errors", { name: "x", rate: "10.0%" }), "x has a failure rate of 10.0%; failed requests may still consume tokens.")
|
||||
})
|
||||
|
||||
test("interface sources outside the table carry no hardcoded Chinese", async () => {
|
||||
for (const f of ["../app/app.js", "../app/explain.js", "../lib/summarize.mjs"]) {
|
||||
const src = await readFile(new URL(f, import.meta.url), "utf8")
|
||||
const lines = src.split("\n").filter((l) => CJK.test(l) && !l.trim().startsWith("//"))
|
||||
assert.deepEqual(lines, [], f)
|
||||
}
|
||||
const html = await readFile(new URL("../app/index.html", import.meta.url), "utf8")
|
||||
for (const l of html.split("\n").filter((l) => CJK.test(l))) assert.match(l, /data-t=|aria-label-t=/, l)
|
||||
})
|
||||
|
||||
test("app.js escapes translated text it puts into HTML", async () => {
|
||||
const src = await readFile(new URL("../app/app.js", import.meta.url), "utf8")
|
||||
// every T(...) interpolated straight into markup goes through esc()
|
||||
const raw = src.split("\n").filter((l) => l.includes("<") && l.includes("${T("))
|
||||
assert.deepEqual(raw, [], "found ${T(...)} in markup without esc()")
|
||||
})
|
||||
|
||||
async function start() {
|
||||
const dir = await mkdtemp(join(tmpdir(), "hw-i18n-"))
|
||||
const usageLog = join(dir, "usage.jsonl")
|
||||
await writeFile(usageLog, "")
|
||||
const srv = createServer()
|
||||
await new Promise((r) => srv.listen(0, "127.0.0.1", r))
|
||||
const port = srv.address().port
|
||||
srv.on("request", createHandler({ port, usageLog, dataDir: dir, token: "t".repeat(64), gatewayUrl: "http://127.0.0.1:9" }))
|
||||
return { port, close: () => srv.close() }
|
||||
}
|
||||
|
||||
test("service serves the shared module as JavaScript and marks the page language", async () => {
|
||||
const s = await start()
|
||||
try {
|
||||
const mod = await fetch(`http://127.0.0.1:${s.port}/i18n.mjs`, { headers: { Origin: "null" } })
|
||||
assert.equal(mod.status, 200)
|
||||
assert.match(mod.headers.get("content-type"), /^text\/javascript/)
|
||||
const en = await (await fetch(`http://127.0.0.1:${s.port}/?lang=en-US`)).text()
|
||||
assert.match(en, /<html lang="en">/)
|
||||
const zh = await (await fetch(`http://127.0.0.1:${s.port}/?lang=zh-CN`)).text()
|
||||
assert.match(zh, /<html lang="zh-CN">/)
|
||||
const bad = await (await fetch(`http://127.0.0.1:${s.port}/?lang=%22%3E%3Cscript%3E`)).text()
|
||||
assert.match(bad, /<html lang="en">/)
|
||||
assert.match(await (await fetch(`http://127.0.0.1:${s.port}/?lang=ja-JP`)).text(), /<html lang="en">/)
|
||||
} finally { s.close() }
|
||||
})
|
||||
@@ -0,0 +1,155 @@
|
||||
import test from "node:test"
|
||||
import assert from "node:assert/strict"
|
||||
import { mkdtempSync, mkdirSync, symlinkSync, writeFileSync, existsSync, realpathSync, rmSync } from "node:fs"
|
||||
import { tmpdir, homedir } from "node:os"
|
||||
import { join, resolve } from "node:path"
|
||||
import { magpieDir, usageLog, toolsLog } from "../lib/paths.mjs"
|
||||
import { gatewayUrl } from "../lib/brands.mjs"
|
||||
import { spawnSync } from "node:child_process"
|
||||
import { createServer } from "node:http"
|
||||
|
||||
function isolated(fn) {
|
||||
const dir = mkdtempSync(join(tmpdir(), "harnessweight-paths-"))
|
||||
const cwd = process.cwd()
|
||||
const keys = ["XDG_CONFIG_HOME", "MAGPIE_ADDR", "MAGPIE_GATEWAY_URL", "HOME"]
|
||||
const previous = Object.fromEntries(keys.map((k) => [k, process.env[k]]))
|
||||
for (const k of keys) delete process.env[k]
|
||||
process.env.HOME = realpathSync(dir)
|
||||
process.chdir(dir)
|
||||
try { return fn(dir) } finally {
|
||||
process.chdir(cwd)
|
||||
for (const k of keys) {
|
||||
if (previous[k] === undefined) delete process.env[k]
|
||||
else process.env[k] = previous[k]
|
||||
}
|
||||
// dir is the absolute directory created by mkdtempSync above.
|
||||
rmSync(realpathSync(dir), { recursive: true, force: true })
|
||||
}
|
||||
}
|
||||
|
||||
test("hook process and service process select the same files", () => isolated((dir) => {
|
||||
const real = realpathSync(dir)
|
||||
writeFileSync(join(real, "plugins.json"), "{}")
|
||||
// The host runs the hook with its cwd on the config dir; the service is
|
||||
// told the same dir through input.directory. Two processes, one answer.
|
||||
const hook = spawnSync(process.execPath, ["--input-type=module", "-e", `
|
||||
import { toolsLog, usageLog } from ${JSON.stringify(new URL("../lib/paths.mjs", import.meta.url).href)}
|
||||
process.stdout.write(JSON.stringify({ tools: toolsLog(), usage: usageLog() }))
|
||||
`], { cwd: real, encoding: "utf8", timeout: 10000 })
|
||||
assert.equal(hook.status, 0, hook.stderr || String(hook.error || ""))
|
||||
const fromHook = JSON.parse(hook.stdout)
|
||||
assert.equal(fromHook.tools, join(real, "harnessweight", "tools.jsonl"))
|
||||
assert.equal(fromHook.usage, join(real, "usage.jsonl"))
|
||||
assert.equal(fromHook.tools, toolsLog({ directory: real }))
|
||||
assert.equal(fromHook.usage, usageLog({ directory: real }))
|
||||
}))
|
||||
|
||||
test("server forwards host input.directory to its usage and tools readers", async () => {
|
||||
const entry = new URL("../index.mjs", import.meta.url).href
|
||||
const directory = realpathSync(mkdtempSync(join(tmpdir(), "harnessweight-portable-")))
|
||||
const probe = createServer()
|
||||
await new Promise((resolve, reject) => {
|
||||
probe.once("error", reject)
|
||||
probe.listen(0, "127.0.0.1", resolve)
|
||||
})
|
||||
const port = probe.address().port
|
||||
await new Promise((resolve, reject) => probe.close((error) => error ? reject(error) : resolve()))
|
||||
try {
|
||||
const result = spawnSync(process.execPath, ["--input-type=module", "-e", `
|
||||
import assert from "node:assert/strict"
|
||||
const { default: plugin } = await import(${JSON.stringify(entry)})
|
||||
assert.equal(process.env.HARNESSWEIGHT_PORT, undefined)
|
||||
await plugin.server({ directory: ${JSON.stringify(directory)} }, { token: "test", port: ${port} })
|
||||
let response
|
||||
for (let attempt = 0; attempt < 50; attempt++) {
|
||||
try {
|
||||
response = await fetch("http://127.0.0.1:${port}/api/summary?k=test")
|
||||
break
|
||||
} catch { await new Promise((resolve) => setTimeout(resolve, 20)) }
|
||||
}
|
||||
assert.ok(response, "service should start")
|
||||
const body = await response.json()
|
||||
assert.equal(body.sources.usageLog, ${JSON.stringify(join(directory, "usage.jsonl"))})
|
||||
assert.equal(body.sources.toolsLog, ${JSON.stringify(join(directory, "harnessweight", "tools.jsonl"))})
|
||||
process.exit(0)
|
||||
`], { encoding: "utf8", timeout: 10000 })
|
||||
assert.equal(result.status, 0, result.stderr || String(result.error || ""))
|
||||
} finally {
|
||||
rmSync(directory, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
test("portable host directory wins, including a fresh directory", () => isolated((dir) => {
|
||||
process.env.XDG_CONFIG_HOME = join(dir, "xdg")
|
||||
writeFileSync(join(dir, "providers.json"), "{}")
|
||||
const directory = join(realpathSync(dir), "fresh-portable")
|
||||
assert.equal(magpieDir({ directory }), directory)
|
||||
assert.equal(usageLog({ directory }), join(directory, "usage.jsonl"))
|
||||
assert.equal(toolsLog({ directory }), join(directory, "harnessweight", "tools.jsonl"))
|
||||
assert.equal(usageLog({ directory, usageLog: "custom.jsonl" }), resolve("custom.jsonl"))
|
||||
assert.equal(toolsLog({ directory, dataDir: "samples" }), resolve("samples/tools.jsonl"))
|
||||
}))
|
||||
|
||||
for (const marker of ["usage.jsonl", "plugins.json", "providers.json"]) {
|
||||
test(`hook cwd and service input agree with ${marker}`, () => isolated((dir) => {
|
||||
process.env.XDG_CONFIG_HOME = join(dir, "wrong-xdg")
|
||||
writeFileSync(join(dir, marker), "")
|
||||
const real = realpathSync(dir)
|
||||
assert.equal(magpieDir(), real)
|
||||
assert.equal(magpieDir({ directory: dir }), real)
|
||||
assert.equal(usageLog(), usageLog({ directory: dir }))
|
||||
assert.equal(toolsLog(), toolsLog({ directory: dir }))
|
||||
}))
|
||||
}
|
||||
|
||||
test("a symlinked config dir names the same directory as its real path", () => isolated((dir) => {
|
||||
writeFileSync(join(dir, "plugins.json"), "{}")
|
||||
const link = join(dir, "link")
|
||||
symlinkSync(dir, link)
|
||||
const real = realpathSync(dir)
|
||||
assert.equal(magpieDir({ directory: link }), real)
|
||||
assert.equal(magpieDir({ directory: dir }), real)
|
||||
assert.equal(magpieDir({ directory: join(link, "not-yet") }), join(real, "not-yet"))
|
||||
}))
|
||||
|
||||
test("standalone uses absolute XDG and rejects relative XDG", () => isolated((dir) => {
|
||||
const expectedHome = magpieDir({ directory: join(homedir(), ".config", "magpie") })
|
||||
assert.equal(magpieDir(), expectedHome)
|
||||
process.env.XDG_CONFIG_HOME = "relative-config"
|
||||
assert.equal(magpieDir(), expectedHome)
|
||||
process.env.XDG_CONFIG_HOME = join(dir, "xdg")
|
||||
assert.equal(magpieDir(), join(realpathSync(dir), "xdg", "magpie"))
|
||||
}))
|
||||
|
||||
test("legacy samples migrate within the selected portable directory", () => isolated((dir) => {
|
||||
writeFileSync(join(dir, "plugins.json"), "{}")
|
||||
const real = realpathSync(dir)
|
||||
mkdirSync(join(real, "agent-lens"))
|
||||
writeFileSync(join(real, "agent-lens", "tools.jsonl"), "sample\n")
|
||||
assert.equal(toolsLog(), join(real, "harnessweight", "tools.jsonl"))
|
||||
assert.equal(existsSync(join(real, "harnessweight", "tools.jsonl")), true)
|
||||
assert.equal(existsSync(join(real, "agent-lens")), false)
|
||||
}))
|
||||
|
||||
test("gateway respects explicit overrides and host address forms", () => isolated(() => {
|
||||
assert.equal(gatewayUrl(), "http://127.0.0.1:3425")
|
||||
for (const [addr, expected] of [
|
||||
["localhost:18086", "localhost:18086"],
|
||||
[" 127.0.0.1:1234 ", "127.0.0.1:1234"],
|
||||
["0.0.0.0:1234", "127.0.0.1:1234"],
|
||||
["[::]:1234", "127.0.0.1:1234"],
|
||||
["[::1]:1234", "[::1]:1234"],
|
||||
["[2001:DB8::1]:1234", "[2001:DB8::1]:1234"],
|
||||
]) {
|
||||
process.env.MAGPIE_ADDR = addr
|
||||
assert.equal(gatewayUrl(), `http://${expected}`)
|
||||
}
|
||||
for (const addr of ["bad", "::1:1234", "localhost:abc", "host:123/path"]) {
|
||||
process.env.MAGPIE_ADDR = addr
|
||||
assert.equal(gatewayUrl(), "http://127.0.0.1:3425")
|
||||
}
|
||||
process.env.MAGPIE_ADDR = "localhost:18086"
|
||||
process.env.MAGPIE_GATEWAY_URL = "https://gateway.example/"
|
||||
assert.equal(gatewayUrl(), "https://gateway.example")
|
||||
assert.equal(gatewayUrl({ gatewayUrl: "http://custom:8080///" }), "http://custom:8080")
|
||||
}))
|
||||
@@ -0,0 +1,163 @@
|
||||
// The migration of the legacy agent-lens samples into harnessweight is done
|
||||
// on the way to the path, so two hosts (the hook and the service) can reach
|
||||
// it at the same time. These tests pin the outcome of that race: one path,
|
||||
// and no sample left behind.
|
||||
import { test } from "node:test"
|
||||
import assert from "node:assert/strict"
|
||||
import { mkdtempSync, mkdirSync, writeFileSync, existsSync, readFileSync, chmodSync, realpathSync, rmSync, readdirSync, symlinkSync } from "node:fs"
|
||||
import { tmpdir } from "node:os"
|
||||
import { join, dirname, basename } from "node:path"
|
||||
import { spawn } from "node:child_process"
|
||||
import { magpieDir, toolsLog, usageLog } from "../lib/paths.mjs"
|
||||
|
||||
const PATHS_URL = new URL("../lib/paths.mjs", import.meta.url).href
|
||||
|
||||
function sandbox() {
|
||||
const dir = realpathSync(mkdtempSync(join(tmpdir(), "hw-migration-")))
|
||||
return dir
|
||||
}
|
||||
|
||||
// A config dir that still holds the legacy samples.
|
||||
function legacy(base, rows = [{ t: Date.now(), agent: "dsh", id: "legacy" }]) {
|
||||
writeFileSync(join(base, "plugins.json"), "{}")
|
||||
mkdirSync(join(base, "agent-lens"))
|
||||
writeFileSync(join(base, "agent-lens", "tools.jsonl"), rows.map((r) => JSON.stringify(r) + "\n").join(""))
|
||||
return base
|
||||
}
|
||||
|
||||
function cleanup(dir) {
|
||||
try { chmodSync(dir, 0o755) } catch { /* already gone */ }
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
}
|
||||
|
||||
test("a host that already migrated is never sent back to the legacy directory", () => {
|
||||
const base = sandbox()
|
||||
try {
|
||||
// The other host won the race: the new directory is there, the old one
|
||||
// is gone.
|
||||
mkdirSync(join(base, "harnessweight"))
|
||||
writeFileSync(join(base, "harnessweight", "tools.jsonl"), "")
|
||||
assert.equal(toolsLog({ directory: base }), join(base, "harnessweight", "tools.jsonl"))
|
||||
} finally {
|
||||
cleanup(base)
|
||||
}
|
||||
})
|
||||
|
||||
test("both directories present keeps the new one and leaves the legacy samples alone", () => {
|
||||
const base = sandbox()
|
||||
try {
|
||||
legacy(base)
|
||||
mkdirSync(join(base, "harnessweight"))
|
||||
writeFileSync(join(base, "harnessweight", "tools.jsonl"), "")
|
||||
assert.equal(toolsLog({ directory: base }), join(base, "harnessweight", "tools.jsonl"))
|
||||
// The legacy samples are untouched, not moved and not deleted.
|
||||
assert.equal(existsSync(join(base, "agent-lens", "tools.jsonl")), true)
|
||||
} finally {
|
||||
cleanup(base)
|
||||
}
|
||||
})
|
||||
|
||||
test("a migration that cannot happen keeps the legacy directory usable", { skip: process.getuid?.() === 0 ? "root ignores directory permissions" : false }, () => {
|
||||
const base = sandbox()
|
||||
try {
|
||||
legacy(base)
|
||||
chmodSync(base, 0o555)
|
||||
// The rename cannot succeed here, so the samples must stay readable
|
||||
// where they are instead of pointing at a directory that never appears.
|
||||
assert.equal(toolsLog({ directory: base }), join(base, "agent-lens", "tools.jsonl"))
|
||||
assert.equal(existsSync(join(base, "agent-lens", "tools.jsonl")), true)
|
||||
} finally {
|
||||
cleanup(base)
|
||||
}
|
||||
})
|
||||
|
||||
// Hosts that ask for the path at the same time must get the same answer.
|
||||
// The loser of the rename is the interesting one: the samples are already
|
||||
// moved, so answering with the legacy path would hide them.
|
||||
test("concurrent hosts agree on one path and every sample survives", async () => {
|
||||
const base = sandbox()
|
||||
try {
|
||||
legacy(base, Array.from({ length: 50 }, (_, i) => ({ t: Date.now(), agent: "dsh", id: "row-" + i })))
|
||||
const workers = 8
|
||||
mkdirSync(join(base, "ready"))
|
||||
const child = `
|
||||
import { writeFileSync, existsSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { toolsLog } from ${JSON.stringify(PATHS_URL)};
|
||||
const base = ${JSON.stringify(base)};
|
||||
writeFileSync(join(base, "ready", ${JSON.stringify("x")} + process.argv[1]), "");
|
||||
while (!existsSync(join(base, "go"))) await new Promise((r) => setTimeout(r, 2));
|
||||
process.stdout.write(toolsLog({ directory: base }));
|
||||
`
|
||||
const runs = Array.from({ length: workers }, (_, i) => new Promise((resolve, reject) => {
|
||||
const child1 = spawn(process.execPath, ["--input-type=module", "-e", child, String(i)], { encoding: "utf8" })
|
||||
let out = ""
|
||||
let err = ""
|
||||
child1.stdout.on("data", (c) => { out += c })
|
||||
child1.stderr.on("data", (c) => { err += c })
|
||||
child1.on("error", reject)
|
||||
child1.on("close", (code) => resolve({ code, out, err }))
|
||||
}))
|
||||
// Release them together.
|
||||
const deadline = Date.now() + 10000
|
||||
while (existsSync(join(base, "ready")) && Date.now() < deadline) {
|
||||
const ready = readdirSync(join(base, "ready"))
|
||||
if (ready.length >= workers) break
|
||||
await new Promise((r) => setTimeout(r, 10))
|
||||
}
|
||||
writeFileSync(join(base, "go"), "")
|
||||
const results = await Promise.all(runs)
|
||||
for (const r of results) assert.equal(r.code, 0, r.err)
|
||||
const paths = new Set(results.map((r) => r.out))
|
||||
assert.equal(paths.size, 1, "every host must name the same file: " + [...paths].join(", "))
|
||||
const expected = join(base, "harnessweight", "tools.jsonl")
|
||||
assert.equal([...paths][0], expected)
|
||||
// The migration happened exactly once and the samples are all there.
|
||||
assert.equal(existsSync(join(base, "agent-lens")), false)
|
||||
const rows = readFileSync(expected, "utf8").trim().split("\n").map((l) => JSON.parse(l))
|
||||
assert.equal(rows.length, 50)
|
||||
assert.equal(new Set(rows.map((r) => r.id)).size, 50)
|
||||
} finally {
|
||||
cleanup(base)
|
||||
}
|
||||
})
|
||||
|
||||
test("hook and service agree on the path in every branch", () => {
|
||||
const base = sandbox()
|
||||
try {
|
||||
legacy(base)
|
||||
// The host names the directory (service) and runs the hook with the
|
||||
// same directory as its working directory (hook). Both must land on
|
||||
// the same file, whichever spelling they use.
|
||||
const fromService = toolsLog({ directory: base })
|
||||
const fromHook = toolsLog({ directory: join(base, "..", base.split("/").pop()) })
|
||||
assert.equal(fromService, fromHook)
|
||||
assert.equal(fromService, join(base, "harnessweight", "tools.jsonl"))
|
||||
// The usage log follows the same directory.
|
||||
assert.equal(usageLog({ directory: base }), join(base, "usage.jsonl"))
|
||||
// An explicit data directory is used as given, by both sides.
|
||||
const data = join(base, "samples")
|
||||
mkdirSync(data)
|
||||
assert.equal(toolsLog({ directory: base, dataDir: data }), join(data, "tools.jsonl"))
|
||||
assert.equal(usageLog({ directory: base, usageLog: join(base, "u.jsonl") }), join(base, "u.jsonl"))
|
||||
} finally {
|
||||
cleanup(base)
|
||||
}
|
||||
})
|
||||
|
||||
test("a symlinked config dir is named the same way by both hosts", () => {
|
||||
const base = sandbox()
|
||||
const linkPath = join(dirname(base), "hw-migration-link-" + basename(base))
|
||||
try {
|
||||
legacy(base)
|
||||
symlinkSync(base, linkPath)
|
||||
const real = realpathSync(base)
|
||||
// The service is told the symlinked path, the hook sees the real one.
|
||||
assert.equal(toolsLog({ directory: linkPath }), join(real, "harnessweight", "tools.jsonl"))
|
||||
assert.equal(toolsLog({ directory: real }), join(real, "harnessweight", "tools.jsonl"))
|
||||
assert.equal(magpieDir({ directory: linkPath }), real)
|
||||
} finally {
|
||||
rmSync(linkPath, { force: true })
|
||||
cleanup(base)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,96 @@
|
||||
import { test } from "node:test"
|
||||
import assert from "node:assert/strict"
|
||||
import { mkdtemp, readFile, writeFile, stat, rename, rm } from "node:fs/promises"
|
||||
import { tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
import { createToolsWriter, MAX_FILE_BYTES, AGE_CHECK_MS } from "../harnessweight.hooks.mjs"
|
||||
import { createToolsReader } from "../lib/tools.mjs"
|
||||
|
||||
const AGE = 30 * 24 * 3600e3
|
||||
async function fixture(t) {
|
||||
const dir = await mkdtemp(join(tmpdir(), "hw-rollover-"))
|
||||
t.after(() => rm(dir, { recursive: true, force: true }))
|
||||
return join(dir, "tools.jsonl")
|
||||
}
|
||||
const sample = (t, id) => ({ t, agent: "test", id })
|
||||
function padded(row, bytes) {
|
||||
const base = JSON.stringify({ ...row, pad: "" }) + "\n"
|
||||
return JSON.stringify({ ...row, pad: "x".repeat(bytes - Buffer.byteLength(base)) }) + "\n"
|
||||
}
|
||||
|
||||
test("concurrent appends crossing 8 MiB preserve every row across both generations", async (t) => {
|
||||
const file = await fixture(t)
|
||||
const now = Date.now()
|
||||
await writeFile(file, padded(sample(now, "seed"), MAX_FILE_BYTES - 300))
|
||||
const append = createToolsWriter()
|
||||
await Promise.all(Array.from({ length: 200 }, (_, i) => append(file, sample(now, i))))
|
||||
for (const path of [file, file + ".1"]) assert.ok((await stat(path)).size <= MAX_FILE_BYTES)
|
||||
const reader = createToolsReader(file)
|
||||
await reader.refresh()
|
||||
assert.equal(reader.rows().length, 201)
|
||||
assert.equal(new Set(reader.rows().map((r) => r.id)).size, 201)
|
||||
assert.equal(reader.rows()[0].id, "seed")
|
||||
})
|
||||
|
||||
test("second rollover retires only the oldest generation", async (t) => {
|
||||
const file = await fixture(t)
|
||||
const now = Date.now()
|
||||
const append = createToolsWriter()
|
||||
const full = (id) => JSON.parse(padded(sample(now, id), MAX_FILE_BYTES))
|
||||
await append(file, full("first"))
|
||||
await append(file, full("second"))
|
||||
await append(file, sample(now, "third"))
|
||||
const reader = createToolsReader(file)
|
||||
await reader.refresh()
|
||||
assert.deepEqual(reader.rows().map((r) => r.id), ["second", "third"])
|
||||
assert.equal((await stat(file + ".1")).size, MAX_FILE_BYTES)
|
||||
})
|
||||
|
||||
test("age check runs hourly even below 512 KiB and reader expires unchanged rows", async (t) => {
|
||||
const file = await fixture(t)
|
||||
let now = Date.now()
|
||||
const append = createToolsWriter({ now: () => now })
|
||||
const old = sample(now - AGE + 1, "aging")
|
||||
await writeFile(file, JSON.stringify(old) + "\n")
|
||||
await append(file, sample(now, "fresh"))
|
||||
now += AGE_CHECK_MS - 1
|
||||
await append(file, sample(now, "before-hour"))
|
||||
await assert.rejects(stat(file + ".1"), { code: "ENOENT" })
|
||||
now += 1
|
||||
await append(file, sample(now, "at-hour"))
|
||||
assert.ok((await readFile(file + ".1", "utf8")).includes("aging"))
|
||||
const reader = createToolsReader(file, { now: () => now })
|
||||
await reader.refresh()
|
||||
assert.deepEqual(reader.rows().map((r) => r.id), ["fresh", "before-hour", "at-hour"])
|
||||
now += AGE + 1
|
||||
await reader.refresh()
|
||||
assert.deepEqual(reader.rows(), [])
|
||||
})
|
||||
|
||||
test("reader detects same-size inode replacement, ignores malformed and incomplete records", async (t) => {
|
||||
const file = await fixture(t)
|
||||
const now = Date.now()
|
||||
await writeFile(file, JSON.stringify(sample(now, "one")) + "\n")
|
||||
const reader = createToolsReader(file)
|
||||
await reader.refresh()
|
||||
await writeFile(file + ".replacement", JSON.stringify(sample(now, "two")) + "\n")
|
||||
await rename(file + ".replacement", file)
|
||||
await reader.refresh()
|
||||
assert.deepEqual(reader.rows().map((r) => r.id), ["two"])
|
||||
await writeFile(file + ".1", 'null\nmalformed\n' + JSON.stringify(sample(now - AGE - 1, "expired")) + "\n")
|
||||
await writeFile(file, JSON.stringify(sample(now, "complete")) + "\n" + JSON.stringify(sample(now, "partial")))
|
||||
await reader.refresh()
|
||||
assert.deepEqual(reader.rows().map((r) => r.id), ["complete"])
|
||||
})
|
||||
|
||||
test("oversized sample is rejected and failed writes do not poison the queue", async (t) => {
|
||||
const file = await fixture(t)
|
||||
const append = createToolsWriter()
|
||||
await assert.rejects(append(file, { pad: "x".repeat(MAX_FILE_BYTES) }), RangeError)
|
||||
await writeFile(file, "")
|
||||
await assert.rejects(append(join(file, "child"), sample(Date.now(), "fail")))
|
||||
// Repair the failed destination and retry the exact same queued path.
|
||||
await rm(file)
|
||||
await append(join(file, "child"), sample(Date.now(), "recovered"))
|
||||
assert.equal(JSON.parse(await readFile(join(file, "child"), "utf8")).id, "recovered")
|
||||
})
|
||||
@@ -0,0 +1,80 @@
|
||||
import { test } from "node:test"
|
||||
import assert from "node:assert/strict"
|
||||
import { createServer } from "node:http"
|
||||
import { mkdtemp, readFile, readdir, writeFile } from "node:fs/promises"
|
||||
import { tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
import { createHandler, TOKEN_HEADER } from "../service.mjs"
|
||||
|
||||
async function start() {
|
||||
const dir = await mkdtemp(join(tmpdir(), "al-svc-"))
|
||||
const usageLog = join(dir, "usage.jsonl")
|
||||
await writeFile(usageLog, JSON.stringify({ t: new Date().toISOString(), agent: "dsh", model: "m", status: 200, in: 1, cache_read: 9, out: 2 }) + "\n")
|
||||
const srv = createServer()
|
||||
await new Promise((r) => srv.listen(0, "127.0.0.1", r))
|
||||
const port = srv.address().port
|
||||
srv.on("request", createHandler({ port, usageLog, dataDir: dir, token: "t".repeat(64), gatewayUrl: "http://127.0.0.1:9" }))
|
||||
return { port, close: () => srv.close() }
|
||||
}
|
||||
const get = (port, path, headers = {}) => fetch(`http://127.0.0.1:${port}${path}`, { headers })
|
||||
|
||||
test("api needs the token; the token is only in the page HTML, which has no CORS header", async () => {
|
||||
const s = await start()
|
||||
try {
|
||||
assert.equal((await get(s.port, "/api/summary")).status, 403)
|
||||
assert.equal((await get(s.port, "/api/summary", { [TOKEN_HEADER]: "wrong" })).status, 403)
|
||||
const ok = await get(s.port, "/api/summary", { [TOKEN_HEADER]: "t".repeat(64), Origin: "null" })
|
||||
assert.equal(ok.status, 200)
|
||||
assert.equal((await ok.json()).agents[0].agent, "dsh")
|
||||
assert.equal((await get(s.port, `/api/summary?k=${"t".repeat(64)}`, { Origin: "null" })).status, 200)
|
||||
const page = await get(s.port, "/", { Origin: "null" })
|
||||
assert.equal(page.headers.get("access-control-allow-origin"), null)
|
||||
assert.match(await page.text(), /name="harnessweight-token" content="t{64}"/)
|
||||
const health = await (await get(s.port, "/api/health")).json()
|
||||
assert.deepEqual(Object.keys(health).sort(), ["ok", "service"])
|
||||
} finally { s.close() }
|
||||
})
|
||||
|
||||
test("other hosts, other origins and path traversal are refused", async () => {
|
||||
const s = await start()
|
||||
try {
|
||||
const h = { [TOKEN_HEADER]: "t".repeat(64) }
|
||||
assert.equal((await get(s.port, "/api/summary", { ...h, Origin: "https://evil.example" })).status, 403)
|
||||
// DNS rebinding: same socket, foreign Host
|
||||
const r = await new Promise((resolve) => {
|
||||
import("node:http").then(({ request }) => {
|
||||
const q = request({ host: "127.0.0.1", port: s.port, path: "/api/summary", headers: { ...h, Host: "evil.example" } }, resolve)
|
||||
q.end()
|
||||
})
|
||||
})
|
||||
assert.equal(r.statusCode, 403)
|
||||
const t = await new Promise((resolve) => {
|
||||
import("node:http").then(({ request }) => {
|
||||
const q = request({ host: "127.0.0.1", port: s.port, path: "/../service.mjs" }, resolve)
|
||||
q.end()
|
||||
})
|
||||
})
|
||||
assert.notEqual(t.statusCode, 200)
|
||||
assert.equal((await get(s.port, '/%E0')).status, 400)
|
||||
} finally { s.close() }
|
||||
})
|
||||
|
||||
test("the service, page bridge and defaults agree on the community port", async () => {
|
||||
const pkg = JSON.parse(await readFile(new URL("../package.json", import.meta.url), "utf8"))
|
||||
const boot = await readFile(new URL("../page/boot.js", import.meta.url), "utf8")
|
||||
const server = await readFile(new URL("../service.mjs", import.meta.url), "utf8")
|
||||
assert.equal(pkg.magpie.page.service.port, 3496)
|
||||
assert.equal(pkg.magpie.options.port, 3496)
|
||||
assert.match(boot, /let port = 3496\b/)
|
||||
assert.match(server, /Number\(options\.port\) > 0 \? Number\(options\.port\) : 3496/)
|
||||
})
|
||||
|
||||
test("the page in magpie's frame reaches no network and declares no reads", async () => {
|
||||
const pkg = JSON.parse(await readFile(new URL("../package.json", import.meta.url), "utf8"))
|
||||
assert.deepEqual(pkg.magpie.permissions, [])
|
||||
const dir = new URL("../page/", import.meta.url)
|
||||
for (const f of (await readdir(dir)).filter((f) => /\.(js|html)$/.test(f))) {
|
||||
const src = await readFile(new URL(f, dir), "utf8")
|
||||
assert.doesNotMatch(src, /\bfetch\s*\(|XMLHttpRequest|WebSocket|EventSource|sendBeacon|magpie\.read\s*\(/, f)
|
||||
}
|
||||
})
|
||||
@@ -282,6 +282,8 @@
|
||||
"summary": { "en": "Muse (Meta) subscription for Magpie and OpenCode: device-code sign-in, minted API key, Wonder and Spark models with reasoning efforts. The -contributor models use Meta's Contributor lane (data may be used for training). Unofficial.", "zh": "使用 Muse (Meta) 订阅:设备码登录,自动换取 API 密钥,提供 Wonder 和 Spark 模型及推理强度设置;以 -contributor 结尾的模型走 Meta 的 Contributor 通道(数据可能用于训练)。(非官方)" } },
|
||||
{ "package": "magpie-model-quota", "kind": "page", "name": "Model Quota",
|
||||
"icon": "https://raw.githubusercontent.com/1sh1ro/magpie-model-quota/main/assets/icon.svg",
|
||||
"summary": { "en": "Estimate how many tokens each model has left, merged across every account and provider. Runs entirely on magpie's local usage history; no telemetry or network requests.", "zh": "把所有账号、所有供应商的额度换算成 token,按模型合并估算还剩多少。完全基于 magpie 本地用量历史,不联网。" } }
|
||||
"summary": { "en": "Estimate how many tokens each model has left, merged across every account and provider. Runs entirely on magpie's local usage history; no telemetry or network requests.", "zh": "把所有账号、所有供应商的额度换算成 token,按模型合并估算还剩多少。完全基于 magpie 本地用量历史,不联网。" } },
|
||||
{ "package": "@magpie-community/page-harnessweight", "name": "HarnessWeight", "kind": "page", "community": true,
|
||||
"summary": { "en": "Compare agent harnesses behind your gateway by input tokens, cache, failures, latency and estimated tool-definition size. Its local service reads this machine's usage ledger; a read-only hook samples tool sizes and tracks in-flight requests.", "zh": "按 Agent 对比网关后面的输入 token、缓存、失败率、延迟与工具定义体积估算。本机服务读取用量记录,只读 hook 采样工具大小并追踪进行中的请求。" } }
|
||||
]
|
||||
}
|
||||
|
||||