@goodandready/dsh-cron 0.3.43 → 0.3.44
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/client.js +998 -3987
- package/lib/llm-ask.js +2 -1
- package/lib/routes/api-actions.js +36 -6
- package/lib/routes/api-item.js +1 -1
- package/lib/routes/api-webhook.js +2 -4
- package/lib/runtimes/runner-external.js +2 -3
- package/lib/runtimes/runner-session.js +385 -0
- package/lib/runtimes/runner-turn.js +255 -0
- package/lib/runtimes/runner.js +43 -616
- package/lib/scheduler/scheduler-execution.js +4 -1
- package/lib/scheduler/scheduler-lifecycle.js +65 -0
- package/lib/scheduler/scheduler-parser.js +261 -0
- package/lib/scheduler/scheduler.js +13 -319
- package/lib/store/store-archive.js +195 -0
- package/lib/store/store-io.js +331 -0
- package/lib/store/store-loader.js +165 -0
- package/lib/store/store-migration.js +38 -0
- package/lib/store/store-settings.js +126 -0
- package/lib/store/store-stats.js +55 -0
- package/lib/store/store.js +75 -888
- package/package.json +8 -6
- package/lib/client-src/00-open.js +0 -63
- package/lib/client-src/10-locales.js +0 -540
- package/lib/client-src/20-styles.js +0 -64
- package/lib/client-src/30-utils.js +0 -372
- package/lib/client-src/40-delivery-settings.js +0 -96
- package/lib/client-src/45-dag-graph-view.js +0 -287
- package/lib/client-src/46-live-logs-modal.js +0 -108
- package/lib/client-src/47-analytics-digest-modal.js +0 -166
- package/lib/client-src/48-timeline-heatmap-view.js +0 -176
- package/lib/client-src/50-cron-screen-state.js +0 -457
- package/lib/client-src/52-cron-screen-actions.js +0 -330
- package/lib/client-src/53-cron-screen-modal-actions.js +0 -677
- package/lib/client-src/54-cron-screen-analytics-actions.js +0 -68
- package/lib/client-src/55-cron-screen-view.js +0 -378
- package/lib/client-src/60-modal-task-form-head.js +0 -581
- package/lib/client-src/62-modal-task-form-tail.js +0 -563
- package/lib/client-src/65-modal-dialogs.js +0 -350
- package/lib/client-src/70-settings-card.js +0 -453
- package/lib/client-src/75-quick-action-bar.js +0 -146
- package/lib/client-src/80-sidebar-jobs.js +0 -200
- package/lib/client-src/90-close.js +0 -219
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
const STYLE_ID = 'dsh-cron-styles';
|
|
2
|
-
const CSS_HREF = '/dsh-cron/client.css';
|
|
3
|
-
|
|
4
|
-
function ensureStyles() {
|
|
5
|
-
if (typeof document === 'undefined') return null;
|
|
6
|
-
let el = document.getElementById(STYLE_ID);
|
|
7
|
-
if (el === null) {
|
|
8
|
-
const head = document.head || document.documentElement;
|
|
9
|
-
if (!head) return null;
|
|
10
|
-
el = document.createElement('link');
|
|
11
|
-
el.id = STYLE_ID;
|
|
12
|
-
el.rel = 'stylesheet';
|
|
13
|
-
el.href = CSS_HREF;
|
|
14
|
-
// Mark ownership before insertion so neighbor cleanups leave it alone (#91)
|
|
15
|
-
el.dataset.dshPlugin = 'dsh-cron';
|
|
16
|
-
head.appendChild(el);
|
|
17
|
-
return el;
|
|
18
|
-
}
|
|
19
|
-
if (el.getAttribute('href') !== CSS_HREF) {
|
|
20
|
-
el.setAttribute('href', CSS_HREF);
|
|
21
|
-
el.href = CSS_HREF;
|
|
22
|
-
}
|
|
23
|
-
return el;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Registry is shared across hot reloads so the newest instance owns exactly
|
|
27
|
-
// one watcher instead of stacking one per module evaluation.
|
|
28
|
-
const STYLE_HEAL_KEY = '__dshCronStyleHeal';
|
|
29
|
-
const STYLE_HEAL_INTERVAL_MS = 2000;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Keep the stylesheet attached: watch <head> (and <html>, which catches a
|
|
33
|
-
* replaced <head>) and re-attach on demand, with a slow interval as the
|
|
34
|
-
* backstop. heal() is idempotent and writes nothing while healthy.
|
|
35
|
-
*/
|
|
36
|
-
function startStyleSelfHeal() {
|
|
37
|
-
if (typeof document === 'undefined') return () => {};
|
|
38
|
-
if (typeof window !== 'undefined' && typeof window[STYLE_HEAL_KEY] === 'function') {
|
|
39
|
-
try { window[STYLE_HEAL_KEY](); } catch (_err) { void _err; }
|
|
40
|
-
}
|
|
41
|
-
const heal = () => { try { ensureStyles(); } catch (_err) { void _err; } };
|
|
42
|
-
heal();
|
|
43
|
-
let observer = null;
|
|
44
|
-
try {
|
|
45
|
-
if (typeof MutationObserver === 'function') {
|
|
46
|
-
observer = new MutationObserver(heal);
|
|
47
|
-
if (document.head) observer.observe(document.head, { childList: true });
|
|
48
|
-
if (document.documentElement) observer.observe(document.documentElement, { childList: true });
|
|
49
|
-
}
|
|
50
|
-
} catch (_err) { observer = null; }
|
|
51
|
-
let timer = null;
|
|
52
|
-
try { timer = setInterval(heal, STYLE_HEAL_INTERVAL_MS); } catch (_err) { timer = null; }
|
|
53
|
-
const onVisibility = () => { if (document.visibilityState !== 'hidden') heal(); };
|
|
54
|
-
try { document.addEventListener('visibilitychange', onVisibility); } catch (_err) { void _err; }
|
|
55
|
-
const stop = () => {
|
|
56
|
-
try { if (observer) observer.disconnect(); } catch (_err) { void _err; }
|
|
57
|
-
try { if (timer !== null) clearInterval(timer); } catch (_err) { void _err; }
|
|
58
|
-
try { document.removeEventListener('visibilitychange', onVisibility); } catch (_err) { void _err; }
|
|
59
|
-
if (typeof window !== 'undefined' && window[STYLE_HEAL_KEY] === stop) window[STYLE_HEAL_KEY] = undefined;
|
|
60
|
-
};
|
|
61
|
-
if (typeof window !== 'undefined') window[STYLE_HEAL_KEY] = stop;
|
|
62
|
-
return stop;
|
|
63
|
-
}
|
|
64
|
-
|
|
@@ -1,372 +0,0 @@
|
|
|
1
|
-
function createErrorBoundary() {
|
|
2
|
-
if (!React || typeof React.Component !== 'function') {
|
|
3
|
-
return function NoopBoundary(props) { return (props && props.children) || null; };
|
|
4
|
-
}
|
|
5
|
-
return class ErrorBoundary extends React.Component {
|
|
6
|
-
constructor(props) {
|
|
7
|
-
super(props);
|
|
8
|
-
this.state = { hasError: false, error: null };
|
|
9
|
-
}
|
|
10
|
-
static getDerivedStateFromError(error) {
|
|
11
|
-
return { hasError: true, error };
|
|
12
|
-
}
|
|
13
|
-
componentDidCatch(error, errorInfo) {
|
|
14
|
-
console.error('[dsh-cron] React error:', error, errorInfo);
|
|
15
|
-
}
|
|
16
|
-
render() {
|
|
17
|
-
if (this.state.hasError) {
|
|
18
|
-
return React.createElement('div', { className: 'dsh-cron-status-banner', 'data-type': 'error', style: { margin: '12px 0' } },
|
|
19
|
-
React.createElement('div', { style: { fontWeight: 600, marginBottom: '6px' } }, '⚠️ Cron UI error:'),
|
|
20
|
-
React.createElement('div', { style: { fontSize: '12px', wordBreak: 'break-all' } }, String((this.state.error && this.state.error.message) || this.state.error)),
|
|
21
|
-
React.createElement('button', {
|
|
22
|
-
type: 'button',
|
|
23
|
-
className: 'dsh-cron-btn-secondary',
|
|
24
|
-
style: { marginTop: '10px', fontSize: '12px', padding: '4px 10px' },
|
|
25
|
-
onClick: () => this.setState({ hasError: false, error: null })
|
|
26
|
-
}, 'Retry')
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
return (this.props && this.props.children) || null;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
const ErrorBoundary = createErrorBoundary();
|
|
34
|
-
|
|
35
|
-
const AGENT_FORM_TYPES = ['llm', 'skill', 'workflow'];
|
|
36
|
-
const CODE_FORM_TYPES = ['script', 'node', 'python', 'ssh', 'docker'];
|
|
37
|
-
|
|
38
|
-
// Delivery channels (#26) — must stay in sync with lib/channels.js.
|
|
39
|
-
const DELIVERY_CHANNELS = ['feishu', 'telegram', 'kanban', 'discord', 'slack', 'ntfy', 'bark', 'pushplus', 'tts', 'gitea'];
|
|
40
|
-
const CHANNEL_LABEL_KEYS = {
|
|
41
|
-
feishu: 'form.channelFeishu',
|
|
42
|
-
telegram: 'form.channelTelegram',
|
|
43
|
-
kanban: 'form.channelKanban',
|
|
44
|
-
discord: 'form.channelDiscord',
|
|
45
|
-
slack: 'form.channelSlack',
|
|
46
|
-
ntfy: 'form.channelNtfy',
|
|
47
|
-
bark: 'form.channelBark',
|
|
48
|
-
pushplus: 'form.channelPushplus',
|
|
49
|
-
tts: 'form.channelTts',
|
|
50
|
-
gitea: 'form.channelGitea',
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// Non-secret delivery settings shown in the settings panel. Secrets are
|
|
54
|
-
// referenced by credential name only (#51) — never typed as values.
|
|
55
|
-
const DELIVERY_SETTING_FIELDS = [
|
|
56
|
-
{ key: 'botTokenRef', labelKey: 'settings.botTokenRefLabel', placeholderKey: 'settings.botTokenRefPlaceholder', group: 'secrets' },
|
|
57
|
-
{ key: 'ntfyTokenRef', labelKey: 'settings.ntfyTokenRefLabel', group: 'secrets' },
|
|
58
|
-
{ key: 'pushplusTokenRef', labelKey: 'settings.pushplusTokenRefLabel', group: 'secrets' },
|
|
59
|
-
{ key: 'giteaTokenRef', labelKey: 'settings.giteaTokenRefLabel', group: 'secrets' },
|
|
60
|
-
// The external API is the one surface where a typed secret is the point:
|
|
61
|
-
// a CI job cannot present a credential reference (#54).
|
|
62
|
-
{ key: 'apiToken', labelKey: 'settings.apiTokenLabel', placeholderKey: 'settings.apiTokenPlaceholder', group: 'secrets' },
|
|
63
|
-
{ key: 'discordWebhookUrl', labelKey: 'settings.discordLabel', group: 'channels' },
|
|
64
|
-
{ key: 'slackWebhookUrl', labelKey: 'settings.slackLabel', group: 'channels' },
|
|
65
|
-
{ key: 'ntfyUrl', labelKey: 'settings.ntfyUrlLabel', group: 'channels' },
|
|
66
|
-
{ key: 'ntfyTopic', labelKey: 'settings.ntfyTopicLabel', group: 'channels' },
|
|
67
|
-
{ key: 'barkServerUrl', labelKey: 'settings.barkServerLabel', group: 'channels' },
|
|
68
|
-
{ key: 'barkKey', labelKey: 'settings.barkKeyLabel', group: 'channels' },
|
|
69
|
-
{ key: 'pushplusUrl', labelKey: 'settings.pushplusUrlLabel', group: 'channels' },
|
|
70
|
-
{ key: 'ttsBaseUrl', labelKey: 'settings.ttsBaseUrlLabel', group: 'channels' },
|
|
71
|
-
{ key: 'giteaBaseUrl', labelKey: 'settings.giteaBaseUrlLabel', group: 'channels' },
|
|
72
|
-
{ key: 'giteaRepo', labelKey: 'settings.giteaRepoLabel', group: 'channels' },
|
|
73
|
-
{ key: 'deliveryTimeoutMs', labelKey: 'settings.deliveryTimeoutMsLabel', group: 'channels', numeric: true, defaultValue: 15000, min: 1000 },
|
|
74
|
-
{ key: 'silentRuleModel', labelKey: 'settings.silentRuleModelLabel', group: 'automation' },
|
|
75
|
-
{ key: 'inspectorModel', labelKey: 'settings.inspectorModelLabel', group: 'automation' },
|
|
76
|
-
];
|
|
77
|
-
const DELIVERY_SETTING_KEYS = DELIVERY_SETTING_FIELDS.map((f) => f.key);
|
|
78
|
-
// The global template plus the per-channel override map (server model).
|
|
79
|
-
const TEMPLATE_SETTING_KEYS = ['template', 'channelTemplates'];
|
|
80
|
-
|
|
81
|
-
/** Collect every delivery key the settings endpoints may return. */
|
|
82
|
-
function parseEnvText(text) {
|
|
83
|
-
const env = {};
|
|
84
|
-
for (const rawLine of String(text || '').split('\n')) {
|
|
85
|
-
const line = rawLine.trim();
|
|
86
|
-
if (!line || line.startsWith('#')) continue;
|
|
87
|
-
const idx = line.indexOf('=');
|
|
88
|
-
if (idx <= 0) continue;
|
|
89
|
-
const key = line.slice(0, idx).trim();
|
|
90
|
-
const value = line.slice(idx + 1).trim();
|
|
91
|
-
if (key) env[key] = value;
|
|
92
|
-
}
|
|
93
|
-
return Object.keys(env).length ? env : undefined;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function formatEnvText(env) {
|
|
97
|
-
if (!env || typeof env !== 'object') return '';
|
|
98
|
-
return Object.entries(env).map(([k, v]) => `${k}=${v}`).join('\n');
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Status colors: core semantic state tokens first (same set dsh-clinebot
|
|
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
|
-
|
|
115
|
-
function createToggle() {
|
|
116
|
-
let open = false;
|
|
117
|
-
const listeners = new Set();
|
|
118
|
-
return {
|
|
119
|
-
isOpen: () => open,
|
|
120
|
-
set: (v) => {
|
|
121
|
-
const next = !!v;
|
|
122
|
-
if (open === next) {
|
|
123
|
-
for (const fn of listeners) fn(open);
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
open = next;
|
|
127
|
-
for (const fn of listeners) fn(open);
|
|
128
|
-
},
|
|
129
|
-
toggle: () => {
|
|
130
|
-
open = !open;
|
|
131
|
-
for (const fn of listeners) fn(open);
|
|
132
|
-
},
|
|
133
|
-
subscribe: (fn) => {
|
|
134
|
-
listeners.add(fn);
|
|
135
|
-
return () => listeners.delete(fn);
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
async function openSession(ctx, sessionId) {
|
|
141
|
-
if (!sessionId) return false;
|
|
142
|
-
const getSessions = () => (ctx && typeof ctx.get === 'function' ? ctx.get('sessions') : (ctx && ctx.sessions));
|
|
143
|
-
let sessions = getSessions();
|
|
144
|
-
|
|
145
|
-
// 1. Try sessions.open(sessionId) immediately
|
|
146
|
-
if (sessions && typeof sessions.open === 'function') {
|
|
147
|
-
try {
|
|
148
|
-
sessions.open(sessionId);
|
|
149
|
-
return true;
|
|
150
|
-
} catch (err) {
|
|
151
|
-
/* sessions.open threw synchronously */
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// 2. If the session is not in manager.summaries yet, refresh from the backend
|
|
156
|
-
if (sessions && typeof sessions.refresh === 'function') {
|
|
157
|
-
try {
|
|
158
|
-
await sessions.refresh();
|
|
159
|
-
sessions.open(sessionId);
|
|
160
|
-
return true;
|
|
161
|
-
} catch (err) {
|
|
162
|
-
/* sessions.refresh threw */
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// 3. Async retries until the WebSocket/SSE event adds the session to the list
|
|
167
|
-
for (let i = 0; i < 15; i++) {
|
|
168
|
-
await new Promise(resolve => setTimeout(resolve, 120));
|
|
169
|
-
sessions = getSessions();
|
|
170
|
-
if (sessions && typeof sessions.open === 'function') {
|
|
171
|
-
try {
|
|
172
|
-
sessions.open(sessionId);
|
|
173
|
-
return true;
|
|
174
|
-
} catch (err) {
|
|
175
|
-
/* retry polling sessions.open threw */
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
// DOM fallback: click the session in the sidebar if it has rendered
|
|
179
|
-
if (typeof document !== 'undefined') {
|
|
180
|
-
const domItem = document.querySelector('[data-session-id="' + sessionId + '"], [role="treeitem"][data-id="' + sessionId + '"], [data-id="' + sessionId + '"]');
|
|
181
|
-
if (domItem) {
|
|
182
|
-
domItem.click();
|
|
183
|
-
return true;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
console.warn('[dsh-cron] could not open session in workspace:', sessionId);
|
|
188
|
-
return false;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function statusLabel(t, status) {
|
|
192
|
-
if (status === 'success') return T_KEY(t, 'history.statusSuccess');
|
|
193
|
-
if (status === 'validation_failed') return T_KEY(t, 'history.statusValidationFailed');
|
|
194
|
-
if (status === 'skipped') return T_KEY(t, 'history.statusSkipped');
|
|
195
|
-
if (status === 'missed') return T_KEY(t, 'history.statusMissed');
|
|
196
|
-
if (status === 'timeout') return T_KEY(t, 'history.statusTimeout');
|
|
197
|
-
if (status === 'uncertain') return T_KEY(t, 'history.statusUncertain');
|
|
198
|
-
return T_KEY(t, 'history.statusFailed');
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* A config-declared task is owned by the profile config file (#50): the
|
|
203
|
-
* panel shows it, but editing, pausing or deleting it here would be undone
|
|
204
|
-
* at the next start, so the row keeps the source label instead of the
|
|
205
|
-
* actions that cannot stick.
|
|
206
|
-
*/
|
|
207
|
-
function isConfigManaged(task) {
|
|
208
|
-
return Boolean(task) && task.managedBy === 'config';
|
|
209
|
-
}
|
|
210
|
-
function T_KEY(t, key, vars) {
|
|
211
|
-
return (typeof t === 'function' ? t : translate)(key, vars);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Issue #307: universal fetch with AbortController timeout (default 15s).
|
|
216
|
-
* Connects with caller signal if supplied and fails closed on timeouts.
|
|
217
|
-
*/
|
|
218
|
-
const fetchWithTimeout = async (url, options = {}, timeoutMs = 15000) => {
|
|
219
|
-
const controller = typeof AbortController !== 'undefined' ? new AbortController() : null;
|
|
220
|
-
const timer = controller ? setTimeout(() => controller.abort(), timeoutMs) : null;
|
|
221
|
-
if (options && options.signal && controller) {
|
|
222
|
-
if (options.signal.aborted) {
|
|
223
|
-
controller.abort();
|
|
224
|
-
} else {
|
|
225
|
-
options.signal.addEventListener('abort', () => controller.abort(), { once: true });
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
try {
|
|
229
|
-
const res = await fetch(url, {
|
|
230
|
-
credentials: 'same-origin',
|
|
231
|
-
...options,
|
|
232
|
-
signal: controller ? controller.signal : (options ? options.signal : undefined),
|
|
233
|
-
});
|
|
234
|
-
return res;
|
|
235
|
-
} catch (err) {
|
|
236
|
-
if (err && (err.name === 'AbortError' || controller?.signal?.aborted)) {
|
|
237
|
-
const timeoutErr = new Error(`Request timed out after ${Math.round(timeoutMs / 1000)}s`);
|
|
238
|
-
timeoutErr.isTimeout = true;
|
|
239
|
-
throw timeoutErr;
|
|
240
|
-
}
|
|
241
|
-
throw err;
|
|
242
|
-
} finally {
|
|
243
|
-
if (timer) clearTimeout(timer);
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Issue #307: universal JSON fetch helper with timeout and aborted body protection.
|
|
249
|
-
*/
|
|
250
|
-
const fetchJsonWithTimeout = async (url, options = {}, timeoutMs = 15000) => {
|
|
251
|
-
const res = await fetchWithTimeout(url, options, timeoutMs);
|
|
252
|
-
let data = {};
|
|
253
|
-
try {
|
|
254
|
-
data = await res.json();
|
|
255
|
-
} catch (jsonErr) {
|
|
256
|
-
if (jsonErr && jsonErr.name === 'AbortError') {
|
|
257
|
-
throw jsonErr;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
return { res, data };
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
// --- CHAT HEADER VISIBILITY SETTINGS (Issue #422) ---
|
|
265
|
-
const HEADER_SETTINGS_STORAGE_KEY = 'dsh-cron:header-settings';
|
|
266
|
-
|
|
267
|
-
let currentHeaderSettings = (function initHeaderSettings() {
|
|
268
|
-
try {
|
|
269
|
-
if (typeof window !== 'undefined' && window.localStorage) {
|
|
270
|
-
const raw = window.localStorage.getItem(HEADER_SETTINGS_STORAGE_KEY);
|
|
271
|
-
if (raw) {
|
|
272
|
-
const parsed = JSON.parse(raw);
|
|
273
|
-
return {
|
|
274
|
-
showChatHeaderButton: parsed.showChatHeaderButton !== false,
|
|
275
|
-
showChatHeaderActions: parsed.showChatHeaderActions !== false,
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
} catch (_e) {
|
|
280
|
-
void _e;
|
|
281
|
-
}
|
|
282
|
-
return {
|
|
283
|
-
showChatHeaderButton: true,
|
|
284
|
-
showChatHeaderActions: true,
|
|
285
|
-
};
|
|
286
|
-
})();
|
|
287
|
-
|
|
288
|
-
const headerSettingsListeners = new Set();
|
|
289
|
-
|
|
290
|
-
function updateHeaderSettings(patch) {
|
|
291
|
-
if (!patch || typeof patch !== 'object') return currentHeaderSettings;
|
|
292
|
-
let changed = false;
|
|
293
|
-
const next = Object.assign({}, currentHeaderSettings);
|
|
294
|
-
if (patch.showChatHeaderButton !== undefined) {
|
|
295
|
-
const val = Boolean(patch.showChatHeaderButton);
|
|
296
|
-
if (next.showChatHeaderButton !== val) {
|
|
297
|
-
next.showChatHeaderButton = val;
|
|
298
|
-
changed = true;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
if (patch.showChatHeaderActions !== undefined) {
|
|
302
|
-
const val = Boolean(patch.showChatHeaderActions);
|
|
303
|
-
if (next.showChatHeaderActions !== val) {
|
|
304
|
-
next.showChatHeaderActions = val;
|
|
305
|
-
changed = true;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
if (changed) {
|
|
309
|
-
currentHeaderSettings = next;
|
|
310
|
-
try {
|
|
311
|
-
if (typeof window !== 'undefined' && window.localStorage) {
|
|
312
|
-
window.localStorage.setItem(HEADER_SETTINGS_STORAGE_KEY, JSON.stringify(next));
|
|
313
|
-
}
|
|
314
|
-
} catch (_e) {
|
|
315
|
-
void _e;
|
|
316
|
-
}
|
|
317
|
-
for (const fn of headerSettingsListeners) {
|
|
318
|
-
try {
|
|
319
|
-
fn(currentHeaderSettings);
|
|
320
|
-
} catch (_err) {
|
|
321
|
-
void _err;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
return currentHeaderSettings;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
let headerSettingsSynced = false;
|
|
329
|
-
let headerSettingsSyncing = null;
|
|
330
|
-
|
|
331
|
-
function syncHeaderSettingsFromServer() {
|
|
332
|
-
if (headerSettingsSyncing) return headerSettingsSyncing;
|
|
333
|
-
headerSettingsSyncing = fetchJsonWithTimeout('/dsh-cron/settings')
|
|
334
|
-
.then(({ data }) => {
|
|
335
|
-
headerSettingsSynced = true;
|
|
336
|
-
if (data && data.ok && data.settings) {
|
|
337
|
-
updateHeaderSettings({
|
|
338
|
-
showChatHeaderButton: data.settings.showChatHeaderButton !== false,
|
|
339
|
-
showChatHeaderActions: data.settings.showChatHeaderActions !== false,
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
})
|
|
343
|
-
.catch((_err) => {
|
|
344
|
-
void _err;
|
|
345
|
-
})
|
|
346
|
-
.finally(() => {
|
|
347
|
-
headerSettingsSyncing = null;
|
|
348
|
-
});
|
|
349
|
-
return headerSettingsSyncing;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
function useHeaderVisibility(key) {
|
|
353
|
-
if (typeof React === 'undefined' || typeof React.useState !== 'function') {
|
|
354
|
-
return Boolean(currentHeaderSettings[key] !== false);
|
|
355
|
-
}
|
|
356
|
-
const [visible, setVisible] = React.useState(Boolean(currentHeaderSettings[key] !== false));
|
|
357
|
-
if (typeof React.useEffect === 'function') {
|
|
358
|
-
React.useEffect(() => {
|
|
359
|
-
if (!headerSettingsSynced) {
|
|
360
|
-
syncHeaderSettingsFromServer();
|
|
361
|
-
}
|
|
362
|
-
const listener = (newSettings) => {
|
|
363
|
-
setVisible(Boolean(newSettings[key] !== false));
|
|
364
|
-
};
|
|
365
|
-
headerSettingsListeners.add(listener);
|
|
366
|
-
return () => {
|
|
367
|
-
headerSettingsListeners.delete(listener);
|
|
368
|
-
};
|
|
369
|
-
}, [key]);
|
|
370
|
-
}
|
|
371
|
-
return visible;
|
|
372
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
function pickDeliverySettings(source) {
|
|
2
|
-
const out = {};
|
|
3
|
-
for (const key of DELIVERY_SETTING_KEYS.concat(TEMPLATE_SETTING_KEYS)) {
|
|
4
|
-
if (source && source[key] !== undefined && source[key] !== null) out[key] = source[key];
|
|
5
|
-
}
|
|
6
|
-
if (out.channelTemplates && typeof out.channelTemplates === 'object') {
|
|
7
|
-
out.channelTemplates = Object.assign({}, out.channelTemplates);
|
|
8
|
-
}
|
|
9
|
-
return out;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Shared delivery form used by both the task panel modal and the plugin
|
|
14
|
-
* settings card, so a new channel is added in exactly one place.
|
|
15
|
-
* Sections collapse via the canonical aria-expanded head contract.
|
|
16
|
-
*/
|
|
17
|
-
function renderDeliverySettings({ T, values, onChange, onChannelTemplate, sections, onToggleSection }) {
|
|
18
|
-
const val = (key) => (values[key] === undefined || values[key] === null ? '' : String(values[key]));
|
|
19
|
-
const field = (f) => React.createElement('div', { className: 'dsh-cron-form-group', key: f.key, style: { marginBottom: '10px' } },
|
|
20
|
-
React.createElement('label', null, T(f.labelKey)),
|
|
21
|
-
React.createElement('input', f.numeric ? {
|
|
22
|
-
type: 'number',
|
|
23
|
-
min: f.min !== undefined ? f.min : 1000,
|
|
24
|
-
step: 1000,
|
|
25
|
-
value: val(f.key),
|
|
26
|
-
placeholder: String(f.defaultValue !== undefined ? f.defaultValue : 15000),
|
|
27
|
-
// #115: clearing the field must send the explicit default. Deleting the
|
|
28
|
-
// key would leave the previously stored value in place (the settings
|
|
29
|
-
// scope skips absent keys), so the field would silently keep 1 ms.
|
|
30
|
-
onChange: (e) => onChange(f.key, e.target.value === ''
|
|
31
|
-
? (f.defaultValue !== undefined ? f.defaultValue : 15000)
|
|
32
|
-
: Number(e.target.value)),
|
|
33
|
-
} : {
|
|
34
|
-
type: 'text',
|
|
35
|
-
value: val(f.key),
|
|
36
|
-
placeholder: f.placeholderKey ? T(f.placeholderKey) : '',
|
|
37
|
-
onChange: (e) => onChange(f.key, e.target.value)
|
|
38
|
-
})
|
|
39
|
-
);
|
|
40
|
-
const section = (key, titleKey, children) => {
|
|
41
|
-
const open = Boolean(sections[key]);
|
|
42
|
-
return React.createElement('div', { className: 'dsh-cron-section', key },
|
|
43
|
-
React.createElement('button', {
|
|
44
|
-
type: 'button',
|
|
45
|
-
className: 'dsh-cron-section-head',
|
|
46
|
-
'aria-expanded': open ? 'true' : 'false',
|
|
47
|
-
onClick: () => onToggleSection(key)
|
|
48
|
-
},
|
|
49
|
-
React.createElement('span', null, T(titleKey)),
|
|
50
|
-
React.createElement('span', { className: 'dsh-cron-section-chevron', 'data-open': open ? 'true' : 'false' }, '▾')
|
|
51
|
-
),
|
|
52
|
-
open && React.createElement('div', { className: 'dsh-cron-section-body' }, children)
|
|
53
|
-
);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
return [
|
|
57
|
-
section('secrets', 'settings.secretsSection', [
|
|
58
|
-
React.createElement('div', { className: 'dsh-cron-hint', key: 'hint', style: { marginBottom: '10px' } }, T('settings.secretsHint')),
|
|
59
|
-
...DELIVERY_SETTING_FIELDS.filter((f) => f.group === 'secrets').map(field),
|
|
60
|
-
]),
|
|
61
|
-
section('channels', 'settings.deliverySection', [
|
|
62
|
-
React.createElement('div', { className: 'dsh-cron-form-row', key: 'row' },
|
|
63
|
-
...DELIVERY_SETTING_FIELDS.filter((f) => f.group === 'channels').map(field)
|
|
64
|
-
),
|
|
65
|
-
]),
|
|
66
|
-
section('automation', 'settings.automationSection', [
|
|
67
|
-
React.createElement('div', { className: 'dsh-cron-hint', key: 'hint', style: { marginBottom: '10px' } }, T('settings.automationHint')),
|
|
68
|
-
React.createElement('div', { className: 'dsh-cron-form-row', key: 'row' },
|
|
69
|
-
...DELIVERY_SETTING_FIELDS.filter((f) => f.group === 'automation').map(field)
|
|
70
|
-
),
|
|
71
|
-
]),
|
|
72
|
-
section('templates', 'settings.templatesSection', [
|
|
73
|
-
React.createElement('div', { className: 'dsh-cron-form-group', key: 'global', style: { marginBottom: '10px' } },
|
|
74
|
-
React.createElement('label', null, T('settings.templateLabel')),
|
|
75
|
-
React.createElement('input', {
|
|
76
|
-
type: 'text',
|
|
77
|
-
value: val('template'),
|
|
78
|
-
onChange: (e) => onChange('template', e.target.value)
|
|
79
|
-
}),
|
|
80
|
-
React.createElement('div', { className: 'dsh-cron-hint' }, T('settings.templateHint'))
|
|
81
|
-
),
|
|
82
|
-
React.createElement('div', { className: 'dsh-cron-form-row', key: 'perchannel' },
|
|
83
|
-
...DELIVERY_CHANNELS.map((id) => React.createElement('div', { className: 'dsh-cron-form-group', key: id, style: { marginBottom: '10px' } },
|
|
84
|
-
React.createElement('label', null, T('settings.channelTemplateLabel', { channel: T(CHANNEL_LABEL_KEYS[id]) })),
|
|
85
|
-
React.createElement('input', {
|
|
86
|
-
type: 'text',
|
|
87
|
-
value: (values.channelTemplates && values.channelTemplates[id]) || '',
|
|
88
|
-
onChange: (e) => onChannelTemplate(id, e.target.value)
|
|
89
|
-
})
|
|
90
|
-
))
|
|
91
|
-
),
|
|
92
|
-
]),
|
|
93
|
-
];
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** Parse a KEY=VALUE textarea into the task env object (#38). */
|