dsh-better-ask-user 0.1.7 → 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/LICENSE +202 -674
- package/NOTICE +23 -1
- package/README.md +23 -4
- package/lib/client.js +772 -360
- package/package.json +14 -13
- package/src/ask-tool.js +7 -1
- package/src/client/AskHistoryRow.module.css +21 -45
- package/src/client/AskHistoryRow.tsx +25 -19
- package/src/client/PlanReviewPanel.module.css +198 -68
- package/src/client/PlanReviewPanel.tsx +69 -13
- package/src/client/QuestionComposer.module.css +289 -357
- package/src/client/QuestionComposer.tsx +92 -85
- package/src/client/QuestionReplyView.module.css +79 -171
- package/src/client/QuestionReplyView.tsx +36 -17
- package/src/client/QuestionWaitBar.module.css +50 -0
- package/src/client/QuestionWaitBar.tsx +39 -0
- package/src/client/contract/slots.ts +19 -4
- package/src/client/index.ts +6 -6
- package/src/client/locales.ts +10 -2
- package/src/client/settings-locales.ts +44 -28
- package/src/client/settings.module.css +119 -0
- package/src/client/settings.tsx +120 -84
- package/src/index.js +2 -14
|
@@ -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,40 @@ 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}>
|
|
103
|
+
<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>
|
|
104
|
+
<h3 className={css.title}>{summary.title}</h3>
|
|
105
|
+
</div>
|
|
69
106
|
{summary.description !== '' && <p className={css.description}>{summary.description}</p>}
|
|
70
107
|
</div>
|
|
71
|
-
<div className={css.footer}>
|
|
72
|
-
<div className={css.feedback} role=
|
|
108
|
+
<div className={css.footer} data-plan-decision>
|
|
109
|
+
<div className={css.feedback} role={error === null ? 'status' : 'alert'} aria-atomic="true" data-error={error !== null || undefined}>
|
|
110
|
+
{busy && <span className={css.spinner} aria-hidden="true" />}
|
|
111
|
+
{error ?? (busy ? t('submitting') : null)}
|
|
112
|
+
</div>
|
|
73
113
|
<div className={css.actions}>
|
|
114
|
+
{decline !== undefined && (
|
|
115
|
+
<button
|
|
116
|
+
type="button" className={css.decline} {...tooltip(decline.description)}
|
|
117
|
+
aria-describedby={decline.description === undefined ? undefined : `plan-decline-${pending.key}`}
|
|
118
|
+
disabled={busy || !canDecide} onClick={() => { decide(decline.label) }}
|
|
119
|
+
>
|
|
120
|
+
{decline.label}
|
|
121
|
+
</button>
|
|
122
|
+
)}
|
|
74
123
|
<Button
|
|
75
124
|
variant="outline" className={css.discuss} icon={<IconEditOutlineRegular size={14} />}
|
|
76
125
|
disabled={busy} onClick={() => { settle(() => pending.dismiss()) }}
|
|
@@ -78,13 +127,20 @@ export function PlanReviewPanel({ pending, review, t, renderSlot }: PlanReviewPa
|
|
|
78
127
|
{t('plan.discuss')}
|
|
79
128
|
</Button>
|
|
80
129
|
<Button
|
|
81
|
-
variant="primary" {...tooltip(review.approve.description)}
|
|
82
|
-
|
|
130
|
+
variant="primary" className={css.primary} {...tooltip(review.approve.description)}
|
|
131
|
+
aria-describedby={review.approve.description === undefined ? undefined : `plan-approve-${pending.key}`}
|
|
132
|
+
disabled={busy || !canDecide} onClick={() => { decide(review.approve.label) }}
|
|
83
133
|
>
|
|
84
134
|
{t('plan.approve')}
|
|
85
135
|
</Button>
|
|
86
136
|
</div>
|
|
87
137
|
</div>
|
|
138
|
+
{decline?.description !== undefined && (
|
|
139
|
+
<span className={css.srOnly} id={`plan-decline-${pending.key}`}>{decline.description}</span>
|
|
140
|
+
)}
|
|
141
|
+
{review.approve.description !== undefined && (
|
|
142
|
+
<span className={css.srOnly} id={`plan-approve-${pending.key}`}>{review.approve.description}</span>
|
|
143
|
+
)}
|
|
88
144
|
</section>
|
|
89
145
|
</div>
|
|
90
146
|
)
|