@goodandready/dsh-cron 0.3.43 → 0.3.45

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.
Files changed (42) hide show
  1. package/lib/client.js +998 -3987
  2. package/lib/llm-ask.js +2 -1
  3. package/lib/routes/api-actions.js +36 -6
  4. package/lib/routes/api-item.js +1 -1
  5. package/lib/routes/api-webhook.js +2 -4
  6. package/lib/runtimes/runner-external.js +2 -3
  7. package/lib/runtimes/runner-session.js +385 -0
  8. package/lib/runtimes/runner-turn.js +255 -0
  9. package/lib/runtimes/runner.js +43 -616
  10. package/lib/scheduler/scheduler-execution.js +4 -1
  11. package/lib/scheduler/scheduler-lifecycle.js +65 -0
  12. package/lib/scheduler/scheduler-parser.js +261 -0
  13. package/lib/scheduler/scheduler.js +13 -319
  14. package/lib/store/store-archive.js +195 -0
  15. package/lib/store/store-io.js +331 -0
  16. package/lib/store/store-loader.js +165 -0
  17. package/lib/store/store-migration.js +38 -0
  18. package/lib/store/store-settings.js +126 -0
  19. package/lib/store/store-stats.js +55 -0
  20. package/lib/store/store.js +75 -888
  21. package/package.json +8 -6
  22. package/lib/client-src/00-open.js +0 -63
  23. package/lib/client-src/10-locales.js +0 -540
  24. package/lib/client-src/20-styles.js +0 -64
  25. package/lib/client-src/30-utils.js +0 -372
  26. package/lib/client-src/40-delivery-settings.js +0 -96
  27. package/lib/client-src/45-dag-graph-view.js +0 -287
  28. package/lib/client-src/46-live-logs-modal.js +0 -108
  29. package/lib/client-src/47-analytics-digest-modal.js +0 -166
  30. package/lib/client-src/48-timeline-heatmap-view.js +0 -176
  31. package/lib/client-src/50-cron-screen-state.js +0 -457
  32. package/lib/client-src/52-cron-screen-actions.js +0 -330
  33. package/lib/client-src/53-cron-screen-modal-actions.js +0 -677
  34. package/lib/client-src/54-cron-screen-analytics-actions.js +0 -68
  35. package/lib/client-src/55-cron-screen-view.js +0 -378
  36. package/lib/client-src/60-modal-task-form-head.js +0 -581
  37. package/lib/client-src/62-modal-task-form-tail.js +0 -563
  38. package/lib/client-src/65-modal-dialogs.js +0 -350
  39. package/lib/client-src/70-settings-card.js +0 -453
  40. package/lib/client-src/75-quick-action-bar.js +0 -146
  41. package/lib/client-src/80-sidebar-jobs.js +0 -200
  42. package/lib/client-src/90-close.js +0 -219
@@ -1,453 +0,0 @@
1
- function CronSettingsCard(props) {
2
- const { ctx, toggle } = props;
3
- const t = props.t || translate;
4
- const [token, setToken] = React.useState('');
5
- const [chatId, setChatId] = React.useState('');
6
- const [notify, setNotify] = React.useState(false);
7
- const [onlyFailure, setOnlyFailure] = React.useState(false);
8
- const [llmActionsEnabled, setLlmActionsEnabled] = React.useState(false);
9
- const [enableDynamicCredentials, setEnableDynamicCredentials] = React.useState(false);
10
- const [showChatHeaderButton, setShowChatHeaderButton] = React.useState(Boolean(currentHeaderSettings.showChatHeaderButton !== false));
11
- const [showChatHeaderActions, setShowChatHeaderActions] = React.useState(Boolean(currentHeaderSettings.showChatHeaderActions !== false));
12
- const [kanbanUrl, setKanbanUrl] = React.useState('http://127.0.0.1:3000');
13
- const [delivery, setDelivery] = React.useState({});
14
- const [sections, setSections] = React.useState({ channels: true });
15
- const [hasDefault, setHasDefault] = React.useState(false);
16
- const [saved, setSaved] = React.useState(false);
17
- const [testInfo, setTestInfo] = React.useState(null);
18
- // Collapsed by default, head is the toggle (canonical card contract, #100)
19
- const [cardOpen, setCardOpen] = React.useState(false);
20
- const [updateState, setUpdateState] = React.useState({
21
- checking: false,
22
- updating: false,
23
- currentVersion: '',
24
- latestVersion: undefined,
25
- updateAvailable: false,
26
- notice: null,
27
- error: null
28
- });
29
-
30
- const checkUpdates = async () => {
31
- setUpdateState(prev => ({ ...prev, checking: true, error: null, notice: null }));
32
- try {
33
- const { res, data } = await fetchJsonWithTimeout('/api/dsh-cron/update');
34
- if (data && data.currentVersion) {
35
- setUpdateState(prev => ({
36
- ...prev,
37
- checking: false,
38
- currentVersion: data.currentVersion,
39
- latestVersion: data.latestVersion,
40
- updateAvailable: Boolean(data.updateAvailable),
41
- error: data.latestCheckFailed ? 'Registry check failed' : null
42
- }));
43
- } else {
44
- setUpdateState(prev => ({ ...prev, checking: false, error: data.error || 'Check failed' }));
45
- }
46
- } catch (err) {
47
- setUpdateState(prev => ({ ...prev, checking: false, error: err.message }));
48
- }
49
- };
50
-
51
- const runUpdate = async () => {
52
- setUpdateState(prev => ({ ...prev, updating: true, error: null, notice: null }));
53
- try {
54
- const { res, data } = await fetchJsonWithTimeout('/api/dsh-cron/update', {
55
- method: 'POST',
56
- headers: { 'Content-Type': 'application/json', 'x-dsh-plugin-update': '1' }
57
- });
58
- if (data && data.updated) {
59
- setUpdateState(prev => ({
60
- ...prev,
61
- updating: false,
62
- updateAvailable: false,
63
- currentVersion: data.updatedVersion || data.latestVersion,
64
- notice: T_KEY(t, 'updater.success', { version: data.updatedVersion || data.latestVersion })
65
- }));
66
- } else {
67
- setUpdateState(prev => ({
68
- ...prev,
69
- updating: false,
70
- error: data.error || data.message || 'Update failed'
71
- }));
72
- }
73
- } catch (err) {
74
- setUpdateState(prev => ({ ...prev, updating: false, error: err.message }));
75
- }
76
- };
77
-
78
- // Settings snapshot status (#102): never render phantom inputs before
79
- // the snapshot arrives; offer a retry when it is unavailable.
80
- const [loadState, setLoadState] = React.useState('loading');
81
- const [reloadTick, setReloadTick] = React.useState(0);
82
-
83
- React.useEffect(() => {
84
- let active = true;
85
- setLoadState('loading');
86
- fetchJsonWithTimeout('/dsh-cron/settings')
87
- .then(({ data }) => {
88
- if (!active) return;
89
- if (data && data.ok && data.settings) {
90
- setToken(data.settings.botToken || '');
91
- setChatId(data.settings.chatId || '');
92
- setNotify(Boolean(data.settings.notifyTelegram));
93
- setOnlyFailure(Boolean(data.settings.onlyOnFailure));
94
- setLlmActionsEnabled(Boolean(data.settings.llmActionsEnabled));
95
- setEnableDynamicCredentials(Boolean(data.settings.enableDynamicCredentials));
96
- const btnVis = data.settings.showChatHeaderButton !== false;
97
- const actVis = data.settings.showChatHeaderActions !== false;
98
- setShowChatHeaderButton(btnVis);
99
- setShowChatHeaderActions(actVis);
100
- updateHeaderSettings({ showChatHeaderButton: btnVis, showChatHeaderActions: actVis });
101
- setKanbanUrl(data.settings.kanbanBaseUrl || 'http://127.0.0.1:3000');
102
- setDelivery(pickDeliverySettings(data.settings));
103
- setHasDefault(Boolean(data.settings.hasDefaultCredentials));
104
- if (data.settings.version) {
105
- setUpdateState(prev => ({ ...prev, currentVersion: data.settings.version }));
106
- }
107
- setLoadState('ready');
108
- } else {
109
- setLoadState('error');
110
- }
111
- })
112
- .catch(() => { if (active) setLoadState('error'); });
113
- return () => { active = false; };
114
- }, [reloadTick]);
115
-
116
- const saveSettings = async (e) => {
117
- if (e) e.preventDefault();
118
- try {
119
- const { res, data } = await fetchJsonWithTimeout('/dsh-cron/settings', {
120
- method: 'POST',
121
- headers: { 'Content-Type': 'application/json' },
122
- body: JSON.stringify(Object.assign({
123
- botToken: token,
124
- chatId,
125
- notifyTelegram: notify,
126
- onlyOnFailure: onlyFailure,
127
- llmActionsEnabled: llmActionsEnabled,
128
- enableDynamicCredentials: enableDynamicCredentials,
129
- showChatHeaderButton: showChatHeaderButton,
130
- showChatHeaderActions: showChatHeaderActions,
131
- kanbanBaseUrl: kanbanUrl
132
- }, delivery))
133
- });
134
- if (data && data.ok) {
135
- setSaved(true);
136
- setTimeout(() => setSaved(false), 2500);
137
- }
138
- } catch (err) {
139
- console.debug('[dsh-cron] save settings failed', err);
140
- }
141
- };
142
-
143
- const testTelegram = async () => {
144
- setTestInfo({ loading: true, message: T_KEY(t, 'settings.sending') });
145
- try {
146
- const { res, data } = await fetchJsonWithTimeout('/dsh-cron/telegram/test', {
147
- method: 'POST',
148
- headers: { 'Content-Type': 'application/json' },
149
- body: JSON.stringify({ botToken: token, chatId })
150
- });
151
- if (data && data.ok) {
152
- setTestInfo({ success: true, message: T_KEY(t, 'settings.testOk') });
153
- } else {
154
- setTestInfo({ success: false, message: T_KEY(t, 'settings.testFail', { error: (data && data.error) || '' }) });
155
- }
156
- } catch (err) {
157
- setTestInfo({ success: false, message: T_KEY(t, 'settings.testFail', { error: err.message }) });
158
- }
159
- };
160
-
161
- const testKanban = async () => {
162
- setTestInfo({ loading: true, message: T_KEY(t, 'settings.checkingKanban') });
163
- try {
164
- const { res, data } = await fetchJsonWithTimeout('/dsh-cron/kanban/test', {
165
- method: 'POST',
166
- headers: { 'Content-Type': 'application/json' },
167
- body: JSON.stringify({ kanbanBaseUrl: kanbanUrl })
168
- });
169
- if (data && data.ok) {
170
- setTestInfo({ success: true, message: T_KEY(t, 'settings.kanbanOk') });
171
- } else {
172
- setTestInfo({ success: false, message: T_KEY(t, 'settings.kanbanFail', { error: (data && data.error) || '' }) });
173
- }
174
- } catch (err) {
175
- setTestInfo({ success: false, message: T_KEY(t, 'settings.kanbanFail', { error: err.message }) });
176
- }
177
- };
178
-
179
- if (loadState !== 'ready') {
180
- return React.createElement('div', { className: 'dsh-cron-card' },
181
- React.createElement('div', { className: 'dsh-cron-card-title' }, T_KEY(t, 'settings.cardTitle')),
182
- React.createElement('div', {
183
- className: 'dsh-cron-status-banner',
184
- 'data-type': loadState === 'error' ? 'error' : 'info',
185
- style: { marginTop: '10px', display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: '10px' }
186
- },
187
- React.createElement('span', null, loadState === 'error' ? T_KEY(t, 'settings.unavailable') : T_KEY(t, 'settings.loading')),
188
- loadState === 'error' && React.createElement('button', {
189
- type: 'button',
190
- className: 'dsh-cron-btn-secondary',
191
- onClick: () => setReloadTick(x => x + 1)
192
- }, T_KEY(t, 'settings.retry'))
193
- )
194
- );
195
- }
196
-
197
- // Row seat (plugins.row.config): the host page draws title/icon/crumb and the
198
- // padding, so the summary is a one-liner and the page drops our card chrome.
199
- if (props && props.view === 'summary') {
200
- return React.createElement('span', { className: 'dsh-cron-card-desc' }, T_KEY(t, 'settings.cardDesc'));
201
- }
202
- const page = !!(props && props.view === 'page');
203
- return React.createElement('div', { className: page ? 'dsh-cron-page' : 'dsh-cron-card' },
204
- React.createElement('button', {
205
- type: 'button',
206
- className: 'dsh-cron-card-head-btn',
207
- style: page ? { display: 'none' } : undefined,
208
- 'aria-expanded': (page || cardOpen) ? 'true' : 'false',
209
- onClick: () => setCardOpen(!cardOpen)
210
- },
211
- React.createElement('span', { className: 'dsh-cron-card-title' }, T_KEY(t, 'settings.cardTitle')),
212
- React.createElement('span', { className: 'dsh-cron-chev' + (cardOpen ? ' dsh-cron-chev-open' : '') }, chevronNode())
213
- ),
214
- (page || cardOpen) && React.createElement('div', { className: 'dsh-cron-card-body' },
215
- React.createElement('div', { className: 'dsh-cron-card-desc' }, T_KEY(t, 'settings.cardDesc')),
216
- React.createElement('div', { style: { display: 'flex', justifyContent: 'flex-end', marginBottom: '12px' } },
217
- React.createElement('button', {
218
- type: 'button',
219
- className: 'dsh-cron-btn-primary',
220
- onClick: () => { if (toggle) toggle.set(true); }
221
- }, T_KEY(t, 'settings.openPanel'))
222
- ),
223
- React.createElement('form', { onSubmit: saveSettings, style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
224
- React.createElement('div', { className: 'dsh-cron-form-group', style: { marginBottom: 0 } },
225
- React.createElement('label', null, T_KEY(t, 'settings.tokenLabel')),
226
- React.createElement('input', {
227
- type: 'password',
228
- value: token,
229
- placeholder: hasDefault ? T_KEY(t, 'settings.tokenPlaceholderDefault') : T_KEY(t, 'settings.tokenPlaceholder'),
230
- onChange: (e) => setToken(e.target.value)
231
- }),
232
- hasDefault && React.createElement('div', { className: 'dsh-cron-hint' }, T_KEY(t, 'settings.defaultHint'))
233
- ),
234
- React.createElement('div', { className: 'dsh-cron-form-group', style: { marginBottom: 0 } },
235
- React.createElement('label', null, T_KEY(t, 'settings.chatIdLabel')),
236
- React.createElement('input', {
237
- value: chatId,
238
- placeholder: T_KEY(t, 'settings.chatIdPlaceholder'),
239
- onChange: (e) => setChatId(e.target.value)
240
- })
241
- ),
242
- React.createElement('div', { className: 'dsh-cron-form-group', style: { marginBottom: 0 } },
243
- React.createElement('label', null, T_KEY(t, 'settings.kanbanUrlLabel')),
244
- React.createElement('input', {
245
- value: kanbanUrl,
246
- placeholder: 'http://127.0.0.1:3000',
247
- onChange: (e) => setKanbanUrl(e.target.value)
248
- })
249
- ),
250
- React.createElement('div', { style: { background: 'var(--dsw-alias-bg-layer-3, color-mix(in srgb, var(--dsw-alias-label-primary) 2%, transparent))', border: '1px solid var(--dsw-alias-border-l2)', borderRadius: '6px', padding: '10px 12px', display: 'flex', flexDirection: 'column', gap: '8px' } },
251
- React.createElement('label', { className: 'dsh-cron-checkbox-row' },
252
- React.createElement('input', {
253
- type: 'checkbox',
254
- checked: notify,
255
- onChange: (e) => setNotify(e.target.checked)
256
- }),
257
- React.createElement('span', null, T_KEY(t, 'settings.globalNotify'))
258
- ),
259
- React.createElement('label', { className: 'dsh-cron-checkbox-row' },
260
- React.createElement('input', {
261
- type: 'checkbox',
262
- checked: onlyFailure,
263
- onChange: (e) => setOnlyFailure(e.target.checked)
264
- }),
265
- React.createElement('span', null, T_KEY(t, 'settings.globalOnlyFailure'))
266
- ),
267
- React.createElement('label', { className: 'dsh-cron-checkbox-row' },
268
- React.createElement('input', {
269
- type: 'checkbox',
270
- checked: llmActionsEnabled,
271
- onChange: (e) => setLlmActionsEnabled(e.target.checked)
272
- }),
273
- React.createElement('span', null, 'Enable Structured LLM Actions (trigger tasks, notify, create issues)')
274
- ),
275
- React.createElement('label', { className: 'dsh-cron-checkbox-row' },
276
- React.createElement('input', {
277
- type: 'checkbox',
278
- checked: enableDynamicCredentials,
279
- onChange: (e) => setEnableDynamicCredentials(e.target.checked)
280
- }),
281
- React.createElement('span', null, T_KEY(t, 'settings.dynamicCredentials'))
282
- ),
283
- React.createElement('label', { className: 'dsh-cron-checkbox-row' },
284
- React.createElement('input', {
285
- type: 'checkbox',
286
- checked: showChatHeaderButton,
287
- onChange: (e) => {
288
- const val = e.target.checked;
289
- setShowChatHeaderButton(val);
290
- updateHeaderSettings({ showChatHeaderButton: val });
291
- }
292
- }),
293
- React.createElement('span', null, T_KEY(t, 'settings.showChatHeaderButton'))
294
- ),
295
- React.createElement('label', { className: 'dsh-cron-checkbox-row' },
296
- React.createElement('input', {
297
- type: 'checkbox',
298
- checked: showChatHeaderActions,
299
- onChange: (e) => {
300
- const val = e.target.checked;
301
- setShowChatHeaderActions(val);
302
- updateHeaderSettings({ showChatHeaderActions: val });
303
- }
304
- }),
305
- React.createElement('span', null, T_KEY(t, 'settings.showChatHeaderActions'))
306
- )
307
- ),
308
- ...renderDeliverySettings({
309
- T: (key, vars) => T_KEY(t, key, vars),
310
- values: delivery,
311
- onChange: (key, value) => setDelivery((prev) => {
312
- const next = Object.assign({}, prev);
313
- if (value === undefined) delete next[key];
314
- else next[key] = value;
315
- return next;
316
- }),
317
- onChannelTemplate: (channelId, value) => setDelivery((prev) => {
318
- const templates = Object.assign({}, prev.channelTemplates || {});
319
- if (value && value.trim()) templates[channelId] = value;
320
- else delete templates[channelId];
321
- return Object.assign({}, prev, { channelTemplates: templates });
322
- }),
323
- sections,
324
- onToggleSection: (key) => setSections((prev) => Object.assign({}, prev, { [key]: !prev[key] })),
325
- }),
326
- testInfo && testInfo.message && React.createElement('div', {
327
- className: 'dsh-cron-status-banner',
328
- 'data-type': testInfo.success ? 'success' : 'error',
329
- style: { margin: 0, padding: '8px 12px' }
330
- }, testInfo.message),
331
- React.createElement('div', {
332
- className: 'dsh-cron-form-group',
333
- style: {
334
- background: 'var(--dsw-alias-bg-layer-2, color-mix(in srgb, var(--dsw-alias-label-primary) 3%, transparent))',
335
- border: '1px solid var(--dsw-alias-border-l2, color-mix(in srgb, var(--dsw-alias-label-primary) 8%, transparent))',
336
- borderRadius: '8px',
337
- padding: '14px',
338
- marginBottom: '16px'
339
- }
340
- },
341
- React.createElement('div', {
342
- style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '8px' }
343
- },
344
- React.createElement('div', { style: { fontWeight: '600', fontSize: '14px' } }, `🚀 ${T_KEY(t, 'updater.title')}`),
345
- React.createElement('div', { style: { display: 'flex', gap: '8px' } },
346
- React.createElement('button', {
347
- type: 'button',
348
- className: 'dsh-cron-btn-secondary',
349
- style: { padding: '4px 10px', fontSize: '12px' },
350
- disabled: updateState.checking || updateState.updating,
351
- onClick: checkUpdates
352
- }, updateState.checking ? T_KEY(t, 'updater.checking') : T_KEY(t, 'updater.btnCheck')),
353
- updateState.updateAvailable ? React.createElement('button', {
354
- type: 'button',
355
- className: 'dsh-cron-btn-primary',
356
- style: { padding: '4px 10px', fontSize: '12px' },
357
- disabled: updateState.updating,
358
- onClick: runUpdate
359
- }, updateState.updating ? T_KEY(t, 'updater.updating') : T_KEY(t, 'updater.btnUpdate', { version: updateState.latestVersion })) : null
360
- )
361
- ),
362
- React.createElement('div', {
363
- style: { fontSize: '12px', color: 'var(--dsw-alias-label-secondary, #999)', marginBottom: '8px' }
364
- }, T_KEY(t, 'updater.desc')),
365
- React.createElement('div', {
366
- style: { display: 'flex', alignItems: 'center', gap: '12px', fontSize: '13px' }
367
- },
368
- React.createElement('span', { style: { color: 'var(--dsw-alias-label-secondary, #aaa)' } },
369
- updateState.currentVersion ? T_KEY(t, 'updater.current', { version: updateState.currentVersion }) : ''
370
- ),
371
- updateState.checking ? React.createElement('span', { className: 'dsh-cron-badge dsh-cron-badge-info' }, T_KEY(t, 'updater.checking')) :
372
- updateState.updateAvailable ? React.createElement('span', { className: 'dsh-cron-badge dsh-cron-badge-warn' }, T_KEY(t, 'updater.available', { version: updateState.latestVersion })) :
373
- updateState.currentVersion && !updateState.error && !updateState.checking ? React.createElement('span', { className: 'dsh-cron-badge dsh-cron-badge-ok' }, `✓ ${T_KEY(t, 'updater.upToDate')}`) : null
374
- ),
375
- updateState.notice ? React.createElement('div', {
376
- style: { marginTop: '8px', color: 'var(--dsw-alias-success)', fontSize: '12px' }
377
- }, updateState.notice) : null,
378
- updateState.error ? React.createElement('div', {
379
- style: { marginTop: '8px', color: 'var(--dsw-alias-error)', fontSize: '12px' }
380
- }, updateState.error) : null
381
- ),
382
- React.createElement('div', { style: { display: 'flex', gap: '8px', alignItems: 'center', flexWrap: 'wrap', marginTop: '4px' } },
383
- React.createElement('button', {
384
- type: 'submit',
385
- className: 'dsh-cron-btn-primary',
386
- style: { minWidth: '140px' }
387
- }, saved ? T_KEY(t, 'settings.saved') : T_KEY(t, 'settings.save')),
388
- React.createElement('button', {
389
- type: 'button',
390
- className: 'dsh-cron-btn-secondary',
391
- onClick: testTelegram,
392
- disabled: testInfo?.loading
393
- }, T_KEY(t, 'settings.testTelegram')),
394
- React.createElement('button', {
395
- type: 'button',
396
- className: 'dsh-cron-btn-secondary',
397
- onClick: testKanban,
398
- disabled: testInfo?.loading
399
- }, T_KEY(t, 'settings.testKanban'))
400
- )
401
- )
402
- )
403
- );
404
- }
405
-
406
- function nativeButton() {
407
- const nodes = document.querySelectorAll('button[class*="newSession"]');
408
- for (const node of nodes) {
409
- if (String(node.className).indexOf('newSessionLabel') === -1) return node;
410
- }
411
- return undefined;
412
- }
413
-
414
- function createEntry(target, toggle, label) {
415
- const entry = target.cloneNode(true);
416
- entry.className = String(target.className) + ' dsh-cron-entry-clone';
417
- entry.setAttribute(ENTRY_ATTR, '');
418
- entry.setAttribute('data-dsh-plugin', 'dsh-cron');
419
- entry.setAttribute('data-dsh-part', 'sidebar-entry');
420
- entry.setAttribute('aria-label', label);
421
- entry.removeAttribute('id');
422
- entry.innerHTML = '';
423
-
424
- const icon = document.createElement('span');
425
- icon.className = 'dsh-cron-entry-icon';
426
- icon.innerHTML = ICON_TIMER;
427
- entry.appendChild(icon);
428
-
429
- const text = document.createElement('span');
430
- text.className = 'dsh-cron-entry-label';
431
- text.textContent = label;
432
- entry.appendChild(text);
433
-
434
- entry.addEventListener('click', (event) => {
435
- event.preventDefault();
436
- event.stopPropagation();
437
- toggle.toggle();
438
- });
439
- return entry;
440
- }
441
-
442
- /**
443
- * Collapsible list of active jobs under the sidebar entry (#34).
444
- *
445
- * Vanilla DOM like the entry itself: the sidebar is not a React root here.
446
- * Collapsed by default, state persisted, capped at a few rows with an
447
- * "and N more" line so a busy schedule cannot push the rest of the sidebar
448
- * off screen. Clicking a row opens the panel and highlights that task.
449
- */
450
- const SIDEBAR_JOBS_KEY = 'dsh-cron-sidebar-open';
451
- const SIDEBAR_JOBS_MAX_ROWS = 5;
452
-
453
- /** Sidebar job row: title plus next run time or the live running state. */
@@ -1,146 +0,0 @@
1
-
2
- // --- IN-SESSION QUICK ACTION BAR (v0.3.37) ---
3
-
4
- function sessionIdOf(ctx, props) {
5
- try {
6
- if (props && props.session && props.session.id) return String(props.session.id);
7
- if (props && props.session && props.session.sessionId) return String(props.session.sessionId);
8
- if (props && props.input && props.input.sessionId) return String(props.input.sessionId);
9
- if (ctx && ctx.scope && ctx.scope.session) return String(ctx.scope.session.id || ctx.scope.session.header?.id || '');
10
- if (ctx && typeof ctx.scope?.id === 'string') return ctx.scope.id;
11
- if (ctx && ctx.session) return String(ctx.session.id || ctx.session.header?.id || '');
12
- } catch (_e) {
13
- void _e;
14
- }
15
- return '';
16
- }
17
-
18
- function SessionQuickActionBar(props) {
19
- const visible = useHeaderVisibility('showChatHeaderActions');
20
- const { ctx, toggle } = props;
21
- const barT = props.t || translate;
22
- const [tasks, setTasks] = React.useState([]);
23
- const [isRunning, setIsRunning] = React.useState(false);
24
- const [runSuccess, setRunSuccess] = React.useState(false);
25
-
26
- const sessionId = sessionIdOf(ctx, props);
27
-
28
- React.useEffect(() => {
29
- if (!visible) return;
30
- let unmounted = false;
31
- const fetchTasks = async () => {
32
- try {
33
- const { res, data } = await fetchJsonWithTimeout('/dsh-cron/tasks');
34
- void res;
35
- if (!unmounted && data && Array.isArray(data.tasks)) {
36
- setTasks(data.tasks);
37
- }
38
- } catch (_e) {
39
- void _e;
40
- }
41
- };
42
- fetchTasks();
43
- const timer = setInterval(fetchTasks, 15000);
44
- return () => {
45
- unmounted = true;
46
- clearInterval(timer);
47
- };
48
- }, [sessionId]);
49
-
50
- const linkedTask = React.useMemo(() => {
51
- if (!sessionId || !tasks.length) return null;
52
- return tasks.find((t) => t.lastSessionId === sessionId || t.targetSessionId === sessionId || t.id === sessionId);
53
- }, [sessionId, tasks]);
54
-
55
- const handleOpenLinked = (e) => {
56
- e.preventDefault();
57
- e.stopPropagation();
58
- if (linkedTask) {
59
- pendingTaskHighlight = linkedTask.id;
60
- }
61
- toggle.set(true);
62
- };
63
-
64
- const handleCreateRecurring = (e) => {
65
- e.preventDefault();
66
- e.stopPropagation();
67
- const sessionObj = props.session || (ctx && ctx.scope && ctx.scope.session);
68
- const titleVal = (sessionObj && (sessionObj.title || sessionObj.name)) || '';
69
- pendingTaskPreset = {
70
- title: titleVal ? titleVal + ' (Cron)' : '',
71
- targetSessionId: sessionId || '',
72
- type: 'llm',
73
- schedule: '0 9 * * 1-5',
74
- };
75
- toggle.set(true);
76
- };
77
-
78
- const handleQuickRun = async (e) => {
79
- e.preventDefault();
80
- e.stopPropagation();
81
- if (!linkedTask || isRunning) return;
82
- setIsRunning(true);
83
- setRunSuccess(false);
84
- try {
85
- const { res, data } = await fetchJsonWithTimeout('/dsh-cron/tasks/' + encodeURIComponent(linkedTask.id) + '/run', {
86
- method: 'POST',
87
- });
88
- void res;
89
- if (data && data.ok) {
90
- setRunSuccess(true);
91
- setTimeout(() => setRunSuccess(false), 3000);
92
- }
93
- } catch (_err) {
94
- void _err;
95
- } finally {
96
- setIsRunning(false);
97
- }
98
- };
99
-
100
- if (!visible) return null;
101
-
102
- if (linkedTask) {
103
- const running = linkedTask.running || isRunning;
104
- return React.createElement('div', {
105
- className: 'dsh-cron-session-bar',
106
- 'data-dsh-plugin': 'dsh-cron',
107
- }, [
108
- React.createElement('span', {
109
- key: 'icon',
110
- className: 'dsh-cron-session-bar-icon',
111
- dangerouslySetInnerHTML: { __html: ICON_TIMER }
112
- }),
113
- React.createElement('button', {
114
- key: 'badge',
115
- type: 'button',
116
- className: 'dsh-cron-session-badge' + (running ? ' dsh-cron-pulse' : ''),
117
- title: linkedTask.title || linkedTask.id,
118
- onClick: handleOpenLinked,
119
- }, linkedTask.title || linkedTask.id),
120
- React.createElement('button', {
121
- key: 'run-btn',
122
- type: 'button',
123
- className: 'dsh-cron-session-run-btn',
124
- disabled: running,
125
- title: T_KEY(barT, 'sessionBar.runNow'),
126
- onClick: handleQuickRun,
127
- }, running ? '...' : (runSuccess ? '✔' : T_KEY(barT, 'sessionBar.run')))
128
- ]);
129
- }
130
-
131
- return React.createElement('button', {
132
- type: 'button',
133
- className: 'dsh-cron-session-add-btn',
134
- 'data-dsh-plugin': 'dsh-cron',
135
- title: T_KEY(barT, 'sessionBar.addRecurringHint'),
136
- 'aria-label': T_KEY(barT, 'sessionBar.addRecurring'),
137
- onClick: handleCreateRecurring,
138
- }, [
139
- React.createElement('span', {
140
- key: 'icon',
141
- className: 'dsh-cron-session-bar-icon',
142
- dangerouslySetInnerHTML: { __html: ICON_TIMER },
143
- }),
144
- React.createElement('span', { key: 'label' }, T_KEY(barT, 'sessionBar.addRecurring'))
145
- ]);
146
- }