cortico 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +47 -0
- package/package.json +43 -0
- package/src/boot.ts +46 -0
- package/src/bot.ts +1342 -0
- package/src/config-file.ts +41 -0
- package/src/core/README.md +92 -0
- package/src/core/billing.ts +26 -0
- package/src/core/blobs.ts +106 -0
- package/src/core/bus.ts +311 -0
- package/src/core/config-schema.ts +201 -0
- package/src/core/config.ts +262 -0
- package/src/core/core.ts +699 -0
- package/src/core/cost.ts +244 -0
- package/src/core/event-store.ts +304 -0
- package/src/core/fork.ts +113 -0
- package/src/core/generation.ts +118 -0
- package/src/core/instance-lock.ts +215 -0
- package/src/core/ipc-logger.ts +105 -0
- package/src/core/language.ts +62 -0
- package/src/core/log-context.ts +38 -0
- package/src/core/loop.ts +1858 -0
- package/src/core/markers.ts +48 -0
- package/src/core/prefix.ts +121 -0
- package/src/core/run.ts +95 -0
- package/src/core/secrets.ts +18 -0
- package/src/core/session.ts +56 -0
- package/src/core/sessions.ts +261 -0
- package/src/core/state.ts +104 -0
- package/src/core/template.ts +72 -0
- package/src/core/timers.ts +129 -0
- package/src/core/tool-log.ts +135 -0
- package/src/core/transcript.ts +92 -0
- package/src/core/truncate.ts +121 -0
- package/src/core/types.ts +1140 -0
- package/src/core/usage-log.ts +79 -0
- package/src/core/util.ts +386 -0
- package/src/deploy-listing.ts +160 -0
- package/src/deploy.ts +162 -0
- package/src/extensions/README.md +72 -0
- package/src/extensions/dry-mount.ts +390 -0
- package/src/extensions/manifest.ts +153 -0
- package/src/extensions/runtime.ts +42 -0
- package/src/extensions.ts +519 -0
- package/src/launcher.ts +285 -0
- package/src/paths.ts +155 -0
- package/src/protocol/open-responses/LICENSE +201 -0
- package/src/protocol/open-responses/README.md +14 -0
- package/src/protocol/open-responses/context-helpers.ts +27 -0
- package/src/protocol/open-responses/context-log.ts +59 -0
- package/src/protocol/open-responses/context.ts +89 -0
- package/src/protocol/open-responses/generated.ts +115 -0
- package/src/protocol/open-responses/index.ts +33 -0
- package/src/protocol/open-responses/openapi.json +4230 -0
- package/src/protocol/open-responses/stream.ts +146 -0
- package/src/protocol/open-responses/tokens.ts +31 -0
- package/src/providers/README.md +86 -0
- package/src/providers/base.ts +111 -0
- package/src/providers/configuration.ts +97 -0
- package/src/providers/console/config.ts +21 -0
- package/src/providers/console/settings.ts +443 -0
- package/src/providers/console/strings.ts +74 -0
- package/src/providers/console/types.ts +11 -0
- package/src/providers/llamacpp/archive.ts +148 -0
- package/src/providers/llamacpp/catalog.ts +247 -0
- package/src/providers/llamacpp/config.ts +36 -0
- package/src/providers/llamacpp/console/client.ts +6 -0
- package/src/providers/llamacpp/console/models-panel.ts +120 -0
- package/src/providers/llamacpp/console/runtime-panel.ts +173 -0
- package/src/providers/llamacpp/console/server.ts +153 -0
- package/src/providers/llamacpp/index.ts +95 -0
- package/src/providers/llamacpp/native.ts +51 -0
- package/src/providers/llamacpp/options.ts +117 -0
- package/src/providers/llamacpp/runtime-store.ts +139 -0
- package/src/providers/llamacpp/runtime.ts +214 -0
- package/src/providers/llamacpp/server.ts +286 -0
- package/src/providers/llamacpp/strings.ts +230 -0
- package/src/providers/openai-responses-compat/config.ts +20 -0
- package/src/providers/openai-responses-compat/index.ts +89 -0
- package/src/providers/openai-responses-compat/native.ts +127 -0
- package/src/providers/openai-responses-compat/strings.ts +19 -0
- package/src/providers/pricebook.ts +75 -0
- package/src/providers/registry.ts +137 -0
- package/src/providers/strings.ts +71 -0
- package/src/providers/transport/chat.ts +156 -0
- package/src/providers/transport/errors.ts +48 -0
- package/src/providers/transport/history.ts +68 -0
- package/src/providers/transport/native-input.ts +83 -0
- package/src/providers/transport/native-types.ts +13 -0
- package/src/providers/transport/response-assembly.ts +191 -0
- package/src/providers/transport/response-http.ts +196 -0
- package/src/providers/transport/response-meters.ts +27 -0
- package/src/providers/transport/responses-input.ts +56 -0
- package/src/web/README.md +84 -0
- package/src/web/client/console-pages/builtins/llm-settings/panel.ts +625 -0
- package/src/web/client/console-pages/builtins/llm-settings/pricing-panel.ts +168 -0
- package/src/web/client/console-pages/builtins/llm-settings/strings.ts +213 -0
- package/src/web/client/console-pages/builtins.ts +10 -0
- package/src/web/client/console-pages/context.ts +135 -0
- package/src/web/client/console-pages/host.ts +633 -0
- package/src/web/client/console-pages/loader.ts +132 -0
- package/src/web/client/console-pages/strings.ts +90 -0
- package/src/web/client/console-pages/tools/strings.ts +49 -0
- package/src/web/client/console-pages/tools/view.ts +215 -0
- package/src/web/client/core/api.ts +200 -0
- package/src/web/client/core/language.ts +56 -0
- package/src/web/client/core/lifecycle.ts +132 -0
- package/src/web/client/core/router.ts +199 -0
- package/src/web/client/core/stream.ts +157 -0
- package/src/web/client/core/websocket.ts +82 -0
- package/src/web/client/features/appearance/index.ts +333 -0
- package/src/web/client/features/appearance/strings.ts +87 -0
- package/src/web/client/features/config/index.ts +11 -0
- package/src/web/client/features/config/strings.ts +41 -0
- package/src/web/client/features/config/view.ts +428 -0
- package/src/web/client/features/core/events.ts +197 -0
- package/src/web/client/features/core/index.ts +254 -0
- package/src/web/client/features/core/run.ts +56 -0
- package/src/web/client/features/core/runlog.ts +214 -0
- package/src/web/client/features/core/sessions.ts +53 -0
- package/src/web/client/features/core/strings.ts +157 -0
- package/src/web/client/features/extensions/index.ts +422 -0
- package/src/web/client/features/extensions/strings.ts +164 -0
- package/src/web/client/features/feature.ts +93 -0
- package/src/web/client/features/live/context.ts +280 -0
- package/src/web/client/features/live/fork.ts +156 -0
- package/src/web/client/features/live/index.ts +392 -0
- package/src/web/client/features/live/onboarding.ts +113 -0
- package/src/web/client/features/live/protocol.ts +122 -0
- package/src/web/client/features/live/sessions.ts +71 -0
- package/src/web/client/features/live/status.ts +68 -0
- package/src/web/client/features/live/strings.ts +252 -0
- package/src/web/client/features/live/timeline.ts +590 -0
- package/src/web/client/features/prompts/editor.ts +292 -0
- package/src/web/client/features/prompts/index.ts +346 -0
- package/src/web/client/features/prompts/strings.ts +136 -0
- package/src/web/client/features/prompts/view.ts +256 -0
- package/src/web/client/features/providers/index.ts +100 -0
- package/src/web/client/features/providers/strings.ts +23 -0
- package/src/web/client/features/settings/general.ts +28 -0
- package/src/web/client/features/settings/index.ts +82 -0
- package/src/web/client/features/settings/strings.ts +33 -0
- package/src/web/client/features/storage/index.ts +1 -0
- package/src/web/client/features/storage/strings.ts +45 -0
- package/src/web/client/features/storage/view.ts +154 -0
- package/src/web/client/features/usage/chart.ts +486 -0
- package/src/web/client/features/usage/index.ts +407 -0
- package/src/web/client/features/usage/labels.ts +46 -0
- package/src/web/client/features/usage/range.ts +36 -0
- package/src/web/client/features/usage/state.ts +37 -0
- package/src/web/client/features/usage/strings.ts +191 -0
- package/src/web/client/features/usage/tooltip.ts +86 -0
- package/src/web/client/features/usage/types.ts +96 -0
- package/src/web/client/features/worlds/index.ts +424 -0
- package/src/web/client/features/worlds/strings.ts +121 -0
- package/src/web/client/main.ts +273 -0
- package/src/web/client/shell/avatar.ts +233 -0
- package/src/web/client/shell/index.ts +549 -0
- package/src/web/client/shell/strings.ts +89 -0
- package/src/web/client/theme/handoff.ts +43 -0
- package/src/web/client/theme/palette.ts +109 -0
- package/src/web/client/theme/registry.ts +130 -0
- package/src/web/client/theme/storage.ts +72 -0
- package/src/web/client/theme/strings.ts +123 -0
- package/src/web/client/theme/studio.ts +366 -0
- package/src/web/client/ui/actions.ts +109 -0
- package/src/web/client/ui/data.ts +185 -0
- package/src/web/client/ui/dom.ts +23 -0
- package/src/web/client/ui/fields.ts +191 -0
- package/src/web/client/ui/format.ts +75 -0
- package/src/web/client/ui/icons.ts +183 -0
- package/src/web/client/ui/images.ts +91 -0
- package/src/web/client/ui/index.ts +89 -0
- package/src/web/client/ui/lamp.ts +125 -0
- package/src/web/client/ui/log.ts +98 -0
- package/src/web/client/ui/overlay.ts +184 -0
- package/src/web/client/ui/page.ts +8 -0
- package/src/web/client/ui/prompt-input.tsx +311 -0
- package/src/web/client/ui/sheet.ts +131 -0
- package/src/web/client/ui/strings.ts +71 -0
- package/src/web/console-pages.ts +367 -0
- package/src/web/files.ts +107 -0
- package/src/web/path-picker.ts +296 -0
- package/src/web/public/index.html +17 -0
- package/src/web/public/styles.css +1715 -0
- package/src/web/server.ts +1883 -0
- package/src/web/shared/client-panel.ts +603 -0
- package/src/web/shared/console-protocol.ts +560 -0
- package/src/web/shared/css.d.ts +1 -0
- package/src/web/shared/path-picker.ts +23 -0
- package/src/web/shared/theme.ts +256 -0
- package/src/web/theme-store.ts +37 -0
- package/src/world.ts +449 -0
- package/src/worlds/bilibili/ENV_PROMPT.md +5 -0
- package/src/worlds/bilibili/README.md +176 -0
- package/src/worlds/bilibili/audience-admission.ts +995 -0
- package/src/worlds/bilibili/client.ts +528 -0
- package/src/worlds/bilibili/coalescing-buffer.ts +125 -0
- package/src/worlds/bilibili/config.ts +185 -0
- package/src/worlds/bilibili/console/client.ts +202 -0
- package/src/worlds/bilibili/definition.ts +35 -0
- package/src/worlds/bilibili/gift-frame.ts +131 -0
- package/src/worlds/bilibili/normalize.ts +452 -0
- package/src/worlds/bilibili/overlay/announcement.ts +76 -0
- package/src/worlds/bilibili/overlay/assets.ts +82 -0
- package/src/worlds/bilibili/overlay/model.ts +494 -0
- package/src/worlds/bilibili/overlay/project.ts +202 -0
- package/src/worlds/bilibili/overlay/server.ts +286 -0
- package/src/worlds/bilibili/overlay/types.ts +217 -0
- package/src/worlds/bilibili/overlay/web/app.js +690 -0
- package/src/worlds/bilibili/overlay/web/editor.css +297 -0
- package/src/worlds/bilibili/overlay/web/editor.html +102 -0
- package/src/worlds/bilibili/overlay/web/editor.js +2116 -0
- package/src/worlds/bilibili/overlay/web/overlay.html +13 -0
- package/src/worlds/bilibili/overlay/web/styles.css +258 -0
- package/src/worlds/bilibili/protobuf.ts +123 -0
- package/src/worlds/bilibili/wire.ts +94 -0
- package/src/worlds/bilibili/world.ts +1389 -0
- package/src/worlds/console-fixture/ENV_PROMPT.md +1 -0
- package/src/worlds/console-fixture/console/client.ts +72 -0
- package/src/worlds/console-fixture/world.ts +73 -0
- package/src/worlds/index.ts +15 -0
- package/src/worlds/minecraft/ENV_PROMPT.md +32 -0
- package/src/worlds/minecraft/ENV_PROMPT_CAMERA.md +2 -0
- package/src/worlds/minecraft/LICENSE-mineflayer-pathfinder.txt +21 -0
- package/src/worlds/minecraft/README.md +917 -0
- package/src/worlds/minecraft/blueprint-plan.ts +915 -0
- package/src/worlds/minecraft/blueprint-registry.ts +566 -0
- package/src/worlds/minecraft/blueprint-repair.ts +236 -0
- package/src/worlds/minecraft/blueprint-resource.ts +272 -0
- package/src/worlds/minecraft/blueprint.ts +492 -0
- package/src/worlds/minecraft/body-lease.ts +340 -0
- package/src/worlds/minecraft/bridge.ts +749 -0
- package/src/worlds/minecraft/check.ts +651 -0
- package/src/worlds/minecraft/chests.ts +292 -0
- package/src/worlds/minecraft/client-launch.ts +272 -0
- package/src/worlds/minecraft/client-options.ts +85 -0
- package/src/worlds/minecraft/client-skins.ts +164 -0
- package/src/worlds/minecraft/client-window.ps1 +91 -0
- package/src/worlds/minecraft/client.ts +423 -0
- package/src/worlds/minecraft/combat-context.ts +109 -0
- package/src/worlds/minecraft/combat.ts +1552 -0
- package/src/worlds/minecraft/config.ts +499 -0
- package/src/worlds/minecraft/console/access.ts +218 -0
- package/src/worlds/minecraft/console/client.ts +244 -0
- package/src/worlds/minecraft/console/log.ts +110 -0
- package/src/worlds/minecraft/console/mount.ts +420 -0
- package/src/worlds/minecraft/console/skin.ts +257 -0
- package/src/worlds/minecraft/console/style.css +154 -0
- package/src/worlds/minecraft/console/world.ts +449 -0
- package/src/worlds/minecraft/deaths.ts +135 -0
- package/src/worlds/minecraft/definition.ts +18 -0
- package/src/worlds/minecraft/engine-child.ts +274 -0
- package/src/worlds/minecraft/engine-ipc.ts +98 -0
- package/src/worlds/minecraft/entity-facts.ts +132 -0
- package/src/worlds/minecraft/escape.ts +407 -0
- package/src/worlds/minecraft/executor.ts +14494 -0
- package/src/worlds/minecraft/explored.ts +156 -0
- package/src/worlds/minecraft/geometry.ts +205 -0
- package/src/worlds/minecraft/goal-plan.ts +647 -0
- package/src/worlds/minecraft/item-break.ts +126 -0
- package/src/worlds/minecraft/item-facts.ts +146 -0
- package/src/worlds/minecraft/item-pick.ts +67 -0
- package/src/worlds/minecraft/level-dat.ts +176 -0
- package/src/worlds/minecraft/log.ts +132 -0
- package/src/worlds/minecraft/mineflayer-fixes.ts +1180 -0
- package/src/worlds/minecraft/names.ts +377 -0
- package/src/worlds/minecraft/pathfinder-lib.d.ts +13 -0
- package/src/worlds/minecraft/pathfinder-perf.ts +796 -0
- package/src/worlds/minecraft/piglin.ts +49 -0
- package/src/worlds/minecraft/policy.ts +547 -0
- package/src/worlds/minecraft/precheck.ts +655 -0
- package/src/worlds/minecraft/proxy.ts +445 -0
- package/src/worlds/minecraft/ranged.ts +635 -0
- package/src/worlds/minecraft/readouts.ts +102 -0
- package/src/worlds/minecraft/round.ts +26 -0
- package/src/worlds/minecraft/search-observation.ts +92 -0
- package/src/worlds/minecraft/server-config.ts +467 -0
- package/src/worlds/minecraft/server.ts +658 -0
- package/src/worlds/minecraft/show.ts +84 -0
- package/src/worlds/minecraft/skills.ts +1763 -0
- package/src/worlds/minecraft/terrain.ts +1735 -0
- package/src/worlds/minecraft/window.ts +96 -0
- package/src/worlds/minecraft/works.ts +179 -0
- package/src/worlds/minecraft/world.ts +6438 -0
- package/src/worlds/qq/ENV_PROMPT.md +5 -0
- package/src/worlds/qq/config.ts +108 -0
- package/src/worlds/qq/console/client.ts +126 -0
- package/src/worlds/qq/console/events.ts +155 -0
- package/src/worlds/qq/console/gate.ts +232 -0
- package/src/worlds/qq/console/roster.ts +203 -0
- package/src/worlds/qq/console/style.css +65 -0
- package/src/worlds/qq/conversation.ts +28 -0
- package/src/worlds/qq/definition.ts +62 -0
- package/src/worlds/qq/driver.ts +375 -0
- package/src/worlds/qq/history-tools.ts +209 -0
- package/src/worlds/qq/normalize.ts +323 -0
- package/src/worlds/qq/qface-map.ts +282 -0
- package/src/worlds/qq/vision-prompt.ts +27 -0
- package/src/worlds/qq/vision.ts +642 -0
- package/src/worlds/qq/vlm.ts +142 -0
- package/src/worlds/qq/world.ts +1503 -0
- package/src/worlds/terminal/ENV_PROMPT.md +11 -0
- package/src/worlds/terminal/config.ts +9 -0
- package/src/worlds/terminal/definition.ts +14 -0
- package/src/worlds/terminal/world.ts +700 -0
- package/src/worlds/websearch/ENV_PROMPT.md +1 -0
- package/src/worlds/websearch/brave-client.ts +261 -0
- package/src/worlds/websearch/config.ts +75 -0
- package/src/worlds/websearch/definition.ts +20 -0
- package/src/worlds/websearch/world.ts +171 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { pick } from '../../core/language.ts';
|
|
2
|
+
|
|
3
|
+
const zh = {
|
|
4
|
+
// index.ts
|
|
5
|
+
navLabel: '用量与成本',
|
|
6
|
+
navGroup: 'Core',
|
|
7
|
+
pageTitle: '用量与成本',
|
|
8
|
+
bucketAuto: '自动',
|
|
9
|
+
bucketMinute: '分',
|
|
10
|
+
bucketHour: '时',
|
|
11
|
+
bucketDay: '天',
|
|
12
|
+
bucketWeek: '周',
|
|
13
|
+
bucketMonth: '月',
|
|
14
|
+
presetToday: '今天',
|
|
15
|
+
preset3: '近 3 天',
|
|
16
|
+
preset7: '近 7 天',
|
|
17
|
+
preset30: '近 30 天',
|
|
18
|
+
preset90: '近 90 天',
|
|
19
|
+
presetCustom: '自定义',
|
|
20
|
+
metricCost: '成本',
|
|
21
|
+
liveRefresh: '自动刷新',
|
|
22
|
+
liveRefreshTitle: (sec: number) => `每 ${sec} 秒重取一次;离开本页自动停`,
|
|
23
|
+
refresh: '刷新',
|
|
24
|
+
granularity: '粒度',
|
|
25
|
+
autoCurrency: '自动币种',
|
|
26
|
+
basisMarginal: '边际费用',
|
|
27
|
+
basisEquivalent: '等价 API 成本',
|
|
28
|
+
ledger: '账本',
|
|
29
|
+
compTitle: '成本构成',
|
|
30
|
+
mainTitle: '用量时间序列',
|
|
31
|
+
mainDesc: "可组合类型、角色与模型进行拆分。",
|
|
32
|
+
split: '拆分',
|
|
33
|
+
dimType: '类型',
|
|
34
|
+
dimRole: '角色',
|
|
35
|
+
dimModel: '模型',
|
|
36
|
+
sortByShare: '占比排序',
|
|
37
|
+
sortByShareTitle: '按各部分占比从大到小堆叠',
|
|
38
|
+
callTitle: 'API 调用次数',
|
|
39
|
+
headCalls: '调用',
|
|
40
|
+
headInput: '输入 tok',
|
|
41
|
+
headOutput: '输出 tok',
|
|
42
|
+
headCache: '缓存命中',
|
|
43
|
+
headCost: '成本',
|
|
44
|
+
headAvg: '均价',
|
|
45
|
+
byRole: '按角色',
|
|
46
|
+
byModel: '按模型',
|
|
47
|
+
cardKnownCost: '已知费用小计',
|
|
48
|
+
unknown: '未知',
|
|
49
|
+
cardCalls: '调用次数',
|
|
50
|
+
cardAvgCost: '成功均价 / 次',
|
|
51
|
+
approxTok: (tok: string) => `≈ ${tok} tok`,
|
|
52
|
+
cardInput: '输入 token',
|
|
53
|
+
hitRate: (pct: string) => `命中率 ${pct}`,
|
|
54
|
+
cardOutput: '输出 token',
|
|
55
|
+
reasoningShare: (pct: string) => `思维链 ${pct}`,
|
|
56
|
+
cardCacheRate: '缓存命中率',
|
|
57
|
+
cardCoverage: '报价覆盖',
|
|
58
|
+
unpriced: (n: number) => `${n} 次在当前账本未完整计价`,
|
|
59
|
+
cardPeak: '峰值',
|
|
60
|
+
cardFailed: '失败流',
|
|
61
|
+
failedCalls: (n: string) => `${n} 次`,
|
|
62
|
+
burned: (tok: string) => `消耗 ≈ ${tok} tok`,
|
|
63
|
+
noCostData: '暂无成本数据',
|
|
64
|
+
partCacheHit: '命中缓存输入',
|
|
65
|
+
partCacheMiss: '未命中输入',
|
|
66
|
+
partOutput: '输出',
|
|
67
|
+
partOther: '其他费用',
|
|
68
|
+
noData: '无数据',
|
|
69
|
+
autoBucket: (label: string) => `自动 → 按${label}`,
|
|
70
|
+
rangeHint: (from: string, to: string, buckets: number) => `${from} ~ ${to} · ${buckets} 桶`,
|
|
71
|
+
billingHint: '按请求时的报价快照统计。' +
|
|
72
|
+
'总量包含失败、抢占与诊断请求;币种和费用口径分别汇总。',
|
|
73
|
+
unknownUsage: (n: number) => ` ${n} 次请求的用量或缓存分布不完整。`,
|
|
74
|
+
ledgerError: (pending: number, error: string) => ` 账目存储异常,${pending} 条待写入:${error}`,
|
|
75
|
+
loadFailed: (msg: string) => '用量加载失败: ' + msg,
|
|
76
|
+
loading: '加载中…',
|
|
77
|
+
|
|
78
|
+
// chart.ts
|
|
79
|
+
total: '合计',
|
|
80
|
+
totalPrefix: '合计 ',
|
|
81
|
+
callsUnit: ' 次',
|
|
82
|
+
weekShort: (s: string) => s + '周',
|
|
83
|
+
weekFull: (bucket: string) => bucket + ' 起 · 周',
|
|
84
|
+
monthFull: (bucket: string) => bucket + ' · 月',
|
|
85
|
+
restOmitted: '… 其余从略',
|
|
86
|
+
tipFoot: (calls: number, hitRate: string, reasoning: string) =>
|
|
87
|
+
`调用 ${calls} · 命中率 ${hitRate} · 思维链 ${reasoning}`,
|
|
88
|
+
noCalls: '这个范围内没有调用记录',
|
|
89
|
+
|
|
90
|
+
// labels.ts
|
|
91
|
+
typeCacheHit: '命中缓存',
|
|
92
|
+
typeCacheMiss: '未命中输入',
|
|
93
|
+
typeOutput: '输出',
|
|
94
|
+
typeOther: '其他费用 / 未分布输入',
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const en: typeof zh = {
|
|
98
|
+
// index.ts
|
|
99
|
+
navLabel: 'Usage & cost',
|
|
100
|
+
navGroup: 'Core',
|
|
101
|
+
pageTitle: 'Usage & cost',
|
|
102
|
+
bucketAuto: 'Auto',
|
|
103
|
+
bucketMinute: 'Minute',
|
|
104
|
+
bucketHour: 'Hour',
|
|
105
|
+
bucketDay: 'Day',
|
|
106
|
+
bucketWeek: 'Week',
|
|
107
|
+
bucketMonth: 'Month',
|
|
108
|
+
presetToday: 'Today',
|
|
109
|
+
preset3: 'Last 3 days',
|
|
110
|
+
preset7: 'Last 7 days',
|
|
111
|
+
preset30: 'Last 30 days',
|
|
112
|
+
preset90: 'Last 90 days',
|
|
113
|
+
presetCustom: 'Custom',
|
|
114
|
+
metricCost: 'Cost',
|
|
115
|
+
liveRefresh: 'Auto refresh',
|
|
116
|
+
liveRefreshTitle: (sec: number) => `Refetches every ${sec} s; stops when you leave this page`,
|
|
117
|
+
refresh: 'Refresh',
|
|
118
|
+
granularity: 'Granularity',
|
|
119
|
+
autoCurrency: 'Auto currency',
|
|
120
|
+
basisMarginal: 'Marginal cost',
|
|
121
|
+
basisEquivalent: 'Equivalent API cost',
|
|
122
|
+
ledger: 'Ledger',
|
|
123
|
+
compTitle: 'Cost breakdown',
|
|
124
|
+
mainTitle: 'Usage time series',
|
|
125
|
+
mainDesc: "Combine type, role and model dimensions.",
|
|
126
|
+
split: 'Split',
|
|
127
|
+
dimType: 'Type',
|
|
128
|
+
dimRole: 'Role',
|
|
129
|
+
dimModel: 'Model',
|
|
130
|
+
sortByShare: 'Sort by share',
|
|
131
|
+
sortByShareTitle: 'Stack parts from largest share to smallest',
|
|
132
|
+
callTitle: 'API calls',
|
|
133
|
+
headCalls: 'Calls',
|
|
134
|
+
headInput: 'Input tok',
|
|
135
|
+
headOutput: 'Output tok',
|
|
136
|
+
headCache: 'Cache hit',
|
|
137
|
+
headCost: 'Cost',
|
|
138
|
+
headAvg: 'Avg price',
|
|
139
|
+
byRole: 'By role',
|
|
140
|
+
byModel: 'By model',
|
|
141
|
+
cardKnownCost: 'Known cost subtotal',
|
|
142
|
+
unknown: 'unknown',
|
|
143
|
+
cardCalls: 'Calls',
|
|
144
|
+
cardAvgCost: 'Avg per successful call',
|
|
145
|
+
approxTok: (tok: string) => `≈ ${tok} tok`,
|
|
146
|
+
cardInput: 'Input tokens',
|
|
147
|
+
hitRate: (pct: string) => `hit rate ${pct}`,
|
|
148
|
+
cardOutput: 'Output tokens',
|
|
149
|
+
reasoningShare: (pct: string) => `reasoning ${pct}`,
|
|
150
|
+
cardCacheRate: 'Cache hit rate',
|
|
151
|
+
cardCoverage: 'Price coverage',
|
|
152
|
+
unpriced: (n: number) => `${n} calls not fully priced in the current ledger`,
|
|
153
|
+
cardPeak: 'Peak',
|
|
154
|
+
cardFailed: 'Failed calls',
|
|
155
|
+
failedCalls: (n: string) => `${n} calls`,
|
|
156
|
+
burned: (tok: string) => `used ≈ ${tok} tok`,
|
|
157
|
+
noCostData: 'No cost data yet',
|
|
158
|
+
partCacheHit: 'Cached input',
|
|
159
|
+
partCacheMiss: 'Uncached input',
|
|
160
|
+
partOutput: 'Output',
|
|
161
|
+
partOther: 'Other charges',
|
|
162
|
+
noData: 'No data',
|
|
163
|
+
autoBucket: (label: string) => `Auto → by ${label}`,
|
|
164
|
+
rangeHint: (from: string, to: string, buckets: number) => `${from} ~ ${to} · ${buckets} buckets`,
|
|
165
|
+
billingHint: 'Computed from the price snapshot at request time. ' +
|
|
166
|
+
'Totals include failed, preempted and diagnostic requests; currencies and cost bases are summed separately.',
|
|
167
|
+
unknownUsage: (n: number) => ` ${n} requests have an incomplete usage or cache breakdown.`,
|
|
168
|
+
ledgerError: (pending: number, error: string) => ` Ledger storage error, ${pending} entries pending: ${error}`,
|
|
169
|
+
loadFailed: (msg: string) => 'Failed to load usage: ' + msg,
|
|
170
|
+
loading: 'Loading…',
|
|
171
|
+
|
|
172
|
+
// chart.ts
|
|
173
|
+
total: 'Total',
|
|
174
|
+
totalPrefix: 'Total ',
|
|
175
|
+
callsUnit: ' calls',
|
|
176
|
+
weekShort: (s: string) => s + ' wk',
|
|
177
|
+
weekFull: (bucket: string) => bucket + ' · week',
|
|
178
|
+
monthFull: (bucket: string) => bucket + ' · month',
|
|
179
|
+
restOmitted: '… rest omitted',
|
|
180
|
+
tipFoot: (calls: number, hitRate: string, reasoning: string) =>
|
|
181
|
+
`calls ${calls} · hit rate ${hitRate} · reasoning ${reasoning}`,
|
|
182
|
+
noCalls: 'No calls recorded in this range',
|
|
183
|
+
|
|
184
|
+
// labels.ts
|
|
185
|
+
typeCacheHit: 'Cached',
|
|
186
|
+
typeCacheMiss: 'Uncached input',
|
|
187
|
+
typeOutput: 'Output',
|
|
188
|
+
typeOther: 'Other charges / unclassified input',
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export const S = pick({ zh, en });
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 随鼠标移动的 tooltip 与当前色块高亮。tooltip 位于本页 root,使用 fixed 定位并随卸载移除。
|
|
3
|
+
* 移出色块、重画图表与卸载统一通过 setHi/clearHi 更新高亮,避免残留描边。
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Disposable } from '../../../shared/client-panel.ts';
|
|
7
|
+
|
|
8
|
+
/** 鼠标与浮层之间留的空隙,也是碰到视口边缘时翻转的余量。 */
|
|
9
|
+
const TIP_PAD = 14;
|
|
10
|
+
/** 贴边时离视口边缘至少留这么多。 */
|
|
11
|
+
const TIP_EDGE = 8;
|
|
12
|
+
|
|
13
|
+
export interface UsageTip extends Disposable {
|
|
14
|
+
/** 浮层节点本身(`.u-tip`)。 */
|
|
15
|
+
readonly el: HTMLElement;
|
|
16
|
+
/**
|
|
17
|
+
* 显示一段正文。`key` 相同就**不重写 innerHTML**——鼠标在同一个段里移动会每帧
|
|
18
|
+
* 触发一次,重写等于每帧重建一棵子树(也会打断文本选取)。
|
|
19
|
+
*/
|
|
20
|
+
show(html: string, key: string): void;
|
|
21
|
+
/** 跟着鼠标走,碰到视口边缘翻到另一侧。 */
|
|
22
|
+
move(ev: { clientX: number; clientY: number }): void;
|
|
23
|
+
/** 收起,并顺手清掉高亮。 */
|
|
24
|
+
hide(): void;
|
|
25
|
+
setHi(rect: Element): void;
|
|
26
|
+
clearHi(): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** host 通常为 feature 的 root。HTML 来自 uTipHtml,所有外部文本必须经过 escaping。 */
|
|
30
|
+
export function createUsageTip(doc: Document, host: HTMLElement): UsageTip {
|
|
31
|
+
const el = doc.createElement('div');
|
|
32
|
+
el.className = 'u-tip viewport-overlay hidden';
|
|
33
|
+
host.appendChild(el);
|
|
34
|
+
let hi: Element | null = null;
|
|
35
|
+
let curKey: string | undefined;
|
|
36
|
+
let disposed = false;
|
|
37
|
+
|
|
38
|
+
const clearHi = (): void => {
|
|
39
|
+
if (hi) {
|
|
40
|
+
hi.classList.remove('seghi');
|
|
41
|
+
hi = null;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
el,
|
|
47
|
+
show(html, key) {
|
|
48
|
+
if (disposed) return;
|
|
49
|
+
if (curKey !== key) {
|
|
50
|
+
el.innerHTML = html;
|
|
51
|
+
curKey = key;
|
|
52
|
+
}
|
|
53
|
+
el.classList.remove('hidden');
|
|
54
|
+
},
|
|
55
|
+
move(ev) {
|
|
56
|
+
if (disposed) return;
|
|
57
|
+
const view = doc.defaultView;
|
|
58
|
+
const r = el.getBoundingClientRect();
|
|
59
|
+
let x = ev.clientX + TIP_PAD;
|
|
60
|
+
let y = ev.clientY + TIP_PAD;
|
|
61
|
+
const vw = view?.innerWidth ?? 0;
|
|
62
|
+
const vh = view?.innerHeight ?? 0;
|
|
63
|
+
if (vw && x + r.width > vw - TIP_EDGE) x = ev.clientX - r.width - TIP_PAD;
|
|
64
|
+
if (vh && y + r.height > vh - TIP_EDGE) y = ev.clientY - r.height - TIP_PAD;
|
|
65
|
+
el.style.left = Math.max(4, x) + 'px';
|
|
66
|
+
el.style.top = Math.max(4, y) + 'px';
|
|
67
|
+
},
|
|
68
|
+
hide() {
|
|
69
|
+
el.classList.add('hidden');
|
|
70
|
+
clearHi();
|
|
71
|
+
},
|
|
72
|
+
setHi(rect) {
|
|
73
|
+
if (hi === rect) return;
|
|
74
|
+
clearHi();
|
|
75
|
+
rect.classList.add('seghi');
|
|
76
|
+
hi = rect;
|
|
77
|
+
},
|
|
78
|
+
clearHi,
|
|
79
|
+
dispose() {
|
|
80
|
+
if (disposed) return;
|
|
81
|
+
disposed = true;
|
|
82
|
+
clearHi();
|
|
83
|
+
el.remove();
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* /api/usage 的线上 JSON 形状。usage 未挂载时允许空 series、null totals 和缺失字段,因此与服务端聚合器内部必填类型分开定义;数值由 uMetricVal/uTypeVal 集中归一。
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/** 一个累计单元:总量 + 成本三档拆分。桶点、子拆分、分组合计共用此形。 */
|
|
6
|
+
export interface UsageAccum {
|
|
7
|
+
calls?: number;
|
|
8
|
+
promptTokens?: number;
|
|
9
|
+
completionTokens?: number;
|
|
10
|
+
cacheHitTokens?: number;
|
|
11
|
+
cacheMissTokens?: number;
|
|
12
|
+
reasoningTokens?: number;
|
|
13
|
+
cost?: number;
|
|
14
|
+
costCacheHit?: number;
|
|
15
|
+
costCacheMiss?: number;
|
|
16
|
+
costOutput?: number;
|
|
17
|
+
costOther?: number;
|
|
18
|
+
unclassifiedInputTokens?: number;
|
|
19
|
+
pricedCalls?: number;
|
|
20
|
+
unpricedCalls?: number;
|
|
21
|
+
unknownUsageCalls?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** 时间序列上的一个桶。三张子拆分表是"任意维度交叉堆叠"的寻址面。 */
|
|
25
|
+
export interface UsagePoint extends UsageAccum {
|
|
26
|
+
/** 本地时区前缀,如 `2026-07-19T14:30` / `2026-07-19` / `2026-07` */
|
|
27
|
+
bucket: string;
|
|
28
|
+
byRole?: Record<string, UsageAccum>;
|
|
29
|
+
byModel?: Record<string, UsageAccum>;
|
|
30
|
+
/** `byRoleModel[role][model]`:角色×模型的交叉格 */
|
|
31
|
+
byRoleModel?: Record<string, Record<string, UsageAccum>>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 按 role / model 分组的合计。
|
|
36
|
+
*
|
|
37
|
+
* `key` 是不透明 id(角色 id 由Persona定义,模型名由供应商定义),
|
|
38
|
+
* `label` 是**声明方随数据给的人话名**。控制台不为任何一个 id 备一张中文名表——
|
|
39
|
+
* 备了就等于把某个具体 bot 的角色集写进了框架。给不出 label 时原样显示 `key`。
|
|
40
|
+
*/
|
|
41
|
+
export interface UsageGroupStat extends UsageAccum {
|
|
42
|
+
key: string;
|
|
43
|
+
/** 声明方给的显示名;缺省时用 `key`。 */
|
|
44
|
+
label?: string;
|
|
45
|
+
cacheHitRate?: number | null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** 已解析的具体粒度。 */
|
|
49
|
+
export type UsageBucketUnit = 'minute' | 'hour' | 'day' | 'week' | 'month';
|
|
50
|
+
/** 请求粒度:具体粒度或 `auto`(按跨度自适应)。 */
|
|
51
|
+
export type UsageBucketOption = UsageBucketUnit | 'auto';
|
|
52
|
+
|
|
53
|
+
export interface UsageAggregate {
|
|
54
|
+
ledger?: { pending: number; error: string | null };
|
|
55
|
+
currency?: string;
|
|
56
|
+
basis?: 'marginal' | 'equivalent';
|
|
57
|
+
balances?: Array<{ currency: string; basis: 'marginal' | 'equivalent'; knownAmount: number; pricedCalls: number; partialCalls: number }>;
|
|
58
|
+
successful?: UsageAccum;
|
|
59
|
+
bucket?: UsageBucketUnit;
|
|
60
|
+
from?: string | null;
|
|
61
|
+
to?: string | null;
|
|
62
|
+
series?: UsagePoint[];
|
|
63
|
+
/** `usage` 未挂载时为 null。 */
|
|
64
|
+
totals?: UsageGroupStat | null;
|
|
65
|
+
byRole?: UsageGroupStat[];
|
|
66
|
+
byModel?: UsageGroupStat[];
|
|
67
|
+
/** 失败、丢弃和中断均计入 totals;此字段用于核对失败消耗。 */
|
|
68
|
+
failed?: UsageAccum;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 图上纵轴画的是什么。`calls` 只出现在下面那张调用图。 */
|
|
72
|
+
export type UsageMetric = 'cost' | 'tokens' | 'calls';
|
|
73
|
+
|
|
74
|
+
/** 可拆分的三个维度。优先级(嵌套序)恒为 类型 > 角色 > 模型。 */
|
|
75
|
+
export type UsageDim = 'type' | 'role' | 'model';
|
|
76
|
+
|
|
77
|
+
/** 成本/token 的三档分量。与 `U_TYPES` 的 key 对应。 */
|
|
78
|
+
export type UsageTypeKey = 'cacheHit' | 'cacheMiss' | 'output' | 'other';
|
|
79
|
+
|
|
80
|
+
/** 一段组合里的一格:某个维度取了某个键。 */
|
|
81
|
+
export interface UsageCompPart {
|
|
82
|
+
dim: UsageDim;
|
|
83
|
+
key: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 一个堆叠段的身份 = 各维度取值的笛卡尔积中的一项。
|
|
88
|
+
* 空数组表示"不拆分"(整根柱子就是合计)。
|
|
89
|
+
*/
|
|
90
|
+
export type UsageComposite = UsageCompPart[];
|
|
91
|
+
|
|
92
|
+
/** 拆分维度的勾选状态。调用图没有 `type` 档,所以逐个可选。 */
|
|
93
|
+
export type UsageDimFlags = Partial<Record<UsageDim, boolean>>;
|
|
94
|
+
|
|
95
|
+
/** 颜色解析器:把主题 token(`chart-1` / `chart-hit`)解析成一个具体颜色。 */
|
|
96
|
+
export type ColorResolver = (token: string) => string;
|