dsh-budget 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/CHANGELOG.md +26 -0
- package/LICENSE +201 -0
- package/README.es.md +140 -0
- package/README.hi.md +140 -0
- package/README.md +140 -0
- package/README.pt.md +140 -0
- package/README.zh.md +140 -0
- package/SECURITY.md +37 -0
- package/THIRD_PARTY_NOTICES.md +23 -0
- package/cordis.patch.yml +73 -0
- package/lib/client.js +4893 -0
- package/lib/client.js.map +1 -0
- package/lib/index.js +1225 -0
- package/lib/typert.host.js +26 -0
- package/lib/types/aggregate/usage.d.ts +112 -0
- package/lib/types/aggregate/usage.d.ts.map +1 -0
- package/lib/types/client/BudgetTab.d.ts +18 -0
- package/lib/types/client/BudgetTab.d.ts.map +1 -0
- package/lib/types/client/index.d.ts +35 -0
- package/lib/types/client/index.d.ts.map +1 -0
- package/lib/types/client/locales.d.ts +42 -0
- package/lib/types/client/locales.d.ts.map +1 -0
- package/lib/types/client/present.d.ts +19 -0
- package/lib/types/client/present.d.ts.map +1 -0
- package/lib/types/client/remote.d.ts +270 -0
- package/lib/types/client/remote.d.ts.map +1 -0
- package/lib/types/client/styles.d.ts +12 -0
- package/lib/types/client/styles.d.ts.map +1 -0
- package/lib/types/command.d.ts +51 -0
- package/lib/types/command.d.ts.map +1 -0
- package/lib/types/config.d.ts +132 -0
- package/lib/types/config.d.ts.map +1 -0
- package/lib/types/estimate/carbon.d.ts +128 -0
- package/lib/types/estimate/carbon.d.ts.map +1 -0
- package/lib/types/estimate/cost.d.ts +71 -0
- package/lib/types/estimate/cost.d.ts.map +1 -0
- package/lib/types/estimate/latency-stats.d.ts +111 -0
- package/lib/types/estimate/latency-stats.d.ts.map +1 -0
- package/lib/types/estimate/models.d.ts +29 -0
- package/lib/types/estimate/models.d.ts.map +1 -0
- package/lib/types/estimate/prices.d.ts +85 -0
- package/lib/types/estimate/prices.d.ts.map +1 -0
- package/lib/types/estimate/sanitize.d.ts +56 -0
- package/lib/types/estimate/sanitize.d.ts.map +1 -0
- package/lib/types/events.d.ts +57 -0
- package/lib/types/events.d.ts.map +1 -0
- package/lib/types/governance.d.ts +67 -0
- package/lib/types/governance.d.ts.map +1 -0
- package/lib/types/index.d.ts +50 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/service.d.ts +67 -0
- package/lib/types/service.d.ts.map +1 -0
- package/lib/types/typert.host.d.ts +258 -0
- package/lib/types/typert.host.d.ts.map +1 -0
- package/lib/types/wire.d.ts +629 -0
- package/lib/types/wire.d.ts.map +1 -0
- package/lib/wire-DVO8yw7L.js +4219 -0
- package/package.json +164 -0
package/README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# 💰 dsh-budget
|
|
4
|
+
|
|
5
|
+
**Cost governance for DeepSeek Harness: budgets, carbon, and latency in one panel.**
|
|
6
|
+
|
|
7
|
+
*Know what every session costs — before it costs you.*
|
|
8
|
+
|
|
9
|
+
[](LICENSE)
|
|
10
|
+
[](https://github.com/topics/dsh-plugin)
|
|
11
|
+
[](#)
|
|
12
|
+
[](https://github.com/PerryLink/dsh-budget/actions)
|
|
13
|
+
[](https://github.com/PerryLink/dsh-budget/releases)
|
|
14
|
+
[](https://www.npmjs.com/package/dsh-budget)
|
|
15
|
+
[](https://www.npmjs.com/package/dsh-budget)
|
|
16
|
+
|
|
17
|
+
[English](README.md) · [简体中文](README.zh.md) · [Español](README.es.md) · [Português](README.pt.md) · [हिन्दी](README.hi.md)
|
|
18
|
+
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Compatibility
|
|
24
|
+
|
|
25
|
+
| Surface | Status |
|
|
26
|
+
|---|---|
|
|
27
|
+
| Harness | DeepSeek Harness `0.1.0-rc.6` |
|
|
28
|
+
| Node | `^22.19.0 \|\| >=24.0.0` |
|
|
29
|
+
| Surfaces | Host + Web client (Settings budget tab); `/budget` command |
|
|
30
|
+
|
|
31
|
+
## What you get
|
|
32
|
+
|
|
33
|
+
`dsh-budget` turns the session event stream into a four-in-one cost governance loop:
|
|
34
|
+
|
|
35
|
+
- **Aggregated metering** — tokens (uncached input / output / cache read / cache write), estimated USD cost, and carbon footprint per model, session, and day, priced through a built-in USD-per-1M table merged with your `config.prices`.
|
|
36
|
+
- **Budget governance** — session/daily/monthly caps; a warn-ratio threshold alert (webhook POST + desktop-notification flag) and three over-limit policies: `alert` (notify only), `block` (short-circuit new model requests until the user lifts the block), `degrade` (block with corrective guidance naming the cheaper model from your `degradation` map).
|
|
37
|
+
- **Carbon & latency** — token→carbon bridge (tokens × kWh/token × PUE × regional grid intensity, ported from AI-Carbon-Footprint-Calculator) and per-model latency percentiles.
|
|
38
|
+
- **Surfaces** — the Settings budget tab (usage bars, model breakdown, alerts, cap editors, unblock buttons) and the `/budget` command (`/budget`, `/budget models`, `/budget unblock <scope>`).
|
|
39
|
+
|
|
40
|
+
## Quick start
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
# 1. install the bundle into your profile
|
|
44
|
+
dsh plugin --profile web add "github:PerryLink/dsh-budget#main"
|
|
45
|
+
|
|
46
|
+
# or from npm (published releases)
|
|
47
|
+
dsh plugin --profile web add dsh-budget
|
|
48
|
+
|
|
49
|
+
# 2. restart and verify the row
|
|
50
|
+
dsh --profile web --dump-config | grep -A2 'id: budget'
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Then ask the agent: `/budget` — and watch the Settings tab fill in.
|
|
54
|
+
|
|
55
|
+
## Install & uninstall
|
|
56
|
+
|
|
57
|
+
- **git channel** (latest `main`): `dsh plugin --profile web add "github:PerryLink/dsh-budget#main"` — the `prepare` script builds with production dependencies only.
|
|
58
|
+
- **npm channel** (published releases): `dsh plugin --profile web add dsh-budget`.
|
|
59
|
+
- **tarball channel**: `pnpm pack` in this repo, then `dsh plugin --profile web add ./dsh-budget-<version>.tgz`.
|
|
60
|
+
- **uninstall**: `dsh plugin --profile web remove dsh-budget`.
|
|
61
|
+
|
|
62
|
+
> If pnpm reports `ERR_PNPM_IGNORED_BUILDS` for this package (esbuild's harmless platform-binary validation), add `allowBuilds: { esbuild: true }` to your `pnpm-workspace.yaml` — the `dsh` CLI prints the exact snippet.
|
|
63
|
+
|
|
64
|
+
## Configuration
|
|
65
|
+
|
|
66
|
+
All tunables are Schemastery `Config` fields (changeable from cordis.yml). `cordis.patch.yml` documents each key inline.
|
|
67
|
+
|
|
68
|
+
| Key | Default | Meaning |
|
|
69
|
+
|---|---|---|
|
|
70
|
+
| `prices` | `{}` | Per-model USD prices per 1M tokens, merged over the built-in table |
|
|
71
|
+
| `defaultPrice` | `{input: 1.0, output: 3.0}` | Fallback for models absent from both tables |
|
|
72
|
+
| `budgets.session` / `daily` / `monthly` | `10` / `50` / `500` | Budget caps in USD per scope; omit for unlimited |
|
|
73
|
+
| `warnRatio` | `0.8` | Alert once usage reaches this fraction of a cap (0..1) |
|
|
74
|
+
| `overLimit` | `alert` | `alert` / `block` / `degrade` after a cap is crossed |
|
|
75
|
+
| `degradation` | `{}` | Model id → cheaper model id of the same provider |
|
|
76
|
+
| `webhookUrl` | *(none)* | Optional webhook URL for threshold alerts (POST JSON) |
|
|
77
|
+
| `webhookTimeoutMs` | `5000` | Webhook request timeout |
|
|
78
|
+
| `alertsEnabled` | `true` | Master switch for threshold alerts |
|
|
79
|
+
| `alertCooldownMs` | `3600000` | Minimum ms between two alerts of the same scope |
|
|
80
|
+
| `desktopNotifications` | `false` | Browser desktop notifications while the tab is open |
|
|
81
|
+
| `refreshIntervalMs` | `5000` | Settings tab polling interval |
|
|
82
|
+
| `carbon.enabled` / `region` / `pue` / `energyKwhPerToken` | `true` / `global` / `1.58` / `0.000007` | Carbon bridge (regions: global, us, eu, china, india, uk, france, iceland) |
|
|
83
|
+
| `latency.enabled` / `windowSize` | `true` / `200` | Per-model latency percentiles and their window |
|
|
84
|
+
| `currency` | `{code: USD, rate: 1.0, decimals: 2}` | Display currency (costs are computed in USD) |
|
|
85
|
+
| `outputLanguage` | `en` | `/budget` output language: `en` / `zh` |
|
|
86
|
+
| `historyDays` | `30` | Per-day usage history kept in the panel snapshot |
|
|
87
|
+
|
|
88
|
+
## Tools & surfaces
|
|
89
|
+
|
|
90
|
+
| Surface | Kind | Notes |
|
|
91
|
+
|---|---|---|
|
|
92
|
+
| `/budget` | Command | Per-scope overview (usage, ratio, carbon, blocked state) |
|
|
93
|
+
| `/budget models` | Command | Per-model breakdown with latency percentiles |
|
|
94
|
+
| `/budget unblock <scope>` | Command | Lift a blocked scope (`session` / `daily` / `monthly`) |
|
|
95
|
+
| Settings → Plugins → Budget | Settings tab | Usage bars, model breakdown, alerts, cap editors, unblock buttons |
|
|
96
|
+
| `budget/status`, `budget/setSettings`, `budget/unblock` | Typert Remote | The client channel (the tab consumes these) |
|
|
97
|
+
|
|
98
|
+
## Permissions & data
|
|
99
|
+
|
|
100
|
+
- **Permissions**: `network:outbound` (the optional alert webhook only), `session:append` (audit events), `native-code:none`.
|
|
101
|
+
- **Data**: everything displayed comes from the session event stream; the only host-side network call is the configured webhook, whose URL is validated at load and credential-stripped before any log. No prompts or payloads ever leave the host.
|
|
102
|
+
- **Session log**: `budget/alert` and `budget/block` are log-only audit events carrying scope names and USD amounts (microtask-deferred past the session-append reentrancy guard).
|
|
103
|
+
|
|
104
|
+
## Security boundaries
|
|
105
|
+
|
|
106
|
+
- **No fabrication**: a budget block yields a corrective error finish on the `llm/stream` waterfall — the plugin never invents model output.
|
|
107
|
+
- **No request rewriting**: loop-built requests are frozen; `degrade` therefore names the target model in the corrective message instead of swapping the request.
|
|
108
|
+
- **Fail loud**: invalid prices, URLs, ratios, regions, and bounds fail the mount.
|
|
109
|
+
- **Honest scope**: runtime edits from the panel are session-scoped; a reload restores the cordis.yml values.
|
|
110
|
+
|
|
111
|
+
## Known limitations
|
|
112
|
+
|
|
113
|
+
- Aggregation is process-local: usage resets when the harness restarts (per-day/per-month buckets rebuild from the current session log view).
|
|
114
|
+
- `block`/`degrade` rely on the `llm/stream` waterfall; harness builds without that seam cannot block requests (alerts still work).
|
|
115
|
+
- Built-in prices drift; override entries via `config.prices`.
|
|
116
|
+
|
|
117
|
+
## Development
|
|
118
|
+
|
|
119
|
+
```sh
|
|
120
|
+
pnpm install # node ^22.19 || >=24
|
|
121
|
+
pnpm run typecheck # tsc: src + tests against the local harness checkout
|
|
122
|
+
pnpm run typecheck:ci # tsc against the published 0.1.0-rc.6 types (no paths)
|
|
123
|
+
pnpm test # vitest: 45 tests
|
|
124
|
+
pnpm run build # tsc declarations + tsdown bundles (lib/)
|
|
125
|
+
pnpm run verify:self-contained # dependency specs resolve from the registry
|
|
126
|
+
pnpm run verify:artifacts # built ESM face + typert manifest + client bundle
|
|
127
|
+
pnpm pack # the published tarball
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Topics
|
|
131
|
+
|
|
132
|
+
`dsh`, `dsh-plugin`, `deepseek-harness`, `deepseek`, `cordis`, `budget`, `cost-tracking`, `carbon-footprint`, `latency-benchmark`, `token-usage`
|
|
133
|
+
|
|
134
|
+
## Contributors
|
|
135
|
+
|
|
136
|
+
- [@PerryLink](https://github.com/PerryLink) — creator and maintainer: aggregation, budget governance, carbon and latency ports, the Settings tab, and the five-language docs.
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
[Apache License 2.0](LICENSE) © 2026 dsh-budget contributors
|
package/README.pt.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# 💰 dsh-budget
|
|
4
|
+
|
|
5
|
+
**Governança de custos para o DeepSeek Harness: orçamentos, carbono e latência em um só painel.**
|
|
6
|
+
|
|
7
|
+
*Saiba quanto cada sessão custa — antes que custe a você.*
|
|
8
|
+
|
|
9
|
+
[](LICENSE)
|
|
10
|
+
[](https://github.com/topics/dsh-plugin)
|
|
11
|
+
[](#)
|
|
12
|
+
[](https://github.com/PerryLink/dsh-budget/actions)
|
|
13
|
+
[](https://github.com/PerryLink/dsh-budget/releases)
|
|
14
|
+
[](https://www.npmjs.com/package/dsh-budget)
|
|
15
|
+
[](https://www.npmjs.com/package/dsh-budget)
|
|
16
|
+
|
|
17
|
+
[English](README.md) · [简体中文](README.zh.md) · [Español](README.es.md) · [Português](README.pt.md) · [हिन्दी](README.hi.md)
|
|
18
|
+
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Compatibilidade
|
|
24
|
+
|
|
25
|
+
| Superfície | Status |
|
|
26
|
+
|---|---|
|
|
27
|
+
| Harness | DeepSeek Harness `0.1.0-rc.6` |
|
|
28
|
+
| Node | `^22.19.0 \|\| >=24.0.0` |
|
|
29
|
+
| Superfícies | Host + cliente Web (aba Budget em Settings); comando `/budget` |
|
|
30
|
+
|
|
31
|
+
## O que você ganha
|
|
32
|
+
|
|
33
|
+
O `dsh-budget` transforma o fluxo de eventos da sessão em um ciclo de governança de custos quatro em um:
|
|
34
|
+
|
|
35
|
+
- **Medição agregada** — tokens (entrada sem cache / saída / leitura de cache / escrita de cache), custo USD estimado e pegada de carbono por modelo, sessão e dia, precificados por uma tabela integrada de USD por 1M de tokens mesclada com `config.prices`.
|
|
36
|
+
- **Governança de orçamento** — tetos de sessão/diários/mensais; alerta de limiar `warnRatio` (webhook POST + indicador de notificação de desktop) e três políticas ao estourar: `alert` (apenas notificar), `block` (curto-circuitar novas requisições até o usuário liberar), `degrade` (bloqueio com orientação corretiva nomeando o modelo mais barato do seu mapa `degradation`).
|
|
37
|
+
- **Carbono e latência** — ponte token→carbono (tokens × kWh/token × PUE × intensidade da rede regional, portado do AI-Carbon-Footprint-Calculator) e percentis de latência por modelo.
|
|
38
|
+
- **Superfícies** — a aba Budget em Settings (barras de uso, detalhamento por modelo, alertas, editores de teto, botões de desbloqueio) e o comando `/budget` (`/budget`, `/budget models`, `/budget unblock <scope>`).
|
|
39
|
+
|
|
40
|
+
## Início rápido
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
# 1. instale o bundle no seu perfil
|
|
44
|
+
dsh plugin --profile web add "github:PerryLink/dsh-budget#main"
|
|
45
|
+
|
|
46
|
+
# ou pelo npm (versões publicadas)
|
|
47
|
+
dsh plugin --profile web add dsh-budget
|
|
48
|
+
|
|
49
|
+
# 2. reinicie e verifique a linha
|
|
50
|
+
dsh --profile web --dump-config | grep -A2 'id: budget'
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Então peça ao agente: `/budget` — e veja a aba de Settings se preencher.
|
|
54
|
+
|
|
55
|
+
## Instalação e desinstalação
|
|
56
|
+
|
|
57
|
+
- **Canal git** (último `main`): `dsh plugin --profile web add "github:PerryLink/dsh-budget#main"` — o script `prepare` compila apenas com dependências de produção.
|
|
58
|
+
- **Canal npm** (versões publicadas): `dsh plugin --profile web add dsh-budget`.
|
|
59
|
+
- **Canal tarball**: `pnpm pack` neste repositório e então `dsh plugin --profile web add ./dsh-budget-<version>.tgz`.
|
|
60
|
+
- **Desinstalar**: `dsh plugin --profile web remove dsh-budget`.
|
|
61
|
+
|
|
62
|
+
> Se o pnpm reportar `ERR_PNPM_IGNORED_BUILDS` para este pacote (a validação inofensiva do binário de plataforma do esbuild), adicione `allowBuilds: { esbuild: true }` ao seu `pnpm-workspace.yaml` — o CLI `dsh` imprime o trecho exato.
|
|
63
|
+
|
|
64
|
+
## Configuração
|
|
65
|
+
|
|
66
|
+
Todos os ajustes são campos `Config` do Schemastery (alteráveis pelo cordis.yml). O `cordis.patch.yml` documenta cada chave em linha.
|
|
67
|
+
|
|
68
|
+
| Chave | Padrão | Significado |
|
|
69
|
+
|---|---|---|
|
|
70
|
+
| `prices` | `{}` | Preços USD por 1M de tokens por modelo, mesclados sobre a tabela integrada |
|
|
71
|
+
| `defaultPrice` | `{input: 1.0, output: 3.0}` | Reserva para modelos ausentes de ambas as tabelas |
|
|
72
|
+
| `budgets.session` / `daily` / `monthly` | `10` / `50` / `500` | Tetos de orçamento USD por escopo; omitir para ilimitado |
|
|
73
|
+
| `warnRatio` | `0.8` | Alertar quando o uso atingir esta fração do teto (0..1) |
|
|
74
|
+
| `overLimit` | `alert` | `alert` / `block` / `degrade` após cruzar um teto |
|
|
75
|
+
| `degradation` | `{}` | Id de modelo → id de modelo mais barato do mesmo provedor |
|
|
76
|
+
| `webhookUrl` | *(nenhuma)* | URL opcional de webhook para alertas de limiar (POST JSON) |
|
|
77
|
+
| `webhookTimeoutMs` | `5000` | Timeout da requisição webhook |
|
|
78
|
+
| `alertsEnabled` | `true` | Interruptor mestre dos alertas de limiar |
|
|
79
|
+
| `alertCooldownMs` | `3600000` | Mínimo em ms entre dois alertas do mesmo escopo |
|
|
80
|
+
| `desktopNotifications` | `false` | Notificações de desktop do navegador com a aba aberta |
|
|
81
|
+
| `refreshIntervalMs` | `5000` | Intervalo de sondagem da aba |
|
|
82
|
+
| `carbon.enabled` / `region` / `pue` / `energyKwhPerToken` | `true` / `global` / `1.58` / `0.000007` | Ponte de carbono (regiões: global, us, eu, china, india, uk, france, iceland) |
|
|
83
|
+
| `latency.enabled` / `windowSize` | `true` / `200` | Percentis de latência por modelo e sua janela |
|
|
84
|
+
| `currency` | `{code: USD, rate: 1.0, decimals: 2}` | Moeda de exibição (custos calculados em USD) |
|
|
85
|
+
| `outputLanguage` | `en` | Idioma de saída do `/budget`: `en` / `zh` |
|
|
86
|
+
| `historyDays` | `30` | Dias de histórico de uso diário no snapshot |
|
|
87
|
+
|
|
88
|
+
## Ferramentas e superfícies
|
|
89
|
+
|
|
90
|
+
| Superfície | Tipo | Notas |
|
|
91
|
+
|---|---|---|
|
|
92
|
+
| `/budget` | Comando | Visão geral por escopo (uso, proporção, carbono, estado bloqueado) |
|
|
93
|
+
| `/budget models` | Comando | Detalhamento por modelo com percentis de latência |
|
|
94
|
+
| `/budget unblock <scope>` | Comando | Liberar um escopo bloqueado (`session` / `daily` / `monthly`) |
|
|
95
|
+
| Settings → Plugins → Budget | Aba de Settings | Barras de uso, detalhamento, alertas, editores de teto, desbloqueio |
|
|
96
|
+
| `budget/status`, `budget/setSettings`, `budget/unblock` | Typert Remote | Canal do cliente (consumido pela aba) |
|
|
97
|
+
|
|
98
|
+
## Permissões e dados
|
|
99
|
+
|
|
100
|
+
- **Permissões**: `network:outbound` (apenas o webhook de alerta opcional), `session:append` (eventos de auditoria), `native-code:none`.
|
|
101
|
+
- **Dados**: tudo exibido vem do fluxo de eventos da sessão; a única chamada de rede é o webhook configurado, validado ao carregar e sem credenciais nos registros. Nenhum prompt ou payload sai do host.
|
|
102
|
+
- **Registro de sessão**: `budget/alert` e `budget/block` são eventos de auditoria somente-registro com nomes de escopo e valores USD (adiados por microtarefa ante o guard de reentrância do append).
|
|
103
|
+
|
|
104
|
+
## Limites de segurança
|
|
105
|
+
|
|
106
|
+
- **Sem fabricação**: um bloqueio de orçamento produz um final de erro corretivo no waterfall `llm/stream` — o plugin nunca inventa saída de modelo.
|
|
107
|
+
- **Sem reescrita de requisições**: requisições do loop são congeladas; `degrade` nomeia o modelo alvo na mensagem corretiva em vez de substituir a requisição.
|
|
108
|
+
- **Falha ruidosa**: preços, URLs, proporções, regiões ou limites inválidos falham o mount.
|
|
109
|
+
- **Escopo honesto**: edições em tempo de execução do painel valem por sessão; uma recarga restaura os valores do cordis.yml.
|
|
110
|
+
|
|
111
|
+
## Limitações conhecidas
|
|
112
|
+
|
|
113
|
+
- A agregação é local ao processo: o uso zera ao reiniciar o harness (os buckets diários/mensais se reconstroem da visão atual do log).
|
|
114
|
+
- `block`/`degrade` dependem do waterfall `llm/stream`; builds sem esse seam não podem bloquear requisições (alertas continuam funcionando).
|
|
115
|
+
- Os preços integrados ficam defasados; sobrescreva entradas via `config.prices`.
|
|
116
|
+
|
|
117
|
+
## Desenvolvimento
|
|
118
|
+
|
|
119
|
+
```sh
|
|
120
|
+
pnpm install # node ^22.19 || >=24
|
|
121
|
+
pnpm run typecheck # tsc: src + tests contra o checkout local do harness
|
|
122
|
+
pnpm run typecheck:ci # tsc contra os tipos publicados 0.1.0-rc.6 (sem paths)
|
|
123
|
+
pnpm test # vitest: 45 testes
|
|
124
|
+
pnpm run build # declarações tsc + bundles tsdown (lib/)
|
|
125
|
+
pnpm run verify:self-contained # especificações de dependências resolvem pelo registry
|
|
126
|
+
pnpm run verify:artifacts # face ESM + manifesto typert + bundle de cliente
|
|
127
|
+
pnpm pack # o tarball publicado
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Topics
|
|
131
|
+
|
|
132
|
+
`dsh`, `dsh-plugin`, `deepseek-harness`, `deepseek`, `cordis`, `budget`, `cost-tracking`, `carbon-footprint`, `latency-benchmark`, `token-usage`
|
|
133
|
+
|
|
134
|
+
## Contributors
|
|
135
|
+
|
|
136
|
+
- [@PerryLink](https://github.com/PerryLink) — criador e mantenedor: agregação, governança de orçamento, portes de carbono e latência, a aba de Settings e a documentação em cinco idiomas.
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
[Apache License 2.0](LICENSE) © 2026 dsh-budget contributors
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# 💰 dsh-budget
|
|
4
|
+
|
|
5
|
+
**DeepSeek Harness 的成本治理:预算、碳足迹与延迟,一个面板全览。**
|
|
6
|
+
|
|
7
|
+
*让每次会话的成本在超支之前就被看清。*
|
|
8
|
+
|
|
9
|
+
[](LICENSE)
|
|
10
|
+
[](https://github.com/topics/dsh-plugin)
|
|
11
|
+
[](#)
|
|
12
|
+
[](https://github.com/PerryLink/dsh-budget/actions)
|
|
13
|
+
[](https://github.com/PerryLink/dsh-budget/releases)
|
|
14
|
+
[](https://www.npmjs.com/package/dsh-budget)
|
|
15
|
+
[](https://www.npmjs.com/package/dsh-budget)
|
|
16
|
+
|
|
17
|
+
[English](README.md) · [简体中文](README.zh.md) · [Español](README.es.md) · [Português](README.pt.md) · [हिन्दी](README.hi.md)
|
|
18
|
+
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 兼容性
|
|
24
|
+
|
|
25
|
+
| 方面 | 状态 |
|
|
26
|
+
|---|---|
|
|
27
|
+
| Harness | DeepSeek Harness `0.1.0-rc.6` |
|
|
28
|
+
| Node | `^22.19.0 \|\| >=24.0.0` |
|
|
29
|
+
| 界面 | Host + Web 客户端(设置页预算页签);`/budget` 命令 |
|
|
30
|
+
|
|
31
|
+
## 你能得到什么
|
|
32
|
+
|
|
33
|
+
`dsh-budget` 把会话事件流变成四合一成本治理闭环:
|
|
34
|
+
|
|
35
|
+
- **聚合计量** —— token(未缓存输入 / 输出 / 缓存读 / 缓存写)、估算 USD 成本与碳足迹,按模型/会话/天聚合;内置 USD/百万 token 价目表与 `config.prices` 合并定价。
|
|
36
|
+
- **预算治理** —— 会话/日/月三档封顶;warnRatio 阈值告警(webhook POST + 桌面通知开关)与三种超限策略:`alert`(仅告警)、`block`(在用户解除前短路新模型请求)、`degrade`(阻断并给出指向 `degradation` 映射中更便宜模型的修正提示)。
|
|
37
|
+
- **碳足迹与延迟** —— token→碳桥接(tokens × kWh/token × PUE × 区域电网强度,移植自 AI-Carbon-Footprint-Calculator)与按模型延迟百分位。
|
|
38
|
+
- **界面** —— 设置页预算页签(用量条、模型明细、告警、上限编辑、解除阻断按钮)与 `/budget` 命令(`/budget`、`/budget models`、`/budget unblock <scope>`)。
|
|
39
|
+
|
|
40
|
+
## 快速开始
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
# 1. 把 bundle 装进你的 profile
|
|
44
|
+
dsh plugin --profile web add "github:PerryLink/dsh-budget#main"
|
|
45
|
+
|
|
46
|
+
# 或从 npm 安装(正式发布版)
|
|
47
|
+
dsh plugin --profile web add dsh-budget
|
|
48
|
+
|
|
49
|
+
# 2. 重启并核实行
|
|
50
|
+
dsh --profile web --dump-config | grep -A2 'id: budget'
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
然后在会话里输入 `/budget`,并在设置页查看预算页签。
|
|
54
|
+
|
|
55
|
+
## 安装与卸载
|
|
56
|
+
|
|
57
|
+
- **git 通道**(最新 `main`):`dsh plugin --profile web add "github:PerryLink/dsh-budget#main"` —— `prepare` 脚本仅用生产依赖构建。
|
|
58
|
+
- **npm 通道**(正式发布版):`dsh plugin --profile web add dsh-budget`。
|
|
59
|
+
- **tarball 通道**:在本仓库执行 `pnpm pack`,然后 `dsh plugin --profile web add ./dsh-budget-<version>.tgz`。
|
|
60
|
+
- **卸载**:`dsh plugin --profile web remove dsh-budget`。
|
|
61
|
+
|
|
62
|
+
> 如果 pnpm 对本包报 `ERR_PNPM_IGNORED_BUILDS`(esbuild 的平台二进制无害校验),在你的 `pnpm-workspace.yaml` 中加入 `allowBuilds: { esbuild: true }` —— `dsh` CLI 会打印确切片段。
|
|
63
|
+
|
|
64
|
+
## 配置
|
|
65
|
+
|
|
66
|
+
所有可调项都是 Schemastery `Config` 字段(可在 cordis.yml 中修改)。`cordis.patch.yml` 内联说明每个键。
|
|
67
|
+
|
|
68
|
+
| 键 | 默认值 | 含义 |
|
|
69
|
+
|---|---|---|
|
|
70
|
+
| `prices` | `{}` | 每模型 USD/百万 token 价格,合并覆盖内置价目表 |
|
|
71
|
+
| `defaultPrice` | `{input: 1.0, output: 3.0}` | 两表均无该模型时的回退价格 |
|
|
72
|
+
| `budgets.session` / `daily` / `monthly` | `10` / `50` / `500` | 各作用域 USD 预算上限;缺省表示不限 |
|
|
73
|
+
| `warnRatio` | `0.8` | 用量达到上限该比例时告警(0..1) |
|
|
74
|
+
| `overLimit` | `alert` | 超限后策略:`alert` / `block` / `degrade` |
|
|
75
|
+
| `degradation` | `{}` | 模型 id → 同厂商更便宜模型 id 的映射 |
|
|
76
|
+
| `webhookUrl` | *(无)* | 可选阈值告警 webhook URL(POST JSON) |
|
|
77
|
+
| `webhookTimeoutMs` | `5000` | webhook 请求超时 |
|
|
78
|
+
| `alertsEnabled` | `true` | 阈值告警总开关 |
|
|
79
|
+
| `alertCooldownMs` | `3600000` | 同一作用域两次告警的最小间隔(ms) |
|
|
80
|
+
| `desktopNotifications` | `false` | 页签打开时的浏览器桌面通知 |
|
|
81
|
+
| `refreshIntervalMs` | `5000` | 设置页签轮询间隔 |
|
|
82
|
+
| `carbon.enabled` / `region` / `pue` / `energyKwhPerToken` | `true` / `global` / `1.58` / `0.000007` | 碳桥接(区域:global, us, eu, china, india, uk, france, iceland) |
|
|
83
|
+
| `latency.enabled` / `windowSize` | `true` / `200` | 按模型延迟百分位与其窗口 |
|
|
84
|
+
| `currency` | `{code: USD, rate: 1.0, decimals: 2}` | 展示货币(成本以 USD 计算,仅展示换算) |
|
|
85
|
+
| `outputLanguage` | `en` | `/budget` 输出语言:`en` / `zh` |
|
|
86
|
+
| `historyDays` | `30` | 面板快照保留的按天用量历史天数 |
|
|
87
|
+
|
|
88
|
+
## 工具与界面
|
|
89
|
+
|
|
90
|
+
| 界面 | 类型 | 说明 |
|
|
91
|
+
|---|---|---|
|
|
92
|
+
| `/budget` | 命令 | 各作用域概览(用量、比例、碳足迹、阻断状态) |
|
|
93
|
+
| `/budget models` | 命令 | 按模型明细 + 延迟百分位 |
|
|
94
|
+
| `/budget unblock <scope>` | 命令 | 解除某作用域阻断(`session` / `daily` / `monthly`) |
|
|
95
|
+
| 设置 → 插件 → 预算 | 设置页签 | 用量条、模型明细、告警、上限编辑、解除阻断按钮 |
|
|
96
|
+
| `budget/status`、`budget/setSettings`、`budget/unblock` | Typert Remote | 客户端通道(页签消费这些方法) |
|
|
97
|
+
|
|
98
|
+
## 权限与数据
|
|
99
|
+
|
|
100
|
+
- **权限**:`network:outbound`(仅可选告警 webhook)、`session:append`(审计事件)、`native-code:none`。
|
|
101
|
+
- **数据**:展示内容全部来自会话事件流;主机侧唯一网络调用是配置的 webhook,URL 在加载时校验、入日志前剥离凭据。任何 prompt/载荷都不会离开主机。
|
|
102
|
+
- **会话日志**:`budget/alert` 与 `budget/block` 是仅日志审计事件,只携带作用域名与 USD 金额(微任务延后以绕过会话 append 重入保护)。
|
|
103
|
+
|
|
104
|
+
## 安全边界
|
|
105
|
+
|
|
106
|
+
- **不伪造数据**:预算阻断在 `llm/stream` 瀑布上产出修正性错误 finish —— 插件绝不编造模型输出。
|
|
107
|
+
- **不改写请求**:loop 构建的请求被冻结;`degrade` 因此在修正消息中点名目标模型,而非替换请求。
|
|
108
|
+
- **失败大声**:非法价格、URL、比例、区域与边界在挂载时即失败。
|
|
109
|
+
- **如实作用域**:面板的运行时编辑仅会话级生效;重载后恢复 cordis.yml 配置。
|
|
110
|
+
|
|
111
|
+
## 已知限制
|
|
112
|
+
|
|
113
|
+
- 聚合为进程本地:harness 重启后用量清零(日/月桶从当前会话日志视图重建)。
|
|
114
|
+
- `block`/`degrade` 依赖 `llm/stream` 瀑布;无此 seam 的构建无法阻断请求(告警仍有效)。
|
|
115
|
+
- 内置价目会漂移;用 `config.prices` 覆盖条目。
|
|
116
|
+
|
|
117
|
+
## 开发
|
|
118
|
+
|
|
119
|
+
```sh
|
|
120
|
+
pnpm install # node ^22.19 || >=24
|
|
121
|
+
pnpm run typecheck # tsc:src + tests,对照本地 harness checkout
|
|
122
|
+
pnpm run typecheck:ci # tsc:对照已发布的 0.1.0-rc.6 类型(无 paths)
|
|
123
|
+
pnpm test # vitest:45 个测试
|
|
124
|
+
pnpm run build # tsc 声明 + tsdown bundles(lib/)
|
|
125
|
+
pnpm run verify:self-contained # 依赖声明全部来自 registry
|
|
126
|
+
pnpm run verify:artifacts # 构建产物 ESM 面 + typert manifest + 客户端 bundle
|
|
127
|
+
pnpm pack # 发布用 tarball
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Topics
|
|
131
|
+
|
|
132
|
+
`dsh`, `dsh-plugin`, `deepseek-harness`, `deepseek`, `cordis`, `budget`, `cost-tracking`, `carbon-footprint`, `latency-benchmark`, `token-usage`
|
|
133
|
+
|
|
134
|
+
## Contributors
|
|
135
|
+
|
|
136
|
+
- [@PerryLink](https://github.com/PerryLink) —— 创建者与维护者:聚合、预算治理、碳足迹与延迟移植、设置页签与五语文档。
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
[Apache License 2.0](LICENSE) © 2026 dsh-budget contributors
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Security policy
|
|
2
|
+
|
|
3
|
+
## Reporting a vulnerability
|
|
4
|
+
|
|
5
|
+
Please **do not** open a public issue for security vulnerabilities.
|
|
6
|
+
|
|
7
|
+
Report privately through GitHub's private vulnerability reporting:
|
|
8
|
+
|
|
9
|
+
**https://github.com/PerryLink/dsh-budget/security/advisories/new**
|
|
10
|
+
|
|
11
|
+
That flow keeps the report confidential while we triage, and it is the channel we watch first.
|
|
12
|
+
|
|
13
|
+
## Before you report
|
|
14
|
+
|
|
15
|
+
- **Redact sensitive data** from any logs, session excerpts, or config files you attach: tokens, API keys, secrets, webhook URLs with credentials, Authorization headers, personal paths, and account identifiers.
|
|
16
|
+
- Include, when possible: the plugin version, the harness (`dsh`) version, Node and OS versions, and the minimal steps to reproduce.
|
|
17
|
+
|
|
18
|
+
## What to expect
|
|
19
|
+
|
|
20
|
+
- **Acknowledgment**: within 5 business days.
|
|
21
|
+
- **Triage**: within 10 business days we confirm the issue and assess severity, or ask for more details.
|
|
22
|
+
- **Fix**: security fixes are prepared in a private fork, released as a patch version, and announced in the release notes.
|
|
23
|
+
|
|
24
|
+
## Disclosure and credit
|
|
25
|
+
|
|
26
|
+
- We follow coordinated disclosure: a public advisory (and CVE request where appropriate) is published once a fix ships.
|
|
27
|
+
- Reporters are credited in the advisory unless they ask to remain anonymous. There is no bug bounty program at this time.
|
|
28
|
+
|
|
29
|
+
## Scope
|
|
30
|
+
|
|
31
|
+
This plugin meters and budgets the harness's model usage. Its own guarantees:
|
|
32
|
+
|
|
33
|
+
- The only network call the plugin can make is the configured threshold-alert webhook; the URL is validated at load, sanitized (credentials dropped) before any log line, and requests are timeout-bounded and fire-and-forget.
|
|
34
|
+
- Everything shown to the model or written to the session log is sanitized; the audit events carry amounts and scope names only — never prompts, payloads, or credentials.
|
|
35
|
+
- Budget blocks manifest as a corrective error finish on the `llm/stream` waterfall; the plugin never fabricates model output and never rewrites loop-built requests.
|
|
36
|
+
|
|
37
|
+
Vulnerabilities in the harness itself should be reported to the official harness maintainers instead.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
The following upstream projects (all by the plugin author, all Apache-2.0) were
|
|
4
|
+
ported into `src/estimate/` for this plugin. No upstream source files are
|
|
5
|
+
bundled verbatim; the ports keep the upstream data and formulas and are
|
|
6
|
+
annotated per module with the source file and commit:
|
|
7
|
+
|
|
8
|
+
| Upstream project | License | Ported into |
|
|
9
|
+
|---|---|---|
|
|
10
|
+
| [LLM-Cost-Estimator-CN](https://github.com/PerryLink/LLM-Cost-Estimator-CN) (commit `aa6cc2f`) | Apache-2.0 | `src/estimate/models.ts` (CNY price table, verbatim), `src/estimate/cost.ts` (cost formulas) |
|
|
11
|
+
| [Mode-Latency-Benchmark](https://github.com/PerryLink/Mode-Latency-Benchmark) (commit `8123838`) | Apache-2.0 | `src/estimate/latency-stats.ts` (benchmark vocabulary + percentile statistics) |
|
|
12
|
+
| [AI-Carbon-Footprint-Calculator](https://github.com/PerryLink/AI-Carbon-Footprint-Calculator) (commit `d8d52b5`) | Apache-2.0 | `src/estimate/carbon.ts` (GPU/region/PUE data, formulas, equivalence comparisons) |
|
|
13
|
+
|
|
14
|
+
The read-only reference checkouts live under `upstream/` (gitignored, never
|
|
15
|
+
shipped). The operational USD price table in `src/estimate/prices.ts` is
|
|
16
|
+
maintained separately; entries converted from the upstream CNY table carry
|
|
17
|
+
`source: 'upstream-cny'` with the fixed conversion rate captured at porting
|
|
18
|
+
time.
|
|
19
|
+
|
|
20
|
+
At runtime the plugin depends only on the official `@deepseek-ai/*` packages
|
|
21
|
+
listed as peerDependencies, plus the build-time tools (`typescript`,
|
|
22
|
+
`tsdown`) and `zod` declared as regular dependencies for the git-channel
|
|
23
|
+
`prepare` build.
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# dsh-budget: cost governance for DeepSeek Harness.
|
|
2
|
+
#
|
|
3
|
+
# Aggregated token/cost metering (per model, session, day), session/daily/monthly
|
|
4
|
+
# budget caps with threshold alerts (webhook + desktop notification) and
|
|
5
|
+
# alert / block / degrade over-limit policies, carbon footprint estimation,
|
|
6
|
+
# per-model latency statistics, a Settings budget tab, and the /budget command.
|
|
7
|
+
#
|
|
8
|
+
# Every key below is a Schemastery-validated config field; an invalid value
|
|
9
|
+
# fails loudly at load time. Empty caps mean "unlimited" for that scope.
|
|
10
|
+
- insert:
|
|
11
|
+
- id: budget
|
|
12
|
+
name: dsh-budget
|
|
13
|
+
inject: [sessions]
|
|
14
|
+
config:
|
|
15
|
+
# Per-model USD prices per 1M tokens, merged OVER the built-in table.
|
|
16
|
+
# Keys are model ids ("deepseek-chat", "gpt-4o", ...); each entry
|
|
17
|
+
# supports input/output and optional cacheRead/cacheWrite prices.
|
|
18
|
+
prices: {}
|
|
19
|
+
# Fallback price for models absent from both tables.
|
|
20
|
+
defaultPrice: { input: 1.0, output: 3.0 }
|
|
21
|
+
# Budget caps in USD per scope; omit a scope for unlimited.
|
|
22
|
+
budgets:
|
|
23
|
+
session: 10
|
|
24
|
+
daily: 50
|
|
25
|
+
monthly: 500
|
|
26
|
+
# Alert once usage reaches this fraction of a cap (0..1).
|
|
27
|
+
warnRatio: 0.8
|
|
28
|
+
# Behavior after a cap is crossed:
|
|
29
|
+
# alert - notify only (webhook/notification/session event)
|
|
30
|
+
# block - fail new model requests until unblocked by the user
|
|
31
|
+
# degrade - rewrite the model to the configured cheaper tier
|
|
32
|
+
overLimit: alert
|
|
33
|
+
# Degradation map: model id -> cheaper model id of the SAME provider.
|
|
34
|
+
# Example: { "gpt-4o": "gpt-4o-mini" }
|
|
35
|
+
degradation: {}
|
|
36
|
+
# Optional webhook URL for threshold alerts (POST JSON). Credentials in
|
|
37
|
+
# the URL are never logged; use an https endpoint you control.
|
|
38
|
+
webhookUrl: ''
|
|
39
|
+
# Webhook request timeout in milliseconds.
|
|
40
|
+
webhookTimeoutMs: 5000
|
|
41
|
+
# Master switch for threshold alerts; the Settings tab can override
|
|
42
|
+
# this at runtime until the plugin reloads.
|
|
43
|
+
alertsEnabled: true
|
|
44
|
+
# Minimum milliseconds between two alerts of the same scope.
|
|
45
|
+
alertCooldownMs: 3600000
|
|
46
|
+
# Browser desktop notifications for new alerts while the Settings
|
|
47
|
+
# budget tab is open (requires browser permission).
|
|
48
|
+
desktopNotifications: false
|
|
49
|
+
# Settings budget tab polling interval in milliseconds.
|
|
50
|
+
refreshIntervalMs: 5000
|
|
51
|
+
# Carbon footprint estimation (token-based bridge over the upstream
|
|
52
|
+
# GPU-hours model).
|
|
53
|
+
carbon:
|
|
54
|
+
enabled: true
|
|
55
|
+
# Electricity region key: global us eu china india uk france iceland.
|
|
56
|
+
region: global
|
|
57
|
+
# Power usage effectiveness (datacenter overhead multiplier).
|
|
58
|
+
pue: 1.58
|
|
59
|
+
# IT energy per token in kWh; default derives from an A100 (400 W TDP)
|
|
60
|
+
# serving ~25 tokens/s: 400 W / 3600 s / 25 tok/s = 4.4e-6 kWh, rounded.
|
|
61
|
+
energyKwhPerToken: 0.000007
|
|
62
|
+
# Per-model latency statistics over the llm/stream wrapper.
|
|
63
|
+
latency:
|
|
64
|
+
enabled: true
|
|
65
|
+
# Samples kept per model for percentile computation.
|
|
66
|
+
windowSize: 200
|
|
67
|
+
# Display currency (code, units per USD, decimals). Costs are computed
|
|
68
|
+
# in USD; this only converts for display.
|
|
69
|
+
currency: { code: USD, rate: 1.0, decimals: 2 }
|
|
70
|
+
# /budget command output language: en | zh.
|
|
71
|
+
outputLanguage: en
|
|
72
|
+
# Days of per-day usage history kept in the panel snapshot.
|
|
73
|
+
historyDays: 30
|