dsh-cyrene-thinking 0.0.0-stage → 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Cyrene-xl
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.md CHANGED
@@ -1,3 +1,32 @@
1
- # Temporary Holding Version
1
+ # dsh-cyrene-thinking
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 把 DSH 聊天里「正在分析请求 / Thinking」旁边的小图标,换成昔涟的思考循环动画。
4
+
5
+ - **底部运行状态**:`正在分析请求` 旁边的鲸鱼尾(`runningIcon`)→ 小昔涟 GIF;
6
+ - **过程标题**:运行中的思考行同样替换;标题文字变成「已完成分析」后自动还原,不碰历史;
7
+ - 设置 → 通用 → **「思考动画」** 开关,默认开;配置存 `<DSH_HOME>/dsh-cyrene-thinking.json`;
8
+ - 动画由宿主路由 `/dsh-cyrene-thinking/thinking.gif` 提供,不内联进 JS。
9
+
10
+ ![效果](./assets/thinking.gif)
11
+
12
+ ## 安装
13
+
14
+ ```bash
15
+ dsh plugin --profile web add link:$PWD/packages/thinking-animation
16
+ ```
17
+
18
+ 重启 DSH 生效。
19
+
20
+ ## 兼容性
21
+
22
+ - 需要 DSH **0.1.5 ~ 0.2.1**、Node **22+**;
23
+ - 依赖 DSH 的 `button[data-process-activity]` 与 `[class*="_runningIcon"]` 结构,
24
+ 升级大版本后如果动画不出现,多半是这两个选择器改名了;
25
+ - 只在 Web 端生效,不影响模型输出。
26
+
27
+ ## 素材来源与授权
28
+
29
+ `assets/thinking.gif` 来自 [Cyrene-Agent](https://github.com/Playa-Cyrene/Cyrene-Agent)
30
+ 的 `assets/ui/cyrene-thinking-loop/`(MIT 仓库);角色「昔涟」版权归 HoYoverse / 米哈游,
31
+ 属非商用同人素材,**禁止商用**,详见根目录
32
+ [`THIRD_PARTY_NOTICES.md`](../../THIRD_PARTY_NOTICES.md)。
Binary file
package/client.js ADDED
@@ -0,0 +1,239 @@
1
+ /**
2
+ * dsh-cyrene-thinking 的浏览器半边。
3
+ *
4
+ * 目标:模型思考时,把过程标题前的图标换成昔涟思考动画;**只对运行中的行**生效
5
+ * (已完成的分析行 activity 仍是 thinking,但文字是「已完成分析」,不能替换)。
6
+ *
7
+ * 定位:`button[data-process-activity="thinking"]`,由客户端按文字排除「已完成 / Completed」,
8
+ * 给运行中的按钮加 `cyrene-thinking-run` 类;CSS 只认这个类,不碰 React。
9
+ */
10
+ window.__ModuleLoader__.load({
11
+ id: 'dsh-cyrene-thinking',
12
+ factory: (require) => {
13
+ var module = { exports: {} };
14
+ var exports = module.exports;
15
+ var react = require('react');
16
+
17
+ var NS = 'dsh-cyrene-thinking';
18
+ var API = '/dsh-cyrene-thinking-api';
19
+ var IMAGE = '/dsh-cyrene-thinking/thinking.gif';
20
+ var STYLE_ID = 'dsh-cyrene-thinking-style';
21
+ var RUN_CLASS = 'cyrene-thinking-run';
22
+
23
+ var enabled = true;
24
+ var styleEl = null;
25
+ var observer = null;
26
+ var scheduled = false;
27
+
28
+ function ensureStyle() {
29
+ if (styleEl && styleEl.isConnected) return styleEl;
30
+ var existing = document.getElementById(STYLE_ID);
31
+ if (existing) {
32
+ styleEl = existing;
33
+ return styleEl;
34
+ }
35
+ var style = document.createElement('style');
36
+ style.id = STYLE_ID;
37
+ style.textContent =
38
+ 'button.' + RUN_CLASS + ' [data-step-process-icon] svg{display:none!important}'
39
+ + 'button.' + RUN_CLASS + ' [data-step-process-icon]::before{'
40
+ + 'content:"";position:absolute;inset:-3px;z-index:1;'
41
+ + 'background:url("' + IMAGE + '") center/contain no-repeat;border-radius:50%;pointer-events:none;'
42
+ + '}'
43
+ /* 底部「正在分析请求」旁的 running 图标(鲸鱼尾):只在这个运行状态存在 */
44
+ + '[class*="_runningIcon"]{width:20px!important;height:20px!important;overflow:visible!important;contain:none!important}'
45
+ + '[class*="_runningIcon"] > span,[class*="_runningIcon"] > svg{display:none!important}'
46
+ + '[class*="_runningIcon"]::before{'
47
+ + 'content:"";position:absolute;inset:0;z-index:1;'
48
+ + 'background:url("' + IMAGE + '") center/contain no-repeat;border-radius:50%;pointer-events:none;'
49
+ + '}';
50
+ (document.head || document.documentElement).appendChild(style);
51
+ styleEl = style;
52
+ return styleEl;
53
+ }
54
+
55
+ function isFinished(text) {
56
+ return /已完成|完成分析|Completed/i.test(String(text || ''));
57
+ }
58
+
59
+ function scan() {
60
+ scheduled = false;
61
+ if (!enabled) {
62
+ var all = document.querySelectorAll('button.' + RUN_CLASS);
63
+ for (var k = 0; k < all.length; k++) all[k].classList.remove(RUN_CLASS);
64
+ return;
65
+ }
66
+ var buttons = document.querySelectorAll('button[data-process-activity="thinking"]');
67
+ for (var i = 0; i < buttons.length; i++) {
68
+ var button = buttons[i];
69
+ if (isFinished(button.textContent)) button.classList.remove(RUN_CLASS);
70
+ else button.classList.add(RUN_CLASS);
71
+ }
72
+ var running = document.querySelectorAll('button.' + RUN_CLASS);
73
+ for (var j = 0; j < running.length; j++) {
74
+ if (running[j].getAttribute('data-process-activity') !== 'thinking') {
75
+ running[j].classList.remove(RUN_CLASS);
76
+ }
77
+ }
78
+ }
79
+
80
+ function schedule() {
81
+ if (scheduled) return;
82
+ scheduled = true;
83
+ window.requestAnimationFrame(scan);
84
+ }
85
+
86
+ function ensureObserver() {
87
+ if (observer) return;
88
+ if (!document.body) {
89
+ window.setTimeout(ensureObserver, 150);
90
+ return;
91
+ }
92
+ observer = new MutationObserver(schedule);
93
+ observer.observe(document.body, {
94
+ childList: true,
95
+ subtree: true,
96
+ characterData: true,
97
+ attributes: true,
98
+ attributeFilter: ['data-process-activity']
99
+ });
100
+ scan();
101
+ }
102
+
103
+ function applyEnabled(on) {
104
+ enabled = on === true;
105
+ ensureStyle().disabled = !enabled;
106
+ if (enabled) ensureObserver();
107
+ else scan();
108
+ }
109
+
110
+ function loadEnabled() {
111
+ fetch(API, { headers: { accept: 'application/json' } })
112
+ .then(function (res) { return res.json(); })
113
+ .then(function (body) {
114
+ applyEnabled(!body || body.ok !== true ? true : body.enabled !== false);
115
+ })
116
+ .catch(function () { applyEnabled(true); });
117
+ }
118
+
119
+ function ThinkingRow(props) {
120
+ var t = props && typeof props.t === 'function' ? props.t : function (key) { return key; };
121
+ var statePair = react.useState({ loading: true, enabled: true, busy: false, error: '' });
122
+ var view = statePair[0];
123
+ var setView = statePair[1];
124
+
125
+ function patch(next) {
126
+ setView(function (prev) {
127
+ var out = {};
128
+ for (var k in prev) out[k] = prev[k];
129
+ for (var j in next) out[j] = next[j];
130
+ return out;
131
+ });
132
+ }
133
+
134
+ react.useEffect(function () {
135
+ var alive = true;
136
+ fetch(API, { headers: { accept: 'application/json' } })
137
+ .then(function (res) { return res.json(); })
138
+ .then(function (body) {
139
+ if (!alive) return;
140
+ if (!body || body.ok !== true) throw new Error((body && body.error) || t('loadFailed'));
141
+ patch({ loading: false, enabled: body.enabled !== false, error: '' });
142
+ })
143
+ .catch(function (err) {
144
+ if (alive) patch({ loading: false, error: String((err && err.message) || err) });
145
+ });
146
+ return function () { alive = false; };
147
+ }, []);
148
+
149
+ function toggle() {
150
+ if (view.loading || view.busy) return;
151
+ var next = !view.enabled;
152
+ patch({ busy: true, error: '' });
153
+ fetch(API, {
154
+ method: 'POST',
155
+ headers: { 'content-type': 'application/json', accept: 'application/json' },
156
+ body: JSON.stringify({ enabled: next })
157
+ })
158
+ .then(function (res) { return res.json(); })
159
+ .then(function (body) {
160
+ if (!body || body.ok !== true) throw new Error((body && body.error) || t('saveFailed'));
161
+ var on = body.enabled !== false;
162
+ applyEnabled(on);
163
+ patch({ busy: false, enabled: on });
164
+ })
165
+ .catch(function (err) {
166
+ patch({ busy: false, error: String((err && err.message) || err) });
167
+ });
168
+ }
169
+
170
+ var rowStyle = {
171
+ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '16px',
172
+ padding: '14px 16px', borderBottom: '1px solid var(--dsw-alias-border-l1)'
173
+ };
174
+ var titleStyle = { fontSize: '14px', fontWeight: '600', lineHeight: '22px', color: 'var(--dsw-alias-label-primary)' };
175
+ var descStyle = { marginTop: '2px', fontSize: '12px', lineHeight: '18px', color: 'var(--dsw-alias-label-secondary)' };
176
+ var errorStyle = { marginTop: '4px', fontSize: '12px', lineHeight: '18px', color: 'var(--dsw-alias-danger)' };
177
+ var switchStyle = {
178
+ position: 'relative', width: '40px', height: '22px', border: 'none', borderRadius: '999px',
179
+ background: view.enabled ? 'var(--dsw-alias-brand-primary)' : 'var(--dsw-alias-border-l2)',
180
+ cursor: view.busy ? 'default' : 'pointer', flex: '0 0 auto', padding: 0, transition: 'background .15s'
181
+ };
182
+ var knobStyle = {
183
+ position: 'absolute', top: '3px', left: view.enabled ? '21px' : '3px', width: '16px', height: '16px',
184
+ borderRadius: '50%', background: '#fff', transition: 'left .15s'
185
+ };
186
+
187
+ return react.createElement('div', { style: rowStyle },
188
+ react.createElement('div', { style: { minWidth: 0 } },
189
+ react.createElement('div', { style: titleStyle }, t('title')),
190
+ react.createElement('div', { style: descStyle }, view.loading ? t('loading') : (view.enabled ? t('onHint') : t('offHint'))),
191
+ view.error ? react.createElement('div', { style: errorStyle }, view.error) : null
192
+ ),
193
+ react.createElement('button', {
194
+ type: 'button', role: 'switch', 'aria-checked': view.enabled,
195
+ 'aria-label': t('title'), title: t('title'),
196
+ disabled: view.loading || view.busy, style: switchStyle, onClick: toggle
197
+ }, react.createElement('span', { style: knobStyle }))
198
+ );
199
+ }
200
+
201
+ var inject = ['slots', 'locale'];
202
+
203
+ function apply(ctx) {
204
+ ctx.effect(function () {
205
+ return ctx.locale.register(NS, {
206
+ zh: {
207
+ title: '思考动画',
208
+ onHint: '模型思考时,把「思考中」前的小图标换成昔涟的思考循环动画。',
209
+ offHint: '已关闭:使用 DSH 默认的思考图标。',
210
+ loading: '正在读取开关…',
211
+ loadFailed: '读取开关失败',
212
+ saveFailed: '保存开关失败'
213
+ },
214
+ en: {
215
+ title: 'Thinking animation',
216
+ onHint: 'Replace the small "Thinking" icon with Cyrene\'s animated thinking loop.',
217
+ offHint: 'Off: use the default DSH thinking icon.',
218
+ loading: 'Loading…',
219
+ loadFailed: 'Could not load the setting',
220
+ saveFailed: 'Could not save the setting'
221
+ }
222
+ });
223
+ });
224
+
225
+ ctx.slots.inject('settings.general.item', function () {
226
+ return ctx.slots.register({
227
+ name: 'settings.general.item', id: 'cyrene-thinking', order: 42, locale: NS
228
+ }, ThinkingRow);
229
+ });
230
+
231
+ applyEnabled(true);
232
+ loadEnabled();
233
+ }
234
+
235
+ exports.apply = apply;
236
+ exports.inject = inject;
237
+ return module.exports;
238
+ }
239
+ });
@@ -0,0 +1,4 @@
1
+ # dsh-cyrene-thinking bundle patch:只插入一行插件。
2
+ - insert:
3
+ - id: dsh-cyrene-thinking
4
+ name: 'dsh-cyrene-thinking'
package/index.js ADDED
@@ -0,0 +1,116 @@
1
+ /**
2
+ * dsh-cyrene-thinking 的主机半边。
3
+ *
4
+ * 两件事:
5
+ * 1. 把 assets/thinking.gif 通过 webServer 暴露成固定 URL;
6
+ * 2. 提供开关接口(默认开),配置存 <DSH_HOME>/dsh-cyrene-thinking.json。
7
+ */
8
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
9
+ import { homedir } from 'node:os'
10
+ import { dirname, join } from 'node:path'
11
+ import { fileURLToPath } from 'node:url'
12
+
13
+ const HERE = dirname(fileURLToPath(import.meta.url))
14
+ const HOME = process.env.DSH_HOME || join(homedir(), '.dsh')
15
+ const STORE = join(HOME, 'dsh-cyrene-thinking.json')
16
+ const ASSET = join(HERE, 'assets', 'thinking.gif')
17
+ const ROUTE = '/dsh-cyrene-thinking/thinking.gif'
18
+ const API = '/dsh-cyrene-thinking-api'
19
+
20
+ const name = 'dsh-cyrene-thinking'
21
+ const inject = ['webServer']
22
+
23
+ function readEnabled() {
24
+ try {
25
+ const raw = JSON.parse(readFileSync(STORE, 'utf8'))
26
+ return raw?.enabled !== false
27
+ } catch {
28
+ return true
29
+ }
30
+ }
31
+
32
+ function writeEnabled(enabled) {
33
+ try {
34
+ mkdirSync(HOME, { recursive: true })
35
+ writeFileSync(STORE, JSON.stringify({ enabled: enabled === true }, null, 2) + '\n', 'utf8')
36
+ return true
37
+ } catch {
38
+ return false
39
+ }
40
+ }
41
+
42
+ function json(res, body, status = 200) {
43
+ res.writeHead(status, { 'content-type': 'application/json; charset=utf-8' })
44
+ res.end(JSON.stringify(body))
45
+ }
46
+
47
+ function readBody(req) {
48
+ return new Promise((resolve, reject) => {
49
+ let text = ''
50
+ req.on('data', (chunk) => { text += chunk })
51
+ req.on('end', () => resolve(text))
52
+ req.on('error', reject)
53
+ })
54
+ }
55
+
56
+ function apply(ctx) {
57
+ const webServer = ctx.webServer
58
+ let cachedGif = null
59
+
60
+ ctx.effect(() => webServer.register({
61
+ kind: 'exact',
62
+ path: ROUTE,
63
+ handler: (req, res) => {
64
+ try {
65
+ if (cachedGif === null) cachedGif = readFileSync(ASSET)
66
+ res.writeHead(200, {
67
+ 'content-type': 'image/gif',
68
+ 'content-length': String(cachedGif.length),
69
+ 'cache-control': 'public, max-age=86400'
70
+ })
71
+ res.end(cachedGif)
72
+ } catch (err) {
73
+ res.writeHead(404, { 'content-type': 'text/plain; charset=utf-8' })
74
+ res.end('dsh-cyrene-thinking: assets/thinking.gif 读取失败 — ' + String((err && err.message) || err))
75
+ }
76
+ }
77
+ }), 'dsh-cyrene-thinking: animation route')
78
+
79
+ ctx.effect(() => webServer.register({
80
+ kind: 'exact',
81
+ path: API,
82
+ async handler(req, res) {
83
+ try {
84
+ if (req.method === 'GET') {
85
+ json(res, { ok: true, enabled: readEnabled(), path: STORE })
86
+ return
87
+ }
88
+ if (req.method !== 'POST') {
89
+ json(res, { ok: false, error: '只支持 GET / POST' }, 405)
90
+ return
91
+ }
92
+ const raw = await readBody(req)
93
+ let payload = {}
94
+ try {
95
+ payload = raw ? JSON.parse(raw) : {}
96
+ } catch {
97
+ json(res, { ok: false, error: '请求体不是 JSON' }, 400)
98
+ return
99
+ }
100
+ if (typeof payload.enabled !== 'boolean') {
101
+ json(res, { ok: false, error: 'enabled 必须是 true / false' }, 400)
102
+ return
103
+ }
104
+ if (!writeEnabled(payload.enabled)) {
105
+ json(res, { ok: false, error: '写入 ' + STORE + ' 失败' }, 500)
106
+ return
107
+ }
108
+ json(res, { ok: true, enabled: readEnabled() })
109
+ } catch (error) {
110
+ json(res, { ok: false, error: String((error && error.message) || error) }, 500)
111
+ }
112
+ }
113
+ }), 'dsh-cyrene-thinking: settings api')
114
+ }
115
+
116
+ export { name, inject, apply }
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "dsh-cyrene-thinking",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "把 DSH 聊天里「思考中」的小图标换成昔涟的思考循环动画(可开关)",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "exports": {
8
+ ".": "./index.js",
9
+ "./client": "./client.js",
10
+ "./cordis.patch.yml": "./cordis.patch.yml",
11
+ "./package.json": "./package.json"
12
+ },
13
+ "files": [
14
+ "index.js",
15
+ "client.js",
16
+ "cordis.patch.yml",
17
+ "assets",
18
+ "README.md"
19
+ ],
20
+ "dsh": {
21
+ "bundle": {
22
+ "patch": "./cordis.patch.yml"
23
+ },
24
+ "client": {
25
+ "platform": "web",
26
+ "inject": [
27
+ "@deepseek-ai/dsh-client-ui-slots",
28
+ "@deepseek-ai/dsh-client-locale",
29
+ "@deepseek-ai/dsh-client-ui-settings-general"
30
+ ]
31
+ }
32
+ },
33
+ "license": "MIT",
34
+ "author": {
35
+ "name": "Cyrene-xl",
36
+ "url": "https://github.com/Cyrene-xl"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/Cyrene-xl/DSH-Cyrene-UI.git",
41
+ "directory": "packages/thinking-animation"
42
+ },
43
+ "homepage": "https://github.com/Cyrene-xl/DSH-Cyrene-UI/tree/main/packages/thinking-animation",
44
+ "bugs": {
45
+ "url": "https://github.com/Cyrene-xl/DSH-Cyrene-UI/issues"
46
+ },
47
+ "keywords": [
48
+ "dsh",
49
+ "dsh-plugin",
50
+ "ui",
51
+ "thinking",
52
+ "animation"
53
+ ],
54
+ "engines": {
55
+ "node": ">=22",
56
+ "dsh": ">=0.1.5 <0.3.0"
57
+ },
58
+ "publishConfig": {
59
+ "access": "public"
60
+ }
61
+ }