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
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
/** Settings-page dictionaries. */
|
|
2
2
|
|
|
3
3
|
export const settingsZh = {
|
|
4
|
-
summary: '
|
|
5
|
-
title: '
|
|
6
|
-
|
|
7
|
-
waitLabel: '
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
summary: '等待与超时',
|
|
5
|
+
title: '提问',
|
|
6
|
+
discard: '放弃修改',
|
|
7
|
+
waitLabel: '等待回答',
|
|
8
|
+
durationLabel: '等待时长',
|
|
9
|
+
timed: '倒计时',
|
|
10
|
+
unlimited: '不限时',
|
|
11
|
+
seconds: '秒',
|
|
12
|
+
waitHint: '输入时重新计时。修改对新提问和计划审核生效。',
|
|
13
|
+
unlimitedHint: '一直等待回答,输入无需续期。',
|
|
14
|
+
timeoutTitle: '倒计时结束后',
|
|
15
|
+
behaviorLabel: '普通会话',
|
|
16
|
+
goalBehaviorLabel: 'Goal 活跃时',
|
|
17
|
+
native: '保留问题,稍后回答',
|
|
18
|
+
default: '自动选择默认答案',
|
|
19
|
+
nativeHint: '超时后仍可回答,不会自动同意。',
|
|
20
|
+
defaultHint: '自动结果会标记:单选取首项,多选取推荐项(无则首项),无选项则跳过。',
|
|
21
|
+
timeoutDisabled: '不限时,无需超时处理。以下选择会保留。',
|
|
15
22
|
readonly: '当前配置为只读。',
|
|
16
23
|
loading: '正在读取设置…',
|
|
17
24
|
unavailable: '当前连接下该配置不可用。',
|
|
18
|
-
waiting: '
|
|
19
|
-
invalidWait: '
|
|
25
|
+
waiting: '正在等待宿主配置…',
|
|
26
|
+
invalidWait: '等待时长须为 1 到 2147483 的整数。',
|
|
20
27
|
save: '保存',
|
|
21
28
|
saving: '保存中…',
|
|
22
|
-
saved: '
|
|
29
|
+
saved: '已保存',
|
|
23
30
|
conflict: '设置已被其他窗口修改,请重试。',
|
|
24
31
|
saveFailed: '保存失败:',
|
|
25
32
|
dirty: '有未保存的修改',
|
|
@@ -28,25 +35,32 @@ export const settingsZh = {
|
|
|
28
35
|
export type SettingsKey = keyof typeof settingsZh
|
|
29
36
|
|
|
30
37
|
export const settingsEn = {
|
|
31
|
-
summary: '
|
|
32
|
-
title: '
|
|
33
|
-
|
|
34
|
-
waitLabel: 'Wait
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
summary: 'Wait and timeout',
|
|
39
|
+
title: 'Questions',
|
|
40
|
+
discard: 'Discard',
|
|
41
|
+
waitLabel: 'Wait for answers',
|
|
42
|
+
durationLabel: 'Wait duration',
|
|
43
|
+
timed: 'Countdown',
|
|
44
|
+
unlimited: 'Unlimited',
|
|
45
|
+
seconds: 'sec',
|
|
46
|
+
waitHint: 'Typing restarts the countdown. Changes apply to new questions and plan reviews.',
|
|
47
|
+
unlimitedHint: 'Wait until answered, with no countdown to extend.',
|
|
48
|
+
timeoutTitle: 'When the countdown ends',
|
|
49
|
+
behaviorLabel: 'Standard session',
|
|
50
|
+
goalBehaviorLabel: 'Active Goal',
|
|
51
|
+
native: 'Keep questions pending',
|
|
52
|
+
default: 'Select default answers',
|
|
53
|
+
nativeHint: 'You can still answer after timeout. Nothing is automatically approved.',
|
|
54
|
+
defaultHint: 'Marked as automatic: first option for single choice; recommended options (or first) for multiple choice. No options skips the question.',
|
|
55
|
+
timeoutDisabled: 'Inactive with unlimited wait. These choices are kept for timed waits.',
|
|
42
56
|
readonly: 'This configuration is read-only.',
|
|
43
57
|
loading: 'Loading settings…',
|
|
44
58
|
unavailable: 'This configuration is unavailable on the current connection.',
|
|
45
|
-
waiting: 'Waiting for
|
|
46
|
-
invalidWait: '
|
|
59
|
+
waiting: 'Waiting for host configuration…',
|
|
60
|
+
invalidWait: 'Enter a whole number from 1 to 2147483 seconds.',
|
|
47
61
|
save: 'Save',
|
|
48
62
|
saving: 'Saving…',
|
|
49
|
-
saved: 'Saved
|
|
63
|
+
saved: 'Saved',
|
|
50
64
|
conflict: 'The settings changed in another window; try again.',
|
|
51
65
|
saveFailed: 'Save failed: ',
|
|
52
66
|
dirty: 'Unsaved changes',
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/* Flat settings groups with one local page title. */
|
|
2
|
+
.cfg {
|
|
3
|
+
--cfg-accent: #3388BB;
|
|
4
|
+
--dsw-alias-button-primary-fill: color-mix(in srgb, var(--cfg-accent) 85%, black);
|
|
5
|
+
--dsw-alias-button-primary-fill-hover: color-mix(in srgb, var(--cfg-accent) 72%, black);
|
|
6
|
+
--dsw-alias-label-primary-foreground: #fff;
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
gap: 24px;
|
|
10
|
+
max-width: 760px;
|
|
11
|
+
min-width: 0;
|
|
12
|
+
color: var(--dsw-alias-label-primary);
|
|
13
|
+
font-size: 13px;
|
|
14
|
+
line-height: 20px;
|
|
15
|
+
}
|
|
16
|
+
.cfg *, .cfg { box-sizing: border-box; }
|
|
17
|
+
.title { margin: 0; font-size: 18px; line-height: 26px; font-weight: 500; }
|
|
18
|
+
.note, .dependency {
|
|
19
|
+
margin: 0;
|
|
20
|
+
color: var(--dsw-alias-label-secondary);
|
|
21
|
+
font-size: 12px;
|
|
22
|
+
line-height: 1.5;
|
|
23
|
+
}
|
|
24
|
+
.group { display: flex; flex-direction: column; gap: 32px; min-width: 0; }
|
|
25
|
+
.waitSection, .timeoutSection { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
|
|
26
|
+
.timeoutSection { padding-top: 24px; border-top: 1px solid var(--dsw-alias-border-l2); }
|
|
27
|
+
.sectionTitle { margin: 0; font-size: 14px; line-height: 20px; font-weight: 500; }
|
|
28
|
+
.choiceGroup { min-width: 0; padding: 0; margin: 0; border: 0; }
|
|
29
|
+
.rowTitle { padding: 0; margin-bottom: 4px; color: var(--dsw-alias-label-tertiary); font-size: 12px; line-height: 18px; font-weight: 400; }
|
|
30
|
+
.waitSection > .choiceGroup > .rowTitle { margin-bottom: 12px; color: var(--dsw-alias-label-primary); font-size: 14px; line-height: 20px; font-weight: 500; }
|
|
31
|
+
.choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px; padding: 2px; border-radius: 10px; background: var(--dsw-alias-bg-module-platform, var(--dsw-alias-bg-layer-2)); }
|
|
32
|
+
.choice {
|
|
33
|
+
position: relative;
|
|
34
|
+
display: flex;
|
|
35
|
+
align-items: center;
|
|
36
|
+
justify-content: center;
|
|
37
|
+
gap: 6px;
|
|
38
|
+
min-width: 0;
|
|
39
|
+
min-height: 28px;
|
|
40
|
+
padding: 0 12px;
|
|
41
|
+
border: 0.5px solid transparent;
|
|
42
|
+
border-radius: 8px;
|
|
43
|
+
background: transparent;
|
|
44
|
+
color: var(--dsw-alias-label-secondary);
|
|
45
|
+
cursor: pointer;
|
|
46
|
+
transition: background-color 100ms ease, border-color 100ms ease;
|
|
47
|
+
}
|
|
48
|
+
.choice:has(:checked) {
|
|
49
|
+
border-color: var(--dsw-alias-border-l3);
|
|
50
|
+
background: var(--dsw-alias-bg-layer-1);
|
|
51
|
+
color: var(--dsw-alias-label-primary);
|
|
52
|
+
font-weight: 500;
|
|
53
|
+
}
|
|
54
|
+
.choice:hover:not(:has(:disabled)) { background: var(--dsw-alias-interactive-bg-hover); }
|
|
55
|
+
.choice:has(:checked):hover:not(:has(:disabled)) { background: var(--dsw-alias-bg-layer-1); }
|
|
56
|
+
.choice:active:not(:has(:disabled)) { border-color: var(--cfg-accent); }
|
|
57
|
+
.choice:has(:focus-visible) { outline: 2px solid var(--cfg-accent); outline-offset: 2px; }
|
|
58
|
+
.choice:has(:disabled) { opacity: .4; cursor: not-allowed; }
|
|
59
|
+
.choiceInput { position: absolute; width: 1px; height: 1px; margin: 0; overflow: hidden; clip-path: inset(50%); }
|
|
60
|
+
.choiceInput:focus-visible { outline: none; }
|
|
61
|
+
.duration { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; color: var(--dsw-alias-label-tertiary); font-size: 12px; line-height: 18px; }
|
|
62
|
+
.durationControl { display: flex; align-items: center; gap: 8px; }
|
|
63
|
+
.input {
|
|
64
|
+
width: 112px;
|
|
65
|
+
min-width: 0;
|
|
66
|
+
height: 32px;
|
|
67
|
+
padding: 0 12px;
|
|
68
|
+
border: 1px solid var(--dsw-alias-border-l2);
|
|
69
|
+
border-radius: 6px;
|
|
70
|
+
background: var(--dsw-alias-bg-layer-1);
|
|
71
|
+
color: var(--dsw-alias-label-primary);
|
|
72
|
+
font: inherit;
|
|
73
|
+
font-size: 13px;
|
|
74
|
+
font-variant-numeric: tabular-nums;
|
|
75
|
+
transition: border-color 100ms ease;
|
|
76
|
+
}
|
|
77
|
+
.unit { color: var(--dsw-alias-label-secondary); font-size: 12px; }
|
|
78
|
+
.input:hover:not(:disabled) { border-color: var(--dsw-alias-label-tertiary); }
|
|
79
|
+
.input:focus-visible, .button:focus-visible, .discard:focus-visible { outline: 2px solid var(--cfg-accent); outline-offset: 2px; }
|
|
80
|
+
.input:disabled, .button:disabled, .discard:disabled { opacity: .4; cursor: not-allowed; }
|
|
81
|
+
.input[aria-invalid='true'] { border-color: var(--dsw-alias-state-error-primary); }
|
|
82
|
+
.timeoutChoices { display: flex; flex-direction: column; gap: 24px; }
|
|
83
|
+
.footer { display: flex; align-items: center; gap: 8px; padding-top: 24px; border-top: 1px solid var(--dsw-alias-border-l2); }
|
|
84
|
+
.statusSlot { flex: 1; min-width: 0; }
|
|
85
|
+
.cfg .discard { height: 32px; min-height: 32px; padding: 0 12px; border-radius: 6px; font-size: 13px; line-height: 20px; }
|
|
86
|
+
.cfg .button {
|
|
87
|
+
display: inline-flex;
|
|
88
|
+
align-items: center;
|
|
89
|
+
justify-content: center;
|
|
90
|
+
flex: none;
|
|
91
|
+
height: 32px;
|
|
92
|
+
min-height: 32px;
|
|
93
|
+
padding: 0 12px;
|
|
94
|
+
border: 1px solid var(--dsw-alias-border-l2);
|
|
95
|
+
border-radius: 6px;
|
|
96
|
+
background: var(--dsw-alias-button-primary-fill);
|
|
97
|
+
color: var(--dsw-alias-label-primary-foreground);
|
|
98
|
+
font: inherit;
|
|
99
|
+
font-weight: 500;
|
|
100
|
+
cursor: pointer;
|
|
101
|
+
transition: background-color 100ms ease;
|
|
102
|
+
}
|
|
103
|
+
.cfg .button:hover:not(:disabled), .cfg .button:active:not(:disabled) { background: var(--dsw-alias-button-primary-fill-hover); }
|
|
104
|
+
.status { flex: 1; min-width: 0; color: var(--dsw-alias-label-secondary); font-size: 12px; overflow-wrap: anywhere; }
|
|
105
|
+
.statusOk { color: var(--dsw-alias-state-success-primary); }
|
|
106
|
+
.statusError { color: var(--dsw-alias-state-error-primary); }
|
|
107
|
+
@media (max-width: 640px) {
|
|
108
|
+
.choices { grid-template-columns: 1fr; }
|
|
109
|
+
.choice, .input, .cfg .button, .cfg .discard { min-height: 44px; }
|
|
110
|
+
.duration { align-items: flex-start; flex-direction: column; gap: 8px; }
|
|
111
|
+
.durationControl { width: 100%; }
|
|
112
|
+
.input { flex: 1; }
|
|
113
|
+
.footer { align-items: center; flex-wrap: wrap; }
|
|
114
|
+
.statusSlot:not(:empty) { flex-basis: 100%; }
|
|
115
|
+
.discard { margin-left: auto; }
|
|
116
|
+
}
|
|
117
|
+
@media (prefers-reduced-motion: reduce) {
|
|
118
|
+
.choice, .input, .cfg .button { transition: none; }
|
|
119
|
+
}
|
package/src/client/settings.tsx
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/** Row configuration page: question wait and timeout behavior. */
|
|
2
2
|
import { useCallback, useState } from 'react'
|
|
3
|
+
import { Button } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
3
4
|
import type { SettingsKey } from './settings-locales.ts'
|
|
4
5
|
import { settingsEn } from './settings-locales.ts'
|
|
6
|
+
import css from './settings.module.css'
|
|
5
7
|
|
|
6
8
|
const DEFAULTS = { questionTimeoutSeconds: 120, timeoutBehavior: 'native', goalTimeoutBehavior: 'native' } as const
|
|
7
9
|
const MAX_QUESTION_TIMEOUT_SECONDS = 2147483
|
|
@@ -63,11 +65,35 @@ function parseDraft(draft: Draft): ConfigValue | undefined {
|
|
|
63
65
|
return { questionTimeoutSeconds: seconds, timeoutBehavior: draft.timeoutBehavior, goalTimeoutBehavior: draft.goalTimeoutBehavior }
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
/** Native radios retain the browser's arrow-key and focus behavior. */
|
|
69
|
+
function ChoiceGroup({ id, label, value, options, disabled, hint, onChange }: {
|
|
70
|
+
id: string; label: string; value: string; options: Array<{ value: string; label: string }>;
|
|
71
|
+
disabled: boolean; hint: string; onChange: (value: string) => void
|
|
72
|
+
}) {
|
|
73
|
+
return (
|
|
74
|
+
<fieldset className={css.choiceGroup} id={id} disabled={disabled} aria-describedby={hint}>
|
|
75
|
+
<legend className={css.rowTitle}>{label}</legend>
|
|
76
|
+
<div className={css.choices}>
|
|
77
|
+
{options.map(option => (
|
|
78
|
+
<label className={css.choice} key={option.value}>
|
|
79
|
+
<input
|
|
80
|
+
className={css.choiceInput}
|
|
81
|
+
id={`${id}-${option.value}`}
|
|
82
|
+
type="radio"
|
|
83
|
+
name={id}
|
|
84
|
+
value={option.value}
|
|
85
|
+
checked={value === option.value}
|
|
86
|
+
disabled={disabled}
|
|
87
|
+
aria-describedby={hint}
|
|
88
|
+
onChange={() => onChange(option.value)}
|
|
89
|
+
/>
|
|
90
|
+
<span>{option.label}</span>
|
|
91
|
+
</label>
|
|
92
|
+
))}
|
|
93
|
+
</div>
|
|
94
|
+
</fieldset>
|
|
95
|
+
)
|
|
96
|
+
}
|
|
71
97
|
|
|
72
98
|
/** Page body, rendered inside the settings host's row config page. */
|
|
73
99
|
export function SettingsPage({ form, t = fallbackT }: { form?: any; t?: (key: SettingsKey) => string }) {
|
|
@@ -77,6 +103,7 @@ export function SettingsPage({ form, t = fallbackT }: { form?: any; t?: (key: Se
|
|
|
77
103
|
const base = host === null ? null : toDraft(host)
|
|
78
104
|
const [draft, setDraft] = useState<DraftState | null>(null)
|
|
79
105
|
const [busy, setBusy] = useState(false)
|
|
106
|
+
const [timedSeconds, setTimedSeconds] = useState(String(DEFAULTS.questionTimeoutSeconds))
|
|
80
107
|
const [notice, setNotice] = useState<{ tone: 'ok' | 'error'; text: string } | null>(null)
|
|
81
108
|
|
|
82
109
|
const live = draft !== null && draft.revision === revision ? draft.value : base
|
|
@@ -121,95 +148,128 @@ export function SettingsPage({ form, t = fallbackT }: { form?: any; t?: (key: Se
|
|
|
121
148
|
}, [busy, dirty, form, host, parsed, revision, t, writable])
|
|
122
149
|
|
|
123
150
|
if (state === undefined) {
|
|
124
|
-
return <div
|
|
151
|
+
return <div className={css.cfg}><p className={css.note} role="status">{t('waiting')}</p></div>
|
|
125
152
|
}
|
|
126
153
|
if (state.status === 'loading') {
|
|
127
|
-
return <div
|
|
154
|
+
return <div className={css.cfg}><p className={css.note} role="status">{t('loading')}</p></div>
|
|
128
155
|
}
|
|
129
156
|
if (host === null || live === null) {
|
|
130
|
-
return <div
|
|
157
|
+
return <div className={css.cfg}><p className={css.note} role="alert">{t('unavailable')}</p></div>
|
|
131
158
|
}
|
|
132
159
|
|
|
133
160
|
const invalid = parsed === undefined
|
|
134
161
|
const status = notice !== null
|
|
135
|
-
? <span
|
|
162
|
+
? <span className={`${css.status} ${notice.tone === 'ok' ? css.statusOk : css.statusError}`} role={notice.tone === 'error' ? 'alert' : 'status'}>{notice.text}</span>
|
|
136
163
|
: invalid
|
|
137
|
-
? <span
|
|
164
|
+
? <span className={`${css.status} ${css.statusError}`} id="better-ask-user-error" role="alert">{t('invalidWait')}</span>
|
|
138
165
|
: dirty
|
|
139
|
-
? <span
|
|
166
|
+
? <span className={css.status} role="status">{t('dirty')}</span>
|
|
140
167
|
: null
|
|
141
168
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
<h3 style={{ margin: '0 0 6px', fontSize: 16 }}>{t('title')}</h3>
|
|
145
|
-
<p style={{ ...hintStyle, marginBottom: 18 }}>{t('intro')}</p>
|
|
146
|
-
{writable ? null : <p style={{ ...statusStyle, marginBottom: 14 }}>{t('readonly')}</p>}
|
|
147
|
-
|
|
148
|
-
<div style={fieldStyle}>
|
|
149
|
-
<label style={labelStyle} htmlFor="better-ask-user-wait">{t('waitLabel')}</label>
|
|
150
|
-
<input
|
|
151
|
-
id="better-ask-user-wait"
|
|
152
|
-
type="number"
|
|
153
|
-
min={-1}
|
|
154
|
-
max={MAX_QUESTION_TIMEOUT_SECONDS}
|
|
155
|
-
step={1}
|
|
156
|
-
style={inputStyle}
|
|
157
|
-
value={live.questionTimeoutSeconds}
|
|
158
|
-
disabled={!writable || busy}
|
|
159
|
-
onChange={(event) => {
|
|
160
|
-
const next = event.target.value
|
|
161
|
-
edit((current) => ({ ...current, questionTimeoutSeconds: next }))
|
|
162
|
-
}}
|
|
163
|
-
/>
|
|
164
|
-
<p style={hintStyle}>{t('waitHint')}</p>
|
|
165
|
-
</div>
|
|
169
|
+
const unlimited = live.questionTimeoutSeconds === '-1'
|
|
170
|
+
const controlsDisabled = !writable || busy
|
|
166
171
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
172
|
+
return (
|
|
173
|
+
<div className={css.cfg} aria-busy={busy}>
|
|
174
|
+
<h2 className={css.title} id="better-ask-user-title">{t('title')}</h2>
|
|
175
|
+
{writable ? null : <p className={css.note} role="status">{t('readonly')}</p>}
|
|
176
|
+
<section className={css.group} aria-label={t('title')}>
|
|
177
|
+
<div className={css.waitSection}>
|
|
178
|
+
<ChoiceGroup
|
|
179
|
+
id="better-ask-user-wait-mode"
|
|
180
|
+
label={t('waitLabel')}
|
|
181
|
+
value={unlimited ? 'unlimited' : 'timed'}
|
|
182
|
+
options={[{ value: 'timed', label: t('timed') }, { value: 'unlimited', label: t('unlimited') }]}
|
|
183
|
+
disabled={controlsDisabled}
|
|
184
|
+
hint="better-ask-user-wait-hint"
|
|
185
|
+
onChange={(value) => {
|
|
186
|
+
const nextUnlimited = value === 'unlimited'
|
|
187
|
+
if (nextUnlimited && !invalid) setTimedSeconds(live.questionTimeoutSeconds)
|
|
188
|
+
edit(current => ({ ...current, questionTimeoutSeconds: nextUnlimited ? '-1' : timedSeconds }))
|
|
189
|
+
}}
|
|
190
|
+
/>
|
|
191
|
+
{unlimited ? null : <div className={css.duration}>
|
|
192
|
+
<label htmlFor="better-ask-user-wait">{t('durationLabel')}</label>
|
|
193
|
+
<div className={css.durationControl}>
|
|
194
|
+
<input
|
|
195
|
+
id="better-ask-user-wait"
|
|
196
|
+
className={css.input}
|
|
197
|
+
aria-describedby={invalid ? 'better-ask-user-error' : 'better-ask-user-wait-hint'}
|
|
198
|
+
type="number"
|
|
199
|
+
min={1}
|
|
200
|
+
max={MAX_QUESTION_TIMEOUT_SECONDS}
|
|
201
|
+
step={1}
|
|
202
|
+
inputMode="numeric"
|
|
203
|
+
aria-invalid={invalid || undefined}
|
|
204
|
+
value={live.questionTimeoutSeconds}
|
|
205
|
+
disabled={controlsDisabled}
|
|
206
|
+
onChange={(event) => {
|
|
207
|
+
const next = event.target.value
|
|
208
|
+
edit(current => ({ ...current, questionTimeoutSeconds: next }))
|
|
209
|
+
}}
|
|
210
|
+
/>
|
|
211
|
+
<span className={css.unit}>{t('seconds')}</span>
|
|
212
|
+
</div>
|
|
213
|
+
</div>}
|
|
214
|
+
<p className={css.dependency} id="better-ask-user-wait-hint">{t(unlimited ? 'unlimitedHint' : 'waitHint')}</p>
|
|
215
|
+
</div>
|
|
216
|
+
<div className={css.timeoutSection}>
|
|
217
|
+
<h3 className={css.sectionTitle}>{t('timeoutTitle')}</h3>
|
|
218
|
+
<div className={css.timeoutChoices}>
|
|
219
|
+
<ChoiceGroup
|
|
220
|
+
id="better-ask-user-behavior"
|
|
221
|
+
label={t('behaviorLabel')}
|
|
222
|
+
value={live.timeoutBehavior}
|
|
223
|
+
options={[{ value: 'native', label: t('native') }, { value: 'default', label: t('default') }]}
|
|
224
|
+
disabled={controlsDisabled || unlimited}
|
|
225
|
+
hint="better-ask-user-timeout-hint"
|
|
226
|
+
onChange={(value) => {
|
|
227
|
+
const next = value === 'default' ? 'default' : 'native'
|
|
228
|
+
edit(current => ({ ...current, timeoutBehavior: next }))
|
|
229
|
+
}}
|
|
230
|
+
/>
|
|
231
|
+
<ChoiceGroup
|
|
232
|
+
id="better-ask-user-goal-behavior"
|
|
233
|
+
label={t('goalBehaviorLabel')}
|
|
234
|
+
value={live.goalTimeoutBehavior}
|
|
235
|
+
options={[{ value: 'native', label: t('native') }, { value: 'default', label: t('default') }]}
|
|
236
|
+
disabled={controlsDisabled || unlimited}
|
|
237
|
+
hint="better-ask-user-timeout-hint"
|
|
238
|
+
onChange={(value) => {
|
|
239
|
+
const next = value === 'default' ? 'default' : 'native'
|
|
240
|
+
edit(current => ({ ...current, goalTimeoutBehavior: next }))
|
|
241
|
+
}}
|
|
242
|
+
/>
|
|
243
|
+
</div>
|
|
244
|
+
<p className={css.dependency} id="better-ask-user-timeout-hint">
|
|
245
|
+
{t(unlimited ? 'timeoutDisabled' : live.timeoutBehavior === 'default' || live.goalTimeoutBehavior === 'default' ? 'defaultHint' : 'nativeHint')}
|
|
246
|
+
</p>
|
|
247
|
+
</div>
|
|
248
|
+
</section>
|
|
184
249
|
|
|
185
|
-
<div
|
|
186
|
-
<
|
|
187
|
-
<
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
disabled={
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
250
|
+
<div className={css.footer} id="better-ask-user-settings-footer">
|
|
251
|
+
<div className={css.statusSlot}>{status}</div>
|
|
252
|
+
<Button
|
|
253
|
+
variant="outline"
|
|
254
|
+
className={css.discard}
|
|
255
|
+
id="better-ask-user-discard"
|
|
256
|
+
disabled={controlsDisabled || ((draft === null || draft.revision !== revision) && notice === null)}
|
|
257
|
+
onClick={() => {
|
|
258
|
+
setDraft(null)
|
|
259
|
+
setNotice(null)
|
|
260
|
+
setTimedSeconds(String(host.questionTimeoutSeconds === -1 ? DEFAULTS.questionTimeoutSeconds : host.questionTimeoutSeconds))
|
|
195
261
|
}}
|
|
196
262
|
>
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
<div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
|
|
204
|
-
<button
|
|
205
|
-
type="button"
|
|
263
|
+
{t('discard')}
|
|
264
|
+
</Button>
|
|
265
|
+
<Button
|
|
266
|
+
variant="primary"
|
|
267
|
+
className={css.button}
|
|
206
268
|
disabled={!writable || busy || !dirty || invalid}
|
|
207
269
|
onClick={() => { void save() }}
|
|
208
|
-
style={{ padding: '7px 16px', borderRadius: 8, border: '1px solid rgba(127,127,127,.35)', background: 'rgba(127,127,127,.12)', color: 'inherit', font: 'inherit', cursor: 'pointer' }}
|
|
209
270
|
>
|
|
210
271
|
{busy ? t('saving') : t('save')}
|
|
211
|
-
</
|
|
212
|
-
{status}
|
|
272
|
+
</Button>
|
|
213
273
|
</div>
|
|
214
274
|
</div>
|
|
215
275
|
)
|
package/src/settings.js
CHANGED
|
@@ -12,9 +12,11 @@ function hasOwn(value, key) {
|
|
|
12
12
|
return value !== null && typeof value === 'object' && Object.hasOwn(value, key)
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
function descriptor(service, ns) {
|
|
15
|
+
async function descriptor(service, ns) {
|
|
16
16
|
try {
|
|
17
|
-
|
|
17
|
+
const rows = await service.describe()
|
|
18
|
+
if (!Array.isArray(rows)) return undefined
|
|
19
|
+
return rows.find(row => row?.ns === ns)
|
|
18
20
|
} catch {
|
|
19
21
|
return undefined
|
|
20
22
|
}
|
|
@@ -36,25 +38,25 @@ export async function migrateLegacyQuestionTimeout(service) {
|
|
|
36
38
|
return { status: 'unavailable' }
|
|
37
39
|
}
|
|
38
40
|
const deadline = Date.now() + WAIT_MS
|
|
39
|
-
let source = descriptor(service, LEGACY_GOAL_NS)
|
|
40
|
-
let target = descriptor(service, ASK_NS)
|
|
41
|
+
let source = await descriptor(service, LEGACY_GOAL_NS)
|
|
42
|
+
let target = await descriptor(service, ASK_NS)
|
|
41
43
|
while ((source === undefined || target === undefined) && Date.now() < deadline) {
|
|
42
44
|
await sleep(WAIT_INTERVAL_MS)
|
|
43
|
-
source = descriptor(service, LEGACY_GOAL_NS)
|
|
44
|
-
target = descriptor(service, ASK_NS)
|
|
45
|
+
source = await descriptor(service, LEGACY_GOAL_NS)
|
|
46
|
+
target = await descriptor(service, ASK_NS)
|
|
45
47
|
}
|
|
46
48
|
if (source === undefined || target === undefined) return { status: 'pending' }
|
|
47
49
|
if (!hasOwn(source.user, 'questionTimeoutSeconds')) return { status: 'no-change' }
|
|
48
50
|
if (hasOwn(target.user, 'questionTimeoutSeconds')) return { status: 'no-change' }
|
|
49
51
|
const value = source.value?.questionTimeoutSeconds
|
|
50
52
|
if (!validSeconds(value)) return { status: 'no-change' }
|
|
51
|
-
if (
|
|
53
|
+
if (service.writable === false) return { status: 'pending' }
|
|
52
54
|
try {
|
|
53
55
|
await service.update(ASK_NS, { questionTimeoutSeconds: value }, target.revision)
|
|
54
56
|
} catch (error) {
|
|
55
57
|
return { status: 'error', error: error instanceof Error ? error.message : String(error) }
|
|
56
58
|
}
|
|
57
|
-
const after = descriptor(service, ASK_NS)
|
|
59
|
+
const after = await descriptor(service, ASK_NS)
|
|
58
60
|
return after?.user?.questionTimeoutSeconds === value
|
|
59
61
|
? { status: 'complete', value }
|
|
60
62
|
: { status: 'pending', value }
|
|
@@ -76,4 +78,4 @@ export function mountLegacyMigration(ctx) {
|
|
|
76
78
|
inner.logger?.warn?.('better-ask-user: legacy question wait migration failed: ' + String(error))
|
|
77
79
|
})
|
|
78
80
|
})
|
|
79
|
-
}
|
|
81
|
+
}
|