dsh-prompt-scheduler 0.5.2 → 0.5.5
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/README.md +2 -0
- package/client.js +61 -11
- package/index.js +7 -3
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -28,6 +28,8 @@
|
|
|
28
28
|
- **谷时 / 自定义**:`谷时` = 按 DeepSeek 官方峰谷规则算出的下一个可发送的非峰时时刻;`自定义` = 任意日期时间,
|
|
29
29
|
并标出该时刻是谷价 / 峰价 / 平价。
|
|
30
30
|
- **输入框为空时跳过**:到点如果输入框是空的,不会发送,定时自动取消(不会把空消息发出去)。
|
|
31
|
+
- **提前手动发送会取消定时**:在到点之前你自己把消息发了,定时立刻作废
|
|
32
|
+
(否则到点它会去按发送,把那时输入框里的内容——可能是刚打了一半的字——发出去)。
|
|
31
33
|
- **多标签页不重复**:同一时间点由先到达的标签页按一次发送,其它标签页看到后放弃。
|
|
32
34
|
- **视觉跟随 DSH**:只用 `--dsw-*` 主题变量,颜色/圆角/字号跟随宿主主题与深浅色。
|
|
33
35
|
- **独立运行**:不依赖任何其他插件;未装 `cost-meter` 时用内置的 DeepSeek 官方规则。
|
package/client.js
CHANGED
|
@@ -453,6 +453,28 @@ window.__ModuleLoader__.load({
|
|
|
453
453
|
} catch (e) { /* reporting must never break the fire path */ }
|
|
454
454
|
}
|
|
455
455
|
|
|
456
|
+
/**
|
|
457
|
+
* 用户抢在定时之前自己把消息发了:立刻作废这条定时。
|
|
458
|
+
* 不这么做的话,到点它会去按发送,把**那时候输入框里的内容**(可能是刚打了一半的字)发出去,
|
|
459
|
+
* 而用户显然已经用行动表示"我不等了"。
|
|
460
|
+
*/
|
|
461
|
+
function cancelForManualSend() {
|
|
462
|
+
var sessionId = store.state.sessionId
|
|
463
|
+
var timer = store.state.timer
|
|
464
|
+
if (!sessionId || !timer) return
|
|
465
|
+
try {
|
|
466
|
+
console.info('[prompt-scheduler] manual send detected, timer cancelled', {
|
|
467
|
+
fireAtMs: timer.fireAtMs,
|
|
468
|
+
earlyByMs: timer.fireAtMs - Date.now(),
|
|
469
|
+
})
|
|
470
|
+
} catch (e) { /* no console */ }
|
|
471
|
+
try {
|
|
472
|
+
callHost('/timer/clear', { sessionId: sessionId, reason: 'manual-send' }).catch(function () { /* host half may be reloading */ })
|
|
473
|
+
} catch (e) { /* clearing is best effort */ }
|
|
474
|
+
clearEngineTimer()
|
|
475
|
+
patch({ timer: null, open: false, rev: store.state.rev + 1 })
|
|
476
|
+
}
|
|
477
|
+
|
|
456
478
|
function fireNow(reason) {
|
|
457
479
|
if (engine.firing) return
|
|
458
480
|
var timer = store.state.timer
|
|
@@ -489,8 +511,7 @@ window.__ModuleLoader__.load({
|
|
|
489
511
|
reportFire(sessionId, timer, 'sent', method, '')
|
|
490
512
|
finishClear()
|
|
491
513
|
}
|
|
492
|
-
function syncTimer() {
|
|
493
|
-
var sessionId = store.state.sessionId
|
|
514
|
+
function syncTimer() { var sessionId = store.state.sessionId
|
|
494
515
|
if (!sessionId) return
|
|
495
516
|
engine.sessionId = sessionId
|
|
496
517
|
callHost('/timer', { sessionId: sessionId }).then(function (data) {
|
|
@@ -583,11 +604,15 @@ window.__ModuleLoader__.load({
|
|
|
583
604
|
var sessionId = props && props.sessionId ? props.sessionId : null
|
|
584
605
|
var btnRef = React.useRef(null)
|
|
585
606
|
var draft = ''
|
|
607
|
+
var phase = ''
|
|
586
608
|
try {
|
|
587
609
|
if (props && typeof props.useInput === 'function') {
|
|
588
610
|
draft = props.useInput(function (input) { return (input && input.draft) || '' }) || ''
|
|
611
|
+
// dsh 的 composer 状态机:'plain' | 'adjudicating' | 'claimed' | 'submitting' | 'sending'。
|
|
612
|
+
// 'sending' 出现 = 用户(或我们的 pressSend)真的发出了一条消息。
|
|
613
|
+
phase = props.useInput(function (input) { return (input && input.phase) || '' }) || ''
|
|
589
614
|
}
|
|
590
|
-
} catch (e) { draft = '' }
|
|
615
|
+
} catch (e) { draft = ''; phase = '' }
|
|
591
616
|
|
|
592
617
|
React.useEffect(function () {
|
|
593
618
|
if (sessionId && store.state.sessionId !== sessionId) {
|
|
@@ -602,13 +627,33 @@ window.__ModuleLoader__.load({
|
|
|
602
627
|
if (store.state.timer && String(draft || '').trim()) fireNow('draft')
|
|
603
628
|
}, [draft])
|
|
604
629
|
|
|
630
|
+
// 用户自己提前把消息发了 → 定时立刻作废。
|
|
631
|
+
// 否则到点会去按发送,把**那时候输入框里的内容**(可能是刚打了一半的字)发出去。
|
|
632
|
+
// 只在"进入 sending 的那一刻"触发:我们的 pressSend 走这条路时 engine.firing 已经是 true,会跳过。
|
|
633
|
+
var prevPhase = React.useRef(phase)
|
|
634
|
+
React.useEffect(function () {
|
|
635
|
+
var previous = prevPhase.current
|
|
636
|
+
prevPhase.current = phase
|
|
637
|
+
if (phase !== 'sending' || previous === 'sending') return
|
|
638
|
+
if (engine.firing) return
|
|
639
|
+
if (!store.state.timer || !store.state.sessionId) return
|
|
640
|
+
cancelForManualSend()
|
|
641
|
+
}, [phase])
|
|
642
|
+
|
|
605
643
|
var [rect, setRect] = React.useState(null)
|
|
606
644
|
var openPopover = function (event) {
|
|
607
|
-
//
|
|
608
|
-
//
|
|
645
|
+
// 每点必打一行:排查"点不动"时,有这行 = 我们收到了点击(问题在渲染/定位),
|
|
646
|
+
// 没有这行 = 点击根本没到按钮(宿主把工具行禁用了)。别删,成本只有一行 console.
|
|
609
647
|
var rendered = false
|
|
610
648
|
try { rendered = !!document.querySelector('.psx-pop') } catch (e) { rendered = false }
|
|
611
|
-
|
|
649
|
+
try {
|
|
650
|
+
console.info('[prompt-scheduler] button click', {
|
|
651
|
+
open: !!store.state.open,
|
|
652
|
+
rendered: rendered,
|
|
653
|
+
timer: store.state.timer ? store.state.timer.fireAtMs : null,
|
|
654
|
+
firing: engine.firing,
|
|
655
|
+
})
|
|
656
|
+
} catch (e) { /* no console */ }
|
|
612
657
|
var anchor = null
|
|
613
658
|
try {
|
|
614
659
|
var btnRect = event.currentTarget.getBoundingClientRect()
|
|
@@ -623,12 +668,13 @@ window.__ModuleLoader__.load({
|
|
|
623
668
|
anchor = null
|
|
624
669
|
}
|
|
625
670
|
syncTimer()
|
|
671
|
+
// 只开不关:关闭靠 Esc / 点外部 / 卡片右上角 ×。
|
|
672
|
+
// 开关式遇到"状态说开着但没渲染"就会吃掉一次点击,看起来像按钮失灵。
|
|
626
673
|
patch({
|
|
627
|
-
open:
|
|
674
|
+
open: true,
|
|
628
675
|
sessionId: sessionId,
|
|
629
676
|
draft: draft,
|
|
630
|
-
// 万一取不到矩形也绝不能给 null:null 会让卡片停在视口外(left/top = -9999
|
|
631
|
-
// 表现为"点了没反应"。
|
|
677
|
+
// 万一取不到矩形也绝不能给 null:null 会让卡片停在视口外(left/top = -9999)。
|
|
632
678
|
anchor: anchor || composerAnchorRect(),
|
|
633
679
|
})
|
|
634
680
|
}
|
|
@@ -782,7 +828,11 @@ window.__ModuleLoader__.load({
|
|
|
782
828
|
var armedLine = timer && !editing
|
|
783
829
|
? h('div', null,
|
|
784
830
|
h('div', { className: 'psx-armed' },
|
|
785
|
-
|
|
831
|
+
// ClockIcon is a plain function that RETURNS an element: pass the result
|
|
832
|
+
// itself. Wrapping it again (h(ClockIcon(14))) hands React an object as
|
|
833
|
+
// the element type -> minified React error #130, which dsh reports as
|
|
834
|
+
// "slot entry crashed in 'shell.overlay'" and drops for good.
|
|
835
|
+
ClockIcon(14),
|
|
786
836
|
h('span', null, t('armedAt').split('{time}')[0]),
|
|
787
837
|
h('b', null, clockOf(timer.fireAtMs)),
|
|
788
838
|
h('span', null, t('armedAt').split('{time}')[1] || '')
|
|
@@ -849,7 +899,7 @@ window.__ModuleLoader__.load({
|
|
|
849
899
|
return h('div', { ref: cardRef },
|
|
850
900
|
h('div', { className: 'psx-head' },
|
|
851
901
|
h('span', { className: 'psx-title' }, t('title')),
|
|
852
|
-
h('button', { type: 'button', className: 'psx-iconbtn', 'aria-label': t('close'), title: t('close'), onClick: closePopover },
|
|
902
|
+
h('button', { type: 'button', className: 'psx-iconbtn', 'aria-label': t('close'), title: t('close'), onClick: closePopover }, CloseIcon())
|
|
853
903
|
),
|
|
854
904
|
armedLine,
|
|
855
905
|
armedLine ? null : h('p', { className: 'psx-muted', style: { margin: 0 } }, t('hint')),
|
package/index.js
CHANGED
|
@@ -446,14 +446,18 @@ function timerSet(body, cfg, store, events, source) {
|
|
|
446
446
|
return { ok: true, timer: view }
|
|
447
447
|
}
|
|
448
448
|
|
|
449
|
-
/**
|
|
449
|
+
/**
|
|
450
|
+
* 清掉该会话的 deadline;没有则 cleared:false。
|
|
451
|
+
* 请求可带 reason(如 'manual-send':用户提前自己发了,定时作废),只进事件日志,不影响行为。
|
|
452
|
+
*/
|
|
450
453
|
function timerClear(body, store, events, source) {
|
|
451
454
|
const input = body && typeof body === 'object' && !Array.isArray(body) ? body : {}
|
|
452
455
|
const sessionId = textValue(input.sessionId)
|
|
453
456
|
if (!sessionId) return fail('invalid_session', 'sessionId 必须是非空字符串')
|
|
457
|
+
const reason = textValue(input.reason)
|
|
454
458
|
const cleared = store.clearTimer(sessionId)
|
|
455
|
-
events?.record('clear', { sessionId, source, cleared })
|
|
456
|
-
return { ok: true, cleared }
|
|
459
|
+
events?.record('clear', { sessionId, source, cleared, reason })
|
|
460
|
+
return { ok: true, cleared, ...(reason ? { reason } : {}) }
|
|
457
461
|
}
|
|
458
462
|
|
|
459
463
|
/** 记下 set 用的是哪种时间选择方式,方便回看"当初排的是什么"。 */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-prompt-scheduler",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"description": "Arm a timer on the dsh send button: at the chosen time the plugin presses send for you, so the message that leaves the composer is whatever is in it then.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"node": ">=22.19.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
|
-
"check": "node --check index.js && node --check lib/deadline.js && node --check lib/events.js && node --check lib/peak.js && node --check lib/time.js && node --check client.js",
|
|
38
|
+
"check": "node --check index.js && node --check lib/deadline.js && node --check lib/events.js && node --check lib/peak.js && node --check lib/time.js && node --check client.js && node scripts/check-client.mjs",
|
|
39
39
|
"check:manifest": "node scripts/check-manifest.mjs",
|
|
40
40
|
"test": "node test/time.test.mjs && node test/peak.test.mjs && node test/host-smoke.mjs",
|
|
41
41
|
"pack:dry": "npm pack --dry-run"
|
|
@@ -44,7 +44,6 @@
|
|
|
44
44
|
"access": "public",
|
|
45
45
|
"registry": "https://registry.npmjs.org/"
|
|
46
46
|
},
|
|
47
|
-
|
|
48
47
|
"dsh": {
|
|
49
48
|
"bundle": {
|
|
50
49
|
"patch": "./cordis.patch.yml"
|