dsh-open-desktop 0.4.3 → 0.5.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 +50 -13
- package/client.js +23 -2
- package/host/api.js +1 -0
- package/host/board.js +24 -1
- package/host/design-system/scaffold/README.md +2 -0
- package/host/exec.js +4 -14
- package/host/paths.js +0 -1
- package/host/refresh.js +8 -17
- package/package.json +6 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Howell5
|
|
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,8 +1,10 @@
|
|
|
1
|
-
# Open Desktop
|
|
1
|
+
# Open Desktop
|
|
2
2
|
|
|
3
|
-
把 DeepSeek Harness
|
|
3
|
+
把 DeepSeek Harness 的中栏变成**可拖拽的数据卡片墙**。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
每张卡片不是静态组件,而是**一条真实 session 的持久展示位**:agent 在卡片目录里写代码(取数脚本、服务、前端),内容用 `view/` 里的 HTML/CSS/JS 在沙箱 iframe 中渲染。
|
|
6
|
+
|
|
7
|
+

|
|
6
8
|
|
|
7
9
|
## 安装
|
|
8
10
|
|
|
@@ -12,23 +14,58 @@ dsh plugin --profile desktop add dsh-open-desktop
|
|
|
12
14
|
|
|
13
15
|
要求 DSH `>=0.2.2-rc.3`。装完重启一次 DSH,侧栏出现「小组件」。
|
|
14
16
|
|
|
15
|
-
##
|
|
17
|
+
## 它解决什么
|
|
18
|
+
|
|
19
|
+
- **会话用完就沉底** → 卡片把结果留在板上,一眼能看到今天的数据。
|
|
20
|
+
- **dashboard 要手写** → 用一句话 + 模板新建,agent 在卡片自己的会话里把视图做出来。
|
|
21
|
+
- **看板容易假** → 每张卡有真实的数据年龄、失败状态和刷新节奏,不是静态截图。
|
|
22
|
+
|
|
23
|
+
## 特性
|
|
24
|
+
|
|
25
|
+
- **Bento 板面**:12 列网格,拖拽排序、拖右下角改尺寸;虚线占位表示目标位置,松手换位。
|
|
26
|
+
- **每卡独立刷新**:`template` / `command` / `file` / `url` 四种数据源,或每天固定时刻;属性弹窗里直接改频率。
|
|
27
|
+
- **唯一渲染路径**:`view/index.html + style.css + view.js`,沙箱 iframe + CSP,外链资源会被门禁打回。
|
|
28
|
+
- **设计系统注入**:`--od-*` token、`od-*` 组件类、`window.od` 运行时;卡片只写内容,不重画外壳。
|
|
29
|
+
- **31 张模板**:今天 / 工作 / 钱 / 信息 / 生活 / 数字资产,每类 5 张。
|
|
30
|
+
- **原生会话**:点「修改」进入卡片自己的 DSH 会话,顶部可预览卡片或返回板面。
|
|
16
31
|
|
|
17
|
-
|
|
18
|
-
- **卡片内容 = `view/` 里的前端代码**:在沙箱 iframe 中渲染,Host 提供设计系统与取数。
|
|
19
|
-
- **板面 = 12 列 Bento 网格**:拖拽排序、拖右下角改尺寸;`⋯ → 属性…` 可改标题、尺寸和刷新频率。
|
|
20
|
-
- **数据源**:`template` / `command` / `file` / `url`,也可以每天固定时刻更新。
|
|
21
|
-
- 内置 30 张模板;新建卡片就是「一句话 + 一个模板」,agent 在卡片自己的会话里把它做出来。
|
|
32
|
+
## 交互
|
|
22
33
|
|
|
23
|
-
|
|
34
|
+
拖拽时目标格子留出同尺寸虚线占位,其余卡片实时让位;支持触屏长按和键盘(空格拿起 / 方向键移动 / 空格放下 / Escape 取消)。
|
|
24
35
|
|
|
25
|
-

|
|
26
37
|
|
|
27
|
-
|
|
38
|
+
卡片 `⋯ → 属性…` 可以改标题、尺寸和刷新频率;选「每天」时时间下拉固定在第二行,不会挤动「更多」。
|
|
39
|
+
|
|
40
|
+

|
|
41
|
+
|
|
42
|
+
## 卡片模型
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
$DSH_HOME/open-desktop/
|
|
46
|
+
cards/<id>/card.json # 标题/尺寸/顺序/刷新约定
|
|
47
|
+
cards/<id>/view/ # 唯一渲染源:index.html + style.css + view.js
|
|
48
|
+
cards/<id>/data/ # 数据文件(agent 自由写入)
|
|
49
|
+
cards/<id>/... # 其它任何代码
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
发布前 `card_finish` 会跑静态门禁:裸色值、外链资源、小于 11px 字号、直接 `fetch`、`window.open`、JS 语法错误都会被打回。
|
|
28
53
|
|
|
29
54
|
## 开发
|
|
30
55
|
|
|
31
|
-
|
|
56
|
+
```bash
|
|
57
|
+
npm install
|
|
58
|
+
npm run build # src/client/ → client.js(esbuild,react 由宿主注入)
|
|
59
|
+
npm test # 214 条测试
|
|
60
|
+
npm run harness # 可选:普通浏览器里的拖拽验证台
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`client.js` 是构建产物,不要直接改;改 `src/client/`。Host 代码在 `host/`。
|
|
64
|
+
|
|
65
|
+
## 兼容性
|
|
66
|
+
|
|
67
|
+
- DSH `>=0.2.2-rc.3 <0.3.0-0`
|
|
68
|
+
- 已验证:macOS desktop profile,DSH `0.2.2-rc.3`
|
|
32
69
|
|
|
33
70
|
## License
|
|
34
71
|
|
package/client.js
CHANGED
|
@@ -5325,7 +5325,7 @@ window.__ModuleLoader__.load({
|
|
|
5325
5325
|
const csp = "default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; img-src data:; font-src data:; connect-src 'none'";
|
|
5326
5326
|
const runtime = `(function(){
|
|
5327
5327
|
function applyTokens(tokens){if(!tokens)return;var root=document.documentElement;for(var key in tokens){root.style.setProperty("--od-"+key,tokens[key])}}
|
|
5328
|
-
window.dshWidget={data:null,tokens:{},size:{w:0,h:0},fetch:function(url,init){var id="f"+Math.random().toString(36).slice(2);return new Promise(function(resolve,reject){function onMessage(event){var message=event.data||{};if(message.__od!==true||message.type!=="fetch-result"||message.id!==id)return;window.removeEventListener("message",onMessage);if(message.ok)resolve(message.value);else reject(new Error(message.error||"fetch failed"))}window.addEventListener("message",onMessage);parent.postMessage({__od:true,type:"fetch",id:id,url:String(url),init:init||null},"*")})}};
|
|
5328
|
+
window.dshWidget={data:null,tokens:{},size:{w:0,h:0},save:function(value){parent.postMessage({__od:true,type:"save",value:value},"*")},fetch:function(url,init){var id="f"+Math.random().toString(36).slice(2);return new Promise(function(resolve,reject){function onMessage(event){var message=event.data||{};if(message.__od!==true||message.type!=="fetch-result"||message.id!==id)return;window.removeEventListener("message",onMessage);if(message.ok)resolve(message.value);else reject(new Error(message.error||"fetch failed"))}window.addEventListener("message",onMessage);parent.postMessage({__od:true,type:"fetch",id:id,url:String(url),init:init||null},"*")})}};
|
|
5329
5329
|
function report(){try{var d=document.documentElement;var b=document.body;var sh=Math.max(d?d.scrollHeight:0,b?b.scrollHeight:0);var ch=window.innerHeight||(d?d.clientHeight:0);parent.postMessage({__od:true,type:"overflow",scrollHeight:sh,clientHeight:ch},"*")}catch(error){}}
|
|
5330
5330
|
window.addEventListener("message",function(event){var message=event.data||{};if(message.__od!==true)return;if(message.type==="hello"){parent.postMessage({__od:true,type:"ready"},"*");return}if(message.type==="tokens"){window.dshWidget.tokens=message.tokens||{};applyTokens(message.tokens);return}if(message.type==="data"){if(message.tokens)applyTokens(message.tokens);if(message.size)window.dshWidget.size=message.size;window.dshWidget.data=message.value;if(typeof window.dshWidget.onData==="function")window.dshWidget.onData(message.value);report()}});
|
|
5331
5331
|
document.addEventListener("click",function(event){var target=event.target;var link=target&&target.closest?target.closest("a[href]"):null;if(!link)return;var href=link.getAttribute("href")||"";if(!/^https?:\\/\\//i.test(href))return;event.preventDefault();parent.postMessage({__od:true,type:"open",url:href},"*")},true);
|
|
@@ -5418,6 +5418,10 @@ window.__ModuleLoader__.load({
|
|
|
5418
5418
|
if (typeof props.onGrow === "function") props.onGrow(widget);
|
|
5419
5419
|
return;
|
|
5420
5420
|
}
|
|
5421
|
+
if (message.type === "save") {
|
|
5422
|
+
if (typeof props.onSave === "function") props.onSave(message.value);
|
|
5423
|
+
return;
|
|
5424
|
+
}
|
|
5421
5425
|
if (message.type === "fetch") {
|
|
5422
5426
|
props.onFetch({ id: message.id, url: message.url, init: message.init }).then(function(value) {
|
|
5423
5427
|
try {
|
|
@@ -5650,6 +5654,9 @@ window.__ModuleLoader__.load({
|
|
|
5650
5654
|
},
|
|
5651
5655
|
onGrow: function(item) {
|
|
5652
5656
|
props.onGrow?.(item);
|
|
5657
|
+
},
|
|
5658
|
+
onSave: function(value) {
|
|
5659
|
+
props.onSave?.(widget.id, value);
|
|
5653
5660
|
}
|
|
5654
5661
|
});
|
|
5655
5662
|
}
|
|
@@ -6097,6 +6104,7 @@ window.__ModuleLoader__.load({
|
|
|
6097
6104
|
onGrow: props.onGrow,
|
|
6098
6105
|
onOverflow: props.onOverflow,
|
|
6099
6106
|
onFetch: props.onFetch,
|
|
6107
|
+
onSave: props.onSave,
|
|
6100
6108
|
dragging: drag !== null && drag.id === widget.id,
|
|
6101
6109
|
dragStyle: fixed ? dragStyle : null
|
|
6102
6110
|
});
|
|
@@ -6647,6 +6655,15 @@ window.__ModuleLoader__.load({
|
|
|
6647
6655
|
blurb: "\u6211\u5230\u5E95\u5FD8\u4E86 push \u4EC0\u4E48",
|
|
6648
6656
|
prompt: "\u505A\u4E00\u4E2A Git \u5F85\u529E\u5361\u7247\uFF1A\u626B\u63CF ~/Code \u4E0B\u7684\u4ED3\u5E93\uFF08\u628A\u8DEF\u5F84\u6362\u6210\u4F60\u7684\uFF09\uFF0C\u5217\u51FA\u6BCF\u4E2A\u4ED3\u5E93\u7684\u672A\u63D0\u4EA4\u6587\u4EF6\u6570\u3001\u672A\u63A8\u9001\u7684\u63D0\u4EA4\u6570\u3001\u5F53\u524D\u5206\u652F\u3002\u53EA\u663E\u793A\u6709\u672A\u63D0\u4EA4\u6216\u672A\u63A8\u9001\u7684\u4ED3\u5E93\uFF0C\u5168\u90E8\u5E72\u51C0\u65F6\u663E\u793A\u300C\u90FD\u5E72\u51C0\u4E86\u300D\u3002\u7528\u672C\u673A git \u547D\u4EE4\uFF0C\u4E0D\u8981\u8054\u7F51\u3002"
|
|
6649
6657
|
},
|
|
6658
|
+
{
|
|
6659
|
+
id: "todo",
|
|
6660
|
+
category: "work",
|
|
6661
|
+
title: "\u5F85\u529E\u6E05\u5355",
|
|
6662
|
+
size: { w: 5, h: 6 },
|
|
6663
|
+
schedule: every(3e5),
|
|
6664
|
+
blurb: "\u50CF iOS \u63D0\u9192\u4E8B\u9879\u4E00\u6837\u52FE\u9009\u3001\u589E\u5220\u6539",
|
|
6665
|
+
prompt: '\u505A\u4E00\u4E2A\u5F85\u529E\u6E05\u5355\u5361\u7247\uFF0C\u50CF iOS \u63D0\u9192\u4E8B\u9879\uFF1A\u5706\u5F62\u52FE\u9009\u6846\u3001\u5B8C\u6210\u5212\u7EBF\u3001\u53D1\u4E1D\u7EBF\u5206\u884C\u3001\u5E95\u90E8\u8F93\u5165\u6846\u3002\u6570\u636E\u5B58\u5728 data/state.json\uFF0C\u7ED3\u6784\u4E3A {"items":[{"id":1,"text":"...","done":false,"tag":"\u4ECA\u5929"}]}\uFF1B\u9996\u6B21\u521B\u5EFA\u65F6\u5199\u5165\u7A7A\u5217\u8868\u3002\u7528 window.dshWidget.data \u8BFB\u53D6\uFF0C\u65B0\u589E/\u52FE\u9009/\u5220\u9664/\u53CC\u51FB\u7F16\u8F91\u540E\u8C03\u7528 window.dshWidget.save({items})\u3002\u4E0D\u8981\u7528 localStorage\uFF08\u6C99\u7BB1\u4E0D\u5141\u8BB8\uFF09\u3002\u8C03 card_set_refresh \u65F6\u4F20 file="data/state.json"\u3001everyMs=300000\u3002'
|
|
6666
|
+
},
|
|
6650
6667
|
// 钱
|
|
6651
6668
|
{
|
|
6652
6669
|
id: "fx",
|
|
@@ -7695,7 +7712,11 @@ window.__ModuleLoader__.load({
|
|
|
7695
7712
|
return body.value;
|
|
7696
7713
|
});
|
|
7697
7714
|
},
|
|
7698
|
-
onMove: moveWidget
|
|
7715
|
+
onMove: moveWidget,
|
|
7716
|
+
onSave: function(id, value) {
|
|
7717
|
+
run("card-data", { id, value }).catch(function() {
|
|
7718
|
+
});
|
|
7719
|
+
}
|
|
7699
7720
|
})
|
|
7700
7721
|
),
|
|
7701
7722
|
activeCard && h(CardChatPanel, {
|
package/host/api.js
CHANGED
|
@@ -202,6 +202,7 @@ function apiHandler(board, origin) {
|
|
|
202
202
|
case 'card-update': return board.update(args)
|
|
203
203
|
case 'card-remove': return board.remove(args)
|
|
204
204
|
case 'card-reorder': return board.reorder(args)
|
|
205
|
+
case 'card-data': return board.writeData(args)
|
|
205
206
|
case 'card-refresh': return board.refresh(args)
|
|
206
207
|
case 'card-inspect': return board.inspect(args)
|
|
207
208
|
case 'card-turns': return board.turns(args)
|
package/host/board.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
//
|
|
3
3
|
// 板面 = 同一组卡片的网格视图。这里不存卡片(card.json 是唯一真相源),
|
|
4
4
|
// 只负责:组装 State、执行动作、广播变更。
|
|
5
|
-
import { appendFile, mkdir } from 'node:fs/promises'
|
|
5
|
+
import { appendFile, mkdir, rename, writeFile } from 'node:fs/promises'
|
|
6
6
|
import { join } from 'node:path'
|
|
7
7
|
import { TEMPLATE_LIST } from './templates.js'
|
|
8
8
|
import { cardTurns } from './turns.js'
|
|
@@ -12,6 +12,8 @@ import { readViewSync } from './views.js'
|
|
|
12
12
|
|
|
13
13
|
// 同时生成中的卡片上限:不排队,超出直接拒绝并提示。
|
|
14
14
|
const MAX_BUILDING_CARDS = 8
|
|
15
|
+
// 卡片自己保存的交互状态(待办、清单等):只写 data/state.json,限制 64KB。
|
|
16
|
+
const MAX_DATA_BYTES = 64 * 1024
|
|
15
17
|
|
|
16
18
|
export function createBoard({ ctx, paths, cards, refresh, sessions }) {
|
|
17
19
|
const listeners = new Set()
|
|
@@ -141,6 +143,26 @@ export function createBoard({ ctx, paths, cards, refresh, sessions }) {
|
|
|
141
143
|
return { refreshed: list.length }
|
|
142
144
|
}
|
|
143
145
|
|
|
146
|
+
// 交互状态:卡片 view 通过 dshWidget.save(value) 写回自己的 data/state.json。
|
|
147
|
+
// 只允许落在这个卡片的 data/ 下,便于 file 刷新和手动备份。
|
|
148
|
+
const writeData = async ({ id, value } = {}) => {
|
|
149
|
+
const card = requireCard(id)
|
|
150
|
+
let text
|
|
151
|
+
try { text = JSON.stringify(value) } catch (error) { text = undefined }
|
|
152
|
+
if (typeof text !== 'string') throw Object.assign(new Error('卡片状态必须是 JSON'), { code: 'bad-data' })
|
|
153
|
+
const bytes = Buffer.byteLength(text, 'utf8')
|
|
154
|
+
if (bytes > MAX_DATA_BYTES) throw Object.assign(new Error('卡片状态超过 64KB'), { code: 'data-too-large' })
|
|
155
|
+
const dir = join(paths.cardDir(card.id), 'data')
|
|
156
|
+
await mkdir(dir, { recursive: true })
|
|
157
|
+
const file = join(dir, 'state.json')
|
|
158
|
+
const temp = file + '.tmp'
|
|
159
|
+
await writeFile(temp, text, 'utf8')
|
|
160
|
+
await rename(temp, file)
|
|
161
|
+
try { refresh?.refresh?.([card]) } catch { /* 忽略 */ }
|
|
162
|
+
publish()
|
|
163
|
+
return { written: true, bytes }
|
|
164
|
+
}
|
|
165
|
+
|
|
144
166
|
const inspect = async ({ id } = {}) => {
|
|
145
167
|
const card = requireCard(id)
|
|
146
168
|
const result = await sessions.inspect(card.id)
|
|
@@ -228,6 +250,7 @@ export function createBoard({ ctx, paths, cards, refresh, sessions }) {
|
|
|
228
250
|
reorder,
|
|
229
251
|
setPaused,
|
|
230
252
|
refresh: refreshNow,
|
|
253
|
+
writeData,
|
|
231
254
|
inspect,
|
|
232
255
|
cancel,
|
|
233
256
|
turns,
|
|
@@ -20,9 +20,11 @@ window.dshWidget.onData = fn // 每次刷新时调用 fn(value)
|
|
|
20
20
|
window.dshWidget.tokens // 宿主主题 token
|
|
21
21
|
window.dshWidget.size // { w, h } 卡片网格尺寸
|
|
22
22
|
window.dshWidget.fetch(url) // 走宿主代理请求 http(s),返回 Promise
|
|
23
|
+
window.dshWidget.save(value) // 交互卡写回自己的 data/state.json(JSON,≤64KB)
|
|
23
24
|
```
|
|
24
25
|
|
|
25
26
|
- 不要在卡片里直接 `fetch()` / `XMLHttpRequest`:CSP 会拦掉,用 `dshWidget.fetch`。
|
|
27
|
+
- 待办、清单这类要增删改的卡:用 `dshWidget.save(value)` 写回,`card_set_refresh` 配 `file="data/state.json"`;不要用 `localStorage`(沙箱不允许)。
|
|
26
28
|
- 不要用 `window.open`:链接写成 `<a href="https://…">`,宿主会接管打开。
|
|
27
29
|
- 每次刷新只替换内容,不要重载页面。
|
|
28
30
|
|
package/host/exec.js
CHANGED
|
@@ -27,33 +27,23 @@ async function confine(ctx, argv, workspaceRoot) {
|
|
|
27
27
|
return argv
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export async function runCommand(ctx, commandLine, { workspaceRoot = '', timeoutMs =
|
|
30
|
+
export async function runCommand(ctx, commandLine, { workspaceRoot = '', timeoutMs = 8000 } = {}) {
|
|
31
31
|
const parts = tokenize(commandLine)
|
|
32
32
|
if (parts.length === 0) throw Object.assign(new Error('命令为空'), { code: 'bad-command' })
|
|
33
33
|
const argv = await confine(ctx, parts, workspaceRoot)
|
|
34
|
-
const limit = Math.min(120_000, Math.max(1000, Number(timeoutMs) || 30_000))
|
|
35
34
|
return new Promise((resolve, reject) => {
|
|
36
35
|
execFile(
|
|
37
36
|
argv[0],
|
|
38
37
|
argv.slice(1),
|
|
39
38
|
{
|
|
40
|
-
timeout:
|
|
39
|
+
timeout: Math.min(60_000, Math.max(1000, Number(timeoutMs) || 8000)),
|
|
41
40
|
maxBuffer: 512 * 1024,
|
|
42
41
|
cwd: workspaceRoot && workspaceRoot !== '' ? workspaceRoot : undefined,
|
|
43
42
|
env: { ...process.env, LANG: 'en_US.UTF-8' },
|
|
44
43
|
},
|
|
45
|
-
(error, stdout
|
|
44
|
+
(error, stdout) => {
|
|
46
45
|
if (error) {
|
|
47
|
-
|
|
48
|
-
const timedOut = error.killed === true || error.signal === 'SIGTERM' || error.code === 'ETIMEDOUT'
|
|
49
|
-
const firstLine = stderrText.split('\n').map((line) => line.trim()).filter(Boolean)[0] || ''
|
|
50
|
-
const reason = timedOut
|
|
51
|
-
? `超时(${limit}ms 未完成,已终止)`
|
|
52
|
-
: (firstLine.slice(0, 300) || String(error.code || '未知错误'))
|
|
53
|
-
reject(Object.assign(
|
|
54
|
-
new Error(`命令「${String(commandLine).slice(0, 120)}」执行失败:${reason}`),
|
|
55
|
-
{ code: 'script-failed', stderr: stderrText.slice(0, 4000) },
|
|
56
|
-
))
|
|
46
|
+
reject(Object.assign(new Error(`执行失败:${error.message}`), { code: 'script-failed' }))
|
|
57
47
|
return
|
|
58
48
|
}
|
|
59
49
|
resolve(String(stdout ?? ''))
|
package/host/paths.js
CHANGED
|
@@ -69,7 +69,6 @@ export function normalizeRefresh(raw) {
|
|
|
69
69
|
if (file !== '') refresh.file = file
|
|
70
70
|
if (url !== '') refresh.url = url
|
|
71
71
|
if (source.params && typeof source.params === 'object') refresh.params = { ...source.params }
|
|
72
|
-
if (Number.isFinite(Number(source.timeoutMs))) refresh.timeoutMs = clampInt(Number(source.timeoutMs), 1000, 120_000, 30_000)
|
|
73
72
|
return refresh
|
|
74
73
|
}
|
|
75
74
|
|
package/host/refresh.js
CHANGED
|
@@ -36,7 +36,6 @@ export function createRefresh({ ctx, cards, inject } = {}) {
|
|
|
36
36
|
const generations = new Map()
|
|
37
37
|
const signatures = new Map()
|
|
38
38
|
const running = new Set()
|
|
39
|
-
const queued = new Set()
|
|
40
39
|
const templates = inject?.templates ?? TEMPLATES
|
|
41
40
|
const pathOf = inject?.pathOf ?? (() => '')
|
|
42
41
|
const onCommand = inject?.runCommand ?? ((command, options) => runCommand(ctx, command, options))
|
|
@@ -67,8 +66,6 @@ export function createRefresh({ ctx, cards, inject } = {}) {
|
|
|
67
66
|
return 'none'
|
|
68
67
|
}
|
|
69
68
|
const snapshot = () => ({ paused, data: Object.fromEntries([...data.entries()]) })
|
|
70
|
-
// 命令类刷新默认 30s:要大于脚本自己的网络超时(如 12s),否则脚本兜底前就被 Host 杀掉。
|
|
71
|
-
const timeoutOf = (card) => Math.max(1000, Math.min(120_000, Number(card?.refresh?.timeoutMs) || 30_000))
|
|
72
69
|
|
|
73
70
|
const resolveCardFile = (cardId, file) => {
|
|
74
71
|
const dir = pathOf(cardId)
|
|
@@ -77,17 +74,16 @@ export function createRefresh({ ctx, cards, inject } = {}) {
|
|
|
77
74
|
|
|
78
75
|
const pull = async (card, spec) => {
|
|
79
76
|
const workspaceRoot = pathOf(card.id)
|
|
80
|
-
const timeoutMs = timeoutOf(card)
|
|
81
77
|
if (spec.template) {
|
|
82
78
|
const template = templates[spec.template] ?? null
|
|
83
79
|
if (template === null) throw Object.assign(new Error(`没有 ${spec.template} 这个模板`), { code: 'unknown-template' })
|
|
84
80
|
return template.fetch(card, {
|
|
85
|
-
timeoutMs,
|
|
86
|
-
runCommand: (command, options) => onCommand(command, { workspaceRoot, timeoutMs, ...options }),
|
|
81
|
+
timeoutMs: 10_000,
|
|
82
|
+
runCommand: (command, options) => onCommand(command, { workspaceRoot, timeoutMs: 10_000, ...options }),
|
|
87
83
|
})
|
|
88
84
|
}
|
|
89
85
|
if (spec.command) {
|
|
90
|
-
const output = await onCommand(spec.command, { workspaceRoot, timeoutMs })
|
|
86
|
+
const output = await onCommand(spec.command, { workspaceRoot, timeoutMs: 10_000 })
|
|
91
87
|
return parseValue(output)
|
|
92
88
|
}
|
|
93
89
|
if (spec.file) {
|
|
@@ -95,7 +91,7 @@ export function createRefresh({ ctx, cards, inject } = {}) {
|
|
|
95
91
|
return parseValue(text)
|
|
96
92
|
}
|
|
97
93
|
if (spec.url) {
|
|
98
|
-
const response = await fetchImpl(spec.url, { signal: AbortSignal.timeout(
|
|
94
|
+
const response = await fetchImpl(spec.url, { signal: AbortSignal.timeout(10_000), headers: { accept: 'application/json' } })
|
|
99
95
|
if (!response.ok) throw Object.assign(new Error(`HTTP ${response.status}`), { code: 'http-status' })
|
|
100
96
|
return response.json()
|
|
101
97
|
}
|
|
@@ -104,8 +100,7 @@ export function createRefresh({ ctx, cards, inject } = {}) {
|
|
|
104
100
|
|
|
105
101
|
const runOne = async (card) => {
|
|
106
102
|
if (paused || started === false) return
|
|
107
|
-
|
|
108
|
-
if (running.has(card.id)) { queued.add(card.id); return }
|
|
103
|
+
if (running.has(card.id)) return
|
|
109
104
|
if (!hasProvider(card)) {
|
|
110
105
|
if (data.delete(card.id)) emit()
|
|
111
106
|
return
|
|
@@ -122,16 +117,12 @@ export function createRefresh({ ctx, cards, inject } = {}) {
|
|
|
122
117
|
fetchedAt: previous?.fetchedAt ?? 0,
|
|
123
118
|
ttl: previous?.ttl ?? everyMs * 2,
|
|
124
119
|
sourceRef: sourceRefOf(card),
|
|
125
|
-
error: { code: String(error?.code ?? 'fetch-failed'), message: String(error?.message ?? error).slice(0,
|
|
120
|
+
error: { code: String(error?.code ?? 'fetch-failed'), message: String(error?.message ?? error).slice(0, 300), at: Date.now() },
|
|
126
121
|
})
|
|
127
122
|
} finally {
|
|
128
123
|
running.delete(card.id)
|
|
129
124
|
}
|
|
130
125
|
emit()
|
|
131
|
-
if (queued.delete(card.id)) {
|
|
132
|
-
const latest = cards?.get?.(card.id) ?? card
|
|
133
|
-
void runOne(latest)
|
|
134
|
-
}
|
|
135
126
|
}
|
|
136
127
|
|
|
137
128
|
const clearTimer = (id) => {
|
|
@@ -180,9 +171,9 @@ export function createRefresh({ ctx, cards, inject } = {}) {
|
|
|
180
171
|
|
|
181
172
|
return {
|
|
182
173
|
start: (list) => { started = true; sync(list) },
|
|
183
|
-
stop: () => { started = false;
|
|
174
|
+
stop: () => { started = false; for (const id of [...timers.keys()]) clearTimer(id); timers.clear(); signatures.clear() },
|
|
184
175
|
sync,
|
|
185
|
-
pause: () => { paused = true;
|
|
176
|
+
pause: () => { paused = true; for (const id of [...timers.keys()]) clearTimer(id); signatures.clear(); emit() },
|
|
186
177
|
resume: () => { paused = false; sync(cards?.list?.() ?? []); emit() },
|
|
187
178
|
snapshot,
|
|
188
179
|
refresh: (list) => { for (const card of Array.isArray(list) ? list : []) void runOne(card) },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-open-desktop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "把 DSH 的中栏变成可拖拽的数据卡片墙:每张卡片是一条真实会话,用 view/ 里的前端代码渲染,自带刷新节奏。",
|
|
6
6
|
"keywords": [
|
|
@@ -58,16 +58,16 @@
|
|
|
58
58
|
"react": "^19.3.1",
|
|
59
59
|
"react-dom": "^19.3.1"
|
|
60
60
|
},
|
|
61
|
-
"homepage": "https://github.com/Howell5/
|
|
61
|
+
"homepage": "https://github.com/Howell5/dsh-open-desktop#readme",
|
|
62
62
|
"repository": {
|
|
63
63
|
"type": "git",
|
|
64
|
-
"url": "git+https://github.com/Howell5/
|
|
65
|
-
"directory": "plugin"
|
|
64
|
+
"url": "git+https://github.com/Howell5/dsh-open-desktop.git"
|
|
66
65
|
},
|
|
67
66
|
"bugs": {
|
|
68
|
-
"url": "https://github.com/Howell5/
|
|
67
|
+
"url": "https://github.com/Howell5/dsh-open-desktop/issues"
|
|
69
68
|
},
|
|
70
69
|
"engines": {
|
|
71
70
|
"dsh": ">=0.2.2-rc.3 <0.3.0-0"
|
|
72
|
-
}
|
|
71
|
+
},
|
|
72
|
+
"author": "Howell5"
|
|
73
73
|
}
|