cortico-world-agent-speed 0.2.0 → 0.2.2

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.
Files changed (189) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/LICENSE +0 -14
  3. package/README.md +29 -11
  4. package/THIRD_PARTY_NOTICES.md +69 -0
  5. package/activity.d.ts +15 -0
  6. package/activity.js +88 -3
  7. package/describe.json +806 -0
  8. package/dist/webui.css +2 -0
  9. package/dist/webui.css.map +7 -0
  10. package/dist/webui.js +2 -0
  11. package/dist/webui.js.map +7 -0
  12. package/host/app-store.cjs +68 -0
  13. package/host/cursor.cjs +67 -0
  14. package/host/electron-main.cjs +666 -0
  15. package/host/input-shape.cjs +63 -0
  16. package/host/mouse-lease.cjs +77 -0
  17. package/host/overlay.cjs +139 -0
  18. package/host/portrait.cjs +52 -0
  19. package/host/preload.cjs +60 -14
  20. package/host/renderer-gone.cjs +24 -0
  21. package/host/windows.cjs +251 -0
  22. package/package.json +27 -7
  23. package/scripts/build-webui.mjs +40 -0
  24. package/scripts/speech-bank/build.py +166 -0
  25. package/scripts/speech-bank/dicts.py +76 -0
  26. package/src/ENV_PROMPT.en.md +51 -0
  27. package/src/ENV_PROMPT.md +51 -0
  28. package/src/asr/address.ts +25 -0
  29. package/src/asr/hotkey.ts +335 -0
  30. package/src/asr/result.ts +51 -0
  31. package/src/asr/segmenter.ts +269 -0
  32. package/src/asr/sherpa.ts +280 -0
  33. package/src/asr/simplify.ts +38 -0
  34. package/src/asr/system-recognizer.ts +292 -0
  35. package/src/asr/system-sapi.ps1 +173 -0
  36. package/src/asr/transcription-api.ts +176 -0
  37. package/src/chat.ts +212 -0
  38. package/src/config.ts +481 -0
  39. package/src/cua/ENV_PROMPT.en.md +29 -0
  40. package/src/cua/ENV_PROMPT.md +29 -0
  41. package/src/cua/config.ts +88 -0
  42. package/src/cua/cua.ts +712 -0
  43. package/src/cua/engine/darwin.ts +410 -0
  44. package/src/cua/engine/display.ts +55 -0
  45. package/src/cua/engine/fail.ts +15 -0
  46. package/src/cua/engine/foreground.ts +8 -0
  47. package/src/cua/engine/image.ts +57 -0
  48. package/src/cua/engine/keys.ts +70 -0
  49. package/src/cua/engine/linux-keys.ts +29 -0
  50. package/src/cua/engine/linux.ts +343 -0
  51. package/src/cua/engine/mac-keys.ts +57 -0
  52. package/src/cua/engine/user-activity.ts +54 -0
  53. package/src/cua/engine/wait-idle.ts +31 -0
  54. package/src/cua/engine/win32.ts +299 -0
  55. package/src/cua/engine-child.ts +274 -0
  56. package/src/cua/engine-ipc.ts +140 -0
  57. package/src/cua/i18n/de.ts +53 -0
  58. package/src/cua/i18n/en.ts +63 -0
  59. package/src/cua/i18n/es-419.ts +53 -0
  60. package/src/cua/i18n/fr.ts +53 -0
  61. package/src/cua/i18n/index.ts +26 -0
  62. package/src/cua/i18n/it.ts +53 -0
  63. package/src/cua/i18n/ja.ts +53 -0
  64. package/src/cua/i18n/ko.ts +53 -0
  65. package/src/cua/i18n/pt-BR.ts +53 -0
  66. package/src/cua/i18n/ru.ts +59 -0
  67. package/src/cua/i18n/zh-Hant.ts +53 -0
  68. package/src/cua/i18n/zh.ts +59 -0
  69. package/src/cua/model-text.ts +252 -0
  70. package/src/cua/terminal.ts +31 -0
  71. package/src/cua/tools.ts +153 -0
  72. package/src/definition.ts +146 -0
  73. package/src/host-reason.ts +32 -0
  74. package/src/i18n/de.ts +409 -0
  75. package/src/i18n/en.ts +443 -0
  76. package/src/i18n/es-419.ts +409 -0
  77. package/src/i18n/fr.ts +409 -0
  78. package/src/i18n/index.ts +56 -0
  79. package/src/i18n/it.ts +409 -0
  80. package/src/i18n/ja.ts +409 -0
  81. package/src/i18n/ko.ts +409 -0
  82. package/src/i18n/pt-BR.ts +409 -0
  83. package/src/i18n/ru.ts +415 -0
  84. package/src/i18n/zh-Hant.ts +409 -0
  85. package/src/i18n/zh.ts +440 -0
  86. package/src/index.ts +15 -0
  87. package/src/model-text.ts +344 -0
  88. package/src/moves.ts +101 -0
  89. package/src/pack-import.ts +361 -0
  90. package/src/packs.ts +449 -0
  91. package/src/runtime/download.ts +29 -0
  92. package/src/runtime/store.ts +293 -0
  93. package/src/script.ts +202 -0
  94. package/src/self.ts +247 -0
  95. package/src/server.ts +479 -0
  96. package/src/speech/data/CMUDICT-LICENSE +33 -0
  97. package/src/speech/data/IPADIC-COPYING +71 -0
  98. package/src/speech/data/UNICODE-LICENSE +39 -0
  99. package/src/speech/data/en.tsv.gz +0 -0
  100. package/src/speech/data/ja-ipadic.tsv.gz +0 -0
  101. package/src/speech/data/ja-unihan.tsv.gz +0 -0
  102. package/src/speech/data/zh.json +1 -0
  103. package/src/speech/index.ts +204 -0
  104. package/src/speech/ipa.ts +83 -0
  105. package/src/speech/japanese.ts +105 -0
  106. package/src/speech/jukujikun.ts +22 -0
  107. package/src/speech/korean.ts +35 -0
  108. package/src/speech/lang.ts +151 -0
  109. package/src/speech/rules.ts +72 -0
  110. package/src/speech/syllable.ts +76 -0
  111. package/src/status.ts +164 -0
  112. package/src/tools.ts +110 -0
  113. package/src/webui/api-rows.css +2 -0
  114. package/src/webui/api-rows.ts +44 -0
  115. package/src/webui/client.ts +451 -0
  116. package/src/webui/dress-dialog.css +14 -0
  117. package/src/webui/dress-dialog.ts +117 -0
  118. package/src/webui/dress-panel.ts +160 -0
  119. package/src/webui/key-capture.ts +60 -0
  120. package/src/webui/shared/modal.css +13 -0
  121. package/src/webui/shared/modal.ts +77 -0
  122. package/src/webui/shared/problem.css +15 -0
  123. package/src/webui/shared/problem.ts +217 -0
  124. package/src/webui/shared/strings.ts +5 -0
  125. package/src/webui/style.css +50 -0
  126. package/src/window-host.ts +116 -0
  127. package/src/world.ts +2926 -0
  128. package/web/activity-motion.js +117 -0
  129. package/web/appearance.js +60 -0
  130. package/web/body-host.js +257 -0
  131. package/web/coo/coo.js +384 -0
  132. package/web/coo/figure.js +15 -0
  133. package/web/coo/figure.json +1224 -0
  134. package/web/dist/dress-dialog.css +1 -0
  135. package/web/dist/dress-dialog.js +1 -0
  136. package/web/drag-row.js +49 -0
  137. package/web/drag.js +149 -0
  138. package/web/dress.css +170 -0
  139. package/web/dress.html +37 -0
  140. package/web/dress.js +786 -0
  141. package/web/figure-frame.html +16 -0
  142. package/web/figure-frame.js +128 -0
  143. package/web/frame-loop.js +55 -0
  144. package/web/hints.js +77 -0
  145. package/web/i18n/de.js +170 -0
  146. package/web/i18n/en.js +177 -0
  147. package/web/i18n/es-419.js +170 -0
  148. package/web/i18n/fr.js +170 -0
  149. package/web/i18n/it.js +170 -0
  150. package/web/i18n/ja.js +170 -0
  151. package/web/i18n/ko.js +170 -0
  152. package/web/i18n/pt-BR.js +170 -0
  153. package/web/i18n/ru.js +170 -0
  154. package/web/i18n/zh-Hant.js +170 -0
  155. package/web/i18n/zh.js +175 -0
  156. package/web/i18n.js +54 -0
  157. package/{renderer/vendor → web}/kit/body.js +31 -58
  158. package/web/looks.js +70 -0
  159. package/web/mic-worklet.js +36 -0
  160. package/web/mic.js +117 -0
  161. package/web/motion-frames.js +80 -0
  162. package/web/motion-level.js +40 -0
  163. package/web/new-year-2027.svg +238 -0
  164. package/web/overlay.html +16 -0
  165. package/web/overlay.js +100 -0
  166. package/web/pet-app.js +3000 -0
  167. package/web/pet.css +642 -0
  168. package/web/pet.html +21 -0
  169. package/web/scale-slider.js +259 -0
  170. package/web/show-hide.js +49 -0
  171. package/web/sound.js +245 -0
  172. package/web/speech/zh.json +1 -0
  173. package/web/speech/zh.ogg +0 -0
  174. package/web/speech.js +197 -0
  175. package/web/stage.js +160 -0
  176. package/web/swap-motion.js +119 -0
  177. package/web/ui.js +195 -0
  178. package/host/launch.js +0 -187
  179. package/host/library.cjs +0 -638
  180. package/host/main.cjs +0 -389
  181. package/index.js +0 -93
  182. package/renderer/index.html +0 -22
  183. package/renderer/pet-sandbox.html +0 -11
  184. package/renderer/pet.css +0 -38
  185. package/renderer/pet.js +0 -251
  186. package/renderer/vendor/activity-motion.js +0 -101
  187. package/renderer/vendor/figure-frame.js +0 -115
  188. package/renderer/vendor/pack.css +0 -2
  189. /package/{renderer/vendor → web}/kit/rig.js +0 -0
package/src/self.ts ADDED
@@ -0,0 +1,247 @@
1
+ /**
2
+ * The settings the bot may change on its own (`speed_pet_set`), each in one of two tiers:
3
+ *
4
+ * - `self`: changed at once;
5
+ * - `ask`: changed once the person says yes in the bubble.
6
+ *
7
+ * Which item is in which tier is the person's `selfAdjust` (config.ts `directSettings`): by default the
8
+ * bot's own looks and habits (figure and its picks, how much it walks about, how long it snores) are
9
+ * `self`, and what reaches the person's screen, ears or name (sounds, size, bubble and text size, the dark/light look, the
10
+ * hover buttons, what it calls them) is `ask`; on the Habits page they can make every item `self`,
11
+ * pick per item, or take the whole of it back.
12
+ *
13
+ * Everything else (computer use, voice input, the microphone, statistics, the model) is not the
14
+ * bot's to change.
15
+ *
16
+ * The change lines and errors are in the model-text language (`model-text.ts`); each change is also
17
+ * said in the app language (`show`, from `consent` in src/i18n) for the bubble that asks the person.
18
+ */
19
+ import type { Language } from 'cortico/core/language.ts';
20
+ import type { DeepPartial } from 'cortico/world.ts';
21
+ import { BUBBLE_SIZE_MAX, BUBBLE_SIZE_MIN, MAX_HOVER_BUTTONS, PET_ACTIONS, SCALE_MAX, SCALE_MIN, SELF_KEYS, USER_MAX, directSettings, hoverButtonList, scaleOf, type DesktopPetConfigSection, type SelfKey } from './config.ts';
22
+ import { charCount, petText } from './i18n/index.ts';
23
+ import type { ModelLanguage } from './model-text.ts';
24
+ import { COO, lookOf, lookPatch, modelName, nameIn, type FigurePack } from './packs.ts';
25
+
26
+ export type Tier = 'self' | 'ask';
27
+
28
+ export interface SettingChange {
29
+ key: SelfKey;
30
+ tier: Tier;
31
+ /** What changes, from what to what, for the receipt. */
32
+ say: string;
33
+ /** What changes, in the app language, for the bubble that asks the person. */
34
+ show: string;
35
+ patch: DeepPartial<DesktopPetConfigSection>;
36
+ }
37
+
38
+ const zh = {
39
+ roam: { free: '常走动', calm: '多待着', off: '不乱动' } as Record<string, string>,
40
+ theme: { dark: '夜间(浅色身体)', light: '白天(深色身体)' } as Record<string, string>,
41
+ pick: (axis: string, option: string) => `${axis}:${option}`,
42
+ picks: (words: string[]) => words.join(','),
43
+ badFigure: (ids: string[], got: string) => `figure 应为 ${ids.join('、')} 之一,收到 ${got}`,
44
+ figure: (from: string, to: string) => `形象 ${from} → ${to}`,
45
+ figureMissing: (figure: string) => `现在的形象 ${figure} 没有装,不能换打扮`,
46
+ badScheme: (pack: string, got: string) => `scheme 不是${pack}的预设或选项组合:${got}`,
47
+ scheme: (pack: string, from: string | null, to: string) => `${pack}的打扮 ${from ?? '默认'} → ${to}`,
48
+ badRoam: 'roam 应为 free、calm 或 off',
49
+ roamTo: (from: string, to: string) => `走动 ${from} → ${to}`,
50
+ badSnore: 'snoreSeconds 应为 0–3600 的整数',
51
+ snore: (seconds: number) => `每次睡着打呼噜 ${seconds === 0 ? '一直打到醒' : `${seconds} 秒`}`,
52
+ badSound: 'sound 应为 true 或 false',
53
+ sound: (on: boolean) => `音效 ${on ? '打开' : '关掉'}`,
54
+ badScale: `scale 应为 ${SCALE_MIN}–${SCALE_MAX} 的数`,
55
+ scale: (from: number, to: number) => `在屏幕上的大小 ${from} 倍 → ${to} 倍`,
56
+ badBubbleSize: `bubbleSize 应为 ${BUBBLE_SIZE_MIN}–${BUBBLE_SIZE_MAX} 的数`,
57
+ bubbleSize: (from: number, to: number) => `气泡尺寸 ${from} 倍 → ${to} 倍`,
58
+ badFontSize: `fontSize 应为 ${BUBBLE_SIZE_MIN}–${BUBBLE_SIZE_MAX} 的数`,
59
+ fontSize: (from: number, to: number) => `字体尺寸 ${from} 倍 → ${to} 倍`,
60
+ badTheme: 'theme 应为 dark 或 light',
61
+ themeTo: (to: string) => `换成${to}`,
62
+ badHover: `hoverButtons 应为 0–${MAX_HOVER_BUTTONS} 个不重复的 ${PET_ACTIONS.join('、')}`,
63
+ hover: (list: string[]) => (list.length ? `悬停按钮换成 ${list.join('、')}` : '去掉全部悬停按钮,右键菜单里也不再有这些动作,只剩应用提供的设置、暂停和退出'),
64
+ badUser: (max: number) => `user 应为 1–${max} 个字`,
65
+ user: (from: string, to: string) => `对你的称呼「${from}」→「${to}」`,
66
+ unknown: (key: string) => `${key} 不是你能改的设置`,
67
+ /** An id with its name, for the dress list. */
68
+ named: (id: string, name: string) => `${id}(${name})`,
69
+ figures: (list: string[]) => `- figure:${list.join('、')}`,
70
+ schemes: (pack: string, presets: string[], order: string | null, axes: string[]) =>
71
+ `- ${pack} 的 scheme:预设 ${presets.join('、') || '无'}${order ? `;或按 ${order} 的顺序用 - 连起来的组合,${axes.join(';')}` : ''}`,
72
+ axis: (name: string, options: string[]) => `${name}:${options.join('、')}`,
73
+ };
74
+
75
+ const en: typeof zh = {
76
+ roam: { free: 'free', calm: 'calm', off: 'off' },
77
+ theme: { dark: 'night (light body)', light: 'day (dark body)' },
78
+ pick: (axis, option) => `${axis}: ${option}`,
79
+ picks: (words) => words.join(', '),
80
+ badFigure: (ids, got) => `figure must be one of ${ids.join(', ')}; got ${got}`,
81
+ figure: (from, to) => `figure ${from} → ${to}`,
82
+ figureMissing: (figure) => `the current figure ${figure} is not installed, so its dress cannot change`,
83
+ badScheme: (pack, got) => `scheme is not a preset or option combination of ${pack}: ${got}`,
84
+ scheme: (pack, from, to) => `${pack} dress ${from ?? 'default'} → ${to}`,
85
+ badRoam: 'roam must be free, calm or off',
86
+ roamTo: (from, to) => `walking ${from} → ${to}`,
87
+ badSnore: 'snoreSeconds must be an integer from 0 to 3600',
88
+ snore: (seconds) => `snoring in each sleep → ${seconds === 0 ? 'until waking' : `${seconds} s`}`,
89
+ badSound: 'sound must be true or false',
90
+ sound: (on) => `sound effects ${on ? 'on' : 'off'}`,
91
+ badScale: `scale must be a number from ${SCALE_MIN} to ${SCALE_MAX}`,
92
+ scale: (from, to) => `size on screen ${from}× → ${to}×`,
93
+ badBubbleSize: `bubbleSize must be a number from ${BUBBLE_SIZE_MIN} to ${BUBBLE_SIZE_MAX}`,
94
+ bubbleSize: (from, to) => `bubble size ${from}× → ${to}×`,
95
+ badFontSize: `fontSize must be a number from ${BUBBLE_SIZE_MIN} to ${BUBBLE_SIZE_MAX}`,
96
+ fontSize: (from, to) => `text size ${from}× → ${to}×`,
97
+ badTheme: 'theme must be dark or light',
98
+ themeTo: (to) => `theme → ${to}`,
99
+ badHover: `hoverButtons must be 0–${MAX_HOVER_BUTTONS} distinct items of ${PET_ACTIONS.join(', ')}`,
100
+ hover: (list) => (list.length ? `hover buttons → ${list.join(', ')}` : 'hover buttons → none; the right-click menu loses them too, keeping only the settings, pause and quit the app provides'),
101
+ badUser: (max) => `user must be 1–${max} characters`,
102
+ user: (from, to) => `what I call you "${from}" → "${to}"`,
103
+ unknown: (key) => `${key} is not a setting you can change`,
104
+ named: (id, name) => (name === id ? id : `${id} (${name})`),
105
+ figures: (list) => `- figure: ${list.join(', ')}`,
106
+ schemes: (pack, presets, order, axes) =>
107
+ `- scheme for ${pack}: presets ${presets.join(', ') || 'none'}${order ? `; or one option per axis joined with - in the order ${order}: ${axes.join('; ')}` : ''}`,
108
+ axis: (name, options) => `${name}: ${options.join(', ')}`,
109
+ };
110
+
111
+ const SELF_TEXT: Record<ModelLanguage, typeof zh> = { zh, en };
112
+
113
+ /** A size change as `speed_pet_set`'s receipt says it. */
114
+ export const sayScale = (from: number, to: number, language: ModelLanguage = 'zh'): string => SELF_TEXT[language].scale(from, to);
115
+
116
+ /** The pack's pick named by `scheme`, as `axis:option` words; null when it picks nothing of the pack. */
117
+ export function pickWords(pack: FigurePack, scheme: string, language: ModelLanguage = 'zh'): string | null {
118
+ const t = SELF_TEXT[language];
119
+ return pickNames(pack, scheme, (n, id) => modelName(n, id, language), t.pick, t.picks);
120
+ }
121
+
122
+ /** `pickWords` with the names and the joining of a language. */
123
+ function pickNames(pack: FigurePack, scheme: string, name: (n: Record<string, string> | undefined, id: string) => string,
124
+ pick: (axis: string, option: string) => string, picks: (words: string[]) => string): string | null {
125
+ const m = pack.manifest;
126
+ const preset = m.presets.find((p) => p.id === scheme);
127
+ const parts = scheme.split('-');
128
+ const words: string[] = [];
129
+ for (const [i, a] of m.axes.entries()) {
130
+ const id = preset ? preset.pick[a.id] : parts[i];
131
+ const o = a.options.find((x) => x.id === id);
132
+ if (!o) return null;
133
+ words.push(pick(name(a.name, a.id), name(o.name, o.id)));
134
+ }
135
+ if (!preset && parts.length !== m.axes.length) return null;
136
+ return picks(words);
137
+ }
138
+
139
+ const figureName = (id: string, packs: readonly FigurePack[], language: ModelLanguage) => modelName(packs.find((p) => p.id === id)?.manifest.name, id, language);
140
+
141
+ /**
142
+ * Checks what `speed_pet_set` asks for against the current config; returns the changes, each in the tier the
143
+ * person's `selfAdjust` puts it, or why one cannot be made. A value equal to the current one is left out.
144
+ * `userMax`: the longest name for the person, in characters as seen.
145
+ */
146
+ export function planSettings(args: Record<string, unknown>, cfg: DesktopPetConfigSection, packs: readonly FigurePack[], language: ModelLanguage = 'zh', userMax = USER_MAX,
147
+ appLanguage: Language = 'zh'): { changes: SettingChange[]; errors: string[] } {
148
+ const t = SELF_TEXT[language];
149
+ const a = petText(appLanguage).consent;
150
+ const direct = directSettings(cfg);
151
+ const tier = (key: SelfKey): Tier => (direct[key] ? 'self' : 'ask');
152
+ const shown = (n: Record<string, string> | undefined, id: string) => (n ? nameIn(n, appLanguage) : id);
153
+ const changes: SettingChange[] = [];
154
+ const errors: string[] = [];
155
+ const skin = cfg.skin;
156
+ // figure first: a scheme given with it is checked against the new figure
157
+ let figure = skin.figure ?? COO;
158
+ if ('figure' in args) {
159
+ const v = args.figure;
160
+ if (typeof v !== 'string' || !packs.some((p) => p.id === v)) errors.push(t.badFigure(packs.map((p) => p.id), JSON.stringify(v)));
161
+ else if (v !== figure) {
162
+ const pack = packs.find((p) => p.id === v)!;
163
+ // a pack starts in its first pick; Coo keeps the one it had
164
+ const scheme = pack.manifest.presets[0]?.id ?? pack.manifest.axes.map((a) => a.options[0]!.id).join('-');
165
+ changes.push({ key: 'figure', tier: tier('figure'), say: t.figure(figureName(figure, packs, language), figureName(v, packs, language)), show: a.figure(shown(pack.manifest.name, v)), patch: { skin: { figure: v, ...(v !== COO && !('scheme' in args) ? { scheme } : {}) } } });
166
+ figure = v;
167
+ }
168
+ }
169
+ if ('scheme' in args) {
170
+ const v = args.scheme;
171
+ const pack = packs.find((p) => p.id === figure);
172
+ const words = pack && typeof v === 'string' ? pickWords(pack, v, language) : null;
173
+ if (!pack) errors.push(t.figureMissing(figure));
174
+ else if (!words) errors.push(t.badScheme(modelName(pack.manifest.name, pack.id, language), JSON.stringify(v)));
175
+ else {
176
+ const now = lookOf(pack, skin);
177
+ if (v !== now || figure !== skin.figure) {
178
+ const before = (skin.figure ?? COO) === figure ? pickWords(pack, now, language) : null;
179
+ const look = pickNames(pack, v as string, shown, a.pick, a.list) ?? (v as string);
180
+ changes.push({ key: 'scheme', tier: tier('scheme'), say: t.scheme(modelName(pack.manifest.name, pack.id, language), before, words), show: a.scheme(shown(pack.manifest.name, pack.id), look), patch: { skin: lookPatch(pack, v as string) } });
181
+ }
182
+ }
183
+ }
184
+ if ('roam' in args) {
185
+ const v = args.roam;
186
+ if (typeof v !== 'string' || !(v in t.roam)) errors.push(t.badRoam);
187
+ else if (v !== cfg.roam) changes.push({ key: 'roam', tier: tier('roam'), say: t.roamTo(t.roam[cfg.roam]!, t.roam[v]!), show: a.roamTo(a.roam[v as 'free']), patch: { roam: v as DesktopPetConfigSection['roam'] } });
188
+ }
189
+ if ('snoreSeconds' in args) {
190
+ const v = args.snoreSeconds;
191
+ if (typeof v !== 'number' || !Number.isInteger(v) || v < 0 || v > 3600) errors.push(t.badSnore);
192
+ else if (v !== cfg.sounds.snoreSeconds) changes.push({ key: 'snoreSeconds', tier: tier('snoreSeconds'), say: t.snore(v), show: a.snore(v), patch: { sounds: { snoreSeconds: v } } });
193
+ }
194
+ if ('sound' in args) {
195
+ const v = args.sound;
196
+ if (typeof v !== 'boolean') errors.push(t.badSound);
197
+ else if (v !== cfg.sound) changes.push({ key: 'sound', tier: tier('sound'), say: t.sound(v), show: a.sound(v), patch: { sound: v } });
198
+ }
199
+ if ('scale' in args) {
200
+ const s = scaleOf(args.scale);
201
+ if (s === null) errors.push(t.badScale);
202
+ else {
203
+ if (s !== cfg.window.scale) changes.push({ key: 'scale', tier: tier('scale'), say: t.scale(cfg.window.scale, s), show: a.scale(cfg.window.scale, s), patch: { window: { scale: s } } });
204
+ }
205
+ }
206
+ for (const key of ['bubbleSize', 'fontSize'] as const) {
207
+ if (!(key in args)) continue;
208
+ const v = args[key];
209
+ if (typeof v !== 'number' || !(v >= BUBBLE_SIZE_MIN && v <= BUBBLE_SIZE_MAX)) { errors.push(key === 'bubbleSize' ? t.badBubbleSize : t.badFontSize); continue; }
210
+ const s = Math.round(v * 20) / 20, from = cfg.window[key];
211
+ if (s !== from) changes.push({ key, tier: tier(key), say: t[key](from, s), show: a[key](from, s), patch: { window: { [key]: s } } });
212
+ }
213
+ if ('theme' in args) {
214
+ const v = args.theme;
215
+ if (typeof v !== 'string' || !(v in t.theme)) errors.push(t.badTheme);
216
+ else if (v !== cfg.theme) changes.push({ key: 'theme', tier: tier('theme'), say: t.themeTo(t.theme[v]!), show: a.theme[v as 'dark'], patch: { theme: v as DesktopPetConfigSection['theme'] } });
217
+ }
218
+ if ('hoverButtons' in args) {
219
+ const v = args.hoverButtons;
220
+ const ids = Array.isArray(v) ? v.filter((x): x is string => typeof x === 'string') : [];
221
+ const list = hoverButtonList(ids.join(','));
222
+ // an empty list is an answer too: no hover buttons, and a right-click menu of the run controls alone
223
+ if (!Array.isArray(v) || list.length !== v.length) errors.push(t.badHover);
224
+ else if (list.join(',') !== cfg.hoverButtons) changes.push({ key: 'hoverButtons', tier: tier('hoverButtons'), say: t.hover(list), show: list.length ? a.hover(a.list(list.map((id) => a.actions[id]))) : a.hoverNone, patch: { hoverButtons: list.join(',') } });
225
+ }
226
+ if ('user' in args) {
227
+ const v = typeof args.user === 'string' ? args.user.trim() : '';
228
+ if (!v || charCount(v) > userMax) errors.push(t.badUser(userMax));
229
+ else if (v !== cfg.user) changes.push({ key: 'user', tier: tier('user'), say: t.user(cfg.user, v), show: a.user(v), patch: { user: v } });
230
+ }
231
+ const known = new Set<string>(SELF_KEYS);
232
+ for (const k of Object.keys(args)) if (!known.has(k)) errors.push(t.unknown(k));
233
+ return { changes, errors };
234
+ }
235
+
236
+ /** What `speed_pet_set` can pick from, for the bot's prompt: the figures and their picks. */
237
+ export function dressTable(packs: readonly FigurePack[], language: ModelLanguage = 'zh'): string {
238
+ const t = SELF_TEXT[language];
239
+ const lines = [t.figures(packs.map((p) => t.named(p.id, modelName(p.manifest.name, p.id, language))))];
240
+ for (const p of packs) {
241
+ const m = p.manifest;
242
+ const presets = m.presets.map((x) => (x.name ? t.named(x.id, modelName(x.name, x.id, language)) : x.id));
243
+ const axes = m.axes.map((a) => t.axis(modelName(a.name, a.id, language), a.options.map((o) => t.named(o.id, modelName(o.name, o.id, language)))));
244
+ lines.push(t.schemes(p.id, presets, m.axes.length > 1 ? m.axes.map((a) => a.id).join('-') : null, axes));
245
+ }
246
+ return lines.join('\n');
247
+ }