@restregular/dsh-powerup 0.19.5 → 0.19.7
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 +22 -2
- package/client.js +237 -2
- package/index.js +69 -1
- package/lib/quick-replies.js +193 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -7,8 +7,10 @@ data, an optional **stop reason for background jobs**, an in-place
|
|
|
7
7
|
**plugin installer**, and a **sidebar launcher** that turns the left sidebar's
|
|
8
8
|
panel list into an adaptive icon grid with drag sorting, folders, a
|
|
9
9
|
back-to-conversation tile, and restart/close tiles. It also adds a
|
|
10
|
-
**task-progress panel** with three-layer requirements and browsable history,
|
|
11
|
-
|
|
10
|
+
**task-progress panel** with three-layer requirements and browsable history, a
|
|
11
|
+
**direct-ask button** for one-shot model answers without an Agent, and
|
|
12
|
+
**quick-reply options** that let the Agent offer tappable text buttons above the
|
|
13
|
+
composer.
|
|
12
14
|
|
|
13
15
|
## Install
|
|
14
16
|
|
|
@@ -109,6 +111,24 @@ omitted by default because they are large. The tool is workspace-agnostic: it
|
|
|
109
111
|
reads the session named in the reference through `ctx.sessionQuery`, so an agent
|
|
110
112
|
can open a step in a session it never had to locate on disk.
|
|
111
113
|
|
|
114
|
+
### Quick replies
|
|
115
|
+
|
|
116
|
+
The Agent can call the **`powerup_quick_replies`** tool to publish a short list
|
|
117
|
+
of tappable options for the current session:
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{ "options": [
|
|
121
|
+
{ "label": "继续", "message": "请继续完成剩下的步骤" },
|
|
122
|
+
{ "label": "换个方案", "message": "换一个方案试试" }
|
|
123
|
+
] }
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Up to 8 options appear as pills above the composer. Tapping one sends its
|
|
127
|
+
`message` as a normal user message. The options disappear as soon as the user
|
|
128
|
+
sends any message — tapping an option, pressing Enter, or clicking the host's
|
|
129
|
+
Send button. The Agent can also pass an empty `options` array to clear them
|
|
130
|
+
immediately.
|
|
131
|
+
|
|
112
132
|
### Sidebar launcher
|
|
113
133
|
|
|
114
134
|
The left sidebar's global panel buttons (Conversation, Files, Plugins, and the
|
package/client.js
CHANGED
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
const requirementCreateDraft = { workspaceId: null, title: '', text: '', scope: 'current' };
|
|
86
86
|
/** Fallback bucket when the hero cannot resolve an owning workspace yet. */
|
|
87
87
|
const UNSCOPED_WORKSPACE = '__unscoped__';
|
|
88
|
-
const VERSION = '0.19.
|
|
88
|
+
const VERSION = '0.19.7';
|
|
89
89
|
const MENU_GAP = 8;
|
|
90
90
|
const MENU_WIDTH = 248;
|
|
91
91
|
/** Reference scheme understood by the Host's `powerup_step_read` tool. */
|
|
@@ -143,6 +143,11 @@
|
|
|
143
143
|
'page.dualSendTitle': '双发送按钮',
|
|
144
144
|
'page.dualSendDesc': '在输入框右侧增加两个发送按钮:普通发送(等待/排队)与插话发送(立即打断当前生成)。快捷键 Enter 固定为等待发送、Ctrl+Shift+Enter 固定为插话发送,不受系统「繁忙时发送行为」设置影响。',
|
|
145
145
|
'page.dualSendHow': '启用后输入框里会出现两个按钮,鼠标悬停可看到各自说明;输入文字后按 Enter 排队发送,按 Ctrl+Shift+Enter 立即插话发送。',
|
|
146
|
+
'page.quickRepliesTitle': '快捷回复选项',
|
|
147
|
+
'page.quickRepliesDesc': '允许 Agent 在回复后提供一组带文本的按钮选项。点击选项会立即把对应文本作为新消息发送,用户发出任意新消息(包括点击选项)后,这些选项会自动移除。',
|
|
148
|
+
'page.quickRepliesHow': 'Agent 通过 powerup_quick_replies 工具发布选项;选项出现于输入框上方,点击即可快速回复。',
|
|
149
|
+
'quickReplies.title': '快捷回复',
|
|
150
|
+
'quickReplies.hint': '选择一个选项快速发送',
|
|
146
151
|
'mask.tab': '内容屏蔽',
|
|
147
152
|
'mask.tabFeatures': '功能',
|
|
148
153
|
'mask.tabWorkspace': '工作区设置',
|
|
@@ -768,6 +773,11 @@
|
|
|
768
773
|
'page.taskProgressHow': 'Click Progress in any session header to see the last report; on first use press Generate. You can keep working in the session while it runs.',
|
|
769
774
|
'page.taskProgressCooldown': 'Refresh cooldown (seconds)',
|
|
770
775
|
'page.taskProgressCooldownHint': 'Minimum gap between refreshes to avoid accidental clicks; 0 disables the limit.',
|
|
776
|
+
'page.quickRepliesTitle': 'Quick reply options',
|
|
777
|
+
'page.quickRepliesDesc': 'Let the Agent offer a short list of text buttons after its reply. Tapping one sends its text as a new message immediately; the options are removed automatically once the user sends any message (including tapping an option).',
|
|
778
|
+
'page.quickRepliesHow': 'The Agent publishes options through the powerup_quick_replies tool; they appear above the composer and can be tapped to reply quickly.',
|
|
779
|
+
'quickReplies.title': 'Quick replies',
|
|
780
|
+
'quickReplies.hint': 'Pick an option to send it right away',
|
|
771
781
|
'progress.title': 'Task progress',
|
|
772
782
|
'progress.label': 'Progress',
|
|
773
783
|
'progress.subtitle': 'Generated in the background by this session model',
|
|
@@ -947,6 +957,7 @@
|
|
|
947
957
|
workspacePrompts: true,
|
|
948
958
|
taskProgress: true,
|
|
949
959
|
taskProgressCooldown: 5,
|
|
960
|
+
quickReplies: true,
|
|
950
961
|
directAsk: true,
|
|
951
962
|
directAskAutoTitle: false,
|
|
952
963
|
oneClickEnable: true,
|
|
@@ -976,6 +987,7 @@
|
|
|
976
987
|
const value = Number(parsed.taskProgressCooldown);
|
|
977
988
|
return Number.isFinite(value) && value >= 0 ? Math.min(300, Math.max(0, Math.floor(value))) : DEFAULT_SETTINGS.taskProgressCooldown;
|
|
978
989
|
})(),
|
|
990
|
+
quickReplies: parsed.quickReplies !== false,
|
|
979
991
|
directAsk: parsed.directAsk !== false,
|
|
980
992
|
directAskAutoTitle: parsed.directAskAutoTitle === true,
|
|
981
993
|
oneClickEnable: parsed.oneClickEnable !== false,
|
|
@@ -4442,6 +4454,16 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
4442
4454
|
.dsh-powerup-mask-default:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}
|
|
4443
4455
|
.dsh-powerup-mask-empty{color:var(--dsw-alias-label-secondary);font-size:12px}
|
|
4444
4456
|
@media (max-width:680px){.dsh-powerup-mask-row{grid-template-columns:minmax(0,1fr)}}
|
|
4457
|
+
`;
|
|
4458
|
+
|
|
4459
|
+
const QUICK_REPLIES_CSS = `
|
|
4460
|
+
/* Quick-reply options rendered just above the composer card. */
|
|
4461
|
+
.dsh-powerup-quick-replies{display:flex;flex-wrap:wrap;align-items:center;gap:6px;padding:6px 2px 2px}
|
|
4462
|
+
.dsh-powerup-quick-replies-label{font-size:11px;line-height:18px;color:var(--dsw-alias-label-caption);margin-right:2px}
|
|
4463
|
+
.dsh-powerup-quick-reply{display:inline-flex;align-items:center;max-width:100%;padding:5px 11px;border:.5px solid var(--dsw-alias-border-l2);border-radius:999px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-brand-primary,var(--dsw-alias-label-primary));font:inherit;font-size:12px;line-height:18px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;cursor:pointer;transition:background .12s ease,border-color .12s ease,transform .12s ease}
|
|
4464
|
+
.dsh-powerup-quick-reply:hover{background:var(--dsw-alias-interactive-bg-hover);border-color:var(--dsw-alias-brand-primary,var(--dsw-alias-border-l3));transform:translateY(-1px)}
|
|
4465
|
+
.dsh-powerup-quick-reply:disabled{opacity:.5;cursor:not-allowed;transform:none}
|
|
4466
|
+
.dsh-powerup-quick-reply:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}
|
|
4445
4467
|
`;
|
|
4446
4468
|
|
|
4447
4469
|
const PROMPTS_CSS = `
|
|
@@ -5982,7 +6004,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
5982
6004
|
try {
|
|
5983
6005
|
const style = document.createElement('style');
|
|
5984
6006
|
style.setAttribute('data-dsh-powerup', '');
|
|
5985
|
-
style.textContent = CSS + '\n' + LAUNCHER_CSS + '\n' + SESSION_SWITCH_CSS + '\n' + LOCATE_CSS + '\n' + SCROLL_TOP_CSS + '\n' + RENDERING_CSS + '\n' + PROMPTS_CSS + '\n' + PROGRESS_CSS;
|
|
6007
|
+
style.textContent = CSS + '\n' + LAUNCHER_CSS + '\n' + SESSION_SWITCH_CSS + '\n' + LOCATE_CSS + '\n' + SCROLL_TOP_CSS + '\n' + RENDERING_CSS + '\n' + QUICK_REPLIES_CSS + '\n' + PROMPTS_CSS + '\n' + PROGRESS_CSS;
|
|
5986
6008
|
document.head.appendChild(style);
|
|
5987
6009
|
ctx.effect(() => () => style.remove(), 'dsh-powerup: styles');
|
|
5988
6010
|
} catch (error) {
|
|
@@ -10060,6 +10082,204 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
10060
10082
|
);
|
|
10061
10083
|
}
|
|
10062
10084
|
|
|
10085
|
+
// ------------------------------------------------------------------
|
|
10086
|
+
// Quick replies: tappable message options published by the Agent.
|
|
10087
|
+
// ------------------------------------------------------------------
|
|
10088
|
+
const QUICK_REPLIES_API = '/dsh-powerup/api/quick-replies';
|
|
10089
|
+
/** Last state per session, so options survive a component remount. */
|
|
10090
|
+
const quickRepliesCache = new Map();
|
|
10091
|
+
|
|
10092
|
+
async function quickRepliesRequest(sessionId, action, extra = {}) {
|
|
10093
|
+
const url = action === 'get'
|
|
10094
|
+
? `${QUICK_REPLIES_API}?sessionId=${encodeURIComponent(sessionId)}`
|
|
10095
|
+
: QUICK_REPLIES_API;
|
|
10096
|
+
const init = action === 'get'
|
|
10097
|
+
? {}
|
|
10098
|
+
: {
|
|
10099
|
+
method: 'POST',
|
|
10100
|
+
headers: { 'content-type': 'application/json' },
|
|
10101
|
+
body: JSON.stringify({ sessionId, ...extra }),
|
|
10102
|
+
};
|
|
10103
|
+
const response = await fetch(url, init);
|
|
10104
|
+
const body = await response.json();
|
|
10105
|
+
if (!body?.ok) throw new Error(body?.error ?? `HTTP ${response.status}`);
|
|
10106
|
+
return body;
|
|
10107
|
+
}
|
|
10108
|
+
|
|
10109
|
+
/**
|
|
10110
|
+
* Resolve the session id from the slot prop or the live DOM contract.
|
|
10111
|
+
* @param {string} sessionId
|
|
10112
|
+
*/
|
|
10113
|
+
function quickOwnerId(sessionId) {
|
|
10114
|
+
if (typeof sessionId === 'string' && sessionId !== '') return sessionId;
|
|
10115
|
+
try {
|
|
10116
|
+
const el = document.querySelector('[data-conversation-session]');
|
|
10117
|
+
const id = el === null ? null : el.getAttribute('data-conversation-session');
|
|
10118
|
+
return typeof id === 'string' && id !== '' ? id : '';
|
|
10119
|
+
} catch {
|
|
10120
|
+
return '';
|
|
10121
|
+
}
|
|
10122
|
+
}
|
|
10123
|
+
|
|
10124
|
+
/**
|
|
10125
|
+
* Render the Agent-published reply options as pill buttons directly above
|
|
10126
|
+
* the composer card. Any user message (host send button, Enter, or one of
|
|
10127
|
+
* these buttons) clears them through the Host route.
|
|
10128
|
+
*/
|
|
10129
|
+
function QuickReplies({ sessionId, ctx, t: translate }) {
|
|
10130
|
+
const settings = useSettings();
|
|
10131
|
+
const ownerId = quickOwnerId(sessionId);
|
|
10132
|
+
const ownerRef = useRef(ownerId);
|
|
10133
|
+
ownerRef.current = ownerId;
|
|
10134
|
+
const [container, setContainer] = useState(null);
|
|
10135
|
+
const cached = ownerId !== '' ? quickRepliesCache.get(ownerId) : undefined;
|
|
10136
|
+
const [state, setState] = useState(() => ({
|
|
10137
|
+
options: cached?.options ?? [],
|
|
10138
|
+
version: cached?.version ?? '',
|
|
10139
|
+
}));
|
|
10140
|
+
const stateRef = useRef(state);
|
|
10141
|
+
stateRef.current = state;
|
|
10142
|
+
|
|
10143
|
+
const applyState = useCallback((next) => {
|
|
10144
|
+
const value = {
|
|
10145
|
+
options: Array.isArray(next?.options) ? next.options : [],
|
|
10146
|
+
version: typeof next?.version === 'string' ? next.version : '',
|
|
10147
|
+
};
|
|
10148
|
+
stateRef.current = value;
|
|
10149
|
+
if (ownerRef.current !== '') quickRepliesCache.set(ownerRef.current, value);
|
|
10150
|
+
setState(value);
|
|
10151
|
+
}, []);
|
|
10152
|
+
|
|
10153
|
+
// Poll the Host store while a session is active.
|
|
10154
|
+
useEffect(() => {
|
|
10155
|
+
if (!settings.quickReplies || ownerId === '') {
|
|
10156
|
+
applyState({ options: [], version: '' });
|
|
10157
|
+
return undefined;
|
|
10158
|
+
}
|
|
10159
|
+
let alive = true;
|
|
10160
|
+
const refresh = async () => {
|
|
10161
|
+
try {
|
|
10162
|
+
const body = await quickRepliesRequest(ownerId, 'get');
|
|
10163
|
+
if (!alive) return;
|
|
10164
|
+
const current = stateRef.current;
|
|
10165
|
+
const same = body.options?.length === current.options?.length
|
|
10166
|
+
&& body.version === current.version
|
|
10167
|
+
&& (body.options ?? []).every((o, i) => o.label === current.options[i]?.label
|
|
10168
|
+
&& o.message === current.options[i]?.message);
|
|
10169
|
+
if (!same) applyState(body);
|
|
10170
|
+
} catch {
|
|
10171
|
+
/* A transient fetch failure keeps the last known options. */
|
|
10172
|
+
}
|
|
10173
|
+
};
|
|
10174
|
+
void refresh();
|
|
10175
|
+
const timer = window.setInterval(refresh, 700);
|
|
10176
|
+
return () => { alive = false; window.clearInterval(timer); };
|
|
10177
|
+
}, [settings.quickReplies, ownerId, applyState]);
|
|
10178
|
+
|
|
10179
|
+
// Mount a small container as the first child of the composer seat, so
|
|
10180
|
+
// the options sit above the input card in normal layout.
|
|
10181
|
+
useEffect(() => {
|
|
10182
|
+
if (!settings.quickReplies || ownerId === '') { setContainer(null); return undefined; }
|
|
10183
|
+
let node = null;
|
|
10184
|
+
const locate = () => {
|
|
10185
|
+
const seat = findComposerSeat(ownerRef.current);
|
|
10186
|
+
if (seat === null || seat.contains(node)) return;
|
|
10187
|
+
if (node !== null) node.remove();
|
|
10188
|
+
node = document.createElement('div');
|
|
10189
|
+
node.setAttribute('data-powerup-quick-replies', '');
|
|
10190
|
+
node.className = 'dsh-powerup-quick-replies-mount';
|
|
10191
|
+
seat.insertBefore(node, seat.firstChild);
|
|
10192
|
+
setContainer(node);
|
|
10193
|
+
};
|
|
10194
|
+
locate();
|
|
10195
|
+
const timer = window.setInterval(locate, 600);
|
|
10196
|
+
return () => {
|
|
10197
|
+
window.clearInterval(timer);
|
|
10198
|
+
if (node !== null) node.remove();
|
|
10199
|
+
setContainer(null);
|
|
10200
|
+
};
|
|
10201
|
+
}, [settings.quickReplies, ownerId]);
|
|
10202
|
+
|
|
10203
|
+
/** Clear the current options through the Host, guarded by version. */
|
|
10204
|
+
const clear = useCallback(() => {
|
|
10205
|
+
const id = ownerRef.current;
|
|
10206
|
+
const version = stateRef.current.version;
|
|
10207
|
+
if (id === '') return;
|
|
10208
|
+
applyState({ options: [], version: '' });
|
|
10209
|
+
void quickRepliesRequest(id, 'clear', { action: 'clear', version }).catch(() => {});
|
|
10210
|
+
}, [applyState]);
|
|
10211
|
+
|
|
10212
|
+
// Detect a normal user send: host Send button click, or Enter in the
|
|
10213
|
+
// composer editor. We only clear; the host performs the actual send.
|
|
10214
|
+
useEffect(() => {
|
|
10215
|
+
if (!settings.quickReplies || ownerId === '') return undefined;
|
|
10216
|
+
const onClick = (event) => {
|
|
10217
|
+
const target = event.target;
|
|
10218
|
+
if (target === null || typeof target.closest !== 'function') return;
|
|
10219
|
+
const button = target.closest('button[aria-busy]');
|
|
10220
|
+
if (button === null) return;
|
|
10221
|
+
const seat = findComposerSeat(ownerRef.current);
|
|
10222
|
+
if (seat === null || !seat.contains(button)) return;
|
|
10223
|
+
clear();
|
|
10224
|
+
};
|
|
10225
|
+
const onKeyDown = (event) => {
|
|
10226
|
+
if (event.key !== 'Enter' || event.isComposing === true || event.repeat === true) return;
|
|
10227
|
+
const target = event.target;
|
|
10228
|
+
const editor = target !== null && typeof target.closest === 'function'
|
|
10229
|
+
? target.closest('[data-composer-input]') : null;
|
|
10230
|
+
if (editor === null || editor.hasAttribute('data-composer-composing')
|
|
10231
|
+
|| editor.hasAttribute('data-composer-chip-selected')) return;
|
|
10232
|
+
const openMenu = document.querySelector?.(
|
|
10233
|
+
'[aria-haspopup="listbox"][aria-expanded="true"], [aria-haspopup="menu"][aria-expanded="true"], [role="listbox"]:not([hidden]), [role="menu"]:not([hidden])',
|
|
10234
|
+
);
|
|
10235
|
+
if (openMenu !== null && openMenu !== undefined) return;
|
|
10236
|
+
clear();
|
|
10237
|
+
};
|
|
10238
|
+
document.addEventListener('click', onClick, true);
|
|
10239
|
+
document.addEventListener('keydown', onKeyDown, true);
|
|
10240
|
+
return () => {
|
|
10241
|
+
document.removeEventListener('click', onClick, true);
|
|
10242
|
+
document.removeEventListener('keydown', onKeyDown, true);
|
|
10243
|
+
};
|
|
10244
|
+
}, [settings.quickReplies, ownerId, clear]);
|
|
10245
|
+
|
|
10246
|
+
/** Send one option as a normal user message, then clear the options. */
|
|
10247
|
+
const pick = useCallback((option) => {
|
|
10248
|
+
const id = ownerRef.current;
|
|
10249
|
+
const value = typeof option?.message === 'string' ? option.message.trim() : '';
|
|
10250
|
+
if (id === '' || value === '') return;
|
|
10251
|
+
try {
|
|
10252
|
+
const sessions = ctx.get('sessions');
|
|
10253
|
+
const binding = sessions?.binding?.(id);
|
|
10254
|
+
const session = binding?.session;
|
|
10255
|
+
if (session !== undefined && typeof session.prompt === 'function') {
|
|
10256
|
+
const handle = typeof session.beginSubmission === 'function'
|
|
10257
|
+
? session.beginSubmission({ mode: 'queue', text: value, attachments: [] })
|
|
10258
|
+
: null;
|
|
10259
|
+
void session.prompt([{ type: 'text', text: value }], 'queue', undefined, handle?.requestId);
|
|
10260
|
+
}
|
|
10261
|
+
} catch (error) {
|
|
10262
|
+
console.warn('[dsh-powerup] quick reply send failed:', error?.message ?? error);
|
|
10263
|
+
}
|
|
10264
|
+
clear();
|
|
10265
|
+
}, [ctx, clear]);
|
|
10266
|
+
|
|
10267
|
+
const options = state.options;
|
|
10268
|
+
if (container === null || options.length === 0) return null;
|
|
10269
|
+
const content = h('div', { className: 'dsh-powerup-quick-replies' },
|
|
10270
|
+
h('span', { className: 'dsh-powerup-quick-replies-label' }, translate('quickReplies.title')),
|
|
10271
|
+
options.map((option, index) => h('button', {
|
|
10272
|
+
type: 'button',
|
|
10273
|
+
key: `${option.label}-${index}`,
|
|
10274
|
+
className: 'dsh-powerup-quick-reply',
|
|
10275
|
+
title: option.message,
|
|
10276
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
10277
|
+
onClick: () => pick(option),
|
|
10278
|
+
}, option.label)),
|
|
10279
|
+
);
|
|
10280
|
+
return createPortal !== null ? createPortal(content, container) : content;
|
|
10281
|
+
}
|
|
10282
|
+
|
|
10063
10283
|
/**
|
|
10064
10284
|
* Conversation View tab for per-workspace Power-Up settings. Registered
|
|
10065
10285
|
* after Trajectory so it appears last in the header tab row.
|
|
@@ -10690,6 +10910,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
10690
10910
|
featureCard('scrollToTop', ScrollTopIcon, 'page.scrollToTopTitle', 'page.scrollToTopDesc', 'page.scrollToTopHow'),
|
|
10691
10911
|
featureCard('contentRendering', PowerUpLineIcon, 'page.renderingTitle', 'page.renderingDesc', 'page.renderingHow'),
|
|
10692
10912
|
featureCard('dualSend', LauncherIcon, 'page.dualSendTitle', 'page.dualSendDesc', 'page.dualSendHow'),
|
|
10913
|
+
featureCard('quickReplies', TagIcon, 'page.quickRepliesTitle', 'page.quickRepliesDesc', 'page.quickRepliesHow'),
|
|
10693
10914
|
featureCard('taskProgress', ProgressIcon, 'page.taskProgressTitle', 'page.taskProgressDesc', 'page.taskProgressHow',
|
|
10694
10915
|
h('div', { className: 'dsh-powerup-card-detail' },
|
|
10695
10916
|
numberRow('taskProgressCooldown', settings.taskProgressCooldown, t('page.taskProgressCooldown'), t('page.taskProgressCooldownHint')),
|
|
@@ -11897,6 +12118,15 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
11897
12118
|
t: (key, params) => translateCurrent(key, params),
|
|
11898
12119
|
}), 'dsh-powerup: direct ask');
|
|
11899
12120
|
|
|
12121
|
+
register('conversation.input.right', {
|
|
12122
|
+
id: 'powerup-quick-replies',
|
|
12123
|
+
order: 84,
|
|
12124
|
+
}, (props) => h(QuickReplies, {
|
|
12125
|
+
...props,
|
|
12126
|
+
ctx,
|
|
12127
|
+
t: (key, params) => translateCurrent(key, params),
|
|
12128
|
+
}), 'dsh-powerup: quick replies');
|
|
12129
|
+
|
|
11900
12130
|
// In an ongoing session, place the prompt picker in the bottom tool row
|
|
11901
12131
|
// just after the host's permission / plan dropdowns; its popover opens
|
|
11902
12132
|
// upward so it is not clipped by the screen bottom.
|
|
@@ -11978,6 +12208,10 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
11978
12208
|
RENDERING_CSS,
|
|
11979
12209
|
PROMPTS_CSS,
|
|
11980
12210
|
PROGRESS_CSS,
|
|
12211
|
+
QUICK_REPLIES_CSS,
|
|
12212
|
+
QuickReplies,
|
|
12213
|
+
quickRepliesRequest,
|
|
12214
|
+
quickOwnerId,
|
|
11981
12215
|
ProgressControl,
|
|
11982
12216
|
ProgressItem,
|
|
11983
12217
|
ProgressModelSelect,
|
|
@@ -12095,3 +12329,4 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
12095
12329
|
},
|
|
12096
12330
|
});
|
|
12097
12331
|
})();
|
|
12332
|
+
|
package/index.js
CHANGED
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
* tool powerup_step_read → resolves a `dsh-step:` reference
|
|
23
23
|
* copied from the Trajectory menu into
|
|
24
24
|
* the raw session events it identifies
|
|
25
|
+
* tool powerup_quick_replies → publishes tappable text reply options
|
|
26
|
+
* for the current session's composer
|
|
27
|
+
* GET /dsh-powerup/api/quick-replies → reads the current session's options
|
|
28
|
+
* POST /dsh-powerup/api/quick-replies → clears them after a user message
|
|
25
29
|
*
|
|
26
30
|
* The Client half drives other plugins' installation through the built-in
|
|
27
31
|
* `pluginManager` Remote. Only the process restart, the self-update handoff,
|
|
@@ -51,6 +55,10 @@ import {
|
|
|
51
55
|
import { createStepReadTool } from './lib/step-tool.js';
|
|
52
56
|
import { createProgressManager } from './lib/progress-manager.js';
|
|
53
57
|
import { buildAskPrompt, cleanAskText, directAsk, generateTitle } from './lib/direct-ask.js';
|
|
58
|
+
import {
|
|
59
|
+
createQuickRepliesStore,
|
|
60
|
+
createQuickRepliesTool,
|
|
61
|
+
} from './lib/quick-replies.js';
|
|
54
62
|
|
|
55
63
|
/** Prefix owned by this plugin. */
|
|
56
64
|
const ROUTE = '/dsh-powerup/api';
|
|
@@ -76,6 +84,8 @@ const PROMPTS_FILE = 'prompts.json';
|
|
|
76
84
|
const MASK_RULES_FILE = 'mask-rules.json';
|
|
77
85
|
/** Pending continuation prompts recorded by forced restart / close. */
|
|
78
86
|
const TASK_RESUME_FILE_NAME = TASK_RESUME_FILE;
|
|
87
|
+
/** Persisted quick-reply options, keyed by session id. */
|
|
88
|
+
const QUICK_REPLIES_FILE = 'quick-replies.json';
|
|
79
89
|
/** Persisted progress-generation requirements (global + per workspace/session). */
|
|
80
90
|
const PROGRESS_REQUIREMENTS_FILE = 'progress-requirements.json';
|
|
81
91
|
/** Story of generated progress reports, kept on disk so refreshes never drop history. */
|
|
@@ -473,11 +483,50 @@ async function handle(req, res, ctx) {
|
|
|
473
483
|
|
|
474
484
|
const url = new URL(req.url ?? ROUTE, 'http://localhost');
|
|
475
485
|
const op = url.pathname.slice(ROUTE.length).replace(/^\/+/u, '') || url.searchParams.get('op') || '';
|
|
476
|
-
if (op !== '' && op !== 'restart' && op !== 'close' && op !== 'self-update' && op !== 'audit' && op !== 'job-kill' && op !== 'prompts' && op !== 'mask-rules' && op !== 'progress' && op !== 'progress-requirements' && op !== 'progress-history' && op !== 'direct-ask' && op !== 'ask-title') {
|
|
486
|
+
if (op !== '' && op !== 'restart' && op !== 'close' && op !== 'self-update' && op !== 'audit' && op !== 'job-kill' && op !== 'prompts' && op !== 'mask-rules' && op !== 'progress' && op !== 'progress-requirements' && op !== 'progress-history' && op !== 'direct-ask' && op !== 'ask-title' && op !== 'quick-replies') {
|
|
477
487
|
sendJson(res, { ok: false, error: 'not-found' }, 404);
|
|
478
488
|
return;
|
|
479
489
|
}
|
|
480
490
|
|
|
491
|
+
if (op === 'quick-replies') {
|
|
492
|
+
const store = createQuickRepliesStore({
|
|
493
|
+
file: storePath(QUICK_REPLIES_FILE),
|
|
494
|
+
readFile: readFileSync,
|
|
495
|
+
writeFile: writeFileSync,
|
|
496
|
+
mkdir: mkdirSync,
|
|
497
|
+
dirname,
|
|
498
|
+
});
|
|
499
|
+
if (req.method === 'GET') {
|
|
500
|
+
const sessionId = typeof url.searchParams.get('sessionId') === 'string'
|
|
501
|
+
? url.searchParams.get('sessionId').trim() : '';
|
|
502
|
+
sendJson(res, { ok: true, ...store.read(sessionId) });
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
if (req.method === 'POST') {
|
|
506
|
+
try {
|
|
507
|
+
const body = await readJsonBody(req);
|
|
508
|
+
const sessionId = typeof body?.sessionId === 'string' ? body.sessionId.trim() : '';
|
|
509
|
+
if (sessionId === '') {
|
|
510
|
+
sendJson(res, { ok: false, code: 'invalid-request', error: 'sessionId is required' }, 400);
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
const action = body?.action === 'clear' ? 'clear' : 'set';
|
|
514
|
+
if (action === 'clear') {
|
|
515
|
+
const cleared = store.clearIfVersion(sessionId, typeof body?.version === 'string' ? body.version : '');
|
|
516
|
+
sendJson(res, { ok: true, cleared, options: [], version: '' });
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
const result = store.set(sessionId, body?.options);
|
|
520
|
+
sendJson(res, { ok: true, ...result });
|
|
521
|
+
} catch (error) {
|
|
522
|
+
sendJson(res, { ok: false, error: String(error?.message ?? error) }, 500);
|
|
523
|
+
}
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
sendJson(res, { ok: false, error: 'method-not-allowed' }, 405);
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
|
|
481
530
|
if (op === 'progress-requirements') {
|
|
482
531
|
const filePath = storePath(PROGRESS_REQUIREMENTS_FILE);
|
|
483
532
|
if (req.method === 'POST') {
|
|
@@ -959,6 +1008,22 @@ export function apply(ctx) {
|
|
|
959
1008
|
})),
|
|
960
1009
|
'dsh-powerup: step reference reader',
|
|
961
1010
|
);
|
|
1011
|
+
// Quick replies are keyed by the calling Agent's session id. The tool is
|
|
1012
|
+
// registered alongside step_read because both need the tools service.
|
|
1013
|
+
const quickStore = createQuickRepliesStore({
|
|
1014
|
+
file: storePath(QUICK_REPLIES_FILE),
|
|
1015
|
+
readFile: readFileSync,
|
|
1016
|
+
writeFile: writeFileSync,
|
|
1017
|
+
mkdir: mkdirSync,
|
|
1018
|
+
dirname,
|
|
1019
|
+
});
|
|
1020
|
+
scope.effect(
|
|
1021
|
+
() => tools.register(createQuickRepliesTool(defineTool, {
|
|
1022
|
+
getSessionId: () => '',
|
|
1023
|
+
getStore: () => quickStore,
|
|
1024
|
+
})),
|
|
1025
|
+
'dsh-powerup: quick replies',
|
|
1026
|
+
);
|
|
962
1027
|
});
|
|
963
1028
|
// The progress side call needs both `llm` and `sessionQuery`. Wait for them
|
|
964
1029
|
// through inject so a late-provided service still creates the manager.
|
|
@@ -1124,7 +1189,10 @@ export const __test = {
|
|
|
1124
1189
|
TASK_RESUME_FILE_NAME,
|
|
1125
1190
|
PROGRESS_REQUIREMENTS_FILE,
|
|
1126
1191
|
PROGRESS_HISTORY_FILE,
|
|
1192
|
+
QUICK_REPLIES_FILE,
|
|
1127
1193
|
createProgressManager,
|
|
1194
|
+
createQuickRepliesStore,
|
|
1195
|
+
createQuickRepliesTool,
|
|
1128
1196
|
cleanResumePrompt,
|
|
1129
1197
|
readJsonObject,
|
|
1130
1198
|
};
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quick replies: the model-facing half.
|
|
3
|
+
*
|
|
4
|
+
* The Agent calls `powerup_quick_replies` to publish a small set of tappable
|
|
5
|
+
* message options for the current session. The options are stored in the
|
|
6
|
+
* central Power-Up state file; the Client polls a matching Host route and
|
|
7
|
+
* renders them above the composer. The options disappear once the user sends
|
|
8
|
+
* any message (clicking an option is itself a message send).
|
|
9
|
+
*
|
|
10
|
+
* This module holds the pure normalization/storage logic so offline tests can
|
|
11
|
+
* exercise it without loading DSH packages.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** Maximum number of buttons offered at once. */
|
|
15
|
+
export const QUICK_REPLIES_LIMIT = 8;
|
|
16
|
+
|
|
17
|
+
/** Maximum characters of a button label. */
|
|
18
|
+
export const QUICK_LABEL_LIMIT = 80;
|
|
19
|
+
|
|
20
|
+
/** Maximum characters of the message a button sends. */
|
|
21
|
+
export const QUICK_MESSAGE_LIMIT = 4000;
|
|
22
|
+
|
|
23
|
+
/** Stable tool name registered with the Host tool registry. */
|
|
24
|
+
export const QUICK_REPLIES_TOOL_NAME = 'powerup_quick_replies';
|
|
25
|
+
|
|
26
|
+
export const QUICK_REPLIES_DESCRIPTION = [
|
|
27
|
+
'Offer the user a short list of tappable reply options in the current conversation.',
|
|
28
|
+
'Use this after answering when the next step has a few obvious choices (for example confirm, reject, or a follow-up question).',
|
|
29
|
+
'Each option has a short button label and the full message that is sent when it is tapped.',
|
|
30
|
+
'The options are shown above the composer and are removed automatically once the user sends any message.',
|
|
31
|
+
'Pass an empty options list to clear the current options without waiting for a message.',
|
|
32
|
+
].join(' ');
|
|
33
|
+
|
|
34
|
+
/** Bound and clean arbitrary text. */
|
|
35
|
+
function cleanText(value, limit) {
|
|
36
|
+
if (typeof value !== 'string') return '';
|
|
37
|
+
return value.replace(/\u0000/gu, '').trim().slice(0, limit);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Normalize a raw options array into a bounded, UI-safe list.
|
|
42
|
+
* @param {unknown} raw
|
|
43
|
+
* @returns {Array<{label: string, message: string}>}
|
|
44
|
+
*/
|
|
45
|
+
export function normalizeQuickReplies(raw) {
|
|
46
|
+
if (!Array.isArray(raw)) return [];
|
|
47
|
+
const options = [];
|
|
48
|
+
const seen = new Set();
|
|
49
|
+
for (const item of raw) {
|
|
50
|
+
if (options.length >= QUICK_REPLIES_LIMIT) break;
|
|
51
|
+
if (item === null || typeof item !== 'object') continue;
|
|
52
|
+
// Accept both {label, message} and the convenient {label, text} alias.
|
|
53
|
+
const label = cleanText(item.label ?? item.title, QUICK_LABEL_LIMIT);
|
|
54
|
+
const message = cleanText(item.message ?? item.text, QUICK_MESSAGE_LIMIT);
|
|
55
|
+
if (label === '' || message === '') continue;
|
|
56
|
+
const key = `${label}\u0000${message}`;
|
|
57
|
+
if (seen.has(key)) continue;
|
|
58
|
+
seen.add(key);
|
|
59
|
+
options.push({ label, message });
|
|
60
|
+
}
|
|
61
|
+
return options;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Create the central-state writer used by both the tool and the HTTP route.
|
|
66
|
+
* @param {{ storePath: (file: string) => string, readFile: (path: string, enc: string) => string,
|
|
67
|
+
* writeFile: (path: string, data: string, enc: string) => void,
|
|
68
|
+
* mkdir: (path: string, opts: object) => void,
|
|
69
|
+
* dirname: (path: string) => string,
|
|
70
|
+
* file: string,
|
|
71
|
+
* now?: () => number,
|
|
72
|
+
* uuid?: () => string }} deps
|
|
73
|
+
*/
|
|
74
|
+
export function createQuickRepliesStore(deps) {
|
|
75
|
+
const file = deps?.file;
|
|
76
|
+
const now = typeof deps?.now === 'function' ? deps.now : () => Date.now();
|
|
77
|
+
const uuid = typeof deps?.uuid === 'function' ? deps.uuid : () => `q-${Math.random().toString(36).slice(2)}`;
|
|
78
|
+
if (typeof file !== 'string' || file === '') throw new TypeError('createQuickRepliesStore requires a file');
|
|
79
|
+
|
|
80
|
+
const readAll = () => {
|
|
81
|
+
try {
|
|
82
|
+
const parsed = JSON.parse(deps.readFile(file, 'utf8'));
|
|
83
|
+
return parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (error?.code === 'ENOENT') return {};
|
|
86
|
+
return {};
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const writeAll = (all) => {
|
|
91
|
+
deps.mkdir(deps.dirname(file), { recursive: true });
|
|
92
|
+
deps.writeFile(file, JSON.stringify(all, null, 2) + '\n', 'utf8');
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
/** @param {string} sessionId */
|
|
97
|
+
read(sessionId) {
|
|
98
|
+
if (typeof sessionId !== 'string' || sessionId === '') return { options: [], version: '' };
|
|
99
|
+
const record = readAll()[sessionId];
|
|
100
|
+
const options = record !== null && typeof record === 'object' ? normalizeQuickReplies(record.options) : [];
|
|
101
|
+
const version = record !== null && typeof record === 'object' && typeof record.version === 'string' ? record.version : '';
|
|
102
|
+
return { options, version };
|
|
103
|
+
},
|
|
104
|
+
/**
|
|
105
|
+
* Replace a session's options. An empty list removes the session record.
|
|
106
|
+
* @param {string} sessionId
|
|
107
|
+
* @param {unknown} rawOptions
|
|
108
|
+
*/
|
|
109
|
+
set(sessionId, rawOptions) {
|
|
110
|
+
if (typeof sessionId !== 'string' || sessionId === '') throw new TypeError('sessionId is required');
|
|
111
|
+
const options = normalizeQuickReplies(rawOptions);
|
|
112
|
+
const all = readAll();
|
|
113
|
+
if (options.length === 0) delete all[sessionId];
|
|
114
|
+
else all[sessionId] = { options, version: `${now()}-${uuid()}`, updatedAt: now() };
|
|
115
|
+
writeAll(all);
|
|
116
|
+
return { options, version: all[sessionId]?.version ?? '' };
|
|
117
|
+
},
|
|
118
|
+
/**
|
|
119
|
+
* Clear a session's options only when a version matches (used when the
|
|
120
|
+
* user sends a message, so a stale clear cannot erase newer options).
|
|
121
|
+
* @param {string} sessionId
|
|
122
|
+
* @param {string} version
|
|
123
|
+
*/
|
|
124
|
+
clearIfVersion(sessionId, version) {
|
|
125
|
+
if (typeof sessionId !== 'string' || sessionId === '') return false;
|
|
126
|
+
const all = readAll();
|
|
127
|
+
const record = all[sessionId];
|
|
128
|
+
if (record === null || typeof record !== 'object') return false;
|
|
129
|
+
if (typeof version === 'string' && version !== '' && record.version !== version) return false;
|
|
130
|
+
delete all[sessionId];
|
|
131
|
+
writeAll(all);
|
|
132
|
+
return true;
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Build the tool definition. `defineTool` is passed in from the Host so this
|
|
139
|
+
* module stays importable by offline tests.
|
|
140
|
+
* @param {(definition: unknown) => any} defineTool
|
|
141
|
+
* @param {{ getSessionId: () => string, getStore: () => any }} options
|
|
142
|
+
*/
|
|
143
|
+
export function createQuickRepliesTool(defineTool, options) {
|
|
144
|
+
if (typeof defineTool !== 'function') throw new TypeError('createQuickRepliesTool requires defineTool');
|
|
145
|
+
const getSessionId = options?.getSessionId;
|
|
146
|
+
const getStore = options?.getStore;
|
|
147
|
+
if (typeof getSessionId !== 'function' || typeof getStore !== 'function') {
|
|
148
|
+
throw new TypeError('createQuickRepliesTool requires getSessionId and getStore');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return defineTool({
|
|
152
|
+
name: QUICK_REPLIES_TOOL_NAME,
|
|
153
|
+
description: QUICK_REPLIES_DESCRIPTION,
|
|
154
|
+
parameters: {
|
|
155
|
+
options: {
|
|
156
|
+
type: 'array',
|
|
157
|
+
required: true,
|
|
158
|
+
description: `The reply options to show, 1-${QUICK_REPLIES_LIMIT} items. Pass [] to clear.`,
|
|
159
|
+
items: {
|
|
160
|
+
type: 'object',
|
|
161
|
+
additionalProperties: false,
|
|
162
|
+
properties: {
|
|
163
|
+
label: {
|
|
164
|
+
type: 'string',
|
|
165
|
+
description: `Required. Short text shown on the button (max ${QUICK_LABEL_LIMIT} characters).`,
|
|
166
|
+
},
|
|
167
|
+
message: {
|
|
168
|
+
type: 'string',
|
|
169
|
+
description: `Required. Full message sent when the button is tapped (max ${QUICK_MESSAGE_LIMIT} characters).`,
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
output: {
|
|
176
|
+
schema: { type: 'string' },
|
|
177
|
+
render: (_args, value) => [{ type: 'text', text: value }],
|
|
178
|
+
},
|
|
179
|
+
isConcurrencySafe: () => true,
|
|
180
|
+
async execute(args, exec) {
|
|
181
|
+
const sessionId = typeof exec?.agent?.id === 'string' ? exec.agent.id : getSessionId();
|
|
182
|
+
if (typeof sessionId !== 'string' || sessionId === '') {
|
|
183
|
+
return 'Quick replies were not published: no current session is available.';
|
|
184
|
+
}
|
|
185
|
+
if (exec?.signal?.aborted) return 'Quick replies were not published: the call was cancelled.';
|
|
186
|
+
const store = getStore();
|
|
187
|
+
const result = store.set(sessionId, args?.options);
|
|
188
|
+
if (result.options.length === 0) return 'Quick reply options were cleared.';
|
|
189
|
+
const lines = result.options.map((o, i) => `${i + 1}. ${o.label} → ${o.message}`);
|
|
190
|
+
return `Published ${result.options.length} quick reply option(s):\n${lines.join('\n')}`;
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@restregular/dsh-powerup",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.7",
|
|
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",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"lib/progress-manager.js",
|
|
26
26
|
"lib/task-resume.js",
|
|
27
27
|
"lib/direct-ask.js",
|
|
28
|
+
"lib/quick-replies.js",
|
|
28
29
|
"locale/*.json",
|
|
29
30
|
"icon.svg",
|
|
30
31
|
"README.md",
|
|
@@ -98,8 +99,9 @@
|
|
|
98
99
|
"node": ">=22.13.0"
|
|
99
100
|
},
|
|
100
101
|
"scripts": {
|
|
101
|
-
"test": "node test/smoke.mjs && node test/host.mjs && node test/progress.mjs && node test/task-resume.mjs && node test/direct-ask.mjs"
|
|
102
|
+
"test": "node test/smoke.mjs && node test/host.mjs && node test/progress.mjs && node test/task-resume.mjs && node test/direct-ask.mjs && node test/quick-replies.mjs"
|
|
102
103
|
},
|
|
103
104
|
"license": "MIT",
|
|
104
105
|
"author": "RestRegular"
|
|
105
106
|
}
|
|
107
|
+
|