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.
@@ -1,25 +1,32 @@
1
1
  /** Settings-page dictionaries. */
2
2
 
3
3
  export const settingsZh = {
4
- summary: '提问等待、输入续期与超时行为',
5
- title: '提问设置',
6
- intro: '控制 ask_user_question 的等待时长、输入续期和超时行为;修改后对之后开始的提问生效。',
7
- waitLabel: '等待时长(秒)',
8
- waitHint: '-1 表示不超时;其他值为 1 到 2147483。卡片内每次真实输入都会从该时长重新计时。',
9
- behaviorLabel: '普通会话超时行为',
10
- goalBehaviorLabel: 'Goal 活跃时的超时行为',
11
- native: '原生 pending',
12
- default: '超时后默认选择',
13
- nativeHint: '到点后返回官方的 pending 结果,用户仍可稍后回答。',
14
- defaultHint: '到点后按规则选择默认项,并明确标记为自动选择而非用户回答。',
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: '等待时长必须是 -1 或 1 到 2147483 的整数。',
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: 'Question wait, input extension and timeout behavior',
32
- title: 'Question settings',
33
- intro: 'Controls the wait, input extension and timeout behavior for ask_user_question. Changes apply to questions started afterwards.',
34
- waitLabel: 'Wait duration (seconds)',
35
- waitHint: '-1 never times out; otherwise 1 to 2147483. Every real input in the card restarts this window.',
36
- behaviorLabel: 'Inactive-session timeout behavior',
37
- goalBehaviorLabel: 'Goal-active timeout behavior',
38
- native: 'Native pending',
39
- default: 'Default selection at timeout',
40
- nativeHint: 'Return the official pending result; the user can still answer later.',
41
- defaultHint: 'Select defaults by rule at timeout and mark the result as auto-selected, not a user answer.',
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 the host configuration snapshot…',
46
- invalidWait: 'The wait must be -1 or an integer from 1 to 2147483.',
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
+ }
@@ -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
- const fieldStyle = { display: 'grid', gap: 6, marginBottom: 18 } as const
67
- const labelStyle = { fontWeight: 600, fontSize: 13 } as const
68
- const hintStyle = { margin: 0, fontSize: 12, opacity: 0.65, lineHeight: 1.45 } as const
69
- const inputStyle = { maxWidth: 320, padding: '7px 9px', borderRadius: 8, border: '1px solid rgba(127,127,127,.35)', background: 'transparent', color: 'inherit', font: 'inherit' } as const
70
- const statusStyle = { fontSize: 12, lineHeight: 1.5 } as const
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 style={{ padding: 4 }}><p style={statusStyle}>{t('waiting')}</p></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 style={{ padding: 4 }}><p style={statusStyle}>{t('loading')}</p></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 style={{ padding: 4 }}><p style={statusStyle}>{t('unavailable')}</p></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 style={{ ...statusStyle, color: notice.tone === 'ok' ? '#2f8f4e' : '#c0392b' }}>{notice.text}</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 style={{ ...statusStyle, color: '#c0392b' }}>{t('invalidWait')}</span>
164
+ ? <span className={`${css.status} ${css.statusError}`} id="better-ask-user-error" role="alert">{t('invalidWait')}</span>
138
165
  : dirty
139
- ? <span style={statusStyle}>{t('dirty')}</span>
166
+ ? <span className={css.status} role="status">{t('dirty')}</span>
140
167
  : null
141
168
 
142
- return (
143
- <div style={{ padding: '4px 2px', maxWidth: 720 }}>
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
- <div style={fieldStyle}>
168
- <label style={labelStyle} htmlFor="better-ask-user-behavior">{t('behaviorLabel')}</label>
169
- <select
170
- id="better-ask-user-behavior"
171
- style={inputStyle}
172
- value={live.timeoutBehavior}
173
- disabled={!writable || busy}
174
- onChange={(event) => {
175
- const next = event.target.value === 'default' ? 'default' : 'native'
176
- edit((current) => ({ ...current, timeoutBehavior: next }))
177
- }}
178
- >
179
- <option value="native">{t('native')}</option>
180
- <option value="default">{t('default')}</option>
181
- </select>
182
- <p style={hintStyle}>{t(live.timeoutBehavior === 'default' ? 'defaultHint' : 'nativeHint')}</p>
183
- </div>
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 style={fieldStyle}>
186
- <label style={labelStyle} htmlFor="better-ask-user-goal-behavior">{t('goalBehaviorLabel')}</label>
187
- <select
188
- id="better-ask-user-goal-behavior"
189
- style={inputStyle}
190
- value={live.goalTimeoutBehavior}
191
- disabled={!writable || busy}
192
- onChange={(event) => {
193
- const next = event.target.value === 'default' ? 'default' : 'native'
194
- edit((current) => ({ ...current, goalTimeoutBehavior: next }))
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
- <option value="native">{t('native')}</option>
198
- <option value="default">{t('default')}</option>
199
- </select>
200
- <p style={hintStyle}>{t(live.goalTimeoutBehavior === 'default' ? 'defaultHint' : 'nativeHint')}</p>
201
- </div>
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
- </button>
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
- return service.describe(ns)
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 (target.writable !== true) return { status: 'pending' }
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
+ }