@goodandready/dsh-cron 0.3.27 → 0.3.29
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/lib/channels.js +25 -1
- package/lib/client-src/00-open.js +1 -1
- package/lib/client-src/10-locales.js +2 -0
- package/lib/client-src/30-utils.js +15 -1
- package/lib/client-src/80-sidebar-jobs.js +2 -2
- package/lib/client-src/90-close.js +8 -5
- package/lib/client.js +25 -9
- package/lib/http-utils.js +86 -11
- package/lib/locales.json +8 -1
- package/lib/settings.js +5 -0
- package/lib/tui-settings.js +17 -0
- package/package.json +1 -1
package/lib/channels.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHmac } from 'node:crypto';
|
|
1
2
|
/**
|
|
2
3
|
* Delivery channels and router (#26, #20, #21, #22, #47, #28).
|
|
3
4
|
*
|
|
@@ -11,7 +12,7 @@ import { formatTaskTelegramMessage, sendTelegramMessage, createTelegramTaskKeybo
|
|
|
11
12
|
import { createKanbanCard, shouldCreateKanbanCard } from './integrations.js';
|
|
12
13
|
import { resolveTemplateText, truncateText } from './templates.js';
|
|
13
14
|
|
|
14
|
-
export const CHANNEL_IDS = ['telegram', 'kanban', 'discord', 'slack', 'ntfy', 'bark', 'pushplus', 'tts', 'gitea'];
|
|
15
|
+
export const CHANNEL_IDS = ['feishu', 'telegram', 'kanban', 'discord', 'slack', 'ntfy', 'bark', 'pushplus', 'tts', 'gitea'];
|
|
15
16
|
|
|
16
17
|
// CHANNEL_LABELS removed (#155) — localized via lib/client.js
|
|
17
18
|
|
|
@@ -41,6 +42,8 @@ export function resolveChannels(task, settings = {}) {
|
|
|
41
42
|
if (explicit.length) return explicit;
|
|
42
43
|
}
|
|
43
44
|
const out = [];
|
|
45
|
+
const notifyFeishu = task.notifyFeishu !== undefined ? task.notifyFeishu : settings.notifyFeishu;
|
|
46
|
+
if (notifyFeishu) out.push('feishu');
|
|
44
47
|
const notify = task.notifyTelegram !== undefined ? task.notifyTelegram : settings.notifyTelegram;
|
|
45
48
|
if (notify) out.push('telegram');
|
|
46
49
|
if ((task.kanbanMode || 'none') !== 'none') out.push('kanban');
|
|
@@ -103,6 +106,14 @@ export function buildDiscordPayload({ text, task, runInfo }) {
|
|
|
103
106
|
};
|
|
104
107
|
}
|
|
105
108
|
|
|
109
|
+
export function buildFeishuPayload({ text }) {
|
|
110
|
+
return { msg_type: 'text', content: { text: truncateText(text, 4000) } };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function feishuSign(timestamp, secret) {
|
|
114
|
+
return createHmac('sha256', `${String(timestamp)}\n${String(secret)}`).update('').digest('base64');
|
|
115
|
+
}
|
|
116
|
+
|
|
106
117
|
export function buildSlackPayload({ text }) {
|
|
107
118
|
return { text: truncateText(text, 3000) };
|
|
108
119
|
}
|
|
@@ -299,6 +310,19 @@ async function postJson(http, url, headers, body, channelId, signal, timeoutMs)
|
|
|
299
310
|
* descriptive Error on failure; the router turns that into a failure entry.
|
|
300
311
|
*/
|
|
301
312
|
const CHANNEL_HANDLERS = {
|
|
313
|
+
async feishu({ task, runInfo, settings, http, signal, timeoutMs }) {
|
|
314
|
+
const url = String(settings.feishuWebhookUrl || '').trim();
|
|
315
|
+
if (!url) throw new Error('feishu: feishuWebhookUrl is not configured');
|
|
316
|
+
const payload = buildFeishuPayload({ text: messageTextFor('feishu', task, runInfo, settings) });
|
|
317
|
+
const secret = String(settings.feishuSecret || '').trim();
|
|
318
|
+
if (secret) {
|
|
319
|
+
const timestamp = Math.floor(Date.now() / 1000);
|
|
320
|
+
payload.timestamp = String(timestamp);
|
|
321
|
+
payload.sign = feishuSign(timestamp, secret);
|
|
322
|
+
}
|
|
323
|
+
return sendHttp(http, { url, method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) }, 'feishu', signal, timeoutMs);
|
|
324
|
+
},
|
|
325
|
+
|
|
302
326
|
async telegram({ task, runInfo, settings, secrets, http, signal, timeoutMs }) {
|
|
303
327
|
const botToken = secrets.botToken || '';
|
|
304
328
|
const chatId = String(settings.chatId || '').trim();
|
|
@@ -23,7 +23,7 @@ window.__ModuleLoader__.load({
|
|
|
23
23
|
let pendingTaskHighlight = null;
|
|
24
24
|
const VIEW_ATTR = 'data-dsh-cron-view';
|
|
25
25
|
const COLUMN_SELECTOR = '[data-pane=conversation], [class*=centerCol]';
|
|
26
|
-
const
|
|
26
|
+
const PANEL_OWNED_SELECTOR = '[' + VIEW_ATTR + '], [data-dsh-plugin="dsh-cron"]';
|
|
27
27
|
const SCRIPT_CONFIRM_HEADER = 'x-dsh-cron-confirm';
|
|
28
28
|
|
|
29
29
|
const BACK_ICON = '<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 3.5 5.5 8l4.5 4.5"/></svg>';
|
|
@@ -128,6 +128,7 @@
|
|
|
128
128
|
'form.templateLabel': 'Message template (optional)',
|
|
129
129
|
'form.templatePlaceholder': '⏰ {title} — {status} in {duration}',
|
|
130
130
|
'form.templateHint': 'Variables: {title} {id} {status} {output} {error} {duration} {schedule} {time} {tokens} {cost} {model}. Empty = built-in text.',
|
|
131
|
+
'form.channelFeishu': 'Feishu (Lark)', 'settings.feishuWebhookLabel': 'Feishu webhook URL', 'settings.feishuWebhookPlaceholder': 'https://open.feishu.cn/open-apis/bot/v2/hook/...', 'settings.feishuSecretLabel': 'Signing secret (optional)', 'settings.feishuSecretPlaceholder': 'SEC...', 'settings.feishuGlobalNotify': 'Deliver every run report to Feishu', 'settings.feishuHint': 'Feishu group notification: add a custom bot to the group and paste its webhook URL here. If the bot enables signature verification, paste the signing secret below as well.',
|
|
131
132
|
'form.channelTelegram': 'Telegram', 'form.channelKanban': 'dsh-kanban card',
|
|
132
133
|
'form.channelDiscord': 'Discord', 'form.channelSlack': 'Slack',
|
|
133
134
|
'form.channelNtfy': 'ntfy', 'form.channelBark': 'Bark',
|
|
@@ -360,6 +361,7 @@
|
|
|
360
361
|
'form.notifyOnlyFailure': '仅失败时发送(onlyOnFailure / 成功静默)', 'form.channelsTitle': '推送渠道',
|
|
361
362
|
'form.channelsHint': '任务执行完毕后推送报告的目标渠道。', 'form.templateLabel': '自定义消息模板',
|
|
362
363
|
'form.templatePlaceholder': '⏰ {title} — {status},耗时 {duration}', 'form.templateHint': '可用变量: {title} {id} {status} {output} {error} {duration} {schedule} {time} {tokens} {cost} {model}。留空使用内置文案。',
|
|
364
|
+
'form.channelFeishu': 'Feishu (Lark)', 'settings.feishuWebhookLabel': 'Feishu webhook URL', 'settings.feishuWebhookPlaceholder': 'https://open.feishu.cn/open-apis/bot/v2/hook/...', 'settings.feishuSecretLabel': 'Signing secret (optional)', 'settings.feishuSecretPlaceholder': 'SEC...', 'settings.feishuGlobalNotify': 'Deliver every run report to Feishu', 'settings.feishuHint': 'Feishu group notification: add a custom bot to the group and paste its webhook URL here. If the bot enables signature verification, paste the signing secret below as well.',
|
|
363
365
|
'form.channelTelegram': 'Telegram', 'form.channelKanban': 'dsh-kanban 卡片',
|
|
364
366
|
'form.channelDiscord': 'Discord', 'form.channelSlack': 'Slack',
|
|
365
367
|
'form.channelNtfy': 'ntfy', 'form.channelBark': 'Bark',
|
|
@@ -36,8 +36,9 @@
|
|
|
36
36
|
const CODE_FORM_TYPES = ['script', 'node', 'python', 'ssh', 'docker'];
|
|
37
37
|
|
|
38
38
|
// Delivery channels (#26) — must stay in sync with lib/channels.js.
|
|
39
|
-
const DELIVERY_CHANNELS = ['telegram', 'kanban', 'discord', 'slack', 'ntfy', 'bark', 'pushplus', 'tts', 'gitea'];
|
|
39
|
+
const DELIVERY_CHANNELS = ['feishu', 'telegram', 'kanban', 'discord', 'slack', 'ntfy', 'bark', 'pushplus', 'tts', 'gitea'];
|
|
40
40
|
const CHANNEL_LABEL_KEYS = {
|
|
41
|
+
feishu: 'form.channelFeishu',
|
|
41
42
|
telegram: 'form.channelTelegram',
|
|
42
43
|
kanban: 'form.channelKanban',
|
|
43
44
|
discord: 'form.channelDiscord',
|
|
@@ -99,6 +100,18 @@
|
|
|
99
100
|
|
|
100
101
|
// Status colors: core semantic state tokens first (same set dsh-clinebot
|
|
101
102
|
// uses), plugin fallbacks as a single point of change (#105).
|
|
103
|
+
|
|
104
|
+
function shouldDismissPanel(target) {
|
|
105
|
+
if (target === null || target === undefined) return false;
|
|
106
|
+
if (typeof target.closest !== 'function') return false;
|
|
107
|
+
return target.closest(PANEL_OWNED_SELECTOR) === null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function sidebarJobsSeatIsCurrent(state, entry) {
|
|
111
|
+
const root = state && state.root;
|
|
112
|
+
return root !== undefined && root.isConnected && entry !== null && root.previousElementSibling === entry;
|
|
113
|
+
}
|
|
114
|
+
|
|
102
115
|
function createToggle() {
|
|
103
116
|
let open = false;
|
|
104
117
|
const listeners = new Set();
|
|
@@ -214,6 +227,7 @@
|
|
|
214
227
|
}
|
|
215
228
|
try {
|
|
216
229
|
const res = await fetch(url, {
|
|
230
|
+
credentials: 'same-origin',
|
|
217
231
|
...options,
|
|
218
232
|
signal: controller ? controller.signal : (options ? options.signal : undefined),
|
|
219
233
|
});
|
|
@@ -97,8 +97,8 @@
|
|
|
97
97
|
|
|
98
98
|
/** Keep the section mounted under the sidebar entry across re-renders. */
|
|
99
99
|
function placeSidebarJobs(state, label) {
|
|
100
|
-
if (state.root !== undefined && state.root.isConnected) return;
|
|
101
100
|
const entry = document.querySelector('[' + ENTRY_ATTR + ']');
|
|
101
|
+
if (sidebarJobsSeatIsCurrent(state, entry)) return;
|
|
102
102
|
if (entry === null || entry.parentElement === null) return;
|
|
103
103
|
if (state.root === undefined) {
|
|
104
104
|
entry.insertAdjacentElement('afterend', buildSidebarJobsRoot(state, label));
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
|
|
128
128
|
let rafPending = false;
|
|
129
129
|
const schedulePlace = () => {
|
|
130
|
-
if (state.
|
|
130
|
+
if (sidebarJobsSeatIsCurrent(state, document.querySelector('[' + ENTRY_ATTR + ']'))) return;
|
|
131
131
|
if (rafPending) return;
|
|
132
132
|
rafPending = true;
|
|
133
133
|
const scheduleFn = typeof requestAnimationFrame === 'function' ? requestAnimationFrame : (cb) => setTimeout(cb, 16);
|
|
@@ -51,16 +51,16 @@
|
|
|
51
51
|
const onOtherActivate = (event) => {
|
|
52
52
|
if (event.detail !== PANEL && toggle.isOpen()) toggle.set(false);
|
|
53
53
|
};
|
|
54
|
-
const
|
|
54
|
+
const onOutsideClick = (event) => {
|
|
55
55
|
if (!toggle.isOpen()) return;
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
if (!shouldDismissPanel(event.target)) return;
|
|
57
|
+
toggle.set(false);
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
const waitObserver = new MutationObserver(ensure);
|
|
61
61
|
waitObserver.observe(document.body, { childList: true, subtree: true });
|
|
62
62
|
document.addEventListener(ACTIVATE_EVENT, onOtherActivate);
|
|
63
|
-
document.addEventListener('click',
|
|
63
|
+
document.addEventListener('click', onOutsideClick, true);
|
|
64
64
|
const unsubscribe = toggle.subscribe(applyActive);
|
|
65
65
|
applyActive();
|
|
66
66
|
ensure();
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
return () => {
|
|
69
69
|
waitObserver.disconnect();
|
|
70
70
|
document.removeEventListener(ACTIVATE_EVENT, onOtherActivate);
|
|
71
|
-
document.removeEventListener('click',
|
|
71
|
+
document.removeEventListener('click', onOutsideClick, true);
|
|
72
72
|
unsubscribe();
|
|
73
73
|
document.documentElement.removeAttribute(ACTIVE_ATTR);
|
|
74
74
|
teardownPanel();
|
|
@@ -174,6 +174,7 @@
|
|
|
174
174
|
const chipT = props.t || translate;
|
|
175
175
|
return React.createElement('button', {
|
|
176
176
|
type: 'button',
|
|
177
|
+
'data-dsh-plugin': 'dsh-cron',
|
|
177
178
|
style: { background: 'none', border: 'none', color: 'var(--dsw-alias-label-secondary, #999)', cursor: 'pointer', padding: '4px', display: 'inline-flex', alignItems: 'center' },
|
|
178
179
|
title: T_KEY(chipT, 'chip.title'),
|
|
179
180
|
'aria-label': T_KEY(chipT, 'chip.title'),
|
|
@@ -192,6 +193,8 @@
|
|
|
192
193
|
}, 'dsh-cron: client overlay');
|
|
193
194
|
|
|
194
195
|
exports.slots = { card: cardSlot, chip: chipSlot };
|
|
196
|
+
module.exports.panelDismissRule = shouldDismissPanel;
|
|
197
|
+
module.exports.sidebarJobsSeatIsCurrent = sidebarJobsSeatIsCurrent;
|
|
195
198
|
}
|
|
196
199
|
|
|
197
200
|
module.exports = { apply, inject: ['slots', 'locale'] };
|
package/lib/client.js
CHANGED
|
@@ -17,7 +17,7 @@ const ENTRY_ATTR = 'data-dsh-cron-entry';
|
|
|
17
17
|
let pendingTaskHighlight = null;
|
|
18
18
|
const VIEW_ATTR = 'data-dsh-cron-view';
|
|
19
19
|
const COLUMN_SELECTOR = '[data-pane=conversation], [class*=centerCol]';
|
|
20
|
-
const
|
|
20
|
+
const PANEL_OWNED_SELECTOR = '[' + VIEW_ATTR + '], [data-dsh-plugin="dsh-cron"]';
|
|
21
21
|
const SCRIPT_CONFIRM_HEADER = 'x-dsh-cron-confirm';
|
|
22
22
|
const BACK_ICON = '<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 3.5 5.5 8l4.5 4.5"/></svg>';
|
|
23
23
|
const ICON_TIMER = '<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"></circle><polyline points="12 6 12 12 16 14"></polyline></svg>';
|
|
@@ -174,6 +174,7 @@ en: {
|
|
|
174
174
|
'form.templateLabel': 'Message template (optional)',
|
|
175
175
|
'form.templatePlaceholder': '⏰ {title} — {status} in {duration}',
|
|
176
176
|
'form.templateHint': 'Variables: {title} {id} {status} {output} {error} {duration} {schedule} {time} {tokens} {cost} {model}. Empty = built-in text.',
|
|
177
|
+
'form.channelFeishu': 'Feishu (Lark)', 'settings.feishuWebhookLabel': 'Feishu webhook URL', 'settings.feishuWebhookPlaceholder': 'https://open.feishu.cn/open-apis/bot/v2/hook/...', 'settings.feishuSecretLabel': 'Signing secret (optional)', 'settings.feishuSecretPlaceholder': 'SEC...', 'settings.feishuGlobalNotify': 'Deliver every run report to Feishu', 'settings.feishuHint': 'Feishu group notification: add a custom bot to the group and paste its webhook URL here. If the bot enables signature verification, paste the signing secret below as well.',
|
|
177
178
|
'form.channelTelegram': 'Telegram', 'form.channelKanban': 'dsh-kanban card',
|
|
178
179
|
'form.channelDiscord': 'Discord', 'form.channelSlack': 'Slack',
|
|
179
180
|
'form.channelNtfy': 'ntfy', 'form.channelBark': 'Bark',
|
|
@@ -405,6 +406,7 @@ zh: {
|
|
|
405
406
|
'form.notifyOnlyFailure': '仅失败时发送(onlyOnFailure / 成功静默)', 'form.channelsTitle': '推送渠道',
|
|
406
407
|
'form.channelsHint': '任务执行完毕后推送报告的目标渠道。', 'form.templateLabel': '自定义消息模板',
|
|
407
408
|
'form.templatePlaceholder': '⏰ {title} — {status},耗时 {duration}', 'form.templateHint': '可用变量: {title} {id} {status} {output} {error} {duration} {schedule} {time} {tokens} {cost} {model}。留空使用内置文案。',
|
|
409
|
+
'form.channelFeishu': 'Feishu (Lark)', 'settings.feishuWebhookLabel': 'Feishu webhook URL', 'settings.feishuWebhookPlaceholder': 'https://open.feishu.cn/open-apis/bot/v2/hook/...', 'settings.feishuSecretLabel': 'Signing secret (optional)', 'settings.feishuSecretPlaceholder': 'SEC...', 'settings.feishuGlobalNotify': 'Deliver every run report to Feishu', 'settings.feishuHint': 'Feishu group notification: add a custom bot to the group and paste its webhook URL here. If the bot enables signature verification, paste the signing secret below as well.',
|
|
408
410
|
'form.channelTelegram': 'Telegram', 'form.channelKanban': 'dsh-kanban 卡片',
|
|
409
411
|
'form.channelDiscord': 'Discord', 'form.channelSlack': 'Slack',
|
|
410
412
|
'form.channelNtfy': 'ntfy', 'form.channelBark': 'Bark',
|
|
@@ -612,8 +614,9 @@ return (this.props && this.props.children) || null;
|
|
|
612
614
|
const ErrorBoundary = createErrorBoundary();
|
|
613
615
|
const AGENT_FORM_TYPES = ['llm', 'skill', 'workflow'];
|
|
614
616
|
const CODE_FORM_TYPES = ['script', 'node', 'python', 'ssh', 'docker'];
|
|
615
|
-
const DELIVERY_CHANNELS = ['telegram', 'kanban', 'discord', 'slack', 'ntfy', 'bark', 'pushplus', 'tts', 'gitea'];
|
|
617
|
+
const DELIVERY_CHANNELS = ['feishu', 'telegram', 'kanban', 'discord', 'slack', 'ntfy', 'bark', 'pushplus', 'tts', 'gitea'];
|
|
616
618
|
const CHANNEL_LABEL_KEYS = {
|
|
619
|
+
feishu: 'form.channelFeishu',
|
|
617
620
|
telegram: 'form.channelTelegram',
|
|
618
621
|
kanban: 'form.channelKanban',
|
|
619
622
|
discord: 'form.channelDiscord',
|
|
@@ -663,6 +666,15 @@ function formatEnvText(env) {
|
|
|
663
666
|
if (!env || typeof env !== 'object') return '';
|
|
664
667
|
return Object.entries(env).map(([k, v]) => `${k}=${v}`).join('\n');
|
|
665
668
|
}
|
|
669
|
+
function shouldDismissPanel(target) {
|
|
670
|
+
if (target === null || target === undefined) return false;
|
|
671
|
+
if (typeof target.closest !== 'function') return false;
|
|
672
|
+
return target.closest(PANEL_OWNED_SELECTOR) === null;
|
|
673
|
+
}
|
|
674
|
+
function sidebarJobsSeatIsCurrent(state, entry) {
|
|
675
|
+
const root = state && state.root;
|
|
676
|
+
return root !== undefined && root.isConnected && entry !== null && root.previousElementSibling === entry;
|
|
677
|
+
}
|
|
666
678
|
function createToggle() {
|
|
667
679
|
let open = false;
|
|
668
680
|
const listeners = new Set();
|
|
@@ -757,6 +769,7 @@ options.signal.addEventListener('abort', () => controller.abort(), { once: true
|
|
|
757
769
|
}
|
|
758
770
|
try {
|
|
759
771
|
const res = await fetch(url, {
|
|
772
|
+
credentials: 'same-origin',
|
|
760
773
|
...options,
|
|
761
774
|
signal: controller ? controller.signal : (options ? options.signal : undefined),
|
|
762
775
|
});
|
|
@@ -5096,8 +5109,8 @@ state.listEl = listEl;
|
|
|
5096
5109
|
return root;
|
|
5097
5110
|
}
|
|
5098
5111
|
function placeSidebarJobs(state, label) {
|
|
5099
|
-
if (state.root !== undefined && state.root.isConnected) return;
|
|
5100
5112
|
const entry = document.querySelector('[' + ENTRY_ATTR + ']');
|
|
5113
|
+
if (sidebarJobsSeatIsCurrent(state, entry)) return;
|
|
5101
5114
|
if (entry === null || entry.parentElement === null) return;
|
|
5102
5115
|
if (state.root === undefined) {
|
|
5103
5116
|
entry.insertAdjacentElement('afterend', buildSidebarJobsRoot(state, label));
|
|
@@ -5115,7 +5128,7 @@ const state = { toggle, openTaskSignal, root: undefined, listEl: undefined, head
|
|
|
5115
5128
|
try { state.open = window.localStorage.getItem(SIDEBAR_JOBS_KEY) === '1'; } catch (err) { /* localStorage read failed */ }
|
|
5116
5129
|
let rafPending = false;
|
|
5117
5130
|
const schedulePlace = () => {
|
|
5118
|
-
if (state.
|
|
5131
|
+
if (sidebarJobsSeatIsCurrent(state, document.querySelector('[' + ENTRY_ATTR + ']'))) return;
|
|
5119
5132
|
if (rafPending) return;
|
|
5120
5133
|
rafPending = true;
|
|
5121
5134
|
const scheduleFn = typeof requestAnimationFrame === 'function' ? requestAnimationFrame : (cb) => setTimeout(cb, 16);
|
|
@@ -5225,22 +5238,22 @@ teardownPanel();
|
|
|
5225
5238
|
const onOtherActivate = (event) => {
|
|
5226
5239
|
if (event.detail !== PANEL && toggle.isOpen()) toggle.set(false);
|
|
5227
5240
|
};
|
|
5228
|
-
const
|
|
5241
|
+
const onOutsideClick = (event) => {
|
|
5229
5242
|
if (!toggle.isOpen()) return;
|
|
5230
|
-
|
|
5231
|
-
|
|
5243
|
+
if (!shouldDismissPanel(event.target)) return;
|
|
5244
|
+
toggle.set(false);
|
|
5232
5245
|
};
|
|
5233
5246
|
const waitObserver = new MutationObserver(ensure);
|
|
5234
5247
|
waitObserver.observe(document.body, { childList: true, subtree: true });
|
|
5235
5248
|
document.addEventListener(ACTIVATE_EVENT, onOtherActivate);
|
|
5236
|
-
document.addEventListener('click',
|
|
5249
|
+
document.addEventListener('click', onOutsideClick, true);
|
|
5237
5250
|
const unsubscribe = toggle.subscribe(applyActive);
|
|
5238
5251
|
applyActive();
|
|
5239
5252
|
ensure();
|
|
5240
5253
|
return () => {
|
|
5241
5254
|
waitObserver.disconnect();
|
|
5242
5255
|
document.removeEventListener(ACTIVATE_EVENT, onOtherActivate);
|
|
5243
|
-
document.removeEventListener('click',
|
|
5256
|
+
document.removeEventListener('click', onOutsideClick, true);
|
|
5244
5257
|
unsubscribe();
|
|
5245
5258
|
document.documentElement.removeAttribute(ACTIVE_ATTR);
|
|
5246
5259
|
teardownPanel();
|
|
@@ -5318,6 +5331,7 @@ function CronChip(props) {
|
|
|
5318
5331
|
const chipT = props.t || translate;
|
|
5319
5332
|
return _h('button', {
|
|
5320
5333
|
type: 'button',
|
|
5334
|
+
'data-dsh-plugin': 'dsh-cron',
|
|
5321
5335
|
style: { background: 'none', border: 'none', color: 'var(--dsw-alias-label-secondary, #999)', cursor: 'pointer', padding: '4px', display: 'inline-flex', alignItems: 'center' },
|
|
5322
5336
|
title: T_KEY(chipT, 'chip.title'),
|
|
5323
5337
|
'aria-label': T_KEY(chipT, 'chip.title'),
|
|
@@ -5334,6 +5348,8 @@ mountCronScreen(ctx, toggle)
|
|
|
5334
5348
|
return () => { for (const dispose of off) dispose(); stopStyleSelfHeal(); };
|
|
5335
5349
|
}, 'dsh-cron: client overlay');
|
|
5336
5350
|
exports.slots = { card: cardSlot, chip: chipSlot };
|
|
5351
|
+
module.exports.panelDismissRule = shouldDismissPanel;
|
|
5352
|
+
module.exports.sidebarJobsSeatIsCurrent = sidebarJobsSeatIsCurrent;
|
|
5337
5353
|
}
|
|
5338
5354
|
module.exports = { apply, inject: ['slots', 'locale'] };
|
|
5339
5355
|
return module.exports;
|
package/lib/http-utils.js
CHANGED
|
@@ -121,6 +121,70 @@ export function getDshConnection(req, options = {}) {
|
|
|
121
121
|
* Requests with missing socket / missing remoteAddress and no token are rejected (401).
|
|
122
122
|
* 5. Origin and Sec-Fetch-Site: cannot be null, Origin host must match Host, Sec-Fetch-Site must be same-origin or none.
|
|
123
123
|
*/
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Check if request contains non-loopback forwarding headers (e.g. proxied from LAN/Tailscale) (#371, GH #20).
|
|
127
|
+
*/
|
|
128
|
+
export function hasNonLoopbackForwarding(req) {
|
|
129
|
+
const xff = req?.headers?.['x-forwarded-for'];
|
|
130
|
+
if (xff && typeof xff === 'string') {
|
|
131
|
+
const ips = xff.split(',').map((s) => s.trim());
|
|
132
|
+
if (ips.some((ip) => ip && !isLoopbackAddress(ip))) return true;
|
|
133
|
+
}
|
|
134
|
+
const xRealIp = req?.headers?.['x-real-ip'];
|
|
135
|
+
if (xRealIp && typeof xRealIp === 'string' && !isLoopbackAddress(xRealIp.trim())) {
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Check whether an incoming HTTP request carries a DeepSeek Harness session cookie (#295, GH #20).
|
|
143
|
+
* DSH core sets 'dsh-auth-<hash>=v1...' as a SameSite=Strict HttpOnly cookie.
|
|
144
|
+
*/
|
|
145
|
+
export function hasDshAuthCookie(req) {
|
|
146
|
+
if (!req || !req.headers) return false;
|
|
147
|
+
const cookie = String(req.headers.cookie || '');
|
|
148
|
+
return cookie.includes('dsh-auth-');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Check whether an incoming HTTP request originates from an authentic local Desktop shell (GH #20).
|
|
153
|
+
* Verified against local loopback socket, absence of external proxy forwarding, and
|
|
154
|
+
* authentic Desktop shell signatures (UA @deepseek-ai/dsh-desktop/ or dsh-desktop,
|
|
155
|
+
* dsh-auth- cookie, host 'app', or internal auth headers).
|
|
156
|
+
*/
|
|
157
|
+
export function isDesktopShellRequest(req) {
|
|
158
|
+
if (!req || !req.headers) return false;
|
|
159
|
+
if (hasNonLoopbackForwarding(req)) return false;
|
|
160
|
+
|
|
161
|
+
const remote = req.socket?.remoteAddress || req.connection?.remoteAddress || '';
|
|
162
|
+
if (!isLoopbackAddress(remote)) return false;
|
|
163
|
+
|
|
164
|
+
const agent = String(req.headers['user-agent'] || '');
|
|
165
|
+
const cookie = String(req.headers.cookie || '');
|
|
166
|
+
const host = String(req.headers.host || '').trim().toLowerCase().split(':')[0];
|
|
167
|
+
|
|
168
|
+
// 1. Desktop shell User-Agent and/or session cookie
|
|
169
|
+
if (agent.includes('@deepseek-ai/dsh-desktop/') || agent.includes('dsh-desktop') || agent.includes('electron')) {
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
if (hasDshAuthCookie(req)) {
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// 2. Custom desktop scheme Host or explicit desktop internal auth headers
|
|
177
|
+
if (host === 'app') {
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
const internalAuth = req.headers['x-dsh-internal-auth'] || req.headers['x-dsh-desktop'];
|
|
181
|
+
if (internalAuth === 'true' || internalAuth === '1') {
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
|
|
124
188
|
export function getRequestRejection(req, options = {}) {
|
|
125
189
|
if (!req) return 403;
|
|
126
190
|
|
|
@@ -151,17 +215,23 @@ export function getRequestRejection(req, options = {}) {
|
|
|
151
215
|
|
|
152
216
|
// 3. Validate Origin header if present: cannot be null, host must match Host (CSRF guard)
|
|
153
217
|
if (origin !== undefined) {
|
|
154
|
-
if (origin === 'null'
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (parsed.protocol === 'dsh-app:') {
|
|
158
|
-
const appHost = parsed.host.toLowerCase();
|
|
159
|
-
if (appHost && appHost !== 'app' && appHost !== 'localhost') return 403;
|
|
160
|
-
} else {
|
|
161
|
-
if (!parsed.host || !host || parsed.host.toLowerCase() !== host.toLowerCase()) return 403;
|
|
162
|
-
}
|
|
163
|
-
} catch {
|
|
218
|
+
if (origin === 'null') {
|
|
219
|
+
if (!isDesktopShellRequest(req)) return 403;
|
|
220
|
+
} else if (!origin) {
|
|
164
221
|
return 403;
|
|
222
|
+
} else {
|
|
223
|
+
try {
|
|
224
|
+
const parsed = new URL(origin);
|
|
225
|
+
if (parsed.protocol === 'dsh-app:') {
|
|
226
|
+
const appHost = parsed.host.toLowerCase();
|
|
227
|
+
if (appHost && appHost !== 'app' && appHost !== 'localhost') return 403;
|
|
228
|
+
if (hasNonLoopbackForwarding(req)) return 403;
|
|
229
|
+
} else {
|
|
230
|
+
if (!parsed.host || !host || parsed.host.toLowerCase() !== host.toLowerCase()) return 403;
|
|
231
|
+
}
|
|
232
|
+
} catch {
|
|
233
|
+
return 403;
|
|
234
|
+
}
|
|
165
235
|
}
|
|
166
236
|
}
|
|
167
237
|
|
|
@@ -202,11 +272,15 @@ export function getRequestRejection(req, options = {}) {
|
|
|
202
272
|
const isTasksRead = !isMutating && (urlStr === '/dsh-cron/tasks' || urlStr.startsWith('/dsh-cron/tasks?') || urlStr === '/tasks' || urlStr.startsWith('/tasks?'));
|
|
203
273
|
|
|
204
274
|
const hostStr = host.toLowerCase().split(':')[0];
|
|
205
|
-
const isLoopbackHost = hostStr === '' || hostStr === 'localhost' || hostStr === '127.0.0.1' || hostStr === '::1';
|
|
275
|
+
const isLoopbackHost = hostStr === '' || hostStr === 'localhost' || hostStr === '127.0.0.1' || hostStr === '::1' || hostStr === 'app';
|
|
206
276
|
const requireSource = Boolean(options.requireSource || isMutating || (isTasksRead && !isLoopbackHost));
|
|
207
277
|
|
|
208
278
|
if (requireSource) {
|
|
209
279
|
if (!origin && !referer) {
|
|
280
|
+
// GH #20: Allow authentic local Desktop shell requests lacking Origin/Referer
|
|
281
|
+
if (isDesktopShellRequest(req)) {
|
|
282
|
+
return undefined; // Admitted Desktop shell
|
|
283
|
+
}
|
|
210
284
|
return 403;
|
|
211
285
|
}
|
|
212
286
|
if (!origin && referer) {
|
|
@@ -215,6 +289,7 @@ export function getRequestRejection(req, options = {}) {
|
|
|
215
289
|
if (parsedRef.protocol === 'dsh-app:') {
|
|
216
290
|
const appHost = parsedRef.host.toLowerCase();
|
|
217
291
|
if (appHost && appHost !== 'app' && appHost !== 'localhost') return 403;
|
|
292
|
+
if (hasNonLoopbackForwarding(req)) return 403;
|
|
218
293
|
} else {
|
|
219
294
|
if (!parsedRef.host || !host || parsedRef.host.toLowerCase() !== host.toLowerCase()) {
|
|
220
295
|
return 403;
|
package/lib/locales.json
CHANGED
|
@@ -398,6 +398,13 @@
|
|
|
398
398
|
"settings.templateLabel": "默认消息模板",
|
|
399
399
|
"settings.templateHint": "作用于所有没有单独模板的渠道。留空用内置文案。",
|
|
400
400
|
"settings.deliveryTimeoutMsLabel": "每个渠道的推送超时(毫秒)",
|
|
401
|
-
"settings.automationSection": "自动化模型"
|
|
401
|
+
"settings.automationSection": "自动化模型",
|
|
402
|
+
"form.channelFeishu": "飞书 (Feishu)",
|
|
403
|
+
"settings.feishuWebhookLabel": "飞书 Webhook 地址",
|
|
404
|
+
"settings.feishuWebhookPlaceholder": "https://open.feishu.cn/open-apis/bot/v2/hook/…",
|
|
405
|
+
"settings.feishuSecretLabel": "签名密钥(可选)",
|
|
406
|
+
"settings.feishuSecretPlaceholder": "SEC…",
|
|
407
|
+
"settings.feishuGlobalNotify": "所有任务的运行结果都推送到飞书",
|
|
408
|
+
"settings.feishuHint": "飞书群通知:在目标群里添加「自定义机器人」,把它的 Webhook 地址粘贴到下面;如果机器人开启了「签名校验」,再把签名密钥一并填入。"
|
|
402
409
|
}
|
|
403
410
|
}
|
package/lib/settings.js
CHANGED
|
@@ -31,6 +31,10 @@ export const Config = z.object({
|
|
|
31
31
|
silentRuleModel: z.string().default('').description('Model used to evaluate a task silent rule (empty = the task model)').volatile(),
|
|
32
32
|
inspectorModel: z.string().default('').description('Model used to diagnose failed runs (empty = the task model)').volatile(),
|
|
33
33
|
deliveryTimeoutMs: z.number().min(MIN_DELIVERY_TIMEOUT_MS).default(15000).description('Per-channel delivery timeout in ms (minimum 1000); a slower endpoint is recorded as a failure and does not block other channels or the next tick').volatile(),
|
|
34
|
+
notifyFeishu: z.boolean().default(false).description('Deliver task reports to Feishu for every task').volatile(),
|
|
35
|
+
feishuWebhookUrl: z.string().default('').description('Feishu custom-bot webhook URL').volatile(),
|
|
36
|
+
feishuSecret: z.string().role('secret').default('').description('Feishu custom-bot signing secret').volatile(),
|
|
37
|
+
feishuSecretRef: z.string().default('').description('Credential name for Feishu signing secret').volatile(),
|
|
34
38
|
discordWebhookUrl: z.string().default('').description('Discord webhook URL').volatile(),
|
|
35
39
|
slackWebhookUrl: z.string().default('').description('Slack incoming webhook URL').volatile(),
|
|
36
40
|
ntfyUrl: z.string().default('https://ntfy.sh').description('ntfy server base URL').volatile(),
|
|
@@ -78,6 +82,7 @@ export const unwrapConfigValue = plainConfig;
|
|
|
78
82
|
export const unwrapConfig = plainConfig;
|
|
79
83
|
|
|
80
84
|
export const SETTINGS_SYNC_KEYS = [
|
|
85
|
+
'notifyFeishu', 'feishuWebhookUrl', 'feishuSecret', 'feishuSecretRef',
|
|
81
86
|
'botToken', 'botTokenRef', 'telegramWebhookSecret', 'chatId', 'notifyTelegram', 'onlyOnFailure', 'kanbanBaseUrl',
|
|
82
87
|
'defaultTimezone', 'maxConcurrent', 'heartbeatUrl', 'heartbeatIntervalSec', 'llmActionsEnabled',
|
|
83
88
|
'template', 'channelTemplates', 'deliveryTimeoutMs', 'silentRuleModel', 'inspectorModel',
|
package/lib/tui-settings.js
CHANGED
|
@@ -61,6 +61,23 @@ export function buildTuiSection({ live, store }) {
|
|
|
61
61
|
format: textFormat,
|
|
62
62
|
parse: textParse,
|
|
63
63
|
},
|
|
64
|
+
{
|
|
65
|
+
path: ['feishuWebhookUrl'],
|
|
66
|
+
group: 'delivery',
|
|
67
|
+
kind: 'text',
|
|
68
|
+
label: 'Feishu Webhook URL',
|
|
69
|
+
placeholder: 'https://open.feishu.cn/open-apis/bot/v2/hook/...',
|
|
70
|
+
format: textFormat,
|
|
71
|
+
parse: textParse,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
path: ['feishuSecret'],
|
|
75
|
+
group: 'delivery',
|
|
76
|
+
kind: 'text',
|
|
77
|
+
label: 'Feishu Signing Secret',
|
|
78
|
+
secret: { ref: current.feishuSecretRef || 'FEISHU_SECRET' },
|
|
79
|
+
hint: 'Signing secret for Feishu custom-bot verification.',
|
|
80
|
+
},
|
|
64
81
|
{
|
|
65
82
|
path: ['discordWebhookUrl'],
|
|
66
83
|
group: 'delivery',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodandready/dsh-cron",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.29",
|
|
4
4
|
"description": "Background automation runner for DSH: isolated agent runs, script/HTTP/SSH/Docker runtimes, cost guard, notifications, heartbeats.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|