@restregular/dsh-powerup 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -19
- package/client.js +470 -142
- package/index.js +68 -31
- package/lib/direct-ask.js +13 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -445,30 +445,34 @@ the running agent:
|
|
|
445
445
|
- The feature is on by default and can be switched off on the Power-Up page;
|
|
446
446
|
reports are cached per session in memory and marked stale after a minute.
|
|
447
447
|
|
|
448
|
-
###
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
448
|
+
### Progress requirements, resizable panel and history
|
|
449
|
+
|
|
450
|
+
Requirements are a **list of records** (just like prompts), managed in the
|
|
451
|
+
Power-Up page's dedicated **Requirements** tab and in the conversation's
|
|
452
|
+
Power-Up settings tab. Each record is scoped to a workspace (`''` = global), can
|
|
453
|
+
be enabled/disabled, and describes language, structure, required data or
|
|
454
|
+
questions for the display area. When generating progress you **choose which
|
|
455
|
+
requirements to apply** in the panel — nothing is added unless you check it.
|
|
455
456
|
The panel is wider by default, resizable from its bottom-right corner (size
|
|
456
457
|
persisted), and its header tint shifts from blue toward warning red as the
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
458
|
+
report ages. Every refresh adds a new report to a per-session history stored on
|
|
459
|
+
disk; older reports stay browsable and are never discarded. The panel can switch
|
|
460
|
+
between them, show the exact raw AI text, copy it, and clear the history
|
|
461
|
+
explicitly. "Refresh progress" generates a new report without dropping the old
|
|
462
|
+
ones.
|
|
462
463
|
|
|
463
464
|
### Direct ask (no Agent)
|
|
464
465
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
466
|
+
An **icon-only** lightning button in the composer opens a floating DSH-styled
|
|
467
|
+
chat window. Drag the title bar to move it and the bottom-right corner to
|
|
468
|
+
resize it (position and size persist). It supports **continuous multi-turn Q&A**
|
|
469
|
+
and a browsable **history** of past conversations ("+" starts a new chat, "◷"
|
|
470
|
+
shows history; both clearable). Attach text files with the "+" chip in the
|
|
471
|
+
composer — the native file picker stays hidden. This is deliberately **not an
|
|
472
|
+
Agent**: it uses a single `llm.prepareCall` + stream call per turn with a short
|
|
473
|
+
instruction, so no system prompt sections, tools, skills, memory or background
|
|
474
|
+
jobs are involved, and nothing is written to the session log. Toggle it off on
|
|
475
|
+
the Power-Up page if you don't want the button.
|
|
472
476
|
|
|
473
477
|
### Dual send buttons
|
|
474
478
|
|
package/client.js
CHANGED
|
@@ -383,7 +383,11 @@
|
|
|
383
383
|
'progress.clearHistoryConfirm': '确定清空全部历史进度?此操作不可撤销。',
|
|
384
384
|
'progress.cleared': '历史已清空',
|
|
385
385
|
'progress.requirements': '生成要求',
|
|
386
|
-
'progress.
|
|
386
|
+
'progress.tabRequirements': '要求',
|
|
387
|
+
'progress.reqHint': '每条要求可设置语言、结构、必须包含的数据、额外展示区要回答的问题等;按工作区隔离,留空工作区则对所有工作区生效。生成进度时可勾选本次要应用哪些要求。',
|
|
388
|
+
'progress.reqNew': '新建要求',
|
|
389
|
+
'progress.reqSelect': '本次应用的要求',
|
|
390
|
+
'progress.reqSelectHint': '勾选本次生成要使用要求;不选则不附加任何要求。',
|
|
387
391
|
'progress.reqGlobal': '通用要求(设置页)',
|
|
388
392
|
'progress.reqWorkspace': '工作区要求',
|
|
389
393
|
'progress.reqSession': '会话要求',
|
|
@@ -415,7 +419,12 @@
|
|
|
415
419
|
'directAsk.copied': '已复制',
|
|
416
420
|
'directAsk.close': '关闭',
|
|
417
421
|
'directAsk.hide': '隐藏弹窗',
|
|
418
|
-
'directAsk.showHint': '
|
|
422
|
+
'directAsk.showHint': '输入问题开始对话;可继续追问,点「+」开启新对话,点「◷」查看历史。拖动标题栏移动窗口。',
|
|
423
|
+
'directAsk.newChat': '新对话',
|
|
424
|
+
'directAsk.history': '历史记录',
|
|
425
|
+
'directAsk.historyEmpty': '还没有历史对话',
|
|
426
|
+
'directAsk.clearHistory': '清空历史',
|
|
427
|
+
'directAsk.clearHistoryConfirm': '确定清空全部问答历史?此操作不可撤销。',
|
|
419
428
|
'page.promptsTitle': '工作区提示词',
|
|
420
429
|
'page.promptsDesc': '为每个工作区保存可复用的提示词。开启后,新会话行的 Agent 预设右侧会出现一个下拉列表,选择即可把提示词填入输入框(可继续编辑),或点提示词右侧的发送按钮直接发出。',
|
|
421
430
|
'page.promptsHow': '先启用本功能,再切到「工作区提示词」标签页创建提示词;提示词按工作区隔离,没有标题时显示开头几个字。',
|
|
@@ -761,7 +770,11 @@
|
|
|
761
770
|
'progress.clearHistoryConfirm': 'Clear all progress history? This cannot be undone.',
|
|
762
771
|
'progress.cleared': 'History cleared',
|
|
763
772
|
'progress.requirements': 'Requirements',
|
|
764
|
-
'progress.
|
|
773
|
+
'progress.tabRequirements': 'Requirements',
|
|
774
|
+
'progress.reqHint': 'Each requirement sets language, structure, required data, questions for the display area, etc. Scoped per workspace; a blank workspace applies everywhere. Choose which ones to apply when generating progress.',
|
|
775
|
+
'progress.reqNew': 'New requirement',
|
|
776
|
+
'progress.reqSelect': 'Requirements for this run',
|
|
777
|
+
'progress.reqSelectHint': 'Check the requirements to apply this time; none selected means no extra requirements.',
|
|
765
778
|
'progress.reqGlobal': 'Global requirements (settings)',
|
|
766
779
|
'progress.reqWorkspace': 'Workspace requirements',
|
|
767
780
|
'progress.reqSession': 'Session requirements',
|
|
@@ -793,7 +806,12 @@
|
|
|
793
806
|
'directAsk.copied': 'Copied',
|
|
794
807
|
'directAsk.close': 'Close',
|
|
795
808
|
'directAsk.hide': 'Hide dialog',
|
|
796
|
-
'directAsk.showHint': '
|
|
809
|
+
'directAsk.showHint': 'Type a question to start; follow up anytime, "+" starts a new chat, "◷" shows history. Drag the title bar to move.',
|
|
810
|
+
'directAsk.newChat': 'New chat',
|
|
811
|
+
'directAsk.history': 'History',
|
|
812
|
+
'directAsk.historyEmpty': 'No saved conversations yet',
|
|
813
|
+
'directAsk.clearHistory': 'Clear history',
|
|
814
|
+
'directAsk.clearHistoryConfirm': 'Clear all Q&A history? This cannot be undone.',
|
|
797
815
|
'page.promptsTitle': 'Workspace prompts',
|
|
798
816
|
'page.promptsDesc': 'Save reusable prompts per workspace. When enabled, a dropdown appears next to the Agent preset in the New Session row: pick a prompt to fill the composer (still editable), or click its send button to send it right away.',
|
|
799
817
|
'page.promptsHow': 'Enable this feature, then open the "Workspace prompts" tab to create prompts. Prompts are scoped per workspace; without a title the first few characters are shown.',
|
|
@@ -4591,24 +4609,63 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
4591
4609
|
.dsh-powerup-progress-history-item{padding:3px 9px;border:.5px solid var(--dsw-alias-border-l2);border-radius:999px;background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-secondary);font:inherit;font-size:10.5px;line-height:1.5;cursor:pointer}
|
|
4592
4610
|
.dsh-powerup-progress-history-item.on{border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-brand-primary);background:color-mix(in srgb,var(--dsw-alias-brand-primary) 10%,transparent)}
|
|
4593
4611
|
.dsh-powerup-progress-age{margin:0 0 10px;padding:6px 10px;border-radius:7px;background:color-mix(in srgb,var(--dsw-alias-state-warning-primary,var(--dsw-alias-state-error-primary)) 10%,transparent);color:var(--dsw-alias-state-warning-primary,var(--dsw-alias-state-error-primary));font-size:11px;line-height:1.5}
|
|
4594
|
-
.dsh-powerup-progress-req-pop{padding:10px 16px 0;border-bottom:.5px solid var(--dsw-alias-border-l1)}
|
|
4595
|
-
.dsh-powerup-
|
|
4612
|
+
.dsh-powerup-progress-req-pop{padding:10px 16px 0;border-bottom:.5px solid var(--dsw-alias-border-l1);max-height:160px;overflow-y:auto}
|
|
4613
|
+
.dsh-powerup-req-picker{display:flex;flex-direction:column;gap:4px;padding:4px 0}
|
|
4614
|
+
.dsh-powerup-req-option{display:flex;align-items:center;gap:8px;padding:5px 8px;border-radius:6px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-secondary);font-size:11.5px;cursor:pointer}
|
|
4615
|
+
.dsh-powerup-req-option:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
4616
|
+
.dsh-powerup-req-option input{flex:none;accent-color:var(--dsw-alias-brand-primary)}
|
|
4617
|
+
.dsh-powerup-req-manager{display:flex;flex-direction:column;gap:16px}
|
|
4618
|
+
.dsh-powerup-req-list{display:flex;flex-direction:column;gap:8px;margin:0;padding:0;list-style:none}
|
|
4619
|
+
.dsh-powerup-req-item{display:flex;align-items:flex-start;gap:10px;padding:10px 12px;border:1px solid var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-layer-1)}
|
|
4620
|
+
.dsh-powerup-req-item.off{opacity:.55}
|
|
4621
|
+
.dsh-powerup-req-copy{display:flex;flex:1 1 auto;flex-direction:column;gap:3px;min-width:0}
|
|
4622
|
+
.dsh-powerup-req-title{font-size:12.5px;font-weight:600;color:var(--dsw-alias-label-primary)}
|
|
4623
|
+
.dsh-powerup-req-text{color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:1.5;overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}
|
|
4624
|
+
.dsh-powerup-req-form{display:flex;flex-direction:column;gap:8px;margin-top:8px;padding:10px;border-radius:8px;background:var(--dsw-alias-bg-layer-2)}
|
|
4625
|
+
.dsh-powerup-req-form-foot{display:flex;justify-content:flex-end;gap:8px}
|
|
4596
4626
|
.dsh-powerup-progress-resizer{position:absolute;right:0;bottom:0;width:16px;height:16px;cursor:nwse-resize;background:linear-gradient(135deg,transparent 50%,var(--dsw-alias-border-l3) 50%,transparent 62%,var(--dsw-alias-border-l3) 62%,var(--dsw-alias-border-l3) 72%,transparent 72%)}
|
|
4597
4627
|
.dsh-powerup-progress-req-editor{display:flex;flex-direction:column;gap:10px;padding:8px 0}
|
|
4598
4628
|
@media (prefers-reduced-motion:reduce){.dsh-powerup-progress-panel,.dsh-powerup-progress-btn.is-running svg,.dsh-powerup-progress-fill{animation:none;transition:none}}
|
|
4599
4629
|
/* Direct-ask button + dialog */
|
|
4600
|
-
.dsh-powerup-directask-btn{display:inline-flex;align-items:center;
|
|
4630
|
+
.dsh-powerup-directask-btn{display:inline-flex;align-items:center;justify-content:center;width:26px;height:26px;padding:0;border:.5px solid var(--dsw-alias-border-l2);border-radius:7px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);font:inherit;line-height:1;cursor:pointer}
|
|
4601
4631
|
.dsh-powerup-directask-btn:hover,.dsh-powerup-directask-btn.on{border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-brand-primary)}
|
|
4602
|
-
.dsh-powerup-directask-
|
|
4603
|
-
.dsh-powerup-directask-
|
|
4604
|
-
.dsh-powerup-directask-
|
|
4632
|
+
.dsh-powerup-directask-window{position:fixed;z-index:1600;box-sizing:border-box;display:flex;flex-direction:column;min-width:360px;min-height:280px;border-radius:var(--dsw-radius-panel,14px);background:var(--dsw-alias-bg-layer-2);box-shadow:var(--dsw-elevation-prominent);--dsw-elevation-stroke-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-primary);font-size:13px;line-height:1.6;overflow:hidden;animation:dsh-powerup-progress-in .15s ease-out}
|
|
4633
|
+
.dsh-powerup-directask-titlebar{display:flex;align-items:center;gap:8px;flex:none;padding:10px 12px;border-bottom:.5px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-3);cursor:move;user-select:none}
|
|
4634
|
+
.dsh-powerup-directask-title{font-size:13px;font-weight:600;white-space:nowrap}
|
|
4635
|
+
.dsh-powerup-directask-subtitle{flex:1 1 auto;min-width:0;color:var(--dsw-alias-label-tertiary);font-size:10.5px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
4636
|
+
.dsh-powerup-directask-titlebtn,.dsh-powerup-directask-close{flex:none;display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;padding:0;border:0;border-radius:var(--dsw-radius-sm,6px);background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:15px;line-height:1;cursor:pointer}
|
|
4637
|
+
.dsh-powerup-directask-titlebtn:hover,.dsh-powerup-directask-titlebtn.on,.dsh-powerup-directask-close:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
|
|
4638
|
+
.dsh-powerup-directask-history{flex:none;max-height:180px;overflow-y:auto;padding:10px 14px;border-bottom:.5px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1)}
|
|
4639
|
+
.dsh-powerup-directask-history-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:6px;font-size:11.5px}
|
|
4640
|
+
.dsh-powerup-directask-history-list{margin:0;padding:0;list-style:none}
|
|
4641
|
+
.dsh-powerup-directask-history-list button{width:100%;padding:5px 8px;border:0;border-radius:6px;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:11px;text-align:left;cursor:pointer;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
4642
|
+
.dsh-powerup-directask-history-list button:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
|
|
4643
|
+
.dsh-powerup-directask-thread{flex:1 1 auto;min-height:0;overflow-y:auto;padding:14px 16px;display:flex;flex-direction:column;gap:12px;--dsh-scrollbar-thumb:var(--dsw-alias-scrollbar-bg-l2)}
|
|
4644
|
+
.dsh-powerup-directask-welcome{margin:auto;color:var(--dsw-alias-label-tertiary);font-size:12px;text-align:center}
|
|
4645
|
+
.dsh-powerup-directask-turn{display:flex;flex-direction:column;gap:6px}
|
|
4646
|
+
.dsh-powerup-directask-msg{display:flex;flex-direction:column;gap:4px;max-width:88%}
|
|
4647
|
+
.dsh-powerup-directask-msg.user{align-self:flex-end;align-items:flex-end}
|
|
4648
|
+
.dsh-powerup-directask-msg.assistant{align-self:flex-start;align-items:flex-start}
|
|
4649
|
+
.dsh-powerup-directask-msg-body{padding:8px 12px;border-radius:12px;background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary);font-size:12.5px;line-height:1.7;white-space:pre-wrap;overflow-wrap:anywhere}
|
|
4650
|
+
.dsh-powerup-directask-msg.user .dsh-powerup-directask-msg-body{background:var(--dsw-alias-brand-primary);color:var(--dsw-alias-label-primary-foreground,var(--dsw-alias-bg-layer-1));border-bottom-right-radius:3px}
|
|
4651
|
+
.dsh-powerup-directask-msg.assistant .dsh-powerup-directask-msg-body{border-bottom-left-radius:3px}
|
|
4652
|
+
.dsh-powerup-directask-ctx{display:flex;flex-wrap:wrap;gap:4px;align-self:flex-end}
|
|
4653
|
+
.dsh-powerup-directask-ctx span{padding:2px 7px;border-radius:999px;background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-tertiary);font-size:10px}
|
|
4654
|
+
.dsh-powerup-directask-files{display:flex;flex-wrap:wrap;gap:6px;padding:0 14px 6px}
|
|
4605
4655
|
.dsh-powerup-directask-file{display:inline-flex;align-items:center;gap:5px;padding:3px 8px;border-radius:999px;background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-secondary);font-size:11px}
|
|
4606
4656
|
.dsh-powerup-directask-file button{border:0;background:transparent;color:var(--dsw-alias-label-tertiary);cursor:pointer;font-size:13px;line-height:1}
|
|
4607
|
-
.dsh-powerup-directask-
|
|
4608
|
-
.dsh-powerup-directask-
|
|
4609
|
-
.dsh-powerup-directask-
|
|
4610
|
-
|
|
4611
|
-
.dsh-powerup-directask-
|
|
4657
|
+
.dsh-powerup-directask-composer{flex:none;padding:10px 14px 12px;border-top:.5px solid var(--dsw-alias-border-l1)}
|
|
4658
|
+
.dsh-powerup-directask-inputrow{display:flex;align-items:flex-end;gap:8px;padding:6px 6px 6px 10px;border:1px solid var(--dsw-alias-border-l2);border-radius:14px;background:var(--dsw-alias-bg-layer-3)}
|
|
4659
|
+
.dsh-powerup-directask-inputrow:focus-within{border-color:var(--dsw-alias-brand-primary)}
|
|
4660
|
+
/* Native file input is hidden; only the custom '+' chip is shown. */
|
|
4661
|
+
.dsh-powerup-directask-attach{position:relative;display:inline-flex;align-items:center;justify-content:center;flex:none;width:26px;height:26px;border-radius:7px;color:var(--dsw-alias-label-secondary);font-size:18px;line-height:1;cursor:pointer;overflow:hidden}
|
|
4662
|
+
.dsh-powerup-directask-attach:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
|
|
4663
|
+
.dsh-powerup-directask-attach input[type=file]{position:absolute;inset:0;width:100%;height:100%;opacity:0;cursor:pointer}
|
|
4664
|
+
.dsh-powerup-directask-input{flex:1 1 auto;min-width:0;max-height:140px;border:0;outline:0;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:12.5px;line-height:1.6;resize:none}
|
|
4665
|
+
.dsh-powerup-directask-input::placeholder{color:var(--dsw-alias-label-tertiary)}
|
|
4666
|
+
.dsh-powerup-directask-send{flex:none;display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;border:0;border-radius:8px;background:var(--dsw-alias-brand-primary);color:var(--dsw-alias-label-primary-foreground,var(--dsw-alias-bg-layer-1));cursor:pointer}
|
|
4667
|
+
.dsh-powerup-directask-send:disabled{opacity:.4;cursor:not-allowed}
|
|
4668
|
+
.dsh-powerup-directask-resizer{position:absolute;right:0;bottom:0;width:16px;height:16px;cursor:nwse-resize;background:linear-gradient(135deg,transparent 50%,var(--dsw-alias-border-l3) 50%,transparent 62%,var(--dsw-alias-border-l3) 62%,var(--dsw-alias-border-l3) 72%,transparent 72%)}
|
|
4612
4669
|
`;
|
|
4613
4670
|
|
|
4614
4671
|
/** Max display length of a session option, in Unicode code points. */
|
|
@@ -9111,24 +9168,55 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
9111
9168
|
}
|
|
9112
9169
|
|
|
9113
9170
|
/**
|
|
9114
|
-
*
|
|
9115
|
-
*
|
|
9116
|
-
*
|
|
9171
|
+
* Lightning-bolt button in the composer (icon only). Opens a floating,
|
|
9172
|
+
* draggable + resizable DSH-styled Q&A window that talks straight to the
|
|
9173
|
+
* model — no Agent, system prompt, tools or skills. Supports continuous
|
|
9174
|
+
* multi-turn Q&A and a browsable/clearable history of past exchanges.
|
|
9117
9175
|
*/
|
|
9118
9176
|
function DirectAskButton({ sessionId }) {
|
|
9119
9177
|
const settings = useSettings();
|
|
9120
9178
|
const [open, setOpen] = useState(false);
|
|
9121
9179
|
const [question, setQuestion] = useState('');
|
|
9122
9180
|
const [files, setFiles] = useState([]);
|
|
9123
|
-
const [answer, setAnswer] = useState('');
|
|
9124
9181
|
const [busy, setBusy] = useState(false);
|
|
9125
9182
|
const [error, setError] = useState('');
|
|
9126
9183
|
const [copied, setCopied] = useState(false);
|
|
9184
|
+
/** Current conversation: [{question, answer, context, at}]. */
|
|
9185
|
+
const [turns, setTurns] = useState([]);
|
|
9186
|
+
/** Archived conversations, newest first: [{id, at, turns}]. */
|
|
9187
|
+
const [history, setHistory] = useState(() => {
|
|
9188
|
+
try { return JSON.parse(localStorage.getItem('dsh-powerup:directask:history:v1') || '[]'); }
|
|
9189
|
+
catch { return []; }
|
|
9190
|
+
});
|
|
9191
|
+
const [showHistory, setShowHistory] = useState(false);
|
|
9192
|
+
const [pos, setPos] = useState(() => {
|
|
9193
|
+
try {
|
|
9194
|
+
const saved = JSON.parse(localStorage.getItem('dsh-powerup:directask:pos:v1') || 'null');
|
|
9195
|
+
if (saved !== null && Number.isFinite(saved.x) && Number.isFinite(saved.y)) return { x: saved.x, y: saved.y };
|
|
9196
|
+
} catch { /* fall through */ }
|
|
9197
|
+
return { x: 24, y: 96 };
|
|
9198
|
+
});
|
|
9199
|
+
const [size, setSize] = useState(() => {
|
|
9200
|
+
try {
|
|
9201
|
+
const saved = JSON.parse(localStorage.getItem('dsh-powerup:directask:size:v1') || 'null');
|
|
9202
|
+
if (saved !== null && Number.isFinite(saved.w) && Number.isFinite(saved.h)) {
|
|
9203
|
+
return { w: Math.max(360, Math.min(1100, saved.w)), h: Math.max(280, Math.min(900, saved.h)) };
|
|
9204
|
+
}
|
|
9205
|
+
} catch { /* fall through */ }
|
|
9206
|
+
return { w: 620, h: 560 };
|
|
9207
|
+
});
|
|
9127
9208
|
const dialogRef = useRef(null);
|
|
9209
|
+
const dragRef = useRef(null);
|
|
9210
|
+
const bottomRef = useRef(null);
|
|
9128
9211
|
const sessionRef = useRef(sessionId);
|
|
9129
9212
|
sessionRef.current = sessionId;
|
|
9130
9213
|
const t = useCallback((key, params) => translateCurrent(key, params), []);
|
|
9131
9214
|
|
|
9215
|
+
const persistHistory = useCallback((next) => {
|
|
9216
|
+
setHistory(next);
|
|
9217
|
+
try { localStorage.setItem('dsh-powerup:directask:history:v1', JSON.stringify(next.slice(0, 30))); } catch { /* ignore */ }
|
|
9218
|
+
}, []);
|
|
9219
|
+
|
|
9132
9220
|
useEffect(() => {
|
|
9133
9221
|
if (!open) return undefined;
|
|
9134
9222
|
const onKey = (event) => {
|
|
@@ -9138,12 +9226,58 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
9138
9226
|
return () => document.removeEventListener('keydown', onKey, true);
|
|
9139
9227
|
}, [open]);
|
|
9140
9228
|
|
|
9229
|
+
// Drag (title bar) and resize (bottom-right handle) with native pointers.
|
|
9230
|
+
useEffect(() => {
|
|
9231
|
+
if (!open) return undefined;
|
|
9232
|
+
const onMove = (event) => {
|
|
9233
|
+
const drag = dragRef.current;
|
|
9234
|
+
if (drag === null) return;
|
|
9235
|
+
if (drag.kind === 'move') {
|
|
9236
|
+
setPos({
|
|
9237
|
+
x: Math.max(0, Math.min(window.innerWidth - 120, drag.px + event.clientX - drag.x)),
|
|
9238
|
+
y: Math.max(0, Math.min(window.innerHeight - 60, drag.py + event.clientY - drag.y)),
|
|
9239
|
+
});
|
|
9240
|
+
} else if (drag.kind === 'resize') {
|
|
9241
|
+
setSize({
|
|
9242
|
+
w: Math.max(360, Math.min(1100, drag.w + event.clientX - drag.x)),
|
|
9243
|
+
h: Math.max(280, Math.min(900, drag.h + event.clientY - drag.y)),
|
|
9244
|
+
});
|
|
9245
|
+
}
|
|
9246
|
+
};
|
|
9247
|
+
const onUp = () => {
|
|
9248
|
+
if (dragRef.current === null) return;
|
|
9249
|
+
dragRef.current = null;
|
|
9250
|
+
try {
|
|
9251
|
+
localStorage.setItem('dsh-powerup:directask:pos:v1', JSON.stringify(pos));
|
|
9252
|
+
localStorage.setItem('dsh-powerup:directask:size:v1', JSON.stringify(size));
|
|
9253
|
+
} catch { /* ignore */ }
|
|
9254
|
+
};
|
|
9255
|
+
document.addEventListener('pointermove', onMove);
|
|
9256
|
+
document.addEventListener('pointerup', onUp);
|
|
9257
|
+
return () => {
|
|
9258
|
+
document.removeEventListener('pointermove', onMove);
|
|
9259
|
+
document.removeEventListener('pointerup', onUp);
|
|
9260
|
+
};
|
|
9261
|
+
}, [open, pos, size]);
|
|
9262
|
+
|
|
9263
|
+
useEffect(() => {
|
|
9264
|
+
if (bottomRef.current !== null) bottomRef.current.scrollIntoView?.({ block: 'nearest' });
|
|
9265
|
+
}, [turns, busy]);
|
|
9266
|
+
|
|
9141
9267
|
const send = useCallback(async () => {
|
|
9142
9268
|
const q = question.trim();
|
|
9143
9269
|
if (q === '') { setError(t('directAsk.empty')); return; }
|
|
9270
|
+
const priorContext = files.map((f) => ({ name: f.name, text: f.text }));
|
|
9271
|
+
// Continuous Q&A: send the current turns as prior messages.
|
|
9272
|
+
const historyMsgs = [];
|
|
9273
|
+
for (const turn of turns) {
|
|
9274
|
+
historyMsgs.push({ role: 'user', text: turn.question });
|
|
9275
|
+
if (turn.answer) historyMsgs.push({ role: 'assistant', text: turn.answer });
|
|
9276
|
+
}
|
|
9144
9277
|
setBusy(true);
|
|
9145
9278
|
setError('');
|
|
9146
|
-
|
|
9279
|
+
setQuestion('');
|
|
9280
|
+
setFiles([]);
|
|
9147
9281
|
setCopied(false);
|
|
9148
9282
|
try {
|
|
9149
9283
|
const response = await fetch(DIRECT_ASK_API, {
|
|
@@ -9152,18 +9286,43 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
9152
9286
|
body: JSON.stringify({
|
|
9153
9287
|
sessionId: sessionRef.current ?? '',
|
|
9154
9288
|
question: q,
|
|
9155
|
-
context:
|
|
9289
|
+
context: priorContext,
|
|
9290
|
+
history: historyMsgs,
|
|
9156
9291
|
}),
|
|
9157
9292
|
});
|
|
9158
9293
|
const body = await response.json();
|
|
9159
9294
|
if (!body?.ok) throw new Error(body?.error ?? `HTTP ${response.status}`);
|
|
9160
|
-
|
|
9295
|
+
setTurns((cur) => [...cur, {
|
|
9296
|
+
question: q, answer: typeof body.answer === 'string' ? body.answer : '',
|
|
9297
|
+
context: priorContext, at: Date.now(),
|
|
9298
|
+
}]);
|
|
9161
9299
|
} catch (err) {
|
|
9162
9300
|
setError(err?.message ?? String(err));
|
|
9301
|
+
setQuestion(q);
|
|
9163
9302
|
} finally {
|
|
9164
9303
|
setBusy(false);
|
|
9165
9304
|
}
|
|
9166
|
-
}, [question, files, t]);
|
|
9305
|
+
}, [question, files, turns, t]);
|
|
9306
|
+
|
|
9307
|
+
const newChat = useCallback(() => {
|
|
9308
|
+
if (turns.length > 0) persistHistory([{ id: String(Date.now()), at: Date.now(), turns }, ...history]);
|
|
9309
|
+
setTurns([]);
|
|
9310
|
+
setError('');
|
|
9311
|
+
setShowHistory(false);
|
|
9312
|
+
}, [turns, history, persistHistory]);
|
|
9313
|
+
|
|
9314
|
+
const openArchived = useCallback((entry) => {
|
|
9315
|
+
if (turns.length > 0) persistHistory([{ id: String(Date.now()), at: Date.now(), turns }, ...history.filter((h) => h.id !== entry.id)]);
|
|
9316
|
+
else persistHistory(history.filter((h) => h.id !== entry.id));
|
|
9317
|
+
setTurns(Array.isArray(entry.turns) ? entry.turns : []);
|
|
9318
|
+
setShowHistory(false);
|
|
9319
|
+
}, [turns, history, persistHistory]);
|
|
9320
|
+
|
|
9321
|
+
const clearHistory = useCallback(() => {
|
|
9322
|
+
if (typeof window !== 'undefined' && typeof window.confirm === 'function'
|
|
9323
|
+
&& !window.confirm(t('directAsk.clearHistoryConfirm'))) return;
|
|
9324
|
+
persistHistory([]);
|
|
9325
|
+
}, [t, persistHistory]);
|
|
9167
9326
|
|
|
9168
9327
|
const pickFiles = useCallback(async (event) => {
|
|
9169
9328
|
const picked = Array.from(event?.target?.files ?? []);
|
|
@@ -9182,87 +9341,134 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
9182
9341
|
|
|
9183
9342
|
if (settings.directAsk === false) return null;
|
|
9184
9343
|
|
|
9185
|
-
const lightning = h('svg', { viewBox: '0 0 16 16', width:
|
|
9344
|
+
const lightning = h('svg', { viewBox: '0 0 16 16', width: 16, height: 16, 'aria-hidden': 'true' },
|
|
9186
9345
|
h('path', { d: 'M9 1.5 3.5 9H7l-1 5.5L12.5 7H9l1-5.5Z', fill: 'currentColor' }),
|
|
9187
9346
|
);
|
|
9188
9347
|
|
|
9348
|
+
// Icon-only composer button.
|
|
9189
9349
|
const button = h('button', {
|
|
9190
9350
|
type: 'button',
|
|
9191
9351
|
className: 'dsh-powerup-directask-btn' + (open ? ' on' : ''),
|
|
9192
9352
|
title: t('directAsk.hint'),
|
|
9193
9353
|
'aria-label': t('directAsk.label'),
|
|
9194
9354
|
onClick: () => setOpen((v) => !v),
|
|
9195
|
-
}, lightning
|
|
9355
|
+
}, lightning);
|
|
9196
9356
|
|
|
9197
9357
|
const dialog = !open ? null : h('div', {
|
|
9198
|
-
className: 'dsh-powerup-directask-
|
|
9199
|
-
style: {
|
|
9200
|
-
bottom: '72px',
|
|
9201
|
-
right: '18px',
|
|
9202
|
-
width: 'min(600px, calc(100vw - 36px))',
|
|
9203
|
-
},
|
|
9358
|
+
className: 'dsh-powerup-directask-window',
|
|
9359
|
+
style: { left: `${pos.x}px`, top: `${pos.y}px`, width: `${size.w}px`, height: `${size.h}px` },
|
|
9204
9360
|
},
|
|
9205
9361
|
h('div', {
|
|
9206
|
-
|
|
9207
|
-
|
|
9208
|
-
|
|
9209
|
-
|
|
9362
|
+
className: 'dsh-powerup-directask-titlebar',
|
|
9363
|
+
onPointerDown: (event) => {
|
|
9364
|
+
const target = event.target;
|
|
9365
|
+
if (target instanceof Element && target.closest('button')) return;
|
|
9366
|
+
dragRef.current = { kind: 'move', x: event.clientX, y: event.clientY, px: pos.x, py: pos.y };
|
|
9367
|
+
},
|
|
9210
9368
|
},
|
|
9211
|
-
h('
|
|
9212
|
-
|
|
9213
|
-
|
|
9214
|
-
|
|
9215
|
-
),
|
|
9216
|
-
|
|
9217
|
-
|
|
9218
|
-
|
|
9219
|
-
|
|
9369
|
+
h('span', { className: 'dsh-powerup-directask-title' }, t('directAsk.title')),
|
|
9370
|
+
h('span', { className: 'dsh-powerup-directask-subtitle' }, t('directAsk.subtitle')),
|
|
9371
|
+
h('button', {
|
|
9372
|
+
type: 'button', className: 'dsh-powerup-directask-titlebtn',
|
|
9373
|
+
title: t('directAsk.newChat'), onClick: newChat,
|
|
9374
|
+
}, '+'),
|
|
9375
|
+
h('button', {
|
|
9376
|
+
type: 'button', className: 'dsh-powerup-directask-titlebtn' + (showHistory ? ' on' : ''),
|
|
9377
|
+
title: t('directAsk.history'), onClick: () => setShowHistory((v) => !v),
|
|
9378
|
+
}, '◷'),
|
|
9379
|
+
h('button', {
|
|
9380
|
+
type: 'button', className: 'dsh-powerup-directask-close',
|
|
9381
|
+
'aria-label': t('directAsk.close'), onClick: () => setOpen(false),
|
|
9382
|
+
}, '×'),
|
|
9383
|
+
),
|
|
9384
|
+
showHistory ? h('div', { className: 'dsh-powerup-directask-history' },
|
|
9385
|
+
h('div', { className: 'dsh-powerup-directask-history-head' },
|
|
9386
|
+
h('strong', null, t('directAsk.history')),
|
|
9387
|
+
h('button', { type: 'button', className: 'dsh-powerup-progress-mini', onClick: clearHistory }, t('directAsk.clearHistory')),
|
|
9220
9388
|
),
|
|
9221
|
-
|
|
9222
|
-
|
|
9223
|
-
|
|
9224
|
-
|
|
9225
|
-
h('button', {
|
|
9226
|
-
|
|
9227
|
-
|
|
9228
|
-
|
|
9389
|
+
history.length === 0
|
|
9390
|
+
? h('p', { className: 'dsh-powerup-progress-empty' }, t('directAsk.historyEmpty'))
|
|
9391
|
+
: h('ul', { className: 'dsh-powerup-directask-history-list' },
|
|
9392
|
+
history.map((entry) => h('li', { key: entry.id },
|
|
9393
|
+
h('button', { type: 'button', onClick: () => openArchived(entry) },
|
|
9394
|
+
new Date(entry.at ?? Date.now()).toLocaleString(),
|
|
9395
|
+
' · ', String(entry.turns?.[0]?.question ?? '').slice(0, 40),
|
|
9396
|
+
),
|
|
9229
9397
|
)),
|
|
9230
|
-
) : null,
|
|
9231
|
-
h('label', { className: 'dsh-powerup-directask-label' },
|
|
9232
|
-
h('textarea', {
|
|
9233
|
-
className: 'dsh-powerup-prompt-input dsh-powerup-prompt-textarea',
|
|
9234
|
-
value: question,
|
|
9235
|
-
placeholder: t('directAsk.placeholder'),
|
|
9236
|
-
disabled: busy,
|
|
9237
|
-
onChange: (event) => setQuestion(event.target.value),
|
|
9238
|
-
}),
|
|
9239
9398
|
),
|
|
9240
|
-
|
|
9241
|
-
|
|
9242
|
-
|
|
9399
|
+
) : null,
|
|
9400
|
+
h('div', { className: 'dsh-powerup-directask-thread' },
|
|
9401
|
+
turns.length === 0 && !busy
|
|
9402
|
+
? h('p', { className: 'dsh-powerup-directask-welcome' }, t('directAsk.showHint'))
|
|
9403
|
+
: null,
|
|
9404
|
+
turns.map((turn, i) => h('div', { key: i, className: 'dsh-powerup-directask-turn' },
|
|
9405
|
+
h('div', { className: 'dsh-powerup-directask-msg user' },
|
|
9406
|
+
h('div', { className: 'dsh-powerup-directask-msg-body' }, turn.question),
|
|
9243
9407
|
),
|
|
9244
|
-
h('
|
|
9245
|
-
|
|
9246
|
-
|
|
9247
|
-
|
|
9248
|
-
h('div', { className: 'dsh-powerup-directask-
|
|
9408
|
+
turn.context?.length ? h('div', { className: 'dsh-powerup-directask-ctx' },
|
|
9409
|
+
turn.context.map((f, j) => h('span', { key: j }, f.name)),
|
|
9410
|
+
) : null,
|
|
9411
|
+
h('div', { className: 'dsh-powerup-directask-msg assistant' },
|
|
9412
|
+
h('div', { className: 'dsh-powerup-directask-msg-body' }, turn.answer || '…'),
|
|
9249
9413
|
h('button', {
|
|
9250
9414
|
type: 'button', className: 'dsh-powerup-progress-mini',
|
|
9251
9415
|
onClick: async () => {
|
|
9252
|
-
const ok = await copyText(answer);
|
|
9416
|
+
const ok = await copyText(turn.answer);
|
|
9253
9417
|
if (ok) { setCopied(true); setTimeout(() => setCopied(false), 1500); }
|
|
9254
9418
|
},
|
|
9255
9419
|
}, copied ? t('directAsk.copied') : t('directAsk.copy')),
|
|
9256
|
-
)
|
|
9257
|
-
),
|
|
9258
|
-
h('div', { className: 'dsh-powerup-
|
|
9259
|
-
h('
|
|
9420
|
+
),
|
|
9421
|
+
)),
|
|
9422
|
+
busy ? h('div', { className: 'dsh-powerup-directask-msg assistant' },
|
|
9423
|
+
h('div', { className: 'dsh-powerup-directask-msg-body' }, t('directAsk.sending')),
|
|
9424
|
+
) : null,
|
|
9425
|
+
h('div', { ref: bottomRef }),
|
|
9426
|
+
),
|
|
9427
|
+
error ? h('p', { className: 'dsh-powerup-progress-error' }, error) : null,
|
|
9428
|
+
h('div', { className: 'dsh-powerup-directask-composer' },
|
|
9429
|
+
files.length > 0 ? h('div', { className: 'dsh-powerup-directask-files' },
|
|
9430
|
+
files.map((f, i) => h('span', { key: i, className: 'dsh-powerup-directask-file' },
|
|
9431
|
+
f.name,
|
|
9432
|
+
h('button', {
|
|
9433
|
+
type: 'button', 'aria-label': t('directAsk.removeFile'),
|
|
9434
|
+
onClick: () => setFiles((cur) => cur.filter((_, j) => j !== i)),
|
|
9435
|
+
}, '×'),
|
|
9436
|
+
)),
|
|
9437
|
+
) : null,
|
|
9438
|
+
h('div', { className: 'dsh-powerup-directask-inputrow' },
|
|
9439
|
+
h('label', { className: 'dsh-powerup-directask-attach', title: t('directAsk.attachHint') },
|
|
9440
|
+
h('input', { type: 'file', multiple: true, onChange: (e) => void pickFiles(e) }),
|
|
9441
|
+
h('span', null, '+'),
|
|
9442
|
+
),
|
|
9443
|
+
h('textarea', {
|
|
9444
|
+
className: 'dsh-powerup-directask-input',
|
|
9445
|
+
value: question,
|
|
9446
|
+
placeholder: t('directAsk.placeholder'),
|
|
9447
|
+
disabled: busy,
|
|
9448
|
+
rows: 1,
|
|
9449
|
+
onChange: (event) => setQuestion(event.target.value),
|
|
9450
|
+
onKeyDown: (event) => {
|
|
9451
|
+
if (event.key === 'Enter' && !event.shiftKey && !event.isComposing) {
|
|
9452
|
+
event.preventDefault();
|
|
9453
|
+
void send();
|
|
9454
|
+
}
|
|
9455
|
+
},
|
|
9456
|
+
}),
|
|
9260
9457
|
h('button', {
|
|
9261
|
-
type: 'button', className: 'dsh-powerup-
|
|
9458
|
+
type: 'button', className: 'dsh-powerup-directask-send',
|
|
9262
9459
|
disabled: busy || question.trim() === '', onClick: () => void send(),
|
|
9263
|
-
|
|
9460
|
+
title: t('directAsk.send'),
|
|
9461
|
+
}, h('svg', { viewBox: '0 0 16 16', width: 16, height: 16, 'aria-hidden': 'true' },
|
|
9462
|
+
h('path', { d: 'M3 8h9M8.5 4.5 12 8l-3.5 3.5', fill: 'none', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round', strokeLinejoin: 'round' }))),
|
|
9264
9463
|
),
|
|
9265
9464
|
),
|
|
9465
|
+
h('div', {
|
|
9466
|
+
className: 'dsh-powerup-directask-resizer',
|
|
9467
|
+
onPointerDown: (event) => {
|
|
9468
|
+
event.preventDefault();
|
|
9469
|
+
dragRef.current = { kind: 'resize', x: event.clientX, y: event.clientY, w: size.w, h: size.h };
|
|
9470
|
+
},
|
|
9471
|
+
}),
|
|
9266
9472
|
);
|
|
9267
9473
|
|
|
9268
9474
|
return h(React.Fragment, null, button, renderInBody(dialog));
|
|
@@ -9419,7 +9625,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
9419
9625
|
),
|
|
9420
9626
|
),
|
|
9421
9627
|
h(MaskRuleEditor, { scope: 'workspace', t, workspaceId }),
|
|
9422
|
-
h(
|
|
9628
|
+
h(RequirementManager, { ctx, workspaceOnly: true, workspaceId }),
|
|
9423
9629
|
),
|
|
9424
9630
|
);
|
|
9425
9631
|
}
|
|
@@ -9968,6 +10174,15 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
9968
10174
|
onClick: () => setTab('prompts'),
|
|
9969
10175
|
}, t('prompts.tabManage'))
|
|
9970
10176
|
: null,
|
|
10177
|
+
settings.taskProgress !== false
|
|
10178
|
+
? h('button', {
|
|
10179
|
+
type: 'button',
|
|
10180
|
+
role: 'tab',
|
|
10181
|
+
'aria-selected': tab === 'requirements' ? 'true' : 'false',
|
|
10182
|
+
className: 'dsh-powerup-tab' + (tab === 'requirements' ? ' on' : ''),
|
|
10183
|
+
onClick: () => setTab('requirements'),
|
|
10184
|
+
}, t('progress.tabRequirements'))
|
|
10185
|
+
: null,
|
|
9971
10186
|
);
|
|
9972
10187
|
|
|
9973
10188
|
const featuresContent = h('div', null,
|
|
@@ -9982,11 +10197,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
9982
10197
|
featureCard('scrollToTop', ScrollTopIcon, 'page.scrollToTopTitle', 'page.scrollToTopDesc', 'page.scrollToTopHow'),
|
|
9983
10198
|
featureCard('contentRendering', PowerUpLineIcon, 'page.renderingTitle', 'page.renderingDesc', 'page.renderingHow'),
|
|
9984
10199
|
featureCard('dualSend', LauncherIcon, 'page.dualSendTitle', 'page.dualSendDesc', 'page.dualSendHow'),
|
|
9985
|
-
featureCard('taskProgress', ProgressIcon, 'page.taskProgressTitle', 'page.taskProgressDesc', 'page.taskProgressHow',
|
|
9986
|
-
h('div', { className: 'dsh-powerup-card-detail' },
|
|
9987
|
-
h(ProgressRequirementsEditor, { t }),
|
|
9988
|
-
),
|
|
9989
|
-
),
|
|
10200
|
+
featureCard('taskProgress', ProgressIcon, 'page.taskProgressTitle', 'page.taskProgressDesc', 'page.taskProgressHow'),
|
|
9990
10201
|
featureCard('directAsk', TagIcon, 'page.directAskTitle', 'page.directAskDesc', 'page.directAskHow',
|
|
9991
10202
|
h('div', { className: 'dsh-powerup-card-detail' },
|
|
9992
10203
|
settingRow('directAsk', settings.directAsk !== false, t('page.directAskToggle'), t('page.directAskToggleHint')),
|
|
@@ -10011,7 +10222,9 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
10011
10222
|
? h(MaskRuleEditor, { scope: 'global', t })
|
|
10012
10223
|
: tab === 'prompts' && settings.workspacePrompts !== false
|
|
10013
10224
|
? h(PromptManager, { ctx })
|
|
10014
|
-
:
|
|
10225
|
+
: tab === 'requirements' && settings.taskProgress !== false
|
|
10226
|
+
? h(RequirementManager, { ctx })
|
|
10227
|
+
: featuresContent,
|
|
10015
10228
|
h('footer', { className: 'dsh-powerup-foot' },
|
|
10016
10229
|
h('span', null, format(t('page.footer'), { version: VERSION })),
|
|
10017
10230
|
h('span', { className: 'dsh-powerup-dot' }),
|
|
@@ -10053,8 +10266,8 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
10053
10266
|
const HISTORY_API = '/dsh-powerup/api/progress-history';
|
|
10054
10267
|
const DIRECT_ASK_API = '/dsh-powerup/api/direct-ask';
|
|
10055
10268
|
|
|
10056
|
-
/** Module-level requirements cache:
|
|
10057
|
-
let requirementsCache =
|
|
10269
|
+
/** Module-level requirements cache: flat records [{id,title,text,workspaceId,enabled}]. */
|
|
10270
|
+
let requirementsCache = [];
|
|
10058
10271
|
let requirementsLoaded = false;
|
|
10059
10272
|
const requirementsListeners = new Set();
|
|
10060
10273
|
function emitRequirements() {
|
|
@@ -10062,18 +10275,24 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
10062
10275
|
try { fn(); } catch { /* one listener must not break the rest */ }
|
|
10063
10276
|
}
|
|
10064
10277
|
}
|
|
10278
|
+
function normalizeRequirement(item) {
|
|
10279
|
+
if (item === null || typeof item !== 'object') return null;
|
|
10280
|
+
return {
|
|
10281
|
+
id: typeof item.id === 'string' && item.id !== '' ? item.id : newId(),
|
|
10282
|
+
title: typeof item.title === 'string' ? item.title : '',
|
|
10283
|
+
text: typeof item.text === 'string' ? item.text : '',
|
|
10284
|
+
workspaceId: typeof item.workspaceId === 'string' ? item.workspaceId : '',
|
|
10285
|
+
enabled: item.enabled !== false,
|
|
10286
|
+
};
|
|
10287
|
+
}
|
|
10065
10288
|
async function loadRequirements() {
|
|
10066
10289
|
if (requirementsLoaded) return requirementsCache;
|
|
10067
10290
|
requirementsLoaded = true;
|
|
10068
10291
|
try {
|
|
10069
10292
|
const response = await fetch(REQUIREMENTS_API, { headers: { accept: 'application/json' } });
|
|
10070
10293
|
const data = await response.json();
|
|
10071
|
-
if (data?.ok &&
|
|
10072
|
-
requirementsCache =
|
|
10073
|
-
global: typeof data.requirements.global === 'string' ? data.requirements.global : '',
|
|
10074
|
-
workspaces: data.requirements.workspaces ?? {},
|
|
10075
|
-
sessions: data.requirements.sessions ?? {},
|
|
10076
|
-
};
|
|
10294
|
+
if (data?.ok && Array.isArray(data.requirements)) {
|
|
10295
|
+
requirementsCache = data.requirements.map(normalizeRequirement).filter(Boolean);
|
|
10077
10296
|
}
|
|
10078
10297
|
} catch {
|
|
10079
10298
|
/* Host unavailable: keep the last known value. */
|
|
@@ -10082,12 +10301,12 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
10082
10301
|
return requirementsCache;
|
|
10083
10302
|
}
|
|
10084
10303
|
function saveRequirements(next) {
|
|
10085
|
-
requirementsCache = next;
|
|
10304
|
+
requirementsCache = (Array.isArray(next) ? next : []).map(normalizeRequirement).filter(Boolean);
|
|
10086
10305
|
emitRequirements();
|
|
10087
10306
|
fetch(REQUIREMENTS_API, {
|
|
10088
10307
|
method: 'POST',
|
|
10089
10308
|
headers: { 'content-type': 'application/json', accept: 'application/json' },
|
|
10090
|
-
body: JSON.stringify({ requirements:
|
|
10309
|
+
body: JSON.stringify({ requirements: requirementsCache }),
|
|
10091
10310
|
}).catch(() => { /* in-memory copy still works this session */ });
|
|
10092
10311
|
}
|
|
10093
10312
|
function useRequirements() {
|
|
@@ -10100,6 +10319,12 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
10100
10319
|
}, []);
|
|
10101
10320
|
return requirementsCache;
|
|
10102
10321
|
}
|
|
10322
|
+
/** Requirements visible to one workspace: global (''), plus that workspace. */
|
|
10323
|
+
function requirementsForWorkspace(list, workspaceId) {
|
|
10324
|
+
const id = typeof workspaceId === 'string' ? workspaceId : '';
|
|
10325
|
+
return (Array.isArray(list) ? list : [])
|
|
10326
|
+
.filter((r) => r.workspaceId === '' || r.workspaceId === id);
|
|
10327
|
+
}
|
|
10103
10328
|
|
|
10104
10329
|
/** Textarea field for one requirements layer. */
|
|
10105
10330
|
function RequirementField({ label, hint, value, placeholder, onChange }) {
|
|
@@ -10115,50 +10340,141 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
10115
10340
|
);
|
|
10116
10341
|
}
|
|
10117
10342
|
|
|
10118
|
-
/**
|
|
10119
|
-
|
|
10343
|
+
/**
|
|
10344
|
+
* Multi-record requirement manager, modelled on PromptManager: records are
|
|
10345
|
+
* scoped to a workspace ('' = global) and can be enabled/disabled, edited
|
|
10346
|
+
* and deleted. Used in the Power-Up page's new "Requirements" tab and as
|
|
10347
|
+
* the workspace-scoped editor in the conversation settings tab.
|
|
10348
|
+
*/
|
|
10349
|
+
function RequirementManager({ ctx, workspaceOnly, workspaceId }) {
|
|
10120
10350
|
const reqs = useRequirements();
|
|
10121
|
-
|
|
10122
|
-
|
|
10123
|
-
|
|
10124
|
-
|
|
10125
|
-
|
|
10126
|
-
|
|
10127
|
-
|
|
10128
|
-
|
|
10129
|
-
);
|
|
10130
|
-
|
|
10351
|
+
const [, forceLocale] = useState(0);
|
|
10352
|
+
const [draft, setDraft] = useState(null);
|
|
10353
|
+
const [expanded, setExpanded] = useState(null);
|
|
10354
|
+
const t = (key, params) => translateCurrent(key, params);
|
|
10355
|
+
useEffect(() => {
|
|
10356
|
+
const locale = ctx?.get?.('locale');
|
|
10357
|
+
if (locale === undefined || typeof locale.subscribe !== 'function') return undefined;
|
|
10358
|
+
return locale.subscribe(() => forceLocale((v) => v + 1));
|
|
10359
|
+
}, [ctx]);
|
|
10360
|
+
const workspaces = (() => {
|
|
10361
|
+
try {
|
|
10362
|
+
const snapshot = ctx?.get?.('workspaces')?.list?.getSnapshot?.();
|
|
10363
|
+
return Array.isArray(snapshot?.items) ? snapshot.items : [];
|
|
10364
|
+
} catch { return []; }
|
|
10365
|
+
})();
|
|
10366
|
+
const visible = workspaceOnly
|
|
10367
|
+
? reqs.filter((r) => r.workspaceId === (typeof workspaceId === 'string' ? workspaceId : ''))
|
|
10368
|
+
: reqs;
|
|
10369
|
+
|
|
10370
|
+
const sections = workspaceOnly
|
|
10371
|
+
? [{ id: workspaceId ?? '', label: t('progress.reqWorkspace'), items: visible }]
|
|
10372
|
+
: [
|
|
10373
|
+
{ id: '', label: t('prompts.scopeGlobal'), items: reqs.filter((r) => r.workspaceId === '') },
|
|
10374
|
+
...workspaces.map((ws) => ({
|
|
10375
|
+
id: ws.workspaceId,
|
|
10376
|
+
label: ws.title ?? ws.workspaceId,
|
|
10377
|
+
items: reqs.filter((r) => r.workspaceId === ws.workspaceId),
|
|
10378
|
+
})),
|
|
10379
|
+
];
|
|
10131
10380
|
|
|
10132
|
-
|
|
10133
|
-
|
|
10134
|
-
|
|
10135
|
-
|
|
10136
|
-
|
|
10137
|
-
|
|
10138
|
-
|
|
10139
|
-
|
|
10140
|
-
|
|
10381
|
+
const cancel = () => { setDraft(null); setExpanded(null); };
|
|
10382
|
+
const save = () => {
|
|
10383
|
+
if (draft === null) return;
|
|
10384
|
+
const text = typeof draft.text === 'string' ? draft.text.trim() : '';
|
|
10385
|
+
if (text === '') return;
|
|
10386
|
+
const record = {
|
|
10387
|
+
id: draft.id || newId(),
|
|
10388
|
+
title: typeof draft.title === 'string' ? draft.title.trim() : '',
|
|
10389
|
+
text,
|
|
10390
|
+
workspaceId: typeof draft.workspaceId === 'string' ? draft.workspaceId : '',
|
|
10391
|
+
enabled: draft.enabled !== false,
|
|
10392
|
+
};
|
|
10393
|
+
const next = reqs.filter((r) => r.id !== record.id);
|
|
10394
|
+
next.push(record);
|
|
10395
|
+
saveRequirements(next);
|
|
10396
|
+
cancel();
|
|
10397
|
+
};
|
|
10398
|
+
const remove = (record) => {
|
|
10399
|
+
if (typeof window !== 'undefined' && typeof window.confirm === 'function'
|
|
10400
|
+
&& !window.confirm(t('prompts.confirmDelete'))) return;
|
|
10401
|
+
saveRequirements(reqs.filter((r) => r.id !== record.id));
|
|
10141
10402
|
};
|
|
10142
|
-
const
|
|
10143
|
-
|
|
10144
|
-
sessions[sid] = value;
|
|
10145
|
-
saveRequirements({ ...requirementsCache, sessions });
|
|
10403
|
+
const toggleEnabled = (record) => {
|
|
10404
|
+
saveRequirements(reqs.map((r) => (r.id === record.id ? { ...r, enabled: r.enabled === false } : r)));
|
|
10146
10405
|
};
|
|
10147
|
-
|
|
10148
|
-
|
|
10406
|
+
|
|
10407
|
+
return h('div', { className: 'dsh-powerup-req-manager' },
|
|
10149
10408
|
h('p', { className: 'dsh-powerup-card-desc' }, t('progress.reqHint')),
|
|
10150
|
-
h(
|
|
10151
|
-
|
|
10152
|
-
|
|
10153
|
-
|
|
10154
|
-
|
|
10409
|
+
...sections.map((section) => h('div', { key: `sec-${section.id}` },
|
|
10410
|
+
h('h3', { className: 'dsh-powerup-section-title' }, section.label),
|
|
10411
|
+
h('ul', { className: 'dsh-powerup-req-list' },
|
|
10412
|
+
section.items.map((r) => h('li', { key: r.id, className: 'dsh-powerup-req-item' + (r.enabled === false ? ' off' : '') },
|
|
10413
|
+
h('button', {
|
|
10414
|
+
type: 'button', role: 'switch', 'aria-checked': r.enabled !== false ? 'true' : 'false',
|
|
10415
|
+
className: 'dsh-powerup-switch', title: t('page.enabled'),
|
|
10416
|
+
onClick: () => toggleEnabled(r),
|
|
10417
|
+
}, r.enabled !== false ? t('page.enabled') : t('page.disabled')),
|
|
10418
|
+
h('div', { className: 'dsh-powerup-req-copy' },
|
|
10419
|
+
h('span', { className: 'dsh-powerup-req-title' }, r.title || (r.text.slice(0, 40) + (r.text.length > 40 ? '…' : ''))),
|
|
10420
|
+
h('span', { className: 'dsh-powerup-req-text' }, r.text),
|
|
10421
|
+
),
|
|
10422
|
+
h('button', {
|
|
10423
|
+
type: 'button', className: 'dsh-powerup-prompt-new', onClick: () => { setDraft({ ...r }); setExpanded(r.id); },
|
|
10424
|
+
}, t('prompts.edit')),
|
|
10425
|
+
h('button', {
|
|
10426
|
+
type: 'button', className: 'dsh-powerup-prompt-new', onClick: () => remove(r),
|
|
10427
|
+
}, t('prompts.delete')),
|
|
10428
|
+
)),
|
|
10429
|
+
),
|
|
10430
|
+
expanded === `new-${section.id}` && draft !== null
|
|
10431
|
+
? h(RequirementForm, { draft, setDraft, workspaces, workspaceOnly, scopeId: section.id, t, save, cancel })
|
|
10432
|
+
: null,
|
|
10433
|
+
h('button', {
|
|
10434
|
+
type: 'button', className: 'dsh-powerup-prompt-new',
|
|
10435
|
+
onClick: () => { setDraft({ id: '', title: '', text: '', workspaceId: section.id, enabled: true }); setExpanded(`new-${section.id}`); },
|
|
10436
|
+
}, t('progress.reqNew')),
|
|
10437
|
+
)),
|
|
10438
|
+
);
|
|
10439
|
+
}
|
|
10440
|
+
|
|
10441
|
+
/** Inline create/edit form for one requirement record. */
|
|
10442
|
+
function RequirementForm({ draft, setDraft, workspaces, workspaceOnly, scopeId, t, save, cancel }) {
|
|
10443
|
+
return h('div', { className: 'dsh-powerup-req-form' },
|
|
10444
|
+
h('input', {
|
|
10445
|
+
className: 'dsh-powerup-prompt-input', type: 'text',
|
|
10446
|
+
value: draft.title ?? '', placeholder: t('prompts.titlePlaceholder'),
|
|
10447
|
+
onChange: (e) => setDraft({ ...draft, title: e.target.value }),
|
|
10155
10448
|
}),
|
|
10156
|
-
|
|
10157
|
-
|
|
10158
|
-
value:
|
|
10159
|
-
|
|
10160
|
-
|
|
10449
|
+
h('textarea', {
|
|
10450
|
+
className: 'dsh-powerup-prompt-input dsh-powerup-prompt-textarea',
|
|
10451
|
+
value: draft.text ?? '', placeholder: t('progress.reqPlaceholder'),
|
|
10452
|
+
onChange: (e) => setDraft({ ...draft, text: e.target.value }),
|
|
10453
|
+
}),
|
|
10454
|
+
!workspaceOnly ? h(WorkspaceSelect, {
|
|
10455
|
+
value: draft.workspaceId ?? '',
|
|
10456
|
+
options: [{ value: '', label: t('prompts.anyWorkspace') }, ...workspaces.map((ws) => ({ value: ws.workspaceId, label: ws.title ?? ws.workspaceId }))],
|
|
10457
|
+
onChange: (value) => setDraft({ ...draft, workspaceId: value }),
|
|
10458
|
+
t,
|
|
10161
10459
|
}) : null,
|
|
10460
|
+
h('div', { className: 'dsh-powerup-req-form-foot' },
|
|
10461
|
+
h('button', { type: 'button', className: 'dsh-powerup-update-ghost', onClick: cancel }, t('prompts.cancel')),
|
|
10462
|
+
h('button', { type: 'button', className: 'dsh-powerup-update-primary', onClick: save }, t('prompts.save')),
|
|
10463
|
+
),
|
|
10464
|
+
);
|
|
10465
|
+
}
|
|
10466
|
+
|
|
10467
|
+
/** Panel picker: choose which visible requirements to apply for this generation. */
|
|
10468
|
+
function RequirementPicker({ reqs, selectedIds, onToggle, t }) {
|
|
10469
|
+
if (reqs.length === 0) return h('p', { className: 'dsh-powerup-progress-empty' }, t('progress.reqEmpty'));
|
|
10470
|
+
return h('div', { className: 'dsh-powerup-req-picker' },
|
|
10471
|
+
reqs.map((r) => h('label', { key: r.id, className: 'dsh-powerup-req-option' },
|
|
10472
|
+
h('input', {
|
|
10473
|
+
type: 'checkbox', checked: selectedIds.includes(r.id),
|
|
10474
|
+
onChange: () => onToggle(r.id),
|
|
10475
|
+
}),
|
|
10476
|
+
h('span', null, r.title || (r.text.slice(0, 50) + (r.text.length > 50 ? '…' : ''))),
|
|
10477
|
+
)),
|
|
10162
10478
|
);
|
|
10163
10479
|
}
|
|
10164
10480
|
|
|
@@ -10317,7 +10633,17 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
10317
10633
|
const [historyIndex, setHistoryIndex] = useState(0);
|
|
10318
10634
|
const [showRaw, setShowRaw] = useState(false);
|
|
10319
10635
|
const [showReq, setShowReq] = useState(false);
|
|
10320
|
-
|
|
10636
|
+
// Ids of requirement records selected for the next generation.
|
|
10637
|
+
const [selectedReqIds, setSelectedReqIds] = useState([]);
|
|
10638
|
+
const reqs = useRequirements();
|
|
10639
|
+
// Resolve the owning workspace for requirement filtering.
|
|
10640
|
+
const workspaceId = useMemo(() => {
|
|
10641
|
+
try {
|
|
10642
|
+
const snapshot = ctxRef.current?.get?.('workspaces')?.list?.getSnapshot?.();
|
|
10643
|
+
return resolveWorkspaceIdFromSnapshot(snapshot, sessionRef.current) ?? '';
|
|
10644
|
+
} catch { return ''; }
|
|
10645
|
+
}, [sessionId, open]);
|
|
10646
|
+
const visibleReqs = requirementsForWorkspace(reqs, workspaceId);
|
|
10321
10647
|
const [size, setSize] = useState(() => {
|
|
10322
10648
|
try {
|
|
10323
10649
|
const saved = JSON.parse(localStorage.getItem('dsh-powerup:progress:size:v1') || 'null');
|
|
@@ -10373,7 +10699,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
10373
10699
|
if (typeof id !== 'string' || id === '') return;
|
|
10374
10700
|
setBusy(true);
|
|
10375
10701
|
try {
|
|
10376
|
-
const body = await progressRequest(id, 'start', {
|
|
10702
|
+
const body = await progressRequest(id, 'start', { requirementIds: selectedReqIds });
|
|
10377
10703
|
setView(body);
|
|
10378
10704
|
setHistoryIndex(0);
|
|
10379
10705
|
} catch (error) {
|
|
@@ -10382,7 +10708,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
10382
10708
|
setBusy(false);
|
|
10383
10709
|
if (!open) setOpen(true);
|
|
10384
10710
|
}
|
|
10385
|
-
}, [open,
|
|
10711
|
+
}, [open, selectedReqIds]);
|
|
10386
10712
|
|
|
10387
10713
|
const clearHistory = useCallback(async () => {
|
|
10388
10714
|
const id = sessionRef.current;
|
|
@@ -10425,7 +10751,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
10425
10751
|
const drag = dragRef.current;
|
|
10426
10752
|
if (drag === null) return;
|
|
10427
10753
|
const w = Math.max(320, Math.min(900, drag.w + drag.x - event.clientX));
|
|
10428
|
-
const h = Math.max(240, Math.min(900, drag.h +
|
|
10754
|
+
const h = Math.max(240, Math.min(900, drag.h + event.clientY - drag.y));
|
|
10429
10755
|
setSize({ w, h });
|
|
10430
10756
|
};
|
|
10431
10757
|
const onUp = () => {
|
|
@@ -10547,12 +10873,13 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
10547
10873
|
})();
|
|
10548
10874
|
|
|
10549
10875
|
const requirementsEditor = showReq ? h('div', { className: 'dsh-powerup-progress-req-pop' },
|
|
10550
|
-
h(
|
|
10551
|
-
|
|
10552
|
-
|
|
10553
|
-
|
|
10554
|
-
|
|
10555
|
-
|
|
10876
|
+
h('span', { className: 'dsh-powerup-prompt-field-label' }, t('progress.reqSelect')),
|
|
10877
|
+
h('p', { className: 'dsh-powerup-setting-hint' }, t('progress.reqSelectHint')),
|
|
10878
|
+
h(RequirementPicker, {
|
|
10879
|
+
reqs: visibleReqs,
|
|
10880
|
+
selectedIds: selectedReqIds,
|
|
10881
|
+
t,
|
|
10882
|
+
onToggle: (id) => setSelectedReqIds((cur) => cur.includes(id) ? cur.filter((x) => x !== id) : [...cur, id]),
|
|
10556
10883
|
}),
|
|
10557
10884
|
) : null;
|
|
10558
10885
|
|
|
@@ -10784,8 +11111,9 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
10784
11111
|
PROMPTS_CSS,
|
|
10785
11112
|
PROGRESS_CSS,
|
|
10786
11113
|
ProgressControl,
|
|
10787
|
-
|
|
10788
|
-
|
|
11114
|
+
RequirementManager,
|
|
11115
|
+
RequirementPicker,
|
|
11116
|
+
requirementForWorkspace: requirementsForWorkspace,
|
|
10789
11117
|
DirectAskButton,
|
|
10790
11118
|
ProgressStructure,
|
|
10791
11119
|
ProgressDisplay,
|
package/index.js
CHANGED
|
@@ -483,12 +483,21 @@ async function handle(req, res, ctx) {
|
|
|
483
483
|
if (req.method === 'POST') {
|
|
484
484
|
try {
|
|
485
485
|
const body = await readJsonBody(req);
|
|
486
|
-
|
|
486
|
+
// Keep the flat list form; accept {requirements: [...]} or a bare array.
|
|
487
|
+
const list = Array.isArray(body?.requirements)
|
|
487
488
|
? body.requirements
|
|
488
|
-
:
|
|
489
|
+
: Array.isArray(body) ? body : [];
|
|
490
|
+
const records = list.filter((r) => r !== null && typeof r === 'object')
|
|
491
|
+
.map((r) => ({
|
|
492
|
+
id: typeof r.id === 'string' && r.id !== '' ? r.id : `req-${randomUUID()}`,
|
|
493
|
+
title: typeof r.title === 'string' ? r.title : '',
|
|
494
|
+
text: typeof r.text === 'string' ? r.text : '',
|
|
495
|
+
workspaceId: typeof r.workspaceId === 'string' ? r.workspaceId : '',
|
|
496
|
+
enabled: r.enabled !== false,
|
|
497
|
+
}));
|
|
489
498
|
mkdirSync(dirname(filePath), { recursive: true });
|
|
490
|
-
writeFileSync(filePath, JSON.stringify(
|
|
491
|
-
sendJson(res, { ok: true, requirements });
|
|
499
|
+
writeFileSync(filePath, JSON.stringify(records, null, 2) + '\n', 'utf8');
|
|
500
|
+
sendJson(res, { ok: true, requirements: records });
|
|
492
501
|
} catch (error) {
|
|
493
502
|
sendJson(res, { ok: false, error: String(error?.message ?? error) }, 500);
|
|
494
503
|
}
|
|
@@ -499,7 +508,12 @@ async function handle(req, res, ctx) {
|
|
|
499
508
|
return;
|
|
500
509
|
}
|
|
501
510
|
try {
|
|
502
|
-
|
|
511
|
+
let raw;
|
|
512
|
+
try { raw = JSON.parse(readFileSync(filePath, 'utf8')); } catch { raw = undefined; }
|
|
513
|
+
let records = [];
|
|
514
|
+
if (Array.isArray(raw)) records = raw;
|
|
515
|
+
else if (raw !== null && typeof raw === 'object' && Array.isArray(raw.records)) records = raw.records;
|
|
516
|
+
sendJson(res, { ok: true, requirements: records });
|
|
503
517
|
} catch (error) {
|
|
504
518
|
sendJson(res, { ok: false, error: String(error?.message ?? error) }, 500);
|
|
505
519
|
}
|
|
@@ -547,6 +561,7 @@ async function handle(req, res, ctx) {
|
|
|
547
561
|
}
|
|
548
562
|
const sessionId = typeof body?.sessionId === 'string' ? body.sessionId.trim() : '';
|
|
549
563
|
const context = Array.isArray(body?.context) ? body.context : [];
|
|
564
|
+
const history = Array.isArray(body?.history) ? body.history : [];
|
|
550
565
|
const prompt = buildAskPrompt({ question: cleanAskText(body?.question), context });
|
|
551
566
|
if (prompt === '') {
|
|
552
567
|
sendJson(res, { ok: false, code: 'invalid-request', error: 'question is required' }, 400);
|
|
@@ -578,7 +593,7 @@ async function handle(req, res, ctx) {
|
|
|
578
593
|
const timer = setTimeout(() => controller.abort(), 90_000);
|
|
579
594
|
timer.unref?.();
|
|
580
595
|
try {
|
|
581
|
-
const answer = await directAsk({ llm, route, prompt, signal: controller.signal });
|
|
596
|
+
const answer = await directAsk({ llm, route, prompt, history, signal: controller.signal });
|
|
582
597
|
sendJson(res, { ok: true, answer: answer.text, finish: answer.finish ?? null });
|
|
583
598
|
} catch (error) {
|
|
584
599
|
sendJson(res, { ok: false, code: error?.code ?? 'ask-failed', error: String(error?.message ?? error) }, 500);
|
|
@@ -612,11 +627,11 @@ async function handle(req, res, ctx) {
|
|
|
612
627
|
return;
|
|
613
628
|
}
|
|
614
629
|
try {
|
|
615
|
-
// A one-off requirements
|
|
616
|
-
// the next start; it does not modify the persisted
|
|
617
|
-
if (
|
|
618
|
-
ctx.
|
|
619
|
-
ctx.
|
|
630
|
+
// A one-off requirements selection from the progress panel is kept for
|
|
631
|
+
// the next start; it does not modify the persisted records.
|
|
632
|
+
if (Array.isArray(body?.requirementIds)) {
|
|
633
|
+
ctx.__powerupProgressSelection = ctx.__powerupProgressSelection ?? {};
|
|
634
|
+
ctx.__powerupProgressSelection[sessionId] = body.requirementIds.map(String);
|
|
620
635
|
}
|
|
621
636
|
const view = action === 'start'
|
|
622
637
|
? manager.start(sessionId)
|
|
@@ -904,21 +919,39 @@ export function apply(ctx) {
|
|
|
904
919
|
// The progress side call needs both `llm` and `sessionQuery`. Wait for them
|
|
905
920
|
// through inject so a late-provided service still creates the manager.
|
|
906
921
|
ctx.inject(['llm', 'sessionQuery'], (scope) => {
|
|
907
|
-
// Requirements are
|
|
908
|
-
//
|
|
909
|
-
//
|
|
910
|
-
const requirementsFor = (sessionId,
|
|
911
|
-
const
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
922
|
+
// Requirements are a flat list of records: {id,title,text,workspaceId,enabled}.
|
|
923
|
+
// workspaceId '' = global. The panel sends the ids it wants; the Host only
|
|
924
|
+
// includes records visible to the session's workspace and explicitly picked.
|
|
925
|
+
const requirementsFor = (sessionId, selectedIds) => {
|
|
926
|
+
const file = storePath(PROGRESS_REQUIREMENTS_FILE);
|
|
927
|
+
let raw;
|
|
928
|
+
try {
|
|
929
|
+
raw = JSON.parse(readFileSync(file, 'utf8'));
|
|
930
|
+
} catch {
|
|
931
|
+
raw = undefined;
|
|
932
|
+
}
|
|
933
|
+
let all = [];
|
|
934
|
+
if (Array.isArray(raw)) all = raw;
|
|
935
|
+
else if (raw !== null && typeof raw === 'object' && Array.isArray(raw.records)) all = raw.records;
|
|
936
|
+
else if (raw !== null && typeof raw === 'object') {
|
|
937
|
+
// Legacy object form ({global, workspaces, sessions}) migrated on read.
|
|
938
|
+
const migrated = [];
|
|
939
|
+
if (typeof raw.global === 'string' && raw.global.trim() !== '') {
|
|
940
|
+
migrated.push({ id: 'legacy-global', title: '通用要求', text: raw.global, workspaceId: '', enabled: true });
|
|
941
|
+
}
|
|
942
|
+
const ws = raw.workspaces ?? {};
|
|
943
|
+
for (const [wid, text] of Object.entries(ws)) {
|
|
944
|
+
if (typeof text === 'string' && text.trim() !== '') {
|
|
945
|
+
migrated.push({ id: `legacy-ws-${wid}`, title: '工作区要求', text, workspaceId: wid, enabled: true });
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
all = migrated;
|
|
949
|
+
}
|
|
917
950
|
let workspaceId = '';
|
|
918
951
|
try {
|
|
919
952
|
const registry = scope.get('workspaceRegistry');
|
|
920
|
-
const
|
|
921
|
-
for (const item of Array.isArray(
|
|
953
|
+
const list = typeof registry?.list === 'function' ? registry.list() : [];
|
|
954
|
+
for (const item of Array.isArray(list) ? list : []) {
|
|
922
955
|
if (Array.isArray(item?.sessionIds) && item.sessionIds.includes(sessionId)) {
|
|
923
956
|
workspaceId = typeof item.id === 'string' ? item.id : '';
|
|
924
957
|
break;
|
|
@@ -927,13 +960,17 @@ export function apply(ctx) {
|
|
|
927
960
|
} catch {
|
|
928
961
|
/* workspace layer is optional */
|
|
929
962
|
}
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
963
|
+
const ids = Array.isArray(selectedIds) ? new Set(selectedIds.map(String)) : null;
|
|
964
|
+
const parts = [];
|
|
965
|
+
for (const record of all) {
|
|
966
|
+
if (record === null || typeof record !== 'object') continue;
|
|
967
|
+
if (record.enabled === false) continue;
|
|
968
|
+
if (typeof record.text !== 'string' || record.text.trim() === '') continue;
|
|
969
|
+
const wid = typeof record.workspaceId === 'string' ? record.workspaceId : '';
|
|
970
|
+
if (wid !== '' && wid !== workspaceId) continue; // workspace isolation
|
|
971
|
+
if (ids !== null && !ids.has(String(record.id))) continue; // panel selection
|
|
972
|
+
parts.push(record.text.trim());
|
|
935
973
|
}
|
|
936
|
-
if (typeof override === 'string' && override.trim() !== '') parts.push(override.trim());
|
|
937
974
|
return parts.join('\n\n');
|
|
938
975
|
};
|
|
939
976
|
// Persist progress history to disk so it survives restarts and refreshes.
|
|
@@ -949,7 +986,7 @@ export function apply(ctx) {
|
|
|
949
986
|
? selection
|
|
950
987
|
: undefined;
|
|
951
988
|
},
|
|
952
|
-
getRequirements: (sessionId) => requirementsFor(sessionId, ctx.
|
|
989
|
+
getRequirements: (sessionId) => requirementsFor(sessionId, ctx.__powerupProgressSelection?.[sessionId]),
|
|
953
990
|
onHistoryChange: (sessionId, history) => {
|
|
954
991
|
try {
|
|
955
992
|
const all = readJsonObject(historyPath);
|
|
@@ -977,7 +1014,7 @@ export function apply(ctx) {
|
|
|
977
1014
|
return originalPoll(sessionId);
|
|
978
1015
|
};
|
|
979
1016
|
ctx.__powerupProgress = manager;
|
|
980
|
-
ctx.
|
|
1017
|
+
ctx.__powerupProgressSelection = ctx.__powerupProgressSelection ?? {};
|
|
981
1018
|
scope.effect(() => () => {
|
|
982
1019
|
if (ctx.__powerupProgress === manager) ctx.__powerupProgress = undefined;
|
|
983
1020
|
}, 'dsh-powerup: progress manager');
|
package/lib/direct-ask.js
CHANGED
|
@@ -71,10 +71,11 @@ export function buildAskPrompt(input = {}) {
|
|
|
71
71
|
* @param {object} options.llm Host `ctx.llm` service
|
|
72
72
|
* @param {{provider: string, model: string, reasoningEffort?: string}} options.route
|
|
73
73
|
* @param {string} options.prompt assembled prompt from {@link buildAskPrompt}
|
|
74
|
+
* @param {Array<{role:'user'|'assistant', text:string}>} [options.history] prior turns for continuous Q&A
|
|
74
75
|
* @param {AbortSignal} [options.signal]
|
|
75
76
|
* @returns {Promise<{text: string, finish: string|undefined}>}
|
|
76
77
|
*/
|
|
77
|
-
export async function directAsk({ llm, route, prompt, signal, maxTokens }) {
|
|
78
|
+
export async function directAsk({ llm, route, prompt, history, signal, maxTokens }) {
|
|
78
79
|
if (llm === null || typeof llm !== 'object' || typeof llm.prepareCall !== 'function') {
|
|
79
80
|
throw new DirectAskError('LLM_UNAVAILABLE', 'the llm service is unavailable');
|
|
80
81
|
}
|
|
@@ -90,9 +91,19 @@ export async function directAsk({ llm, route, prompt, signal, maxTokens }) {
|
|
|
90
91
|
maxTokens: Number.isFinite(maxTokens) ? maxTokens : DIRECT_ASK_MAX_TOKENS,
|
|
91
92
|
};
|
|
92
93
|
const call = await llm.prepareCall(config, signal);
|
|
94
|
+
const messages = [];
|
|
95
|
+
for (const turn of Array.isArray(history) ? history : []) {
|
|
96
|
+
if (turn === null || typeof turn !== 'object') continue;
|
|
97
|
+
const role = turn.role === 'assistant' ? 'assistant' : turn.role === 'user' ? 'user' : null;
|
|
98
|
+
if (role === null) continue;
|
|
99
|
+
const text = cleanAskText(turn.text);
|
|
100
|
+
if (text === '') continue;
|
|
101
|
+
messages.push({ role, content: [{ type: 'text', text }] });
|
|
102
|
+
}
|
|
103
|
+
messages.push({ role: 'user', content: [{ type: 'text', text: question }] });
|
|
93
104
|
const options = {
|
|
94
105
|
...call.config,
|
|
95
|
-
messages
|
|
106
|
+
messages,
|
|
96
107
|
system: DIRECT_ASK_SYSTEM_PROMPT,
|
|
97
108
|
purpose: 'powerup-direct-ask',
|
|
98
109
|
...(signal === undefined ? {} : { signal }),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@restregular/dsh-powerup",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "为 DeepSeek Harness 提供一组可选的小型增强:轨迹右键菜单与步骤引用、后台任务停止原因、插件一键安装、侧边栏图标网格、会话切换、定位当前会话、工作区提示词、旁路模型生成的结构化任务进度;所有功能均可在 Power-Up 页面独立开关。 · Opt-in upgrades for DeepSeek Harness: Trajectory context menu and step references, job stop reasons, one-click plugin install, an adaptive sidebar launcher, session switching, locating the current session, workspace prompts, and non-blocking model-generated structured task progress — each toggled independently on the Power-Up page.",
|
|
5
5
|
"icon": "./icon.svg",
|
|
6
6
|
"type": "module",
|