dsh-better-ask-user 0.2.0 → 0.3.1

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.
@@ -3,22 +3,23 @@
3
3
  export const settingsZh = {
4
4
  summary: '等待与超时',
5
5
  title: '提问',
6
- discard: '放弃修改',
7
- waitLabel: '等待回答',
8
- durationLabel: '等待时长',
6
+ waitLabel: '等待',
7
+ durationLabel: '等待时长(秒)',
9
8
  timed: '倒计时',
10
9
  unlimited: '不限时',
11
10
  seconds: '秒',
12
- waitHint: '输入时重新计时。修改对新提问和计划审核生效。',
11
+ waitHint: '输入时重新计时。',
13
12
  unlimitedHint: '一直等待回答,输入无需续期。',
14
- timeoutTitle: '倒计时结束后',
13
+ timeoutTitle: '超时后',
15
14
  behaviorLabel: '普通会话',
16
15
  goalBehaviorLabel: 'Goal 活跃时',
17
- native: '保留问题,稍后回答',
18
- default: '自动选择默认答案',
16
+ native: '继续工作',
17
+ default: '选择默认答案',
18
+ advanced: '高级',
19
+ discard: '放弃改动',
19
20
  nativeHint: '超时后仍可回答,不会自动同意。',
20
- defaultHint: '自动结果会标记:单选取首项,多选取推荐项(无则首项),无选项则跳过。',
21
- timeoutDisabled: '不限时,无需超时处理。以下选择会保留。',
21
+ defaultHint: '超时后自动提交默认答案。',
22
+ timeoutDisabled: '不限时模式下不触发超时行为,保留以下次使用。',
22
23
  readonly: '当前配置为只读。',
23
24
  loading: '正在读取设置…',
24
25
  unavailable: '当前连接下该配置不可用。',
@@ -26,7 +27,7 @@ export const settingsZh = {
26
27
  invalidWait: '等待时长须为 1 到 2147483 的整数。',
27
28
  save: '保存',
28
29
  saving: '保存中…',
29
- saved: '已保存',
30
+ saved: '已保存,对新提问生效',
30
31
  conflict: '设置已被其他窗口修改,请重试。',
31
32
  saveFailed: '保存失败:',
32
33
  dirty: '有未保存的修改',
@@ -37,22 +38,23 @@ export type SettingsKey = keyof typeof settingsZh
37
38
  export const settingsEn = {
38
39
  summary: 'Wait and timeout',
39
40
  title: 'Questions',
40
- discard: 'Discard',
41
- waitLabel: 'Wait for answers',
42
- durationLabel: 'Wait duration',
41
+ waitLabel: 'Wait',
42
+ durationLabel: 'Wait duration in seconds',
43
43
  timed: 'Countdown',
44
44
  unlimited: 'Unlimited',
45
45
  seconds: 'sec',
46
- waitHint: 'Typing restarts the countdown. Changes apply to new questions and plan reviews.',
46
+ waitHint: 'Typing restarts the countdown.',
47
47
  unlimitedHint: 'Wait until answered, with no countdown to extend.',
48
- timeoutTitle: 'When the countdown ends',
48
+ timeoutTitle: 'At timeout',
49
49
  behaviorLabel: 'Standard session',
50
50
  goalBehaviorLabel: 'Active Goal',
51
- native: 'Keep questions pending',
52
- default: 'Select default answers',
51
+ native: 'Continue work',
52
+ default: 'Use defaults',
53
+ advanced: 'Advanced',
54
+ discard: 'Discard',
53
55
  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.',
56
+ defaultHint: 'Submits default answers when the countdown ends.',
57
+ timeoutDisabled: 'Timeout behavior is inactive while waiting without a limit. Your choices are kept.',
56
58
  readonly: 'This configuration is read-only.',
57
59
  loading: 'Loading settings…',
58
60
  unavailable: 'This configuration is unavailable on the current connection.',
@@ -60,7 +62,7 @@ export const settingsEn = {
60
62
  invalidWait: 'Enter a whole number from 1 to 2147483 seconds.',
61
63
  save: 'Save',
62
64
  saving: 'Saving…',
63
- saved: 'Saved',
65
+ saved: 'Saved for new questions',
64
66
  conflict: 'The settings changed in another window; try again.',
65
67
  saveFailed: 'Save failed: ',
66
68
  dirty: 'Unsaved changes',
@@ -1,119 +1,119 @@
1
- /* Flat settings groups with one local page title. */
1
+ /* Ask-user settings: one 920px column, section rows, flat 1px surfaces. */
2
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;
3
+ --ui-accent: #3388bb;
4
+ --ui-accent-solid: #20709e;
5
+ --ui-accent-text: #14587f;
6
+ --ui-accent-fg: #fff;
7
+ --ui-accent-soft: color-mix(in srgb, var(--ui-accent) 10%, transparent);
8
+ --ui-ink-1: var(--dsw-alias-label-primary, #0f1115);
9
+ --ui-ink-2: var(--dsw-alias-label-secondary, #61666b);
10
+ --ui-ink-3: color-mix(in srgb, var(--dsw-alias-label-tertiary, #81858c) 80%, var(--dsw-alias-label-primary, #0f1115));
11
+ --ui-line-1: var(--dsw-alias-border-l1, #0000000a);
12
+ --ui-line-2: var(--dsw-alias-border-l2, #0000001a);
13
+ --ui-line-3: var(--dsw-alias-border-l3, #0000001f);
14
+ --ui-canvas: var(--dsw-alias-bg-layer-1, #fff);
15
+ --ui-raised: var(--dsw-alias-bg-layer-2, #fff);
16
+ --ui-sunken: color-mix(in srgb, var(--ui-ink-1) 4%, var(--ui-canvas));
17
+ --ui-hover: var(--dsw-alias-interactive-bg-hover, color-mix(in srgb, var(--ui-ink-1) 5%, transparent));
18
+ --ui-danger: var(--dsw-alias-state-error-primary, #c8322b);
19
+ --ui-radius-sm: 6px;
20
+ --ui-radius-md: 8px;
7
21
  display: flex;
8
22
  flex-direction: column;
9
- gap: 24px;
10
- max-width: 760px;
23
+ gap: 20px;
24
+ width: 100%;
25
+ max-width: 920px;
26
+ margin: 0 auto;
11
27
  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);
28
+ color: var(--ui-ink-1);
72
29
  font: inherit;
73
- font-size: 13px;
30
+ line-height: 20px;
74
31
  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
32
  }
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); }
33
+ .cfg *,
34
+ .cfg { box-sizing: border-box; }
35
+ .pageHead { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 0; }
36
+ .title { margin: 0; font-size: 20px; line-height: 28px; font-weight: 500; letter-spacing: -.01em; }
37
+ .badge { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border: 1px solid var(--ui-line-2); border-radius: 999px; background: var(--ui-raised); color: var(--ui-ink-3); font-size: 11px; line-height: 18px; white-space: nowrap; }
38
+ .group { display: flex; flex-direction: column; min-width: 0; border-top: 1px solid var(--ui-line-2); }
39
+ .row { display: flex; align-items: center; justify-content: space-between; gap: 24px; min-height: 44px; min-width: 0; padding: 10px 0; border-bottom: 1px solid var(--ui-line-1); }
40
+ .rowText { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
41
+ .rowTitle { color: var(--ui-ink-1); font-size: 13px; line-height: 20px; font-weight: 500; }
42
+ .rowDesc { color: var(--ui-ink-3); font-size: 12px; line-height: 18px; }
43
+ .control { display: flex; align-items: center; gap: 8px; flex: none; min-width: 0; }
44
+ .choices { display: inline-flex; flex: none; gap: 2px; height: 32px; padding: 1px; border: 1px solid var(--ui-line-2); border-radius: var(--ui-radius-md); background: var(--ui-sunken); }
45
+ .choice { position: relative; display: inline-flex; min-width: 0; }
46
+ .choice input { appearance: none; position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
47
+ .choice span { display: flex; align-items: center; justify-content: center; min-height: 28px; padding: 0 12px; border-radius: var(--ui-radius-sm); color: var(--ui-ink-3); font-size: 13px; line-height: 20px; white-space: nowrap; transition: background-color 140ms ease, color 140ms ease, box-shadow 140ms ease; }
48
+ .choice:has(input:checked) span { background: var(--ui-raised); box-shadow: inset 0 0 0 1px var(--ui-line-2); color: var(--ui-accent-text); font-weight: 500; }
49
+ .choice:has(input:hover:not(:disabled):not(:checked)) span { background: var(--ui-hover); color: var(--ui-ink-1); }
50
+ .choice:has(input:focus-visible) span { outline: 2px solid var(--ui-accent); outline-offset: 2px; }
51
+ .choice:has(input:disabled) { opacity: .4; }
52
+ .choice input:disabled { cursor: not-allowed; }
53
+ .input { appearance: none; width: 76px; min-width: 0; height: 32px; padding: 0 8px; border: 1px solid var(--ui-line-2); border-radius: var(--ui-radius-md); background: var(--ui-raised); color: var(--ui-ink-1); font: inherit; font-size: 13px; line-height: 20px; font-variant-numeric: tabular-nums; transition: border-color 140ms ease, box-shadow 140ms ease; }
54
+ .input:hover:not(:disabled) { border-color: var(--ui-line-3); }
55
+ .input:focus-visible { outline: none; border-color: var(--ui-accent); box-shadow: 0 0 0 2px var(--ui-accent-soft); }
56
+ .input[aria-invalid=true] { border-color: var(--ui-danger); }
57
+ .input:disabled { opacity: .4; cursor: not-allowed; }
58
+ .duration { display: inline-flex; align-items: center; gap: 6px; flex: none; }
59
+ .unit { color: var(--ui-ink-3); font-size: 12px; line-height: 18px; }
60
+ .srOnly { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
61
+ .fieldError { margin: 6px 0 0; color: var(--ui-danger); font-size: 12px; line-height: 18px; overflow-wrap: anywhere; }
62
+ .sectionLabel { margin: 20px 0 0; padding-bottom: 6px; border-bottom: 1px solid var(--ui-line-2); color: var(--ui-ink-3); font-size: 12px; line-height: 18px; font-weight: 500; letter-spacing: .02em; }
63
+ .advanced { margin-top: 12px; border-top: 1px solid var(--ui-line-1); }
64
+ .advanced summary { display: flex; align-items: center; gap: 8px; min-height: 32px; padding: 4px 0; color: var(--ui-ink-2); font-size: 13px; line-height: 20px; font-weight: 500; list-style: none; cursor: pointer; }
65
+ .advanced summary::-webkit-details-marker { display: none; }
66
+ .advanced summary:hover { color: var(--ui-ink-1); }
67
+ .advanced summary:focus-visible { outline: 2px solid var(--ui-accent); outline-offset: 2px; border-radius: 4px; }
68
+ .advancedValue { margin-left: auto; color: var(--ui-ink-3); font-size: 11px; line-height: 18px; font-weight: 400; white-space: nowrap; }
69
+ .chevron { width: 6px; height: 6px; margin: 0 4px 3px auto; border-right: 1px solid currentColor; border-bottom: 1px solid currentColor; transform: rotate(45deg); transition: transform 140ms ease; }
70
+ .advancedValue + .chevron { margin-left: 0; }
71
+ .advanced[open] .chevron { transform: rotate(225deg); margin-bottom: -3px; }
72
+ .status { margin: 0; color: var(--ui-ink-3); font-size: 12px; line-height: 18px; overflow-wrap: anywhere; }
73
+ .footer { position: sticky; bottom: 0; z-index: 2; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 0; border-top: 1px solid var(--ui-line-2); background: var(--ui-canvas); margin-top: auto; }
74
+ .footer .status { flex: 1; min-width: 0; }
75
+ .button,
76
+ .primary { appearance: none; display: inline-flex; align-items: center; justify-content: center; flex: none; gap: 6px; height: 32px; padding: 0 12px; border: 1px solid var(--ui-line-2); border-radius: var(--ui-radius-md); background: var(--ui-raised); color: var(--ui-ink-1); font: inherit; font-size: 13px; line-height: 20px; font-weight: 500; cursor: pointer; transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease; }
77
+ .button:hover:not(:disabled) { background: var(--ui-hover); }
78
+ .button:active:not(:disabled) { background: var(--ui-sunken); }
79
+ .primary { min-width: 96px; border-color: transparent; background: var(--ui-accent-solid); color: var(--ui-accent-fg); }
80
+ .primary:hover:not(:disabled) { background: color-mix(in srgb, var(--ui-accent-solid) 88%, black); }
81
+ .primary:active:not(:disabled) { background: color-mix(in srgb, var(--ui-accent-solid) 80%, black); }
82
+ .button:focus-visible,
83
+ .primary:focus-visible { outline: 2px solid var(--ui-accent); outline-offset: 2px; }
84
+ .button:disabled,
85
+ .primary:disabled { opacity: .4; cursor: not-allowed; }
86
+ .spinner { width: 12px; height: 12px; border: 1px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 800ms linear infinite; }
87
+ @keyframes spin { to { transform: rotate(360deg); } }
107
88
  @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; }
89
+ .title { font-size: 18px; line-height: 26px; }
90
+ .row { align-items: stretch; flex-direction: column; gap: 8px; }
91
+ .control { width: 100%; flex-wrap: wrap; }
92
+ .choice { flex: 1; }
93
+ .choice span { width: 100%; }
94
+ .footer { flex-wrap: wrap; }
95
+ .footer .status { flex-basis: 100%; }
96
+ .advancedValue { max-width: 65%; text-align: right; white-space: normal; }
97
+ }
98
+ @media (pointer: coarse) {
99
+ .choices { height: auto; }
100
+ .choice span,
101
+ .input,
102
+ .button,
103
+ .primary { min-height: 44px; }
116
104
  }
117
105
  @media (prefers-reduced-motion: reduce) {
118
- .choice, .input, .cfg .button { transition: none; }
106
+ .spinner { animation: none; }
107
+ .input,
108
+ .choice span,
109
+ .button,
110
+ .primary,
111
+ .chevron { transition: none; }
112
+ }
113
+ [data-ds-dark-theme] .cfg {
114
+ --ui-accent: #4eb0e8;
115
+ --ui-accent-solid: #4eb0e8;
116
+ --ui-accent-text: #6fc0ee;
117
+ --ui-accent-fg: #0e1014;
118
+ --ui-accent-soft: color-mix(in srgb, var(--ui-accent) 14%, transparent);
119
119
  }
@@ -1,6 +1,5 @@
1
1
  /** Row configuration page: question wait and timeout behavior. */
2
- import { useCallback, useState } from 'react'
3
- import { Button } from '@deepseek-ai/dsh-client-ui-primitives'
2
+ import { useCallback, useId, useState, type ReactNode } from 'react'
4
3
  import type { SettingsKey } from './settings-locales.ts'
5
4
  import { settingsEn } from './settings-locales.ts'
6
5
  import css from './settings.module.css'
@@ -65,33 +64,44 @@ function parseDraft(draft: Draft): ConfigValue | undefined {
65
64
  return { questionTimeoutSeconds: seconds, timeoutBehavior: draft.timeoutBehavior, goalTimeoutBehavior: draft.goalTimeoutBehavior }
66
65
  }
67
66
 
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
- }) {
67
+ /** Compact settings row with an optional dependency description. */
68
+ function Row({ id, label, hint, children }: { id: string; label: string; hint?: string; children: ReactNode }) {
73
69
  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
- ))}
70
+ <div className={css.row}>
71
+ <div className={css.rowText}>
72
+ <span className={css.rowTitle} id={`${id}-label`}>{label}</span>
73
+ {hint ? <span className={css.rowDesc} id={`${id}-hint`}>{hint}</span> : null}
93
74
  </div>
94
- </fieldset>
75
+ <div className={css.control}>{children}</div>
76
+ </div>
77
+ )
78
+ }
79
+
80
+ /** Native radio semantics with one compact, fully styled choice surface. */
81
+ function Choices({ id, value, options, disabled, describedBy, onChange }: {
82
+ id: string
83
+ value: string
84
+ options: Array<{ value: string; label: string }>
85
+ disabled: boolean
86
+ describedBy?: string
87
+ onChange: (value: string) => void
88
+ }) {
89
+ const name = useId()
90
+ return (
91
+ <div className={css.choices} id={id} role="radiogroup" aria-labelledby={`${id}-label`} aria-disabled={disabled}>
92
+ {options.map((option) => (
93
+ <label className={css.choice} key={option.value}>
94
+ <input
95
+ id={`${id}-${option.value}`}
96
+ type="radio" name={name} value={option.value}
97
+ checked={value === option.value} disabled={disabled}
98
+ aria-describedby={describedBy}
99
+ onChange={() => { onChange(option.value) }}
100
+ />
101
+ <span>{option.label}</span>
102
+ </label>
103
+ ))}
104
+ </div>
95
105
  )
96
106
  }
97
107
 
@@ -109,7 +119,7 @@ export function SettingsPage({ form, t = fallbackT }: { form?: any; t?: (key: Se
109
119
  const live = draft !== null && draft.revision === revision ? draft.value : base
110
120
  const parsed = live === null ? undefined : parseDraft(live)
111
121
  const writable = state?.status === 'ready' && state?.writable === true
112
- const dirty = host !== null && parsed !== undefined && !same(host, parsed)
122
+ const dirty = host !== null && (parsed === undefined || !same(host, parsed))
113
123
 
114
124
  const edit = useCallback((mutate: (baseDraft: Draft) => Draft) => {
115
125
  setNotice(null)
@@ -139,7 +149,7 @@ export function SettingsPage({ form, t = fallbackT }: { form?: any; t?: (key: Se
139
149
  try {
140
150
  const accepted = await form.mutate(ops, revision)
141
151
  if (accepted) setNotice({ tone: 'ok', text: t('saved') })
142
- else { setDraft(null); setNotice({ tone: 'error', text: t('conflict') }) }
152
+ else setNotice({ tone: 'error', text: t('conflict') })
143
153
  } catch (error) {
144
154
  setNotice({ tone: 'error', text: t('saveFailed') + String((error as any)?.message ?? error) })
145
155
  } finally {
@@ -158,119 +168,85 @@ export function SettingsPage({ form, t = fallbackT }: { form?: any; t?: (key: Se
158
168
  }
159
169
 
160
170
  const invalid = parsed === undefined
161
- const status = notice !== null
162
- ? <span className={`${css.status} ${notice.tone === 'ok' ? css.statusOk : css.statusError}`} role={notice.tone === 'error' ? 'alert' : 'status'}>{notice.text}</span>
163
- : invalid
164
- ? <span className={`${css.status} ${css.statusError}`} id="better-ask-user-error" role="alert">{t('invalidWait')}</span>
165
- : dirty
166
- ? <span className={css.status} role="status">{t('dirty')}</span>
167
- : null
168
-
169
171
  const unlimited = live.questionTimeoutSeconds === '-1'
170
172
  const controlsDisabled = !writable || busy
173
+ const behaviors = [{ value: 'native', label: t('native') }, { value: 'default', label: t('default') }]
171
174
 
172
175
  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
+ <div className={css.cfg} aria-busy={busy} data-settings-dirty={dirty} data-settings-busy={busy}>
177
+ <div className={css.pageHead}>
178
+ <h2 className={css.title} id="better-ask-user-title">{t('title')}</h2>
179
+ {writable ? null : <span className={css.badge} role="status">{t('readonly')}</span>}
180
+ </div>
176
181
  <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
+ <Row id="better-ask-user-wait-mode" label={t('waitLabel')}>
183
+ <Choices
184
+ id="better-ask-user-wait-mode" value={unlimited ? 'unlimited' : 'timed'}
182
185
  options={[{ value: 'timed', label: t('timed') }, { value: 'unlimited', label: t('unlimited') }]}
183
- disabled={controlsDisabled}
184
- hint="better-ask-user-wait-hint"
186
+ disabled={controlsDisabled} describedBy="better-ask-user-wait-hint"
185
187
  onChange={(value) => {
186
188
  const nextUnlimited = value === 'unlimited'
187
189
  if (nextUnlimited && !invalid) setTimedSeconds(live.questionTimeoutSeconds)
188
190
  edit(current => ({ ...current, questionTimeoutSeconds: nextUnlimited ? '-1' : timedSeconds }))
189
191
  }}
190
192
  />
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
- }}
193
+ {unlimited ? null : <span className={css.duration}>
194
+ <input
195
+ id="better-ask-user-wait" className={css.input}
196
+ aria-label={t('durationLabel')}
197
+ aria-describedby={invalid ? 'better-ask-user-error' : 'better-ask-user-wait-hint'}
198
+ type="text" inputMode="numeric" aria-invalid={invalid || undefined}
199
+ value={live.questionTimeoutSeconds} disabled={controlsDisabled}
200
+ onChange={(event) => { edit(current => ({ ...current, questionTimeoutSeconds: event.target.value })) }}
230
201
  />
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
- }}
202
+ <span className={css.unit}>{t('seconds')}</span>
203
+ </span>}
204
+ </Row>
205
+ <p className={css.srOnly} id="better-ask-user-wait-hint">{t(unlimited ? 'unlimitedHint' : 'waitHint')}</p>
206
+ {invalid && <p className={css.fieldError} id="better-ask-user-error" role="alert">{t('invalidWait')}</p>}
207
+ {!unlimited && <>
208
+ <h3 className={css.sectionLabel}>{t('timeoutTitle')}</h3>
209
+ <Row id="better-ask-user-behavior" label={t('behaviorLabel')}>
210
+ <Choices
211
+ id="better-ask-user-behavior" value={live.timeoutBehavior} options={behaviors}
212
+ disabled={controlsDisabled} describedBy="better-ask-user-timeout-hint"
213
+ onChange={(value) => { edit(current => ({ ...current, timeoutBehavior: value as Behavior })) }}
242
214
  />
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>
215
+ </Row>
216
+ <p className={css.srOnly} id="better-ask-user-timeout-hint">{t(live.timeoutBehavior === 'default' ? 'defaultHint' : 'nativeHint')}</p>
217
+ <details className={css.advanced}>
218
+ <summary>
219
+ <span>{t('advanced')}</span>
220
+ {live.goalTimeoutBehavior !== DEFAULTS.goalTimeoutBehavior && <span className={css.advancedValue}>{t('goalBehaviorLabel')} · {t(live.goalTimeoutBehavior)}</span>}
221
+ <span className={css.chevron} aria-hidden="true" />
222
+ </summary>
223
+ <Row id="better-ask-user-goal-behavior" label={t('goalBehaviorLabel')}>
224
+ <Choices
225
+ id="better-ask-user-goal-behavior" value={live.goalTimeoutBehavior} options={behaviors}
226
+ disabled={controlsDisabled} describedBy="better-ask-user-goal-hint"
227
+ onChange={(value) => { edit(current => ({ ...current, goalTimeoutBehavior: value as Behavior })) }}
228
+ />
229
+ </Row>
230
+ <p className={css.srOnly} id="better-ask-user-goal-hint">{t(live.goalTimeoutBehavior === 'default' ? 'defaultHint' : 'nativeHint')}</p>
231
+ </details>
232
+ </>}
248
233
  </section>
249
-
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))
261
- }}
262
- >
263
- {t('discard')}
264
- </Button>
265
- <Button
266
- variant="primary"
267
- className={css.button}
268
- disabled={!writable || busy || !dirty || invalid}
269
- onClick={() => { void save() }}
234
+ {notice !== null && <p className={notice.tone === 'ok' ? css.status : css.fieldError} role={notice.tone === 'error' ? 'alert' : 'status'}>{notice.text}</p>}
235
+ {dirty && <div className={css.footer} id="better-ask-user-settings-footer">
236
+ <span className={css.status}>{t('dirty')}</span>
237
+ <button type="button" className={css.button} id="better-ask-user-discard" disabled={controlsDisabled} onClick={() => {
238
+ setDraft(null)
239
+ setNotice(null)
240
+ setTimedSeconds(String(host.questionTimeoutSeconds === -1 ? DEFAULTS.questionTimeoutSeconds : host.questionTimeoutSeconds))
241
+ }}>{t('discard')}</button>
242
+ <button
243
+ type="button" className={css.primary} data-settings-save disabled={controlsDisabled || invalid}
244
+ aria-busy={busy} onClick={() => { void save() }}
270
245
  >
246
+ {busy && <span className={css.spinner} aria-hidden="true" />}
271
247
  {busy ? t('saving') : t('save')}
272
- </Button>
273
- </div>
248
+ </button>
249
+ </div>}
274
250
  </div>
275
251
  )
276
252
  }
package/src/index.js CHANGED
@@ -16,9 +16,7 @@ export function apply(ctx, config = {}) {
16
16
 
17
17
  const states = new Map()
18
18
 
19
- function refresh(state) {
20
- state.askDispose?.()
21
- state.askDispose = undefined
19
+ function register(state) {
22
20
  const tools = state.actor.get('tools')
23
21
  const base = tools.get('ask_user_question', state.agent)
24
22
  if (base === undefined) return
@@ -29,7 +27,7 @@ export function apply(ctx, config = {}) {
29
27
  if (states.has(agent)) return states.get(agent)
30
28
  const state = { agent, actor: agent.ctx, askDispose: undefined }
31
29
  states.set(agent, state)
32
- refresh(state)
30
+ register(state)
33
31
  return state
34
32
  }
35
33
 
@@ -44,16 +42,6 @@ export function apply(ctx, config = {}) {
44
42
  if (state !== undefined) cleanup(state)
45
43
  states.delete(agent)
46
44
  })
47
- ctx.on('system-prompt/assemble', (assembly, context, next) => {
48
- const state = states.get(context.scope)
49
- if (state === undefined) return next()
50
- refresh(state)
51
- const schema = state.actor.get('tools').schemas(state.agent).find(tool => tool.name === 'ask_user_question')
52
- if (schema !== undefined) {
53
- assembly.tools = assembly.tools.map(tool => tool.name === 'ask_user_question' ? schema : tool)
54
- }
55
- return next()
56
- })
57
45
  for (const agent of ctx.agents.list()) setup(agent)
58
46
  ctx.effect(() => () => {
59
47
  for (const state of states.values()) cleanup(state)