dsh-unitverse 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.en.md +29 -0
- package/CHANGELOG.md +29 -0
- package/LICENSE +21 -0
- package/README.en.md +217 -0
- package/README.md +217 -0
- package/cordis.patch.yml +5 -0
- package/lib/chunk-KLTLDDLU.js +300 -0
- package/lib/client.d.ts +10 -0
- package/lib/client.js +896 -0
- package/lib/convert-D6txqQbW.d.cts +186 -0
- package/lib/convert-D6txqQbW.d.ts +186 -0
- package/lib/convert.cjs +307 -0
- package/lib/convert.d.cts +1 -0
- package/lib/convert.d.ts +1 -0
- package/lib/convert.js +18 -0
- package/lib/index.cjs +408 -0
- package/lib/index.d.cts +22 -0
- package/lib/index.d.ts +22 -0
- package/lib/index.js +101 -0
- package/package.json +121 -0
package/CHANGELOG.en.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
This project follows [Semantic Versioning](https://semver.org/). Chinese version: [CHANGELOG.md](CHANGELOG.md).
|
|
4
|
+
|
|
5
|
+
## [0.1.0] - 2026-09-10
|
|
6
|
+
|
|
7
|
+
First release.
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- **`convert` tool**: converts across ten categories — length, area, volume, time, angle, speed, temperature, pressure, energy/heat and power — with 80+ common units (metric, imperial/US customary, common Chinese units).
|
|
12
|
+
- **Lenient unit spelling**: `km` / `KM` / `kilometer` / `千米` / `公里` all resolve; matching is case-insensitive and accepts symbols, English full names and Chinese names.
|
|
13
|
+
- **Two temperature modes**: absolute scales (°C / °F / K / °R) and temperature differences (`Δ°C` ↔ `Δ°F`); mixing the two is rejected with a clear error.
|
|
14
|
+
- **Web converter view** "单位换算 / Unit Converter": renders next to Conversation / Trajectory in the session view tab bar and runs purely in the browser (the conversion core is bundled into `lib/client.js`, so no model or server round-trip is involved).
|
|
15
|
+
- One module per category: ten category tabs, and each module **only lists its own category's units**, so units are never mixed.
|
|
16
|
+
- Units are picked from dropdowns (`symbol · name`) — nothing has to be typed; one-click swap and one-click copy of the result.
|
|
17
|
+
- The temperature module adds a **difference Δ switch**; recent conversions are stored per category in browser localStorage.
|
|
18
|
+
- All copy, **unit names included**, follows the DSH zh/en UI language and refreshes the moment the language changes.
|
|
19
|
+
- Results are rounded to ~10 significant digits by default; unknown units and cross-category requests return structured errors (`unknown-unit` / `category-mismatch` / `bad-value` / `mixed-delta`).
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
- Renamed the plugin to **`dsh-unitverse`** (formerly `dsh-unit-conversion`; unit + universe). The tool is still `convert` and the view tab is still "单位换算 / Unit Converter".
|
|
24
|
+
|
|
25
|
+
### Release
|
|
26
|
+
|
|
27
|
+
- npm: `dsh-unitverse@0.1.0` (first publish; previously GitHub source only)
|
|
28
|
+
- GitHub: https://github.com/runcat-tommy/dsh-unitverse
|
|
29
|
+
- The browser half ships through the `dsh.client` declaration plus `exports["./client"]`; when it is not loaded, the tool keeps working unchanged.
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# 更新日志
|
|
2
|
+
|
|
3
|
+
本项目遵循[语义化版本](https://semver.org/lang/zh-CN/)。英文版见 [CHANGELOG.en.md](CHANGELOG.en.md)。
|
|
4
|
+
|
|
5
|
+
## [0.1.0] - 2026-09-10
|
|
6
|
+
|
|
7
|
+
首次发布。
|
|
8
|
+
|
|
9
|
+
### 新增
|
|
10
|
+
|
|
11
|
+
- **`convert` 工具**:在十大类单位之间换算 —— 长度、面积、体积、时间、角度、速度、温度、压力、热量/能量、功率,共 80+ 个常用单位(公制、英制/美制、常用中国市制)。
|
|
12
|
+
- **单位写法宽容**:`km` / `KM` / `kilometer` / `千米` / `公里` 均可识别,大小写不敏感,同时接受符号、英文全称与中文名称。
|
|
13
|
+
- **温度双模式**:绝对温标换算(°C / °F / K / °R)与温差换算(`Δ°C` ↔ `Δ°F`),两者不可混用并给出明确报错。
|
|
14
|
+
- **Web 换算视图**「单位换算 / Unit Converter」:与「对话」「轨迹」并列显示在会话视图标签栏中,纯前端运行(换算核心打包进 `lib/client.js`,不经过模型或服务器)。
|
|
15
|
+
- 按类别分模块:10 个类别标签,每个模块**只显示本类别的单位**,不会把不同类别的单位混在一起。
|
|
16
|
+
- 单位用下拉选择(`符号 · 单位名称`),无需手打;支持一键 ⇄ 交换、结果一键复制。
|
|
17
|
+
- 温度模块提供**温差 Δ 开关**;最近换算按类别分别保存在浏览器 localStorage。
|
|
18
|
+
- 界面文案与**单位名称**完整跟随 DSH 中/英文界面语言,切换语言即时刷新。
|
|
19
|
+
- 结果默认保留约 10 位有效数字,避免浮点噪声;非法单位与跨类换算返回结构化错误(`unknown-unit` / `category-mismatch` / `bad-value` / `mixed-delta`)。
|
|
20
|
+
|
|
21
|
+
### 变更
|
|
22
|
+
|
|
23
|
+
- 插件更名为 **`dsh-unitverse`**(原名 `dsh-unit-conversion`,unit + universe)。工具名仍为 `convert`,视图标签仍为「单位换算 / Unit Converter」。
|
|
24
|
+
|
|
25
|
+
### 发布
|
|
26
|
+
|
|
27
|
+
- npm:`dsh-unitverse@0.1.0`(首次发布,此前仅提供 GitHub 源码)
|
|
28
|
+
- GitHub:https://github.com/runcat-tommy/dsh-unitverse
|
|
29
|
+
- 浏览器端(client)部分由 `dsh.client` 声明 + `exports["./client"]` 提供,卸载/未启用时不影响工具功能。
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 runcat-tommy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.en.md
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# dsh-unitverse · Unit Converter
|
|
2
|
+
|
|
3
|
+
English | [中文](README.md) · [Changelog](CHANGELOG.en.md)
|
|
4
|
+
|
|
5
|
+
> The name reads **unit + universe**: ten categories of units in one universe.
|
|
6
|
+
> The GUI view tab is still called **单位换算 / Unit Converter**, and the
|
|
7
|
+
> model-facing tool is still `convert`.
|
|
8
|
+
|
|
9
|
+
A **DeepSeek Harness (DSH) unit conversion plugin** exposing one `convert` tool
|
|
10
|
+
across **length, area, volume, time, angle, speed, temperature, pressure,
|
|
11
|
+
energy/heat and power**, with case-insensitive English and Chinese unit names,
|
|
12
|
+
plus both absolute-temperature and temperature-difference (Δ) modes.
|
|
13
|
+
|
|
14
|
+
## Preview
|
|
15
|
+
|
|
16
|
+
English UI — one independent module per category, listing only that category's units:
|
|
17
|
+
|
|
18
|
+

|
|
19
|
+
|
|
20
|
+
Chinese UI — all copy, category names and unit names in Chinese:
|
|
21
|
+
|
|
22
|
+

|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- ✅ 10 categories, 80+ common units (metric, imperial/US customary, common Chinese units)
|
|
27
|
+
- ✅ Lenient unit spelling: `km` / `KM` / `kilometer` / `千米` / `公里` all resolve
|
|
28
|
+
- ✅ Absolute temperature (°C / °F / K / °R) and temperature difference (`Δ°C` ↔ `Δ°F`)
|
|
29
|
+
- ✅ Pure TypeScript, zero runtime dependencies, side-effect free and unit-testable
|
|
30
|
+
- ✅ Results rounded to ~10 significant digits by default
|
|
31
|
+
- ✅ Clear errors for unknown units or cross-category requests
|
|
32
|
+
- ✅ **Web UI view**: a "Unit Converter" tab next to Conversation / Trajectory
|
|
33
|
+
in the session view bar; the panel is split into ten independent category
|
|
34
|
+
modules (units are never mixed), and all copy — **unit names included** —
|
|
35
|
+
follows the DSH zh/en UI language (since v0.1.0, requires the DSH Web GUI,
|
|
36
|
+
0.1.0-rc.6+)
|
|
37
|
+
|
|
38
|
+
## Supported categories and units
|
|
39
|
+
|
|
40
|
+
| Category | Base | Units (symbols) |
|
|
41
|
+
| --- | --- | --- |
|
|
42
|
+
| length | m | nm, μm, mm, cm, m, km, in, ft, yd, mi, nmi, 里 (li), 尺 (chi) |
|
|
43
|
+
| area | m² | mm², cm², m², km², ha, 亩 (mu), in², ft², yd², acre, mi² |
|
|
44
|
+
| volume | m³ | mL, L, m³, cm³, in³, ft³, yd³, gal (US), gal (UK), qt (US), bbl |
|
|
45
|
+
| time | s | ms, s, min, h, d, wk, mo, yr |
|
|
46
|
+
| angle | rad | rad, ° (deg), grad, ′ (arcmin), ″ (arcsec), turn |
|
|
47
|
+
| speed | m/s | m/s, km/h, mph, kn (knot), ft/s |
|
|
48
|
+
| temperature | K | °C, °F, K, °R (Δ prefix available for differences) |
|
|
49
|
+
| pressure | Pa | Pa, kPa, MPa, hPa, bar, atm, psi, Torr, mmHg, inHg |
|
|
50
|
+
| energy | J | J, kJ, MJ, cal, kcal, Wh, kWh, BTU |
|
|
51
|
+
| power | W | W, kW, MW, GW, hp, PS |
|
|
52
|
+
|
|
53
|
+
Every unit also accepts its **English full name (including plurals) and its
|
|
54
|
+
Chinese name** as aliases — e.g. `ft`, `foot`, `feet` and `英尺` are the same unit.
|
|
55
|
+
|
|
56
|
+
## Installation
|
|
57
|
+
|
|
58
|
+
Install it as a DSH bundle (local checkout, tarball or GitHub all work):
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# From a local checkout
|
|
62
|
+
dsh plugin --profile <profile-name> add ./dsh-unitverse
|
|
63
|
+
|
|
64
|
+
# Or from GitHub (build artifacts are committed, so no allowBuilds needed)
|
|
65
|
+
dsh plugin --profile <profile-name> add github:runcat-tommy/dsh-unitverse
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`package.json` declares `dsh.bundle`, so `dsh plugin add` registers the plugin
|
|
69
|
+
row from `cordis.patch.yml` automatically.
|
|
70
|
+
|
|
71
|
+
> The package also ships a browser half: the `dsh.client` declaration plus
|
|
72
|
+
> `lib/client.js` behind the `exports["./client"]` entry. Installed into a
|
|
73
|
+
> profile that runs the Web GUI, a "Unit Converter" tab appears in the session
|
|
74
|
+
> view bar (see **Web converter view** below). In CLI-only profiles the client
|
|
75
|
+
> part is simply never loaded and the tool keeps working.
|
|
76
|
+
|
|
77
|
+
## Web converter view (v0.1.0+)
|
|
78
|
+
|
|
79
|
+
After installing and restarting the DSH GUI process (`dsh web` etc.), open any
|
|
80
|
+
session: the view tab bar now shows **"Unit Converter"** next to Conversation /
|
|
81
|
+
Trajectory (the Chinese UI shows 单位换算):
|
|
82
|
+
|
|
83
|
+
- **One module per category**: the panel opens with ten category tabs — Length,
|
|
84
|
+
Area, Volume, Time, Angle, Speed, Temperature, Pressure, Heat / Energy and
|
|
85
|
+
Power. Switching a tab switches the module, and a module **only ever lists its
|
|
86
|
+
own units**, so units from different categories are never mixed and a
|
|
87
|
+
cross-category conversion cannot be produced. Each module starts from a common
|
|
88
|
+
unit pair (e.g. Length → km ↔ mi).
|
|
89
|
+
- **Unit dropdowns**: source and target units are picked from a list showing
|
|
90
|
+
`symbol · name` — no unit name has to be typed, so nothing can be misspelled.
|
|
91
|
+
- **Instant result**: typing a value updates the result immediately, shown as a
|
|
92
|
+
large number + unit, the full equation and a category badge, with one-click
|
|
93
|
+
**copy**.
|
|
94
|
+
- One-click **⇄ swap** of source and target.
|
|
95
|
+
- The **Temperature** module adds a **Difference Δ** switch: off converts
|
|
96
|
+
absolute scales (`°C → °F`), on converts intervals (`Δ°C → Δ°F`), with an
|
|
97
|
+
explanatory hint.
|
|
98
|
+
- **Recent conversions are kept per category** (browser localStorage); click any
|
|
99
|
+
row to restore it, or clear the current category’s rows in one click.
|
|
100
|
+
- **Fully follows the DSH UI language**: in a Chinese environment every string —
|
|
101
|
+
including **unit names** such as 千米 / 摄氏度 — is Chinese; in an English
|
|
102
|
+
environment everything is English ("kilometer", "degree Celsius"), category
|
|
103
|
+
names and tabs included. Switching the language refreshes the panel and the
|
|
104
|
+
history immediately.
|
|
105
|
+
- The view is **pure front-end**: the conversion core is bundled into
|
|
106
|
+
`lib/client.js`, so conversions run locally in the browser — no model or
|
|
107
|
+
server round-trip involved.
|
|
108
|
+
|
|
109
|
+
## Usage
|
|
110
|
+
|
|
111
|
+
Once installed, the model can call the `convert` tool:
|
|
112
|
+
|
|
113
|
+
```text
|
|
114
|
+
convert(value=100, from="km", to="mi") -> 62.13711922 mi
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Tool parameters:
|
|
118
|
+
|
|
119
|
+
| Parameter | Type | Required | Description |
|
|
120
|
+
| --- | --- | --- | --- |
|
|
121
|
+
| `value` | number | yes | The numeric amount (finite number) |
|
|
122
|
+
| `from` | string | yes | Source unit: symbol / English / Chinese, case-insensitive |
|
|
123
|
+
| `to` | string | yes | Target unit: symbol / English / Chinese, case-insensitive |
|
|
124
|
+
|
|
125
|
+
Returns a structured result: `{ value, from, to, result, category, categoryZh, summary }`.
|
|
126
|
+
|
|
127
|
+
### Examples
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
"Convert 100 km to miles"
|
|
131
|
+
→ convert(100, "km", "mi") → summary: "100 km = 62.13711922 mi (length)"
|
|
132
|
+
|
|
133
|
+
"How many cm is 5 feet?"
|
|
134
|
+
→ convert(5, "feet", "cm") → summary: "5 feet = 152.4 cm (length)"
|
|
135
|
+
|
|
136
|
+
"36 km/h to m/s" → convert(36, "km/h", "m/s") → 10
|
|
137
|
+
"1 atm to kPa" → convert(1, "atm", "kPa") → 101.325
|
|
138
|
+
"212 °F to °C" → convert(212, "°F", "°C") → 100
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Temperature differences (Δ)
|
|
142
|
+
|
|
143
|
+
Temperature converts as an **absolute scale** by default. For a temperature
|
|
144
|
+
*difference*, prefix BOTH units with `Δ` or `delta`:
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
"What is a 1 °C temperature interval in °F?"
|
|
148
|
+
→ convert(1, "Δ°C", "Δ°F") → 1.8
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Mixing an absolute and a Δ unit (e.g. `Δ°C` → `K`) is rejected to avoid
|
|
152
|
+
ambiguous "degrees Kelvin"-style semantics.
|
|
153
|
+
|
|
154
|
+
## Precision and conventions
|
|
155
|
+
|
|
156
|
+
- Results round to ~**10 significant digits** by default; the core `convert()`
|
|
157
|
+
accepts a `significantDigits` option (1–15).
|
|
158
|
+
- `cal` is the thermochemical calorie (1 cal = 4.184 J); use `kcal` / `大卡`
|
|
159
|
+
for the food "Calorie".
|
|
160
|
+
- `BTU` is the International Table BTU (1 BTU = 1055.05585262 J).
|
|
161
|
+
- `yr` (year) is the Julian year of 365.25 days; `mo` (month) = year / 12.
|
|
162
|
+
- The Chinese character 度 means degrees (angle); write 千瓦时 for kWh
|
|
163
|
+
(avoid ambiguity with 度).
|
|
164
|
+
- Chinese 分/秒 in a time context map to `min`/`s`; use `arcmin`/`arcsec`
|
|
165
|
+
(角分/角秒) for angular minutes/seconds.
|
|
166
|
+
|
|
167
|
+
## Using the core library directly
|
|
168
|
+
|
|
169
|
+
The conversion core is a zero-dependency pure module:
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
import { convert, convertDetailed } from 'dsh-unitverse'
|
|
173
|
+
|
|
174
|
+
convert(100, 'km', 'mi') // 62.13711922
|
|
175
|
+
convert(25, '°C', '°F') // 77
|
|
176
|
+
convert(1, 'Δ°C', 'Δ°F') // 1.8 (temperature difference)
|
|
177
|
+
convertDetailed(3, 'km/h', 'm/s') // { result: 0.833..., summary: '...' }
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
> `src/index.ts` is the DSH plugin entry (depends on `@deepseek-ai/cordis` and
|
|
181
|
+
> `@deepseek-ai/dsh-tools`); `src/convert.ts` + `src/units.ts` form the
|
|
182
|
+
> host-independent core library.
|
|
183
|
+
|
|
184
|
+
## Development
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
npm install
|
|
188
|
+
npm test # full vitest suite (conversions, aliases, temperature, edges,
|
|
189
|
+
# plugin registration, lib/client.js smoke tests)
|
|
190
|
+
npm run typecheck # tsc --noEmit
|
|
191
|
+
npm run build # tsup -> lib/ (ESM + CJS + d.ts), then scripts/build-client.mjs
|
|
192
|
+
# emits lib/client.js (the ModuleLoader lazy-CJS bundle)
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Repository layout
|
|
196
|
+
|
|
197
|
+
```
|
|
198
|
+
src/units.ts unit tables and alias index (single source of truth)
|
|
199
|
+
src/convert.ts conversion engine: parsing, converting, temperature/Δ, precision, errors
|
|
200
|
+
src/index.ts DSH plugin entry (server/CLI side): registers the convert tool
|
|
201
|
+
src/client/ Web client plugin (browser side):
|
|
202
|
+
index.tsx registers the conversation.view entry
|
|
203
|
+
UnitConvertView.tsx converter panel (pure front-end core)
|
|
204
|
+
locales.ts zh/en UI copy
|
|
205
|
+
scripts/build-client.mjs esbuild wrapper that emits lib/client.js (ModuleLoader lazy-CJS format)
|
|
206
|
+
test/ Vitest tests (incl. lib/client.js smoke tests)
|
|
207
|
+
cordis.patch.yml DSH bundle patch layer
|
|
208
|
+
lib/ build output (committed so GitHub installs need no build)
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
`src/convert.ts` + `src/units.ts` form the host-independent core library: the
|
|
212
|
+
server tool imports it, and the same code is bundled into the browser-side
|
|
213
|
+
`lib/client.js`, so conversions in the Web view happen entirely locally.
|
|
214
|
+
|
|
215
|
+
## License
|
|
216
|
+
|
|
217
|
+
[MIT](LICENSE)
|
package/README.md
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# dsh-unitverse · Unit Converter
|
|
2
|
+
|
|
3
|
+
English | [中文](https://github.com/runcat-tommy/dsh-unitverse/blob/main/README.md) · [Changelog](https://github.com/runcat-tommy/dsh-unitverse/blob/main/CHANGELOG.en.md)
|
|
4
|
+
|
|
5
|
+
> The name reads **unit + universe**: ten categories of units in one universe.
|
|
6
|
+
> The GUI view tab is still called **单位换算 / Unit Converter**, and the
|
|
7
|
+
> model-facing tool is still `convert`.
|
|
8
|
+
|
|
9
|
+
A **DeepSeek Harness (DSH) unit conversion plugin** exposing one `convert` tool
|
|
10
|
+
across **length, area, volume, time, angle, speed, temperature, pressure,
|
|
11
|
+
energy/heat and power**, with case-insensitive English and Chinese unit names,
|
|
12
|
+
plus both absolute-temperature and temperature-difference (Δ) modes.
|
|
13
|
+
|
|
14
|
+
## Preview
|
|
15
|
+
|
|
16
|
+
English UI — one independent module per category, listing only that category's units:
|
|
17
|
+
|
|
18
|
+

|
|
19
|
+
|
|
20
|
+
Chinese UI — all copy, category names and unit names in Chinese:
|
|
21
|
+
|
|
22
|
+

|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- ✅ 10 categories, 80+ common units (metric, imperial/US customary, common Chinese units)
|
|
27
|
+
- ✅ Lenient unit spelling: `km` / `KM` / `kilometer` / `千米` / `公里` all resolve
|
|
28
|
+
- ✅ Absolute temperature (°C / °F / K / °R) and temperature difference (`Δ°C` ↔ `Δ°F`)
|
|
29
|
+
- ✅ Pure TypeScript, zero runtime dependencies, side-effect free and unit-testable
|
|
30
|
+
- ✅ Results rounded to ~10 significant digits by default
|
|
31
|
+
- ✅ Clear errors for unknown units or cross-category requests
|
|
32
|
+
- ✅ **Web UI view**: a "Unit Converter" tab next to Conversation / Trajectory
|
|
33
|
+
in the session view bar; the panel is split into ten independent category
|
|
34
|
+
modules (units are never mixed), and all copy — **unit names included** —
|
|
35
|
+
follows the DSH zh/en UI language (since v0.1.0, requires the DSH Web GUI,
|
|
36
|
+
0.1.0-rc.6+)
|
|
37
|
+
|
|
38
|
+
## Supported categories and units
|
|
39
|
+
|
|
40
|
+
| Category | Base | Units (symbols) |
|
|
41
|
+
| --- | --- | --- |
|
|
42
|
+
| length | m | nm, μm, mm, cm, m, km, in, ft, yd, mi, nmi, 里 (li), 尺 (chi) |
|
|
43
|
+
| area | m² | mm², cm², m², km², ha, 亩 (mu), in², ft², yd², acre, mi² |
|
|
44
|
+
| volume | m³ | mL, L, m³, cm³, in³, ft³, yd³, gal (US), gal (UK), qt (US), bbl |
|
|
45
|
+
| time | s | ms, s, min, h, d, wk, mo, yr |
|
|
46
|
+
| angle | rad | rad, ° (deg), grad, ′ (arcmin), ″ (arcsec), turn |
|
|
47
|
+
| speed | m/s | m/s, km/h, mph, kn (knot), ft/s |
|
|
48
|
+
| temperature | K | °C, °F, K, °R (Δ prefix available for differences) |
|
|
49
|
+
| pressure | Pa | Pa, kPa, MPa, hPa, bar, atm, psi, Torr, mmHg, inHg |
|
|
50
|
+
| energy | J | J, kJ, MJ, cal, kcal, Wh, kWh, BTU |
|
|
51
|
+
| power | W | W, kW, MW, GW, hp, PS |
|
|
52
|
+
|
|
53
|
+
Every unit also accepts its **English full name (including plurals) and its
|
|
54
|
+
Chinese name** as aliases — e.g. `ft`, `foot`, `feet` and `英尺` are the same unit.
|
|
55
|
+
|
|
56
|
+
## Installation
|
|
57
|
+
|
|
58
|
+
Install it as a DSH bundle (local checkout, tarball or GitHub all work):
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# From a local checkout
|
|
62
|
+
dsh plugin --profile <profile-name> add ./dsh-unitverse
|
|
63
|
+
|
|
64
|
+
# Or from GitHub (build artifacts are committed, so no allowBuilds needed)
|
|
65
|
+
dsh plugin --profile <profile-name> add github:runcat-tommy/dsh-unitverse
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`package.json` declares `dsh.bundle`, so `dsh plugin add` registers the plugin
|
|
69
|
+
row from `cordis.patch.yml` automatically.
|
|
70
|
+
|
|
71
|
+
> The package also ships a browser half: the `dsh.client` declaration plus
|
|
72
|
+
> `lib/client.js` behind the `exports["./client"]` entry. Installed into a
|
|
73
|
+
> profile that runs the Web GUI, a "Unit Converter" tab appears in the session
|
|
74
|
+
> view bar (see **Web converter view** below). In CLI-only profiles the client
|
|
75
|
+
> part is simply never loaded and the tool keeps working.
|
|
76
|
+
|
|
77
|
+
## Web converter view (v0.1.0+)
|
|
78
|
+
|
|
79
|
+
After installing and restarting the DSH GUI process (`dsh web` etc.), open any
|
|
80
|
+
session: the view tab bar now shows **"Unit Converter"** next to Conversation /
|
|
81
|
+
Trajectory (the Chinese UI shows 单位换算):
|
|
82
|
+
|
|
83
|
+
- **One module per category**: the panel opens with ten category tabs — Length,
|
|
84
|
+
Area, Volume, Time, Angle, Speed, Temperature, Pressure, Heat / Energy and
|
|
85
|
+
Power. Switching a tab switches the module, and a module **only ever lists its
|
|
86
|
+
own units**, so units from different categories are never mixed and a
|
|
87
|
+
cross-category conversion cannot be produced. Each module starts from a common
|
|
88
|
+
unit pair (e.g. Length → km ↔ mi).
|
|
89
|
+
- **Unit dropdowns**: source and target units are picked from a list showing
|
|
90
|
+
`symbol · name` — no unit name has to be typed, so nothing can be misspelled.
|
|
91
|
+
- **Instant result**: typing a value updates the result immediately, shown as a
|
|
92
|
+
large number + unit, the full equation and a category badge, with one-click
|
|
93
|
+
**copy**.
|
|
94
|
+
- One-click **⇄ swap** of source and target.
|
|
95
|
+
- The **Temperature** module adds a **Difference Δ** switch: off converts
|
|
96
|
+
absolute scales (`°C → °F`), on converts intervals (`Δ°C → Δ°F`), with an
|
|
97
|
+
explanatory hint.
|
|
98
|
+
- **Recent conversions are kept per category** (browser localStorage); click any
|
|
99
|
+
row to restore it, or clear the current category’s rows in one click.
|
|
100
|
+
- **Fully follows the DSH UI language**: in a Chinese environment every string —
|
|
101
|
+
including **unit names** such as 千米 / 摄氏度 — is Chinese; in an English
|
|
102
|
+
environment everything is English ("kilometer", "degree Celsius"), category
|
|
103
|
+
names and tabs included. Switching the language refreshes the panel and the
|
|
104
|
+
history immediately.
|
|
105
|
+
- The view is **pure front-end**: the conversion core is bundled into
|
|
106
|
+
`lib/client.js`, so conversions run locally in the browser — no model or
|
|
107
|
+
server round-trip involved.
|
|
108
|
+
|
|
109
|
+
## Usage
|
|
110
|
+
|
|
111
|
+
Once installed, the model can call the `convert` tool:
|
|
112
|
+
|
|
113
|
+
```text
|
|
114
|
+
convert(value=100, from="km", to="mi") -> 62.13711922 mi
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Tool parameters:
|
|
118
|
+
|
|
119
|
+
| Parameter | Type | Required | Description |
|
|
120
|
+
| --- | --- | --- | --- |
|
|
121
|
+
| `value` | number | yes | The numeric amount (finite number) |
|
|
122
|
+
| `from` | string | yes | Source unit: symbol / English / Chinese, case-insensitive |
|
|
123
|
+
| `to` | string | yes | Target unit: symbol / English / Chinese, case-insensitive |
|
|
124
|
+
|
|
125
|
+
Returns a structured result: `{ value, from, to, result, category, categoryZh, summary }`.
|
|
126
|
+
|
|
127
|
+
### Examples
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
"Convert 100 km to miles"
|
|
131
|
+
→ convert(100, "km", "mi") → summary: "100 km = 62.13711922 mi (length)"
|
|
132
|
+
|
|
133
|
+
"How many cm is 5 feet?"
|
|
134
|
+
→ convert(5, "feet", "cm") → summary: "5 feet = 152.4 cm (length)"
|
|
135
|
+
|
|
136
|
+
"36 km/h to m/s" → convert(36, "km/h", "m/s") → 10
|
|
137
|
+
"1 atm to kPa" → convert(1, "atm", "kPa") → 101.325
|
|
138
|
+
"212 °F to °C" → convert(212, "°F", "°C") → 100
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Temperature differences (Δ)
|
|
142
|
+
|
|
143
|
+
Temperature converts as an **absolute scale** by default. For a temperature
|
|
144
|
+
*difference*, prefix BOTH units with `Δ` or `delta`:
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
"What is a 1 °C temperature interval in °F?"
|
|
148
|
+
→ convert(1, "Δ°C", "Δ°F") → 1.8
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Mixing an absolute and a Δ unit (e.g. `Δ°C` → `K`) is rejected to avoid
|
|
152
|
+
ambiguous "degrees Kelvin"-style semantics.
|
|
153
|
+
|
|
154
|
+
## Precision and conventions
|
|
155
|
+
|
|
156
|
+
- Results round to ~**10 significant digits** by default; the core `convert()`
|
|
157
|
+
accepts a `significantDigits` option (1–15).
|
|
158
|
+
- `cal` is the thermochemical calorie (1 cal = 4.184 J); use `kcal` / `大卡`
|
|
159
|
+
for the food "Calorie".
|
|
160
|
+
- `BTU` is the International Table BTU (1 BTU = 1055.05585262 J).
|
|
161
|
+
- `yr` (year) is the Julian year of 365.25 days; `mo` (month) = year / 12.
|
|
162
|
+
- The Chinese character 度 means degrees (angle); write 千瓦时 for kWh
|
|
163
|
+
(avoid ambiguity with 度).
|
|
164
|
+
- Chinese 分/秒 in a time context map to `min`/`s`; use `arcmin`/`arcsec`
|
|
165
|
+
(角分/角秒) for angular minutes/seconds.
|
|
166
|
+
|
|
167
|
+
## Using the core library directly
|
|
168
|
+
|
|
169
|
+
The conversion core is a zero-dependency pure module:
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
import { convert, convertDetailed } from 'dsh-unitverse'
|
|
173
|
+
|
|
174
|
+
convert(100, 'km', 'mi') // 62.13711922
|
|
175
|
+
convert(25, '°C', '°F') // 77
|
|
176
|
+
convert(1, 'Δ°C', 'Δ°F') // 1.8 (temperature difference)
|
|
177
|
+
convertDetailed(3, 'km/h', 'm/s') // { result: 0.833..., summary: '...' }
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
> `src/index.ts` is the DSH plugin entry (depends on `@deepseek-ai/cordis` and
|
|
181
|
+
> `@deepseek-ai/dsh-tools`); `src/convert.ts` + `src/units.ts` form the
|
|
182
|
+
> host-independent core library.
|
|
183
|
+
|
|
184
|
+
## Development
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
npm install
|
|
188
|
+
npm test # full vitest suite (conversions, aliases, temperature, edges,
|
|
189
|
+
# plugin registration, lib/client.js smoke tests)
|
|
190
|
+
npm run typecheck # tsc --noEmit
|
|
191
|
+
npm run build # tsup -> lib/ (ESM + CJS + d.ts), then scripts/build-client.mjs
|
|
192
|
+
# emits lib/client.js (the ModuleLoader lazy-CJS bundle)
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Repository layout
|
|
196
|
+
|
|
197
|
+
```
|
|
198
|
+
src/units.ts unit tables and alias index (single source of truth)
|
|
199
|
+
src/convert.ts conversion engine: parsing, converting, temperature/Δ, precision, errors
|
|
200
|
+
src/index.ts DSH plugin entry (server/CLI side): registers the convert tool
|
|
201
|
+
src/client/ Web client plugin (browser side):
|
|
202
|
+
index.tsx registers the conversation.view entry
|
|
203
|
+
UnitConvertView.tsx converter panel (pure front-end core)
|
|
204
|
+
locales.ts zh/en UI copy
|
|
205
|
+
scripts/build-client.mjs esbuild wrapper that emits lib/client.js (ModuleLoader lazy-CJS format)
|
|
206
|
+
test/ Vitest tests (incl. lib/client.js smoke tests)
|
|
207
|
+
cordis.patch.yml DSH bundle patch layer
|
|
208
|
+
lib/ build output (committed so GitHub installs need no build)
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
`src/convert.ts` + `src/units.ts` form the host-independent core library: the
|
|
212
|
+
server tool imports it, and the same code is bundled into the browser-side
|
|
213
|
+
`lib/client.js`, so conversions in the Web view happen entirely locally.
|
|
214
|
+
|
|
215
|
+
## License
|
|
216
|
+
|
|
217
|
+
[MIT](LICENSE)
|