dsh-better-ask-user 0.2.0 → 0.3.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 -4
- package/lib/client.js +336 -258
- package/package.json +12 -12
- package/src/ask-tool.js +7 -1
- package/src/client/AskHistoryRow.module.css +20 -10
- package/src/client/AskHistoryRow.tsx +18 -6
- package/src/client/PlanReviewPanel.module.css +254 -38
- package/src/client/PlanReviewPanel.tsx +9 -3
- package/src/client/QuestionComposer.module.css +504 -77
- package/src/client/QuestionComposer.tsx +51 -27
- package/src/client/QuestionReplyView.module.css +95 -31
- package/src/client/QuestionReplyView.tsx +25 -15
- package/src/client/QuestionWaitBar.module.css +39 -19
- package/src/client/QuestionWaitBar.tsx +0 -2
- package/src/client/contract/slots.ts +19 -4
- package/src/client/index.ts +5 -5
- package/src/client/locales.ts +4 -0
- package/src/client/settings-locales.ts +22 -20
- package/src/client/settings.module.css +108 -108
- package/src/client/settings.tsx +101 -125
- package/src/index.js +2 -14
|
@@ -42,6 +42,7 @@ export function parseRecommendedLabel(label: string): { label: string; recommend
|
|
|
42
42
|
|
|
43
43
|
/** Only a marked first choice is an implicit draft; the user still submits it. */
|
|
44
44
|
function recommendedFirstOption(question: PendingQuestion['questions'][number]): string | undefined {
|
|
45
|
+
if (question.intent?.kind === 'approval' || question.intent?.kind === 'plan-review') return undefined
|
|
45
46
|
const label = question.options?.[0]?.label
|
|
46
47
|
return label !== undefined && parseRecommendedLabel(label).recommended ? label : undefined
|
|
47
48
|
}
|
|
@@ -200,7 +201,7 @@ function QuestionFlow({ pending, t, useStore, useQuestionCard, actions }: Questi
|
|
|
200
201
|
const [busy, setBusy] = useState<'answer' | 'cancel' | null>(null)
|
|
201
202
|
const [error, setError] = useState<Feedback | null>(null)
|
|
202
203
|
const card = useQuestionCard(pending.key, snapshot => snapshot ?? REMOVED_CARD)
|
|
203
|
-
const canSubmit = card.channel !== 'none'
|
|
204
|
+
const canSubmit = !card.closed && card.channel !== 'none'
|
|
204
205
|
// The answer surface freezes while a submission is in flight, and for good on
|
|
205
206
|
// a review card: its call has already settled.
|
|
206
207
|
const locked = busy !== null || review !== undefined
|
|
@@ -240,13 +241,14 @@ function QuestionFlow({ pending, t, useStore, useQuestionCard, actions }: Questi
|
|
|
240
241
|
// collapsed question must not steal focus from the expand toggle back into
|
|
241
242
|
// the input, so focus is granted once per question index.
|
|
242
243
|
const focusedQuestions = useRef(new Set<number>())
|
|
243
|
-
const answerSurface = useRef<
|
|
244
|
+
const answerSurface = useRef<HTMLElement>(null)
|
|
244
245
|
// Every navigation write stays in bounds and drafts mirrors questions 1:1.
|
|
245
246
|
// oxlint-disable-next-line typescript/no-non-null-assertion
|
|
246
247
|
const question = questions[index]!
|
|
247
248
|
// oxlint-disable-next-line typescript/no-non-null-assertion
|
|
248
249
|
const draft = drafts[index]!
|
|
249
250
|
const hasOptions = (question.options?.length ?? 0) > 0
|
|
251
|
+
const fixedActions = question.intent?.kind === 'approval'
|
|
250
252
|
const questionId = `question-${pending.key}-${String(index)}`
|
|
251
253
|
|
|
252
254
|
const replaceProgress = (nextIndex: number, nextDrafts: QuestionDraftAnswer[]): void => {
|
|
@@ -267,11 +269,11 @@ function QuestionFlow({ pending, t, useStore, useQuestionCard, actions }: Questi
|
|
|
267
269
|
replaceProgress(index, drafts)
|
|
268
270
|
}
|
|
269
271
|
|
|
270
|
-
const focusAnswerSurface = (event: FocusEvent<
|
|
272
|
+
const focusAnswerSurface = (event: FocusEvent<HTMLElement>): void => {
|
|
271
273
|
if (!event.currentTarget.contains(event.relatedTarget)) pending.holdFocus()
|
|
272
274
|
}
|
|
273
275
|
|
|
274
|
-
const blurAnswerSurface = (event: FocusEvent<
|
|
276
|
+
const blurAnswerSurface = (event: FocusEvent<HTMLElement>): void => {
|
|
275
277
|
if (!event.currentTarget.contains(event.relatedTarget)) pending.releaseFocus()
|
|
276
278
|
}
|
|
277
279
|
|
|
@@ -323,7 +325,7 @@ function QuestionFlow({ pending, t, useStore, useQuestionCard, actions }: Questi
|
|
|
323
325
|
setError(null)
|
|
324
326
|
}
|
|
325
327
|
|
|
326
|
-
const choose = (label: string): void => {
|
|
328
|
+
const choose = (label: string, advance = true): void => {
|
|
327
329
|
updateDraft((current) => {
|
|
328
330
|
if (question.multiSelect === true) {
|
|
329
331
|
const selected = current.selected.includes(label)
|
|
@@ -332,7 +334,23 @@ function QuestionFlow({ pending, t, useStore, useQuestionCard, actions }: Questi
|
|
|
332
334
|
return { ...current, selected, skipped: false }
|
|
333
335
|
}
|
|
334
336
|
return { selected: [label], custom: '', skipped: false }
|
|
335
|
-
}, question.multiSelect !== true && index < questions.length - 1 ? index + 1 : index)
|
|
337
|
+
}, advance && question.multiSelect !== true && index < questions.length - 1 ? index + 1 : index)
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const navigateOptions = (event: KeyboardEvent<HTMLButtonElement>, optionIndex: number): void => {
|
|
341
|
+
if (question.multiSelect === true || locked || event.defaultPrevented) return
|
|
342
|
+
const options = question.options ?? []
|
|
343
|
+
let next: number
|
|
344
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowRight') next = (optionIndex + 1) % options.length
|
|
345
|
+
else if (event.key === 'ArrowUp' || event.key === 'ArrowLeft') next = (optionIndex - 1 + options.length) % options.length
|
|
346
|
+
else if (event.key === 'Home') next = 0
|
|
347
|
+
else if (event.key === 'End') next = options.length - 1
|
|
348
|
+
else return
|
|
349
|
+
event.preventDefault()
|
|
350
|
+
event.stopPropagation()
|
|
351
|
+
event.currentTarget.parentElement?.querySelectorAll<HTMLButtonElement>('[role="radio"]')[next]?.focus()
|
|
352
|
+
// Arrow navigation changes the choice without advancing to another question.
|
|
353
|
+
choose(options[next]!.label, false)
|
|
336
354
|
}
|
|
337
355
|
|
|
338
356
|
const answered = (item: QuestionDraftAnswer): boolean =>
|
|
@@ -411,7 +429,7 @@ function QuestionFlow({ pending, t, useStore, useQuestionCard, actions }: Questi
|
|
|
411
429
|
}
|
|
412
430
|
|
|
413
431
|
const continueFromCustom = (event: KeyboardEvent<HTMLTextAreaElement>): void => {
|
|
414
|
-
if (event.key !== 'Enter' || event.shiftKey || isComposing(event)) return
|
|
432
|
+
if (event.defaultPrevented || event.repeat || event.key !== 'Enter' || event.shiftKey || isComposing(event)) return
|
|
415
433
|
event.preventDefault()
|
|
416
434
|
continueFlow()
|
|
417
435
|
}
|
|
@@ -431,24 +449,31 @@ function QuestionFlow({ pending, t, useStore, useQuestionCard, actions }: Questi
|
|
|
431
449
|
return (
|
|
432
450
|
<div className={css.frame} data-question-key={pending.key}>
|
|
433
451
|
<section
|
|
452
|
+
ref={answerSurface}
|
|
434
453
|
className={clsx(css.card, minimized && css.cardMinimized)}
|
|
454
|
+
onFocusCapture={focusAnswerSurface}
|
|
455
|
+
onBlurCapture={blurAnswerSurface}
|
|
435
456
|
aria-labelledby={questionId}
|
|
436
457
|
aria-busy={busy !== null}
|
|
437
458
|
>
|
|
438
459
|
<header className={css.header}>
|
|
439
460
|
<div className={css.headingBlock}>
|
|
440
|
-
{
|
|
441
|
-
<div
|
|
442
|
-
|
|
461
|
+
<div className={css.titleRow}>
|
|
462
|
+
<div
|
|
463
|
+
className={css.title}
|
|
464
|
+
id={questionId}
|
|
465
|
+
role="heading"
|
|
466
|
+
aria-level={2}
|
|
467
|
+
>
|
|
468
|
+
<MarkdownText text={question.question} variant="compact" labels={markdownLabels} />
|
|
443
469
|
</div>
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
<MarkdownText text={question.question} variant="compact" labels={markdownLabels} />
|
|
470
|
+
{question.header !== undefined && question.header.trim() !== question.question.trim()
|
|
471
|
+
&& !question.question.toLocaleLowerCase().includes(question.header.trim().toLocaleLowerCase()) && (
|
|
472
|
+
<span className={css.headerChip}>
|
|
473
|
+
<MarkdownText text={question.header} variant="compact" labels={markdownLabels} />
|
|
474
|
+
</span>
|
|
475
|
+
)}
|
|
476
|
+
{review !== undefined && <span className={css.statusChip}>{t('review.status')}</span>}
|
|
452
477
|
</div>
|
|
453
478
|
</div>
|
|
454
479
|
<div className={css.headerActions}>
|
|
@@ -473,16 +498,12 @@ function QuestionFlow({ pending, t, useStore, useQuestionCard, actions }: Questi
|
|
|
473
498
|
</div>
|
|
474
499
|
</header>
|
|
475
500
|
<QuestionWaitBar card={card} t={t} busy={busy !== null} onTakeTime={takeTime} />
|
|
476
|
-
{review !== undefined && <div className={css.reviewStatus}>{t('review.status')}</div>}
|
|
477
501
|
|
|
478
502
|
{!minimized && (
|
|
479
503
|
<>
|
|
480
504
|
<div
|
|
481
|
-
ref={answerSurface}
|
|
482
505
|
className={css.body}
|
|
483
506
|
data-question-scroll
|
|
484
|
-
onFocusCapture={focusAnswerSurface}
|
|
485
|
-
onBlurCapture={blurAnswerSurface}
|
|
486
507
|
>
|
|
487
508
|
{question.detail !== undefined && (
|
|
488
509
|
<div className={css.detail}><MarkdownText text={question.detail} labels={markdownLabels} /></div>
|
|
@@ -500,6 +521,8 @@ function QuestionFlow({ pending, t, useStore, useQuestionCard, actions }: Questi
|
|
|
500
521
|
aria-label={display.recommended ? `${display.label}, ${t('option.recommended')}` : display.label}
|
|
501
522
|
aria-describedby={option.description === undefined ? undefined : `${questionId}-option-${String(optionIndex)}`}
|
|
502
523
|
disabled={locked}
|
|
524
|
+
tabIndex={question.multiSelect === true || selected || (draft.selected.length === 0 && optionIndex === 0) ? 0 : -1}
|
|
525
|
+
onKeyDown={(event) => { navigateOptions(event, optionIndex) }}
|
|
503
526
|
onClick={() => { choose(option.label) }}
|
|
504
527
|
>
|
|
505
528
|
{question.multiSelect === true
|
|
@@ -535,7 +558,7 @@ function QuestionFlow({ pending, t, useStore, useQuestionCard, actions }: Questi
|
|
|
535
558
|
{/* A review card keeps the free-text field only when the
|
|
536
559
|
recorded answer used it; an empty disabled box with a
|
|
537
560
|
placeholder would read as somewhere to type. */}
|
|
538
|
-
{(review === undefined || draft.custom !== '') && (hasOptions
|
|
561
|
+
{!fixedActions && (review === undefined || draft.custom !== '') && (hasOptions
|
|
539
562
|
? (
|
|
540
563
|
<div
|
|
541
564
|
className={clsx(
|
|
@@ -606,20 +629,21 @@ function QuestionFlow({ pending, t, useStore, useQuestionCard, actions }: Questi
|
|
|
606
629
|
</button>
|
|
607
630
|
</div>
|
|
608
631
|
)}
|
|
609
|
-
<div className={css.feedback} role="status" aria-atomic="true">
|
|
632
|
+
<div className={css.feedback} role="status" aria-atomic="true" data-error={error !== null && (!('key' in error) || error.key !== 'status.sent') || undefined}>
|
|
610
633
|
{error === null ? null : 'key' in error ? t(error.key) : error.text}
|
|
611
634
|
</div>
|
|
612
635
|
{/* A review card has nothing to send: the pager alone walks the record. */}
|
|
613
636
|
{review === undefined && (
|
|
614
637
|
<div className={css.footerActions}>
|
|
615
|
-
<Button variant="outline" disabled={busy !== null} onClick={skipQuestion}>
|
|
638
|
+
{!fixedActions && <Button variant="outline" className={css.button} disabled={busy !== null} onClick={skipQuestion}>
|
|
616
639
|
{t('action.skip')}
|
|
617
|
-
</Button>
|
|
640
|
+
</Button>}
|
|
618
641
|
<Button
|
|
619
|
-
variant="primary" className={css.
|
|
642
|
+
variant="primary" className={css.primary} aria-busy={busy === 'answer'}
|
|
620
643
|
disabled={busy !== null || !answered(draft) || (index === questions.length - 1 && !canSubmit)}
|
|
621
644
|
onClick={continueFlow}
|
|
622
645
|
>
|
|
646
|
+
{busy === 'answer' && <span className={css.spinner} aria-hidden="true" />}
|
|
623
647
|
{busy === 'answer'
|
|
624
648
|
? t('submitting')
|
|
625
649
|
: index === questions.length - 1 ? t('submit') : t('action.next')}
|
|
@@ -1,37 +1,101 @@
|
|
|
1
|
-
.row {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
.row {
|
|
2
|
+
--cfg-line: var(--dsw-alias-border-l2);
|
|
3
|
+
--cfg-line-strong: var(--dsw-alias-border-l3);
|
|
4
|
+
--cfg-surface: var(--dsw-alias-bg-layer-2);
|
|
5
|
+
--cfg-sunken: color-mix(in srgb, var(--dsw-alias-label-primary) 4%, var(--dsw-alias-bg-layer-1));
|
|
6
|
+
--cfg-ink: var(--dsw-alias-label-primary);
|
|
7
|
+
--cfg-muted: var(--dsw-alias-label-secondary);
|
|
8
|
+
--cfg-accent: #3388bb;
|
|
9
|
+
--cfg-accent-text: #14587f;
|
|
10
|
+
--cfg-hover: var(--dsw-alias-interactive-bg-hover);
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
align-items: flex-end;
|
|
14
|
+
gap: 4px;
|
|
15
|
+
min-width: 0;
|
|
16
|
+
padding: 4px 0;
|
|
17
|
+
}
|
|
18
|
+
.bubble {
|
|
19
|
+
max-width: 85%;
|
|
20
|
+
min-width: 0;
|
|
21
|
+
overflow: hidden;
|
|
22
|
+
border: 1px solid var(--cfg-line);
|
|
23
|
+
border-radius: 12px;
|
|
24
|
+
background: var(--cfg-surface);
|
|
25
|
+
color: var(--cfg-ink);
|
|
26
|
+
font-size: inherit;
|
|
27
|
+
line-height: 1.5;
|
|
28
|
+
text-align: left;
|
|
29
|
+
overflow-wrap: anywhere;
|
|
30
|
+
}
|
|
31
|
+
.toggle {
|
|
32
|
+
appearance: none;
|
|
33
|
+
display: block;
|
|
34
|
+
width: 100%;
|
|
35
|
+
padding: 10px 12px;
|
|
36
|
+
border: 0;
|
|
37
|
+
background: transparent;
|
|
38
|
+
color: inherit;
|
|
39
|
+
cursor: pointer;
|
|
40
|
+
font: inherit;
|
|
41
|
+
text-align: left;
|
|
42
|
+
transition: background-color 100ms ease;
|
|
43
|
+
}
|
|
44
|
+
.toggle:hover { background: var(--cfg-hover); }
|
|
45
|
+
.toggle:focus-visible { outline: 2px solid var(--cfg-accent); outline-offset: -3px; border-radius: 8px; }
|
|
46
|
+
.labelRow { display: flex; align-items: center; gap: 6px; }
|
|
47
|
+
.caret { display: inline-flex; flex: none; color: var(--cfg-muted); }
|
|
9
48
|
.caret svg { width: 12px; height: 12px; }
|
|
10
|
-
.label { color: var(--
|
|
11
|
-
.summary {
|
|
49
|
+
.label { color: var(--cfg-muted); font-size: 11px; line-height: 18px; font-weight: 500; }
|
|
50
|
+
.summary {
|
|
51
|
+
display: -webkit-box;
|
|
52
|
+
-webkit-box-orient: vertical;
|
|
53
|
+
-webkit-line-clamp: 3;
|
|
54
|
+
overflow: hidden;
|
|
55
|
+
margin-top: 4px;
|
|
56
|
+
white-space: pre-wrap;
|
|
57
|
+
}
|
|
12
58
|
.text { margin: 0; padding: 0 12px 12px; white-space: pre-wrap; }
|
|
13
|
-
.details {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
59
|
+
.details {
|
|
60
|
+
max-height: min(50vh, 400px);
|
|
61
|
+
margin: 0;
|
|
62
|
+
padding: 0 12px 12px;
|
|
63
|
+
overflow: auto;
|
|
64
|
+
overscroll-behavior: contain;
|
|
65
|
+
scrollbar-width: thin;
|
|
66
|
+
scrollbar-gutter: stable;
|
|
67
|
+
}
|
|
68
|
+
.details > div { padding-top: 10px; border-top: 1px solid var(--cfg-line); }
|
|
69
|
+
.details > div + div { margin-top: 12px; }
|
|
70
|
+
.question { display: grid; gap: 4px; font-size: inherit; }
|
|
17
71
|
.questionText { font-weight: 500; }
|
|
18
|
-
.header, .detail { color: var(--
|
|
72
|
+
.header, .detail, .options { color: var(--cfg-muted); font-size: 12px; }
|
|
19
73
|
.detail { white-space: pre-wrap; }
|
|
20
|
-
.options { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none;
|
|
21
|
-
.options li { display: flex; align-items: flex-start; gap:
|
|
22
|
-
.options li[data-selected] { background: color-mix(in srgb, var(--
|
|
23
|
-
.selection { display: grid; place-items: center; width: 16px; height: 18px; flex: none; color:
|
|
24
|
-
.optionCopy { display: grid; min-width: 0; gap:
|
|
25
|
-
.optionDescription { color: var(--
|
|
26
|
-
.answer { margin:
|
|
27
|
-
.answerLabel { margin-right:
|
|
28
|
-
.actions { display: flex; align-items: center; gap:
|
|
29
|
-
.time { font-
|
|
30
|
-
.action { display: inline-flex; align-items: center; justify-content: center; width:
|
|
74
|
+
.options { display: grid; gap: 4px; margin: 4px 0 0; padding: 0; list-style: none; }
|
|
75
|
+
.options li { display: flex; align-items: flex-start; gap: 6px; padding: 6px 8px; border: 1px solid transparent; border-radius: 8px; }
|
|
76
|
+
.options li[data-selected] { border-color: var(--cfg-accent); color: var(--cfg-ink); background: color-mix(in srgb, var(--cfg-accent) 8%, transparent); }
|
|
77
|
+
.selection { display: grid; place-items: center; width: 16px; height: 18px; flex: none; color: var(--cfg-accent); }
|
|
78
|
+
.optionCopy { display: grid; min-width: 0; gap: 2px; }
|
|
79
|
+
.optionDescription { color: var(--cfg-muted); }
|
|
80
|
+
.answer { margin: 8px 0 0; white-space: pre-wrap; }
|
|
81
|
+
.answerLabel { margin-right: 4px; color: var(--cfg-muted); font-size: 11px; line-height: 18px; }
|
|
82
|
+
.actions { display: flex; align-items: center; gap: 4px; padding-right: 2px; color: var(--dsw-alias-label-tertiary); }
|
|
83
|
+
.time { font-size: 11px; font-variant-numeric: tabular-nums; }
|
|
84
|
+
.action { appearance: none; display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: inherit; cursor: pointer; transition: background-color 140ms ease, color 140ms ease; }
|
|
31
85
|
.action svg { width: 14px; height: 14px; }
|
|
32
|
-
.action:hover { background: var(--
|
|
33
|
-
.action:
|
|
34
|
-
.action:
|
|
86
|
+
.action:hover { background: var(--cfg-hover); color: var(--cfg-ink); }
|
|
87
|
+
.action:focus-visible { outline: 2px solid var(--cfg-accent); outline-offset: 2px; }
|
|
88
|
+
.action:disabled { opacity: .4; cursor: default; }
|
|
89
|
+
.copyFeedback { color: var(--cfg-muted); font-size: 12px; }
|
|
90
|
+
.copyFeedback[role='alert'] { color: var(--dsw-alias-state-error-primary); }
|
|
91
|
+
.copyFeedback:empty { display: none; }
|
|
92
|
+
.spinner { width: 12px; height: 12px; border: 1px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 800ms linear infinite; }
|
|
93
|
+
@keyframes spin { to { transform: rotate(360deg); } }
|
|
35
94
|
.question, .answer, .text { min-width: 0; overflow-wrap: anywhere; }
|
|
36
|
-
@media (max-width: 640px) {
|
|
37
|
-
|
|
95
|
+
@media (max-width: 640px) {
|
|
96
|
+
.bubble { max-width: 100%; }
|
|
97
|
+
}
|
|
98
|
+
@media (pointer: coarse) { .toggle { min-height: 44px; } .action { width: 44px; height: 44px; } }
|
|
99
|
+
@media (prefers-reduced-motion: reduce) { .toggle, .action { transition: none; } .spinner { animation: none; } }
|
|
100
|
+
|
|
101
|
+
[data-ds-dark-theme] .row { --cfg-accent: #4eb0e8; --cfg-accent-text: #6fc0ee; }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { memo, useCallback, useEffect, useRef, useState } from 'react'
|
|
1
|
+
import { memo, useCallback, useEffect, useId, useRef, useState } from 'react'
|
|
2
2
|
import type {} from '@deepseek-ai/dsh-client-ui-chat/client'
|
|
3
3
|
import type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'
|
|
4
4
|
import {
|
|
@@ -35,17 +35,23 @@ export function QuestionReplyBubble({ data, t }: { data: QuestionReplyData; t: P
|
|
|
35
35
|
? data.text
|
|
36
36
|
: data.questions.flatMap(question => replyAnswerValues(data, question.id)).join(', ')
|
|
37
37
|
const copyText = replyClipboardText(data, t)
|
|
38
|
-
const
|
|
38
|
+
const detailsId = useId()
|
|
39
|
+
const [copyState, setCopyState] = useState<'idle' | 'copying' | 'copied' | 'error'>('idle')
|
|
39
40
|
const copyTimer = useRef<ReturnType<typeof setTimeout>>()
|
|
40
41
|
useEffect(() => () => { window.clearTimeout(copyTimer.current) }, [])
|
|
41
|
-
const onCopy = useCallback(() => {
|
|
42
|
-
if (copied) return
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
const onCopy = useCallback(async () => {
|
|
43
|
+
if (copyState === 'copying' || copyState === 'copied') return
|
|
44
|
+
window.clearTimeout(copyTimer.current)
|
|
45
|
+
setCopyState('copying')
|
|
46
|
+
try {
|
|
47
|
+
const ok = await writeClipboard(copyText)
|
|
48
|
+
setCopyState(ok ? 'copied' : 'error')
|
|
49
|
+
if (ok) copyTimer.current = window.setTimeout(() => { setCopyState('idle') }, 1500)
|
|
50
|
+
} catch {
|
|
51
|
+
setCopyState('error')
|
|
52
|
+
}
|
|
53
|
+
}, [copyState, copyText])
|
|
54
|
+
const copyLabel = copyState === 'copied' ? t('copied') : t('copy')
|
|
49
55
|
return (
|
|
50
56
|
<div className={css.row} data-question-reply={data.callId} data-reply-outcome={data.outcome} role="group" aria-label={label}>
|
|
51
57
|
<div className={css.bubble}>
|
|
@@ -53,6 +59,7 @@ export function QuestionReplyBubble({ data, t }: { data: QuestionReplyData; t: P
|
|
|
53
59
|
type="button"
|
|
54
60
|
className={css.toggle}
|
|
55
61
|
aria-expanded={open}
|
|
62
|
+
aria-controls={open ? detailsId : undefined}
|
|
56
63
|
aria-label={`${label} · ${toggleLabel}`}
|
|
57
64
|
onClick={() => { setOpen(value => !value) }}
|
|
58
65
|
>
|
|
@@ -67,9 +74,9 @@ export function QuestionReplyBubble({ data, t }: { data: QuestionReplyData; t: P
|
|
|
67
74
|
{!open && <span className={css.summary}>{summary === '' ? t('reply.skipped') : summary}</span>}
|
|
68
75
|
</button>
|
|
69
76
|
{open && (data.questions.length === 0
|
|
70
|
-
? <p className={css.text}>{data.text}</p>
|
|
77
|
+
? <p className={css.text} id={detailsId}>{data.text}</p>
|
|
71
78
|
: (
|
|
72
|
-
<dl className={css.details}>
|
|
79
|
+
<dl className={css.details} id={detailsId}>
|
|
73
80
|
{data.questions.map((question) => {
|
|
74
81
|
const values = replyAnswerValues(data, question.id)
|
|
75
82
|
return (
|
|
@@ -103,11 +110,14 @@ export function QuestionReplyBubble({ data, t }: { data: QuestionReplyData; t: P
|
|
|
103
110
|
<span className={css.time}>
|
|
104
111
|
{new Intl.DateTimeFormat(undefined, { hour: '2-digit', minute: '2-digit', hour12: false }).format(data.time)}
|
|
105
112
|
</span>
|
|
106
|
-
<Tooltip label={
|
|
107
|
-
<button type="button" className={css.action} aria-label={
|
|
108
|
-
{copied ? <IconCheckOutlineRegular /> : <IconCopyOutlineRegular />}
|
|
113
|
+
<Tooltip label={copyLabel} side="bottom">
|
|
114
|
+
<button type="button" className={css.action} aria-label={copyLabel} aria-busy={copyState === 'copying'} disabled={copyState === 'copying'} onClick={() => { void onCopy() }}>
|
|
115
|
+
{copyState === 'copying' ? <span className={css.spinner} aria-hidden="true" /> : copyState === 'copied' ? <IconCheckOutlineRegular /> : <IconCopyOutlineRegular />}
|
|
109
116
|
</button>
|
|
110
117
|
</Tooltip>
|
|
118
|
+
<span className={css.copyFeedback} role={copyState === 'error' ? 'alert' : 'status'}>
|
|
119
|
+
{copyState === 'error' ? t('reply.copyFailed') : copyState === 'copied' ? t('copied') : null}
|
|
120
|
+
</span>
|
|
111
121
|
</div>
|
|
112
122
|
</div>
|
|
113
123
|
)
|
|
@@ -1,30 +1,50 @@
|
|
|
1
|
+
/* Compact countdown strip: ring, tabular time, one ghost action. */
|
|
1
2
|
.bar {
|
|
2
|
-
--
|
|
3
|
+
--ui-accent: #3388bb;
|
|
4
|
+
--ui-accent-text: #14587f;
|
|
5
|
+
--ui-ink-1: var(--dsw-alias-label-primary, #0f1115);
|
|
6
|
+
--ui-ink-2: var(--dsw-alias-label-secondary, #61666b);
|
|
7
|
+
--ui-ink-3: var(--dsw-alias-label-tertiary, #81858c);
|
|
8
|
+
--ui-line-1: var(--dsw-alias-border-l1, #0000000a);
|
|
9
|
+
--ui-line-2: var(--dsw-alias-border-l2, #0000001a);
|
|
10
|
+
--ui-raised: var(--dsw-alias-bg-layer-2, #fff);
|
|
11
|
+
--ui-hover: var(--dsw-alias-interactive-bg-hover, color-mix(in srgb, var(--ui-ink-1) 5%, transparent));
|
|
3
12
|
display: flex;
|
|
4
13
|
align-items: center;
|
|
5
14
|
flex-shrink: 0;
|
|
6
15
|
gap: 8px;
|
|
16
|
+
min-width: 0;
|
|
7
17
|
min-height: 36px;
|
|
8
|
-
margin: 0 16px
|
|
9
|
-
padding:
|
|
10
|
-
border:
|
|
18
|
+
margin: 0 16px 10px;
|
|
19
|
+
padding: 4px 6px 4px 10px;
|
|
20
|
+
border: 1px solid var(--ui-line-2);
|
|
11
21
|
border-radius: 8px;
|
|
12
|
-
background: var(--
|
|
13
|
-
color: var(--
|
|
22
|
+
background: var(--ui-raised);
|
|
23
|
+
color: var(--ui-ink-1);
|
|
14
24
|
}
|
|
15
25
|
.clock { position: relative; display: grid; place-items: center; width: 24px; height: 24px; flex: none; }
|
|
16
26
|
.ring { position: absolute; inset: 0; width: 100%; height: 100%; fill: none; stroke-width: 2; transform: rotate(-90deg); }
|
|
17
|
-
.track { stroke: var(--
|
|
18
|
-
.remaining { stroke: var(--
|
|
19
|
-
.clockHand { width: 8px; height: 9px; margin-top: -4px; margin-left: 5px; border-left: 1.5px solid var(--
|
|
20
|
-
.pause { width: 16px; height: 16px; color: var(--
|
|
21
|
-
.status { display: flex; align-items:
|
|
22
|
-
.time { font-size: 12px; line-height: 20px; }
|
|
23
|
-
.bar[data-wait-state='counting'] .time
|
|
24
|
-
.
|
|
25
|
-
.takeTime
|
|
26
|
-
.takeTime:
|
|
27
|
-
.takeTime:active:not(:disabled) { background: color-mix(in srgb, var(--ask-accent) 10%, transparent); }
|
|
28
|
-
.takeTime:focus-visible { outline: 2px solid var(--ask-accent); outline-offset: 2px; }
|
|
27
|
+
.track { stroke: var(--ui-line-2); }
|
|
28
|
+
.remaining { stroke: var(--ui-accent); }
|
|
29
|
+
.clockHand { width: 8px; height: 9px; margin-top: -4px; margin-left: 5px; border-left: 1.5px solid var(--ui-ink-2); border-bottom: 1.5px solid var(--ui-ink-2); }
|
|
30
|
+
.pause { width: 16px; height: 16px; color: var(--ui-ink-2); }
|
|
31
|
+
.status { display: flex; align-items: center; min-width: 0; }
|
|
32
|
+
.time { color: var(--ui-ink-1); font-size: 12px; line-height: 20px; font-variant-numeric: tabular-nums; white-space: nowrap; }
|
|
33
|
+
.bar[data-wait-state='counting'] .time { font-weight: 500; }
|
|
34
|
+
.takeTime { appearance: none; display: inline-flex; align-items: center; justify-content: center; flex: none; margin-left: auto; min-height: 28px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: var(--ui-ink-3); font: inherit; font-size: 12px; line-height: 18px; font-weight: 500; cursor: pointer; transition: background-color 140ms ease, color 140ms ease; }
|
|
35
|
+
.takeTime:hover:not(:disabled) { background: var(--ui-hover); color: var(--ui-ink-1); }
|
|
36
|
+
.takeTime:focus-visible { outline: 2px solid var(--ui-accent); outline-offset: 2px; }
|
|
29
37
|
.takeTime:disabled { opacity: .4; cursor: default; }
|
|
30
|
-
@media (max-width: 720px) {
|
|
38
|
+
@media (max-width: 720px) {
|
|
39
|
+
.bar { margin: 0 12px 8px; padding: 4px 6px 4px 8px; }
|
|
40
|
+
}
|
|
41
|
+
@media (pointer: coarse) {
|
|
42
|
+
.takeTime { min-height: 44px; }
|
|
43
|
+
}
|
|
44
|
+
@media (prefers-reduced-motion: reduce) {
|
|
45
|
+
.takeTime { transition: none; }
|
|
46
|
+
}
|
|
47
|
+
[data-ds-dark-theme] .bar {
|
|
48
|
+
--ui-accent: #4eb0e8;
|
|
49
|
+
--ui-accent-text: #6fc0ee;
|
|
50
|
+
}
|
|
@@ -32,8 +32,6 @@ export function QuestionWaitBar({ card, t, busy, onTakeTime }: {
|
|
|
32
32
|
</span>
|
|
33
33
|
<div className={css.status} role={held || continued ? 'status' : undefined} aria-atomic="true">
|
|
34
34
|
<span className={css.time} aria-label={status}>{held || continued ? status : `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, '0')}`}</span>
|
|
35
|
-
{!held && !continued && !running && <span className={css.policy}>{t('wait.pauseLabel')}</span>}
|
|
36
|
-
{!held && !continued && <span className={css.policy}>{t(card.timeoutMode === 'default' ? 'wait.auto' : 'wait.extend')}</span>}
|
|
37
35
|
</div>
|
|
38
36
|
{!held && !continued && <button type="button" className={css.takeTime} disabled={busy} onClick={onTakeTime}>{t('wait.takeTime')}</button>}
|
|
39
37
|
</div>
|
|
@@ -281,6 +281,7 @@ export class PendingQuestion {
|
|
|
281
281
|
readonly #siblings: (() => readonly string[]) | undefined
|
|
282
282
|
readonly #listeners = new Set<() => void>()
|
|
283
283
|
#snapshot: QuestionCardSnapshot
|
|
284
|
+
readonly #requiresDecision: boolean
|
|
284
285
|
#waitMs: number | undefined
|
|
285
286
|
#timeoutMode: 'native' | 'default' = 'native'
|
|
286
287
|
#defaultAnswer: QuestionAnswer | undefined
|
|
@@ -302,6 +303,9 @@ export class PendingQuestion {
|
|
|
302
303
|
) {
|
|
303
304
|
this.sessionId = sessionId
|
|
304
305
|
this.questions = questions
|
|
306
|
+
// Intent, not presentation narrowing: a multi-question plan review still needs a human decision.
|
|
307
|
+
this.#requiresDecision = questions.some(question =>
|
|
308
|
+
question.intent?.kind === 'plan-review' || question.intent?.kind === 'approval')
|
|
305
309
|
this.#waitMs = settings?.waitMs
|
|
306
310
|
this.#timeoutMode = settings?.timeoutMode ?? 'native'
|
|
307
311
|
this.#defaultAnswer = settings?.defaultAnswer
|
|
@@ -343,6 +347,14 @@ export class PendingQuestion {
|
|
|
343
347
|
return () => { this.#listeners.delete(listener) }
|
|
344
348
|
}
|
|
345
349
|
|
|
350
|
+
/** Apply timing policy when the forwarded request arrives after its projection created the card. */
|
|
351
|
+
configure(settings: BetterAskConfig): void {
|
|
352
|
+
this.#waitMs = settings.waitMs
|
|
353
|
+
this.#timeoutMode = settings.timeoutMode ?? 'native'
|
|
354
|
+
this.#defaultAnswer = settings.defaultAnswer
|
|
355
|
+
this.publish()
|
|
356
|
+
}
|
|
357
|
+
|
|
346
358
|
/** Read the stable current card state. */
|
|
347
359
|
readonly snapshot = (): QuestionCardSnapshot => this.#snapshot
|
|
348
360
|
|
|
@@ -414,11 +426,12 @@ export class PendingQuestion {
|
|
|
414
426
|
*/
|
|
415
427
|
attachWaterfall(channel: QuestionWaterfallChannel): void {
|
|
416
428
|
this.#waterfall = channel
|
|
417
|
-
this.#
|
|
429
|
+
const deadline = this.#requiresDecision ? undefined : channel.deadline
|
|
430
|
+
this.#timedWait = deadline !== undefined
|
|
418
431
|
if (!this.#held && !this.#engaged) {
|
|
419
|
-
this.#deadline =
|
|
420
|
-
if (this.#focused &&
|
|
421
|
-
this.#remainingMs = Math.max(0,
|
|
432
|
+
this.#deadline = deadline
|
|
433
|
+
if (this.#focused && deadline !== undefined) {
|
|
434
|
+
this.#remainingMs = Math.max(0, deadline - Date.now())
|
|
422
435
|
this.#deadline = undefined
|
|
423
436
|
}
|
|
424
437
|
}
|
|
@@ -538,6 +551,7 @@ export class PendingQuestion {
|
|
|
538
551
|
|
|
539
552
|
/** Settle with the host-authored default answer in default timeout mode. */
|
|
540
553
|
autoSelect(): void {
|
|
554
|
+
if (this.#requiresDecision) return
|
|
541
555
|
if (this.#held || this.#engaged || this.#focused) return
|
|
542
556
|
const channel = this.#waterfall
|
|
543
557
|
if (channel === undefined) return
|
|
@@ -555,6 +569,7 @@ export class PendingQuestion {
|
|
|
555
569
|
|
|
556
570
|
/** Local countdown reached zero: default-select or settle with `ASK_TIMED_OUT`. */
|
|
557
571
|
timeout(): void {
|
|
572
|
+
if (this.#requiresDecision) return
|
|
558
573
|
if (this.#held || this.#engaged || this.#focused) return
|
|
559
574
|
if (this.#timeoutMode === 'default' && this.#defaultAnswer !== undefined) {
|
|
560
575
|
this.autoSelect()
|
package/src/client/index.ts
CHANGED
|
@@ -117,7 +117,10 @@ class QuestionCards {
|
|
|
117
117
|
): QuestionCard {
|
|
118
118
|
if (callId !== undefined) {
|
|
119
119
|
const existing = this.byCallId(sessionId, callId)
|
|
120
|
-
if (existing !== undefined)
|
|
120
|
+
if (existing !== undefined) {
|
|
121
|
+
if (settings !== undefined) existing.pending.configure(settings)
|
|
122
|
+
return existing
|
|
123
|
+
}
|
|
121
124
|
}
|
|
122
125
|
return this.#create(new PendingQuestion(sessionId, questions, callId, () => this.keysFor(sessionId), undefined, settings))
|
|
123
126
|
}
|
|
@@ -419,10 +422,7 @@ export function apply(ctx: ClientContext): void {
|
|
|
419
422
|
name: 'tool.call.toolview',
|
|
420
423
|
key: 'ask_user_question',
|
|
421
424
|
locale: NS,
|
|
422
|
-
// The
|
|
423
|
-
// `ask-question-toolview` for this key at priority 0, and the slot registry
|
|
424
|
-
// rejects a second entry at the same priority (which failed the whole client
|
|
425
|
-
// boot). A lower priority shadows it: lowest renders.
|
|
425
|
+
// The host already owns this key at priority 0; lower priority shadows it.
|
|
426
426
|
priority: -1,
|
|
427
427
|
inject: (sessionId: SessionId) => ({
|
|
428
428
|
revealPanel: (callId: string) => ctx.get('userQuestionPanels')?.reveal(sessionId, callId) ?? false,
|
package/src/client/locales.ts
CHANGED
|
@@ -10,6 +10,8 @@ export const zh = {
|
|
|
10
10
|
'history.title': '问题',
|
|
11
11
|
'history.review': '查看',
|
|
12
12
|
'history.reopen': '打开',
|
|
13
|
+
'history.unavailable': '问题暂时无法打开,请重试。',
|
|
14
|
+
'reply.copyFailed': '复制失败,请重试。',
|
|
13
15
|
'wait.takeTime': '慢慢回答',
|
|
14
16
|
'wait.countdown': '{seconds} 秒后继续工作',
|
|
15
17
|
'wait.autoCountdown': '{seconds} 秒后自动选择默认项',
|
|
@@ -55,6 +57,8 @@ export const en = {
|
|
|
55
57
|
'history.title': 'Question',
|
|
56
58
|
'history.review': 'Review',
|
|
57
59
|
'history.reopen': 'Open',
|
|
60
|
+
'history.unavailable': 'Cannot open this question right now. Try again.',
|
|
61
|
+
'reply.copyFailed': 'Copy failed. Try again.',
|
|
58
62
|
'wait.takeTime': 'Take time',
|
|
59
63
|
'wait.countdown': 'Continuing in {seconds}s',
|
|
60
64
|
'wait.autoCountdown': 'Defaults selected in {seconds}s',
|