dsh-better-ask-user 0.1.6 → 0.2.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/LICENSE +202 -674
- package/NOTICE +23 -1
- package/lib/client.js +662 -323
- package/package.json +4 -3
- package/src/ask-tool.js +47 -5
- package/src/client/AskHistoryRow.module.css +13 -47
- package/src/client/AskHistoryRow.tsx +11 -17
- package/src/client/PlanReviewPanel.module.css +46 -132
- package/src/client/PlanReviewPanel.tsx +63 -13
- package/src/client/QuestionComposer.module.css +85 -580
- package/src/client/QuestionComposer.tsx +46 -63
- package/src/client/QuestionReplyView.module.css +37 -193
- package/src/client/QuestionReplyView.tsx +13 -4
- package/src/client/QuestionWaitBar.module.css +30 -0
- package/src/client/QuestionWaitBar.tsx +41 -0
- package/src/client/index.ts +6 -1
- package/src/client/locales.ts +6 -2
- package/src/client/settings-locales.ts +42 -28
- package/src/client/settings.module.css +119 -0
- package/src/client/settings.tsx +134 -74
- package/src/settings.js +11 -9
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-better-ask-user",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Independent ask_user_question plugin: configurable wait, input-extended countdown, markdown/mobile card, native or default timeout behavior, and PTC deadline exemption.",
|
|
5
|
-
"license": "
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/Menghuan1918/dsh-better-ask-user.git"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@deepseek-ai/schemastery": "~3.18.5",
|
|
28
|
-
"dsh-better-ptc": "0.1.
|
|
28
|
+
"dsh-better-ptc": "0.1.1"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@deepseek-ai/cordis": "~4.0.5",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"react": "^18.2.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
+
"clsx": "^2.1.1",
|
|
41
42
|
"esbuild": "^0.25.0",
|
|
42
43
|
"js-yaml": "^4.2.0",
|
|
43
44
|
"react": "18.3.1",
|
package/src/ask-tool.js
CHANGED
|
@@ -5,12 +5,16 @@ import { buildDefaultAnswer } from './default-answer.js'
|
|
|
5
5
|
/** Model-visible notice for the native pending result. */
|
|
6
6
|
export const PENDING_QUESTION_NOTICE = 'No answer batch arrived before the timeout. This is pending, not a skipped answer. Continue useful independent work. The user can still answer; their reply will be a user message identified as answer_to_pending_question with this callId and the original questions. Do not treat this as permission.'
|
|
7
7
|
|
|
8
|
+
/** Model-visible warning for a host auto-selected default batch. */
|
|
9
|
+
export const AUTO_SELECTED_WARNING = 'These answers were auto-selected by the host timeout behavior, not submitted by the user. Do not treat them as user confirmation.'
|
|
10
|
+
|
|
8
11
|
function questionRequest(questions, exec) {
|
|
9
12
|
return {
|
|
10
13
|
questions: questions.map(question => ({
|
|
11
14
|
id: question.id,
|
|
12
15
|
question: question.question,
|
|
13
16
|
...(question.header !== undefined ? { header: question.header } : {}),
|
|
17
|
+
...(question.detail !== undefined ? { detail: question.detail } : {}),
|
|
14
18
|
...(question.options !== undefined ? {
|
|
15
19
|
options: question.options.map(option => ({ ...option })),
|
|
16
20
|
} : {}),
|
|
@@ -36,14 +40,51 @@ function answerResult(result) {
|
|
|
36
40
|
selected: [...answer.selected],
|
|
37
41
|
...(answer.custom !== undefined ? { custom: answer.custom } : {}),
|
|
38
42
|
})),
|
|
43
|
+
...(result.autoSelected === true ? { autoSelected: true, warning: AUTO_SELECTED_WARNING } : {}),
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Add the optional detail field to the model-visible question schema. */
|
|
48
|
+
function parametersWithDetail(parameters) {
|
|
49
|
+
if (parameters === undefined) return parameters
|
|
50
|
+
const next = structuredClone(parameters)
|
|
51
|
+
const properties = next?.properties?.questions?.items?.properties
|
|
52
|
+
if (properties !== undefined && properties.detail === undefined) {
|
|
53
|
+
properties.detail = {
|
|
54
|
+
type: 'string',
|
|
55
|
+
description: 'Optional longer detail or context rendered as sanitized markdown below the question.',
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return next
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Allow the additive auto-selected warning fields on the normal answer branch. */
|
|
62
|
+
function extendAutoSelectedSchema(schema) {
|
|
63
|
+
const branches = Array.isArray(schema?.oneOf) ? schema.oneOf : [schema]
|
|
64
|
+
for (const branch of branches) {
|
|
65
|
+
const properties = branch?.properties
|
|
66
|
+
if (properties?.answers === undefined) continue
|
|
67
|
+
if (properties.autoSelected === undefined) {
|
|
68
|
+
properties.autoSelected = {
|
|
69
|
+
type: 'boolean',
|
|
70
|
+
description: 'True when the host auto-selected the default batch after the timeout; not a user answer.',
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (properties.warning === undefined) {
|
|
74
|
+
properties.warning = { type: 'string', description: 'Model-visible warning for an auto-selected batch.' }
|
|
75
|
+
}
|
|
39
76
|
}
|
|
77
|
+
return schema
|
|
40
78
|
}
|
|
41
79
|
|
|
42
80
|
/** The timed path can return the official pending shape; keep it valid. */
|
|
43
81
|
function outputWithPending(base) {
|
|
44
82
|
const output = { ...base.output }
|
|
45
|
-
const schema = structuredClone(base.output.schema)
|
|
46
|
-
if (Array.isArray(schema?.oneOf) && schema.oneOf.some(branch => branch?.properties?.pending !== undefined))
|
|
83
|
+
const schema = extendAutoSelectedSchema(structuredClone(base.output.schema))
|
|
84
|
+
if (Array.isArray(schema?.oneOf) && schema.oneOf.some(branch => branch?.properties?.pending !== undefined)) {
|
|
85
|
+
output.schema = schema
|
|
86
|
+
return output
|
|
87
|
+
}
|
|
47
88
|
output.schema = {
|
|
48
89
|
oneOf: [
|
|
49
90
|
schema,
|
|
@@ -71,9 +112,10 @@ function outputWithPending(base) {
|
|
|
71
112
|
*/
|
|
72
113
|
export function createBetterAskTool(ctx, base, readConfig) {
|
|
73
114
|
const output = outputWithPending(base)
|
|
115
|
+
const parameters = parametersWithDetail(base.parameters)
|
|
74
116
|
|
|
75
117
|
const execute = async (args, exec) => {
|
|
76
|
-
const violations = validateJsonSchemaValue(
|
|
118
|
+
const violations = validateJsonSchemaValue(parameters, args, '')
|
|
77
119
|
if (violations.length > 0) throw new ToolArgsError(violations)
|
|
78
120
|
validateQuestionIds(args.questions)
|
|
79
121
|
|
|
@@ -113,5 +155,5 @@ export function createBetterAskTool(ctx, base, readConfig) {
|
|
|
113
155
|
return answerResult(result)
|
|
114
156
|
}
|
|
115
157
|
|
|
116
|
-
return { ...base, output, execute }
|
|
117
|
-
}
|
|
158
|
+
return { ...base, parameters, output, execute }
|
|
159
|
+
}
|
|
@@ -1,47 +1,13 @@
|
|
|
1
|
-
.row {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
.title {
|
|
16
|
-
flex: none;
|
|
17
|
-
font: var(--dsw-font-xs-strong-13);
|
|
18
|
-
color: var(--dsw-alias-label-secondary);
|
|
19
|
-
}
|
|
20
|
-
.summary {
|
|
21
|
-
min-width: 0;
|
|
22
|
-
flex: 1;
|
|
23
|
-
overflow: hidden;
|
|
24
|
-
text-overflow: ellipsis;
|
|
25
|
-
white-space: nowrap;
|
|
26
|
-
font: var(--dsw-font-xs-13);
|
|
27
|
-
color: var(--dsw-alias-label-tertiary);
|
|
28
|
-
}
|
|
29
|
-
.open {
|
|
30
|
-
flex: none;
|
|
31
|
-
cursor: pointer;
|
|
32
|
-
border: .5px solid var(--dsw-alias-border-l4);
|
|
33
|
-
border-radius: 999px;
|
|
34
|
-
background: var(--dsw-alias-bg-base);
|
|
35
|
-
color: var(--dsw-alias-label-secondary);
|
|
36
|
-
padding: 1px 8px;
|
|
37
|
-
font: var(--dsw-font-xxs-12);
|
|
38
|
-
line-height: 16px;
|
|
39
|
-
}
|
|
40
|
-
.open:hover {
|
|
41
|
-
background: var(--dsw-alias-interactive-bg-hover-solid);
|
|
42
|
-
color: var(--dsw-alias-label-primary);
|
|
43
|
-
}
|
|
44
|
-
.open:focus-visible {
|
|
45
|
-
outline: var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary));
|
|
46
|
-
outline-offset: 1px;
|
|
47
|
-
}
|
|
1
|
+
.row { --ask-accent: #3388BB; display: flex; align-items: center; gap: 10px; width: 100%; min-height: 32px; min-width: 0; padding: 4px 8px; border: 0; border-radius: 6px; background: transparent; color: var(--dsw-alias-label-secondary); font: inherit; font-size: 13px; line-height: 20px; text-align: left; }
|
|
2
|
+
button.row { cursor: pointer; transition: background-color 100ms ease; }
|
|
3
|
+
button.row:hover { background: var(--dsw-alias-interactive-bg-hover); }
|
|
4
|
+
button.row:active { background: color-mix(in srgb, var(--ask-accent) 9%, transparent); }
|
|
5
|
+
button.row:focus-visible { outline: 2px solid var(--ask-accent); outline-offset: -2px; }
|
|
6
|
+
.icon { display: inline-flex; flex: none; color: var(--dsw-alias-label-tertiary); }
|
|
7
|
+
.icon svg { width: 14px; height: 14px; }
|
|
8
|
+
.title { flex: none; color: var(--dsw-alias-label-primary); font-weight: 500; }
|
|
9
|
+
.summary { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-secondary); }
|
|
10
|
+
.open { display: inline-flex; align-items: center; gap: 4px; flex: none; color: var(--dsw-alias-label-tertiary); font-size: 12px; }
|
|
11
|
+
.row:hover .open { color: var(--dsw-alias-label-primary); }
|
|
12
|
+
@media (max-width: 640px), (pointer: coarse) { .row { min-height: 44px; } }
|
|
13
|
+
@media (prefers-reduced-motion: reduce) { button.row { transition: none; } }
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/** History row for ask_user_question: compact summary plus a replay button. */
|
|
2
|
-
import {
|
|
2
|
+
import { IconChevronRightOutlineRegular, IconQuestionOutlineRegular } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
3
3
|
import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
|
|
4
4
|
import type { ToolCallViewProps, UserQuestionRecord } from '@deepseek-ai/dsh-client-ui-tool/client'
|
|
5
5
|
import type { AskUserQuestionItem } from '@deepseek-ai/dsh-user-questions/types'
|
|
6
|
-
import type { QuestionKey } from './locales.ts'
|
|
7
6
|
import css from './AskHistoryRow.module.css'
|
|
8
7
|
|
|
9
8
|
type AskHistoryRowProps = ToolCallViewProps & PropsLocale<'question'> & {
|
|
@@ -48,6 +47,7 @@ function questionList(argsRaw: string): AskUserQuestionItem[] | undefined {
|
|
|
48
47
|
id: candidate.id,
|
|
49
48
|
question: candidate.question,
|
|
50
49
|
...(typeof candidate.header === 'string' ? { header: candidate.header } : {}),
|
|
50
|
+
...(typeof candidate.detail === 'string' ? { detail: candidate.detail } : {}),
|
|
51
51
|
...(Array.isArray(candidate.options)
|
|
52
52
|
? {
|
|
53
53
|
options: candidate.options.flatMap(option => isRecord(option) && typeof option.label === 'string'
|
|
@@ -58,7 +58,7 @@ function questionList(argsRaw: string): AskUserQuestionItem[] | undefined {
|
|
|
58
58
|
: []),
|
|
59
59
|
}
|
|
60
60
|
: {}),
|
|
61
|
-
...(typeof candidate.multi_select === 'boolean' ? {
|
|
61
|
+
...(typeof candidate.multi_select === 'boolean' ? { multiSelect: candidate.multi_select } : {}),
|
|
62
62
|
})
|
|
63
63
|
}
|
|
64
64
|
return questions
|
|
@@ -114,21 +114,15 @@ export function AskHistoryRow({
|
|
|
114
114
|
? () => { revealPanel(callId) }
|
|
115
115
|
: undefined
|
|
116
116
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
<span className={css.icon} aria-hidden="true"><
|
|
117
|
+
const content = (
|
|
118
|
+
<>
|
|
119
|
+
<span className={css.icon} aria-hidden="true"><IconQuestionOutlineRegular /></span>
|
|
120
120
|
<span className={css.title}>{t('history.title')}</span>
|
|
121
121
|
<span className={css.summary} title={summary}>{summary}</span>
|
|
122
|
-
{action !== undefined && (
|
|
123
|
-
|
|
124
|
-
type="button"
|
|
125
|
-
className={css.open}
|
|
126
|
-
onClick={action}
|
|
127
|
-
aria-label={review ? t('history.review') : t('history.reopen')}
|
|
128
|
-
>
|
|
129
|
-
{review ? t('history.review') : t('history.reopen')}
|
|
130
|
-
</button>
|
|
131
|
-
)}
|
|
132
|
-
</div>
|
|
122
|
+
{action !== undefined && <span className={css.open}>{review ? t('history.review') : t('history.reopen')}<IconChevronRightOutlineRegular size={14} /></span>}
|
|
123
|
+
</>
|
|
133
124
|
)
|
|
125
|
+
return action === undefined
|
|
126
|
+
? <div className={css.row} data-question-history={callId}>{content}</div>
|
|
127
|
+
: <button type="button" className={css.row} data-question-history={callId} data-history-action={review ? 'review' : 'open'} onClick={action} aria-label={review ? t('history.review') : t('history.reopen')}>{content}</button>
|
|
134
128
|
}
|
|
@@ -1,144 +1,58 @@
|
|
|
1
1
|
.frame {
|
|
2
|
+
--ask-accent: #3388BB;
|
|
2
3
|
display: flex;
|
|
3
4
|
justify-content: center;
|
|
4
|
-
|
|
5
|
-
(input card - 32) at every viewport. */
|
|
6
|
-
padding: 6px calc(var(--dsh-composer-side-clearance) + 16px) 10px;
|
|
5
|
+
padding: 8px calc(var(--dsh-composer-side-clearance) + 16px) calc(12px + env(safe-area-inset-bottom));
|
|
7
6
|
}
|
|
8
|
-
|
|
9
7
|
.card {
|
|
10
8
|
display: flex;
|
|
11
|
-
overflow: hidden;
|
|
12
9
|
flex-direction: column;
|
|
13
10
|
width: 100%;
|
|
11
|
+
min-width: 0;
|
|
14
12
|
max-width: var(--dsh-chat-content-width);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
max-height: min(75vh, 640px);
|
|
14
|
+
max-height: min(75dvh, 640px);
|
|
15
|
+
overflow: hidden;
|
|
16
|
+
border: 0.5px solid var(--dsw-alias-border-l3);
|
|
17
|
+
border-radius: 12px;
|
|
18
|
+
background: var(--dsw-alias-bg-layer-3);
|
|
20
19
|
color: var(--dsw-alias-label-primary);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
.card,
|
|
24
|
-
.card * {
|
|
25
|
-
box-sizing: border-box;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/* Tinted full-width header band, as on the approval takeover. */
|
|
29
|
-
.strip {
|
|
30
|
-
display: flex;
|
|
31
|
-
align-items: center;
|
|
32
|
-
flex-shrink: 0;
|
|
33
|
-
gap: 8px;
|
|
34
|
-
padding: 12px 16px;
|
|
35
|
-
background: var(--dsw-alias-state-warn-tertiary);
|
|
36
|
-
color: var(--dsw-alias-state-warn-primary);
|
|
37
|
-
font-size: 14px;
|
|
20
|
+
font-size: 13px;
|
|
38
21
|
line-height: 20px;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
.title {
|
|
70
|
-
margin: 0;
|
|
71
|
-
overflow: hidden;
|
|
72
|
-
text-overflow: ellipsis;
|
|
73
|
-
white-space: nowrap;
|
|
74
|
-
font-size: 15px;
|
|
75
|
-
font-weight: 500;
|
|
76
|
-
line-height: 22px;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
.description {
|
|
80
|
-
display: -webkit-box;
|
|
81
|
-
-webkit-box-orient: vertical;
|
|
82
|
-
-webkit-line-clamp: 2;
|
|
83
|
-
overflow: hidden;
|
|
84
|
-
margin: 8px 0 0;
|
|
85
|
-
color: var(--dsw-alias-label-secondary);
|
|
86
|
-
font-size: 14px;
|
|
87
|
-
line-height: 24px;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
.discuss {
|
|
91
|
-
gap: 6px;
|
|
92
|
-
}
|
|
93
|
-
|
|
22
|
+
--dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2);
|
|
23
|
+
--dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2);
|
|
24
|
+
}
|
|
25
|
+
.card, .card * { box-sizing: border-box; }
|
|
26
|
+
.strip { display: flex; align-items: center; flex-shrink: 0; flex-wrap: wrap; gap: 12px; min-width: 0; padding: 12px 16px; }
|
|
27
|
+
.panelLabel { color: var(--dsw-alias-label-secondary); font-size: 12px; font-weight: 500; line-height: 20px; }
|
|
28
|
+
.previewActions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; min-width: 0; margin-left: auto; }
|
|
29
|
+
.summary { position: relative; min-width: 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; padding: 4px 16px 24px; }
|
|
30
|
+
.documentHeading { display: flex; align-items: flex-start; gap: 8px; }
|
|
31
|
+
.documentIcon { flex: none; width: 18px; height: 20px; color: var(--dsw-alias-label-tertiary); }
|
|
32
|
+
.title, .description { min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
|
|
33
|
+
.title { margin: 0; font-size: 14px; font-weight: 500; line-height: 20px; }
|
|
34
|
+
.description { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; margin: 8px 0 0; color: var(--dsw-alias-label-secondary); font-size: 13px; line-height: 20px; }
|
|
35
|
+
.footer { display: flex; align-items: center; justify-content: flex-end; flex-shrink: 0; flex-wrap: wrap; gap: 12px; padding: 8px 16px; border-top: 0.5px solid var(--dsw-alias-border-l2); }
|
|
36
|
+
.feedback { flex: 1; min-width: 0; color: var(--dsw-alias-state-error-primary); font-size: 12px; line-height: 18px; overflow-wrap: anywhere; }
|
|
37
|
+
.feedback:empty { display: none; }
|
|
38
|
+
.actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
|
|
39
|
+
.actions > button, .previewActions button { height: 32px; min-height: 32px; padding: 0 12px; border-radius: 6px; font-size: 13px; line-height: 20px; }
|
|
40
|
+
.decline { padding: 0 12px; border: 0; background: transparent; color: var(--dsw-alias-label-secondary); font: inherit; font-size: 13px; line-height: 20px; cursor: pointer; }
|
|
41
|
+
.decline:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); color: var(--dsw-alias-label-primary); }
|
|
42
|
+
.decline:active:not(:disabled) { background: color-mix(in srgb, var(--ask-accent) 10%, transparent); }
|
|
43
|
+
.discuss { gap: 8px; }
|
|
44
|
+
.primaryButton { --dsw-alias-button-primary-fill: color-mix(in srgb, var(--ask-accent) 85%, black); --dsw-alias-button-primary-fill-hover: color-mix(in srgb, var(--ask-accent) 72%, black); --dsw-alias-label-primary-foreground: #fff; border-color: color-mix(in srgb, var(--ask-accent) 25%, var(--dsw-alias-border-l2)); background: var(--dsw-alias-button-primary-fill); color: var(--dsw-alias-label-primary-foreground); }
|
|
45
|
+
.primaryButton:hover:not(:disabled) { background: var(--dsw-alias-button-primary-fill-hover); }
|
|
46
|
+
.primaryButton:active:not(:disabled) { background: var(--dsw-alias-button-primary-fill-hover); }
|
|
47
|
+
.card button:focus-visible { outline: 2px solid var(--ask-accent); outline-offset: -2px; }
|
|
48
|
+
.card button:disabled { opacity: .4; cursor: default; }
|
|
49
|
+
.srOnly { position: absolute; width: 1px; height: 1px; overflow: hidden; padding: 0; border: 0; clip-path: inset(50%); white-space: nowrap; }
|
|
94
50
|
@media (max-width: 720px) {
|
|
95
|
-
.card {
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
.footer {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
.previewActions {
|
|
106
|
-
margin-left: auto;
|
|
107
|
-
display: flex;
|
|
108
|
-
align-items: center;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/* Better ask-user: long plan text and narrow screens. */
|
|
112
|
-
.title,
|
|
113
|
-
.description,
|
|
114
|
-
.summary,
|
|
115
|
-
.strip {
|
|
116
|
-
min-width: 0;
|
|
117
|
-
overflow-wrap: anywhere;
|
|
118
|
-
word-break: break-word;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
.title {
|
|
122
|
-
max-height: 30vh;
|
|
123
|
-
overflow-y: auto;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
@media (max-width: 720px) {
|
|
127
|
-
.card {
|
|
128
|
-
max-height: calc(100vh - 160px);
|
|
129
|
-
max-height: calc(100dvh - 160px);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
.title {
|
|
133
|
-
max-height: 24vh;
|
|
134
|
-
max-height: 24dvh;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
.footer {
|
|
138
|
-
flex-wrap: wrap;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
.actions {
|
|
142
|
-
flex-wrap: wrap;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
51
|
+
.card { max-height: calc(100vh - 160px); max-height: calc(100dvh - 160px); }
|
|
52
|
+
.strip { padding: 12px 16px; }
|
|
53
|
+
.summary { padding: 8px 16px 24px; }
|
|
54
|
+
.card button { min-height: 44px; }
|
|
55
|
+
.footer { padding: 12px 16px; }
|
|
56
|
+
.feedback { flex: 1 1 100%; }
|
|
57
|
+
}
|
|
58
|
+
@media (max-width: 420px) { .actions { width: 100%; } .actions > button { flex: 1; } }
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { useMemo, useState } from 'react'
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
2
2
|
import {
|
|
3
|
-
Button, extractMarkdownPlainText, IconEditOutlineRegular,
|
|
3
|
+
Button, extractMarkdownPlainText, IconEditOutlineRegular,
|
|
4
4
|
} from '@deepseek-ai/dsh-client-ui-primitives'
|
|
5
5
|
import type { PendingQuestion, PlanReview, QuestionComposerProps } from './contract/slots.ts'
|
|
6
|
+
import { QuestionWaitBar } from './QuestionWaitBar.tsx'
|
|
6
7
|
import css from './PlanReviewPanel.module.css'
|
|
7
8
|
|
|
8
9
|
/** The panel's own props: the question domain face, the narrowed review, and the locale seat. */
|
|
9
10
|
export type PlanReviewPanelProps =
|
|
10
|
-
{ pending: PendingQuestion; review: PlanReview } & Pick<QuestionComposerProps, 't' | 'renderSlot'>
|
|
11
|
+
{ pending: PendingQuestion; review: PlanReview } & Pick<QuestionComposerProps, 't' | 'renderSlot' | 'useQuestionCard'>
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Optional-prop spread for a decision button's tooltip: `title` is optional on
|
|
@@ -26,14 +27,41 @@ function tooltip(description: string | undefined): { title?: string } {
|
|
|
26
27
|
* @param props - the question domain face, the narrowed plan review, and `t`.
|
|
27
28
|
* @returns The plan-review takeover for this request.
|
|
28
29
|
*/
|
|
29
|
-
export function PlanReviewPanel({ pending, review, t, renderSlot }: PlanReviewPanelProps) {
|
|
30
|
+
export function PlanReviewPanel({ pending, review, t, renderSlot, useQuestionCard }: PlanReviewPanelProps) {
|
|
30
31
|
// Foreground decisions wait for the resolved frame; accepted Remote decisions
|
|
31
32
|
// hide the panel. A failed send re-enables the buttons and shows the error.
|
|
32
33
|
const [busy, setBusy] = useState(false)
|
|
33
34
|
const [error, setError] = useState<string | null>(null)
|
|
35
|
+
const card = useQuestionCard(pending.key, snapshot => snapshot)
|
|
36
|
+
const canDecide = card !== undefined && !card.closed && card.channel !== 'none'
|
|
37
|
+
const surface = useRef<HTMLElement>(null)
|
|
38
|
+
const sentVia = useRef<'waterfall' | null>(null)
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (sentVia.current !== 'waterfall' || card?.state !== 'continued') return
|
|
41
|
+
sentVia.current = null
|
|
42
|
+
setBusy(false)
|
|
43
|
+
setError(t('error.resubmit'))
|
|
44
|
+
}, [card?.state, t])
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
const release = (): void => { pending.releaseFocus() }
|
|
47
|
+
const refocus = (): void => {
|
|
48
|
+
if (surface.current?.contains(document.activeElement) === true) pending.holdFocus()
|
|
49
|
+
}
|
|
50
|
+
const visibilityChanged = (): void => { if (document.hidden) release(); else refocus() }
|
|
51
|
+
window.addEventListener('blur', release)
|
|
52
|
+
window.addEventListener('focus', refocus)
|
|
53
|
+
document.addEventListener('visibilitychange', visibilityChanged)
|
|
54
|
+
return () => {
|
|
55
|
+
release()
|
|
56
|
+
window.removeEventListener('blur', release)
|
|
57
|
+
window.removeEventListener('focus', refocus)
|
|
58
|
+
document.removeEventListener('visibilitychange', visibilityChanged)
|
|
59
|
+
}
|
|
60
|
+
}, [pending])
|
|
34
61
|
const settle = (send: () => Promise<void>, remote = false): void => {
|
|
35
62
|
setBusy(true)
|
|
36
63
|
setError(null)
|
|
64
|
+
sentVia.current = pending.snapshot().channel === 'waterfall' ? 'waterfall' : null
|
|
37
65
|
void send()
|
|
38
66
|
.then(() => {
|
|
39
67
|
if (!remote) return
|
|
@@ -41,6 +69,7 @@ export function PlanReviewPanel({ pending, review, t, renderSlot }: PlanReviewPa
|
|
|
41
69
|
void pending.dismiss().catch(() => { setError(t('status.sent')) })
|
|
42
70
|
})
|
|
43
71
|
.catch((cause: unknown) => {
|
|
72
|
+
sentVia.current = null
|
|
44
73
|
setBusy(false)
|
|
45
74
|
setError(cause instanceof Error ? cause.message : String(cause))
|
|
46
75
|
})
|
|
@@ -48,6 +77,7 @@ export function PlanReviewPanel({ pending, review, t, renderSlot }: PlanReviewPa
|
|
|
48
77
|
const decide = (label: string): void => {
|
|
49
78
|
settle(() => pending.answer({ answers: [{ id: review.id, selected: [label] }] }), pending.snapshot().channel === 'rpc')
|
|
50
79
|
}
|
|
80
|
+
const decline = review.decline
|
|
51
81
|
const summary = useMemo(() => {
|
|
52
82
|
const title = extractMarkdownPlainText(review.plan, { mode: 'first-line' })
|
|
53
83
|
const description = extractMarkdownPlainText(review.plan, { mode: 'first-paragraph' })
|
|
@@ -56,21 +86,34 @@ export function PlanReviewPanel({ pending, review, t, renderSlot }: PlanReviewPa
|
|
|
56
86
|
|
|
57
87
|
return (
|
|
58
88
|
<div className={css.frame} data-plan-review-key={pending.key}>
|
|
59
|
-
<section
|
|
89
|
+
<section
|
|
90
|
+
ref={surface} className={css.card} aria-label={review.question} aria-busy={busy}
|
|
91
|
+
onFocusCapture={(event) => { if (!event.currentTarget.contains(event.relatedTarget)) pending.holdFocus() }}
|
|
92
|
+
onBlurCapture={(event) => { if (!event.currentTarget.contains(event.relatedTarget)) pending.releaseFocus() }}
|
|
93
|
+
>
|
|
60
94
|
<div className={css.strip}>
|
|
61
|
-
<
|
|
62
|
-
{t('plan.header')}
|
|
95
|
+
<span className={css.panelLabel}>{t('plan.header')}</span>
|
|
63
96
|
<div className={css.previewActions}>
|
|
64
97
|
{renderSlot('conversation.plan-review.actions', { review, requestKey: pending.key })}
|
|
65
98
|
</div>
|
|
66
99
|
</div>
|
|
67
|
-
<
|
|
68
|
-
|
|
100
|
+
<QuestionWaitBar card={card} t={t} busy={busy} onTakeTime={() => { pending.takeTime() }} />
|
|
101
|
+
<div className={css.summary} data-plan-document>
|
|
102
|
+
<div className={css.documentHeading}><svg className={css.documentIcon} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" aria-hidden="true"><path d="M14 3H6a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8zM14 3v5h5M9 12h6M9 16h6" /></svg><h3 className={css.title}>{summary.title}</h3></div>
|
|
69
103
|
{summary.description !== '' && <p className={css.description}>{summary.description}</p>}
|
|
70
104
|
</div>
|
|
71
|
-
<div className={css.footer}>
|
|
72
|
-
<div className={css.feedback} role="status">{error}</div>
|
|
105
|
+
<div className={css.footer} data-plan-decision>
|
|
106
|
+
<div className={css.feedback} role="status" aria-atomic="true">{error}</div>
|
|
73
107
|
<div className={css.actions}>
|
|
108
|
+
{decline !== undefined && (
|
|
109
|
+
<button
|
|
110
|
+
type="button" className={css.decline} {...tooltip(decline.description)}
|
|
111
|
+
aria-describedby={decline.description === undefined ? undefined : `plan-decline-${pending.key}`}
|
|
112
|
+
disabled={busy || !canDecide} onClick={() => { decide(decline.label) }}
|
|
113
|
+
>
|
|
114
|
+
{decline.label}
|
|
115
|
+
</button>
|
|
116
|
+
)}
|
|
74
117
|
<Button
|
|
75
118
|
variant="outline" className={css.discuss} icon={<IconEditOutlineRegular size={14} />}
|
|
76
119
|
disabled={busy} onClick={() => { settle(() => pending.dismiss()) }}
|
|
@@ -78,13 +121,20 @@ export function PlanReviewPanel({ pending, review, t, renderSlot }: PlanReviewPa
|
|
|
78
121
|
{t('plan.discuss')}
|
|
79
122
|
</Button>
|
|
80
123
|
<Button
|
|
81
|
-
variant="primary" {...tooltip(review.approve.description)}
|
|
82
|
-
|
|
124
|
+
variant="primary" className={css.primaryButton} {...tooltip(review.approve.description)}
|
|
125
|
+
aria-describedby={review.approve.description === undefined ? undefined : `plan-approve-${pending.key}`}
|
|
126
|
+
disabled={busy || !canDecide} onClick={() => { decide(review.approve.label) }}
|
|
83
127
|
>
|
|
84
128
|
{t('plan.approve')}
|
|
85
129
|
</Button>
|
|
86
130
|
</div>
|
|
87
131
|
</div>
|
|
132
|
+
{decline?.description !== undefined && (
|
|
133
|
+
<span className={css.srOnly} id={`plan-decline-${pending.key}`}>{decline.description}</span>
|
|
134
|
+
)}
|
|
135
|
+
{review.approve.description !== undefined && (
|
|
136
|
+
<span className={css.srOnly} id={`plan-approve-${pending.key}`}>{review.approve.description}</span>
|
|
137
|
+
)}
|
|
88
138
|
</section>
|
|
89
139
|
</div>
|
|
90
140
|
)
|