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
@@ -0,0 +1,344 @@
1
+ /**
2
+ * What the bot reads from this World (events, receipts, environment prompt values), in Chinese and
3
+ * in English; `en: typeof zh` keeps the two tables' keys and signatures the same. The embedding app
4
+ * picks the language (`DesktopPetAssembly.modelLanguage`), Chinese when it does not. What the person
5
+ * typed, said or answered goes into these lines as it came. The vocabulary table and the dress list
6
+ * have their own tables, in `script.ts` and `self.ts`.
7
+ *
8
+ * The question `speed_pet_set` asks the person in the bubble is in the app language instead: the same
9
+ * changes, written by `show` in `self.ts`.
10
+ */
11
+ import type { SelfKey } from './config.ts';
12
+
13
+ export type ModelLanguage = 'zh' | 'en';
14
+
15
+ interface SayReceipt {
16
+ /** Seconds of earlier lines still ahead of this one. */
17
+ waitSec: number;
18
+ /** Seconds this one stays on screen. */
19
+ selfSec: number;
20
+ chatOpen: boolean;
21
+ /** The unanswered question this one replaced. */
22
+ replaced: string | null;
23
+ /** Markers left out: not in the vocabulary. */
24
+ dropped: string[];
25
+ /** Images shown with it on the chat page. */
26
+ images: number;
27
+ }
28
+
29
+ interface AskReceipt {
30
+ replaced: string | null;
31
+ /** More than three options were given. */
32
+ cut: boolean;
33
+ chatOpen: boolean;
34
+ }
35
+
36
+ /** Why the changes `speed_pet_set` asked about were not made. */
37
+ type NotAsked = 'unavailable' | 'timeout' | 'no';
38
+
39
+ /**
40
+ * Why `speed_pet_see_self` has no picture: the pet page is in a browser tab, the pet window is hidden, no figure is on the
41
+ * page, the window gave no pixels, the page did not answer in time, or it disconnected.
42
+ */
43
+ export type NoPortrait = 'tab' | 'hidden' | 'no-body' | 'capture' | 'timeout' | 'gone';
44
+
45
+ /** The `speed_pet_act` word for the fireworks behind the bot, taken only in the turn the New Year event reaches it. */
46
+ export const FIREWORKS_WORD = 'fireworks_2027';
47
+
48
+ const zh = {
49
+ /** Locale of the weekday in an event's time stamp. */
50
+ dateLocale: 'zh-CN',
51
+ typed: (user: string, text: string) => `[typed] ${user}:${text}`,
52
+ heard: (user: string, text: string) => `[voice] ${user}:${text}`,
53
+ talkKeyUnreadable: (user: string, problem: string) => `[talk-key] 说话键读不到,${user}按说话键说的话收不到:${problem}`,
54
+ image: (user: string, i: number, total: number) => `[${user}发来的图片 ${i}/${total}]`,
55
+ recording: (user: string, seconds: number) => `[${user}说这段话的录音,${seconds} 秒;上面的文字是从它识别出来的]`,
56
+ /** A speech batch sent as its recording alone (`asr.recording.transcript` off). */
57
+ heardRecorded: (user: string) => `[voice] ${user}说了一段话,内容在下面的录音里`,
58
+ recordingAlone: (user: string, seconds: number) => `[${user}说这段话的录音,${seconds} 秒]`,
59
+
60
+ answerClosed: (user: string, question: string) => `[answer] ${user}关掉了提问「${question}」,没有作答。`,
61
+ answerPicked: (user: string, question: string, n: number, option: string) => `[answer] ${user}回答「${question}」:选了第 ${n} 项「${option}」`,
62
+ answerWrote: (user: string, question: string, text: string) => `[answer] ${user}回答「${question}」:自己写了:「${text}」`,
63
+
64
+ touch: (text: string) => `[touch] ${text}`,
65
+ pokedAwake: (user: string) => `${user}把睡着的你戳醒了`,
66
+ poked: (user: string, n: number) => (n > 1 ? `${user}戳了你 ${n} 下` : `${user}戳了你一下`),
67
+ pettedAsleep: (user: string) => `${user}摸了摸睡着的你`,
68
+ petted: (user: string, n: number) => (n > 1 ? `${user}摸了你好几下` : `${user}摸了摸你的头`),
69
+ thrown: (user: string, crashed: boolean) => `${user}把你拎起来甩了出去${crashed ? ',你重重落地,摔晕了一会儿' : ''}`,
70
+ /** `at`: how far across the screen, null when the page did not say. */
71
+ dropped: (user: string, at: string | null, crashed: boolean) => `${user}把你拎起来,放到了屏幕横向 ${at ?? '某'} 处${crashed ? ',你摔晕了一会儿' : ''}`,
72
+ crashed: '你重重落地,摔晕了一会儿',
73
+
74
+ figureFailed: (name: string, reason: string, body: string, note: string) => `[figure] ${name}没能显示出来(${reason}),你现在是${body}。${note ? `\n${note}` : ''}`,
75
+ reasonUnknown: '原因不明',
76
+ figureNow: (body: string) => `[figure] 你现在的样子:${body}。`,
77
+ figureNote: (note: string) => `[figure] ${note}`,
78
+ lookNow: (body: string) => `你现在的样子:${body}。`,
79
+ /** The body as the prompt and the figure events describe it: name, looks, picked options. */
80
+ body: (name: string, about: string, picks: string[]) => `${name},${about}${picks.length ? `(${picks.join(',')})` : ''}`,
81
+ pick: (axis: string, option: string) => `${axis}:${option}`,
82
+
83
+ /** The `[holiday]` events, by the holidays of `HOLIDAYS` in world.ts. */
84
+ holiday: {
85
+ christmas: '[holiday] 今天是圣诞节。',
86
+ newYear2027: `[holiday] 今天是 2027 年元旦。想庆祝的话,可以用你们熟悉的方式说声新年快乐,也可以继续眼前的事。这一轮可以让身后升起写着「2027」的烟花,动作词是 ${FIREWORKS_WORD},只能放一次。`,
87
+ },
88
+
89
+ /** Follows the across share in `at` for a body that stands off the floor: how far down it is (0% the top). */
90
+ downAt: (y: string) => `,纵向 ${y}`,
91
+ walkArrived: (at: string) => `走到了屏幕横向 ${at} 处。`,
92
+ walkStopped: (at: string) => `走到屏幕横向 ${at} 处停下了。`,
93
+ walkGrabbed: (at: string, user: string) => `没走到:走到 ${at} 处时被${user}拎起来了。`,
94
+ walkReplaced: (at: string, by: string) => `没走到:走到 ${at} 处时换成了别的动作(${by})。`,
95
+ walkTimeout: (seconds: number) => `${seconds} 秒内没有走到。`,
96
+ walkWindowGone: '没走到:桌宠窗口断开了。',
97
+ walkWorldStopped: 'World 已停止,没走到。',
98
+ /** A target of the figure's own, by `name`; `by` is what its body said stopped it. */
99
+ moveArrived: (name: string, at: string) => `到了「${name}」,在屏幕横向 ${at} 处。`,
100
+ moveStopped: (name: string, at: string) => `去「${name}」的途中,在屏幕横向 ${at} 处停下了。`,
101
+ moveGrabbed: (name: string, at: string, user: string) => `没到「${name}」:在屏幕横向 ${at} 处被${user}拎起来了。`,
102
+ moveFailed: (name: string, at: string, by: string) => `没到「${name}」(${by}),现在在屏幕横向 ${at} 处。`,
103
+ moveTimeout: (name: string, seconds: number) => `${seconds} 秒内没到「${name}」。`,
104
+ /** `targets`: the ids of the current figure's own targets. */
105
+ moveBadTarget: (got: string, targets: string[]) => `[speed_pet_move_to 没执行] to 应为 0–1 的数字、left / center / right / cursor${targets.length ? `,或现在的形象的目标 ${targets.join(' / ')}` : ''},收到 ${got}。`,
106
+ moveNoTarget: '[speed_pet_move_to 没执行] 缺少 to。',
107
+ /** `target`: the figure's target the params were given for, null for a default one; `spec`: its params as `id min–max`. */
108
+ moveBadParams: (target: string | null, spec: string[], got: string) => `[speed_pet_move_to 没执行] ${target === null ? '默认目标不带 params' : spec.length ? `${target} 的 params 依次是 ${spec.join('、')},可以少给,不能超出范围` : `${target} 不带 params`},收到 ${got}。`,
109
+ walkCannot: (name: string) => `[speed_pet_move_to 没执行] 现在的形象(${name})不会走到默认目标。`,
110
+
111
+ /** `detail`: the window host's own words on why, when it has them. */
112
+ notConnected: (tool: string, detail: string | null, user: string) => `[${tool} 没执行] 桌宠窗口没有连接${detail ? `(${detail})` : ''},${user}看不到。`,
113
+ /** Why the pet window is not there (window-host.ts), as `notConnected` passes it on. */
114
+ window: {
115
+ noElectronFile: (file: string) => `Electron 程序不存在:${file}`,
116
+ noElectron: '没有可用的 Electron:在桌宠面板安装窗口运行时,或在配置里指定 Electron 程序',
117
+ startFailed: (why: string) => `启动失败:${why}`,
118
+ closed: '窗口已关闭',
119
+ exited: (code: number | null) => `窗口进程退出(退出码 ${code})`,
120
+ },
121
+
122
+ sayEmpty: '[speed_pet_say 没执行] 脚本是空的,也没带图片。不想说话就不调用。',
123
+ sayReceipt: (r: SayReceipt) => `${r.waitSec > .5 ? `已排队,前面还有约 ${Math.round(r.waitSec)} 秒` : '已开始显示'},这段约 ${Math.round(r.selfSec)} 秒。`
124
+ + (r.chatOpen ? '对话页开着,这段也显示在那里。' : '')
125
+ + (r.images ? `附带的 ${r.images} 张图片只显示在对话页。` : '')
126
+ + (r.replaced !== null ? `替换了还没回答的提问「${r.replaced}」。` : '')
127
+ + (r.dropped.length ? `\n[执行参数] 当前形象的词表里没有这些标记,已略过:${r.dropped.join('、')}。` : ''),
128
+
129
+ /** `speed_pet_say` with images and an empty script. */
130
+ imagesShown: (n: number, chatOpen: boolean) => `${n} 张图片已显示在对话页${chatOpen ? '' : ',对话页现在没有打开'}。`,
131
+ /** fallbackText of an image `speed_pet_say` showed; that event is stored, never delivered. */
132
+ shownImage: (i: number, total: number) => `[对话页上展示的图片 ${i}/${total}]`,
133
+ imagesNotHandles: '[speed_pet_say 没执行] images 要填附件句柄组成的数组。',
134
+ tooManyImages: (max: number) => `[speed_pet_say 没执行] images 最多 ${max} 个。`,
135
+ imageMissing: (handle: string) => `[speed_pet_say 没执行] 读不到附件 ${handle}。images 填上下文里 [blob …] 行开头的句柄。`,
136
+ imageNotImage: (handle: string, mime: string) => `[speed_pet_say 没执行] ${handle} 是 ${mime},不是图片。`,
137
+
138
+ askEmpty: '[speed_pet_ask 没执行] question 是空的。',
139
+ askNoWay: '[speed_pet_ask 没执行] 没有选项,又不允许自己写,没法作答。',
140
+ askReceipt: (r: AskReceipt) => '已问出。'
141
+ + (r.replaced !== null ? `替换了还没回答的上一个提问「${r.replaced}」。` : '')
142
+ + (r.cut ? '只显示了前 3 个选项。' : '')
143
+ + (r.chatOpen ? '对话页开着,问题也显示在那里,两边都能回答。' : '')
144
+ + '回答到了会以 [answer] 事件送达。',
145
+
146
+ selfAdjustOff: (tool: string, user: string) => `[${tool} 没执行] ${user}在「习惯」页把「自主配置权限」设成了「禁止」。`,
147
+ setErrors: (errors: string[]) => `[speed_pet_set 没执行] ${errors.join(';')}。`,
148
+ setNothing: '要改的都和现在一样,没有改动。',
149
+ setDone: (says: string[]) => `已改:${says.join(';')}。`,
150
+ setAgreed: (user: string, says: string[]) => `${user}同意了,已改:${says.join(';')}。`,
151
+ /** The person answered 「以后都可以」: `items` are changed at once from now on. */
152
+ setAlways: (user: string, says: string[], items: string[]) => `${user}同意了,已改:${says.join(';')}。${user}还说${items.join('、')}以后不用再问,直接改就行。`,
153
+ setNotChanged: (why: NotAsked, user: string, says: string[]) =>
154
+ `${why === 'unavailable' ? '桌宠窗口没有连接,没法问' : why === 'timeout' ? `${user}没有回答` : `${user}没同意`},这些没改:${says.join(';')}。`,
155
+
156
+ quietBad: (max: number) => `[speed_pet_quiet 没执行] minutes 应为 0–${max} 的数。`,
157
+ quietNone: '现在没有在安静。',
158
+ quietEnded: '已结束安静,音效和走动回到设置里的样子。',
159
+ quietUntil: (time: string, sound: boolean, roam: 'off' | 'calm') => `安静到 ${time}:音效${sound ? '照常' : '关'},走动 ${roam === 'off' ? '不乱动' : '多待着'}。设置没变,到时自动恢复。`,
160
+
161
+ actNone: (dropped: string[]) => `[speed_pet_act 没执行] 当前形象的词表里没有这些动作${dropped.length ? `(${dropped.join('、')})` : ''}。`,
162
+ actReceipt: (actions: string[], lasting: string[], dropped: string[]) => `开始依次做:${actions.join(' → ')}。`
163
+ + (lasting.length ? `${lasting.join('、')} 会一直保持到下一个动作。` : '')
164
+ + (dropped.length ? `\n[执行参数] 当前形象的词表里没有这些,已略过:${dropped.join('、')}。` : ''),
165
+
166
+ /** `body`: the figure and its dress, as `body` words them. */
167
+ selfSeen: (width: number, height: number, body: string) => `附图是这次调用时屏幕上画出的你,${width}×${height} 像素:只有身体,灰色底不是桌面,气泡不在图里。形象与打扮:${body}。`,
168
+ selfFallback: (width: number, height: number) => `你当时的样子 ${width}×${height}`,
169
+ /** `seconds`: how long the page was waited for, for `timeout`. */
170
+ selfNot: (why: NoPortrait, seconds: number) => `[speed_pet_see_self 没执行] ${{
171
+ tab: '桌宠现在显示在浏览器页面里,那里取不到图。',
172
+ hidden: '桌宠窗口现在隐藏着,身体没有画出来。',
173
+ 'no-body': '屏幕上还没有形象。',
174
+ capture: '桌宠窗口没有给出图。',
175
+ timeout: `桌宠窗口 ${seconds} 秒内没有交回图。`,
176
+ gone: '桌宠窗口断开了。',
177
+ }[why]}`,
178
+
179
+ on: '开着',
180
+ off: '关着',
181
+ /** `speed_pet_set`'s items, named for the bot with the parameter each is. */
182
+ settingNames: {
183
+ figure: '形象(figure)', scheme: '打扮(scheme)', roam: '走动(roam)', snoreSeconds: '呼噜时长(snoreSeconds)', sound: '音效(sound)',
184
+ scale: '大小(scale)', bubbleSize: '气泡尺寸(bubbleSize)', fontSize: '字体尺寸(fontSize)', theme: '黑白模式(theme)', hoverButtons: '悬停按钮(hoverButtons)', user: '对对方的称呼(user)',
185
+ } as Record<SelfKey, string>,
186
+ /** `{{pet.self}}`: the items that change at once and the ones asked first. */
187
+ selfTiers: (user: string, direct: string[], asked: string[]) => (!asked.length ? '现在这些都直接生效。'
188
+ : !direct.length ? `现在这些都要先在气泡里征得${user}同意。`
189
+ : `现在直接生效的:${direct.join('、')};先在气泡里征得${user}同意的:${asked.join('、')}。`),
190
+ /** `{{pet.self}}` while the person allows no change. */
191
+ selfNone: (user: string) => `${user}在「习惯」页把「自主配置权限」设成了「禁止」,现在这些你都改不了,\`speed_pet_quiet\` 也用不了。`,
192
+ /** `{{pet.chat}}`, when the app has a chat page. */
193
+ chatPage: (_user: string) => '应用的「对话」页按时间列出这些气泡、对方的话,以及你两句话之间调用过的工具名;对方也能在那里打字、发图片(同样是 `[typed]` 事件,图片接在正文后),回答 `speed_pet_ask`。`speed_pet_say` 带的 `images` 只显示在对话页,头顶气泡不显示。',
194
+ /** `{{pet.cua}}` while computer use is off on a system that runs it. */
195
+ cuaOff: (user: string, canOpen: boolean) => `## 电脑操作\n\n电脑操作现在关着:你看不到屏幕,也动不了鼠标和键盘。${user}想让你看屏幕或帮忙操作电脑时,可以提出打开它:在设置窗口「习惯」页的「电脑操作」一节,打开前那里会讲清风险。` +
196
+ (canOpen ? `${user}同意去打开的话,\`speed_pet_cua_open_settings\` 把设置窗口直接打开到那里。` : ''),
197
+ /** The receipt of `speed_pet_cua_open_settings`. */
198
+ cuaSettingsOpened: (user: string) => `设置窗口已打开到「电脑操作」,正弹着风险说明;${user}点「打开」之后,下一条消息起你就能用电脑操作的工具。`,
199
+ /** `{{pet.reply}}`: the language to talk to the person in, named by the app. */
200
+ reply: (user: string, language: string) => `对${user}说的话,气泡、提问和选项,都用${language}。`,
201
+ };
202
+
203
+ const en: typeof zh = {
204
+ dateLocale: 'en-US',
205
+ typed: (user, text) => `[typed] ${user}: ${text}`,
206
+ heard: (user, text) => `[voice] ${user}: ${text}`,
207
+ talkKeyUnreadable: (user, problem) => `[talk-key] The talk key cannot be read, so what ${user} says with it is not heard: ${problem}`,
208
+ image: (user, i, total) => `[image ${i}/${total} from ${user}]`,
209
+ recording: (user, seconds) => `[recording of what ${user} said, ${seconds} s; the text above was recognized from it]`,
210
+ heardRecorded: (user) => `[voice] ${user} said something; it is in the recording below`,
211
+ recordingAlone: (user, seconds) => `[recording of what ${user} said, ${seconds} s]`,
212
+
213
+ answerClosed: (user, question) => `[answer] ${user} closed the question "${question}" without answering.`,
214
+ answerPicked: (user, question, n, option) => `[answer] ${user} answered "${question}": picked option ${n}, "${option}"`,
215
+ answerWrote: (user, question, text) => `[answer] ${user} answered "${question}" in their own words: "${text}"`,
216
+
217
+ touch: (text) => `[touch] ${text}`,
218
+ pokedAwake: (user) => `${user} poked you awake`,
219
+ poked: (user, n) => (n > 1 ? `${user} poked you ${n} times` : `${user} poked you`),
220
+ pettedAsleep: (user) => `${user} patted you while you were asleep`,
221
+ petted: (user, n) => (n > 1 ? `${user} patted you several times` : `${user} patted your head`),
222
+ thrown: (user, crashed) => `${user} picked you up and threw you${crashed ? '; you landed hard and were knocked out for a moment' : ''}`,
223
+ dropped: (user, at, crashed) => `${user} picked you up and put you down ${at ? `at ${at} across the screen` : 'somewhere on the screen'}${crashed ? '; you were knocked out for a moment' : ''}`,
224
+ crashed: 'You landed hard and were knocked out for a moment',
225
+
226
+ figureFailed: (name, reason, body, note) => `[figure] ${name} could not be shown (${reason}); you are now ${body}.${note ? `\n${note}` : ''}`,
227
+ reasonUnknown: 'reason unknown',
228
+ figureNow: (body) => `[figure] You now look like this: ${body}.`,
229
+ figureNote: (note) => `[figure] ${note}`,
230
+ lookNow: (body) => `You now look like this: ${body}.`,
231
+ body: (name, about, picks) => `${name}, ${about}${picks.length ? ` (${picks.join(', ')})` : ''}`,
232
+ pick: (axis, option) => `${axis}: ${option}`,
233
+
234
+ holiday: {
235
+ christmas: '[holiday] Today is Christmas Day.',
236
+ newYear2027: `[holiday] Today is New Year's Day 2027. If you feel like celebrating together, say happy New Year in the way you two know, or carry on with what you were doing. During this turn you can have fireworks rise behind you that spell out 2027, with the action word ${FIREWORKS_WORD}; they play once.`,
237
+ },
238
+
239
+ downAt: (y) => ` (${y} down)`,
240
+ walkArrived: (at) => `Arrived at ${at} across the screen.`,
241
+ walkStopped: (at) => `Stopped at ${at} across the screen.`,
242
+ walkGrabbed: (at, user) => `Did not get there: ${user} picked you up at ${at} across the screen.`,
243
+ walkReplaced: (at, by) => `Did not get there: at ${at} across the screen another action took over (${by}).`,
244
+ walkTimeout: (seconds) => `Did not get there within ${seconds} seconds.`,
245
+ walkWindowGone: 'Did not get there: the pet window disconnected.',
246
+ walkWorldStopped: 'The World stopped; did not get there.',
247
+ moveArrived: (name, at) => `Reached "${name}", at ${at} across the screen.`,
248
+ moveStopped: (name, at) => `Stopped on the way to "${name}", at ${at} across the screen.`,
249
+ moveGrabbed: (name, at, user) => `Did not reach "${name}": ${user} picked you up at ${at} across the screen.`,
250
+ moveFailed: (name, at, by) => `Did not reach "${name}" (${by}); now at ${at} across the screen.`,
251
+ moveTimeout: (name, seconds) => `Did not reach "${name}" within ${seconds} seconds.`,
252
+ moveBadTarget: (got, targets) => `[speed_pet_move_to not run] to must be a number from 0 to 1, left / center / right / cursor${targets.length ? `, or one of the current figure's targets ${targets.join(' / ')}` : ''}; got ${got}.`,
253
+ moveNoTarget: '[speed_pet_move_to not run] to is missing.',
254
+ moveBadParams: (target, spec, got) => `[speed_pet_move_to not run] ${target === null ? 'The default targets take no params' : spec.length ? `The params of ${target} are, in order, ${spec.join(', ')}; fewer may be given, none out of range` : `${target} takes no params`}; got ${got}.`,
255
+ walkCannot: (name) => `[speed_pet_move_to not run] The current figure (${name}) does not walk to the default targets.`,
256
+
257
+ notConnected: (tool, detail, user) => `[${tool} not run] The pet window is not connected${detail ? ` (${detail})` : ''}; ${user} cannot see it.`,
258
+ window: {
259
+ noElectronFile: (file) => `The Electron executable does not exist: ${file}`,
260
+ noElectron: 'No Electron to run: install the window runtime on the pet panel, or set the Electron executable in the config',
261
+ startFailed: (why) => `Failed to start: ${why}`,
262
+ closed: 'The window was closed',
263
+ exited: (code) => `The window process exited (exit code ${code})`,
264
+ },
265
+
266
+ sayEmpty: '[speed_pet_say not run] The script is empty and there are no images. Do not call it when you have nothing to say.',
267
+ sayReceipt: (r) => [
268
+ r.waitSec > .5
269
+ ? `Queued behind about ${Math.round(r.waitSec)} s of earlier lines; this one takes about ${Math.round(r.selfSec)} s.`
270
+ : `Showing now; this one takes about ${Math.round(r.selfSec)} s.`,
271
+ r.chatOpen ? 'The chat page is open and shows it too.' : '',
272
+ r.images ? `The ${r.images} image${r.images > 1 ? 's' : ''} with it show only on the chat page.` : '',
273
+ r.replaced !== null ? `Replaced the unanswered question "${r.replaced}".` : '',
274
+ ].filter(Boolean).join(' ')
275
+ + (r.dropped.length ? `\n[arguments] These markers are not in the current figure's vocabulary and were skipped: ${r.dropped.join(', ')}.` : ''),
276
+
277
+ imagesShown: (n, chatOpen) => `${n} image${n > 1 ? 's' : ''} shown on the chat page${chatOpen ? '' : ', which is not open right now'}.`,
278
+ shownImage: (i, total) => `[image ${i}/${total} shown on the chat page]`,
279
+ imagesNotHandles: '[speed_pet_say not run] images takes an array of attachment handles.',
280
+ tooManyImages: (max) => `[speed_pet_say not run] images takes at most ${max} handles.`,
281
+ imageMissing: (handle) => `[speed_pet_say not run] No attachment ${handle}. Put the handle that starts a [blob …] line in your context into images.`,
282
+ imageNotImage: (handle, mime) => `[speed_pet_say not run] ${handle} is ${mime}, not an image.`,
283
+
284
+ askEmpty: '[speed_pet_ask not run] question is empty.',
285
+ askNoWay: '[speed_pet_ask not run] No options and no own answer allowed, so there is no way to answer.',
286
+ askReceipt: (r) => [
287
+ 'Asked.',
288
+ r.replaced !== null ? `Replaced the previous unanswered question "${r.replaced}".` : '',
289
+ r.cut ? 'Only the first 3 options are shown.' : '',
290
+ r.chatOpen ? 'The chat page is open and shows the question too; it can be answered in either place.' : '',
291
+ 'The answer will arrive as an [answer] event.',
292
+ ].filter(Boolean).join(' '),
293
+
294
+ selfAdjustOff: (tool, user) => `[${tool} not run] ${user} set "Self-adjustment" to "Off" on the Habits page.`,
295
+ setErrors: (errors) => `[speed_pet_set not run] ${errors.join('; ')}.`,
296
+ setNothing: 'Everything asked for is already so; nothing changed.',
297
+ setDone: (says) => `Changed: ${says.join('; ')}.`,
298
+ setAgreed: (user, says) => `${user} agreed; changed: ${says.join('; ')}.`,
299
+ setAlways: (user, says, items) => `${user} agreed; changed: ${says.join('; ')}. ${user} also said there is no need to ask about ${items.join(', ')} again: change ${items.length > 1 ? 'them' : 'it'} directly from now on.`,
300
+ setNotChanged: (why, user, says) =>
301
+ `${why === 'unavailable' ? 'The pet window is not connected, so there was no way to ask' : why === 'timeout' ? `${user} did not answer` : `${user} said no`}; not changed: ${says.join('; ')}.`,
302
+
303
+ quietBad: (max) => `[speed_pet_quiet not run] minutes must be a number from 0 to ${max}.`,
304
+ quietNone: 'Not keeping quiet right now.',
305
+ quietEnded: 'Quiet ended; sound effects and walking are back as the settings have them.',
306
+ quietUntil: (time, sound, roam) => `Quiet until ${time}: sound effects ${sound ? 'as usual' : 'off'}, walking ${roam}. The settings are unchanged and come back on their own then.`,
307
+
308
+ actNone: (dropped) => `[speed_pet_act not run] None of these are in the current figure's vocabulary${dropped.length ? ` (${dropped.join(', ')})` : ''}.`,
309
+ actReceipt: (actions, lasting, dropped) => `Doing in order: ${actions.join(' → ')}.`
310
+ + (lasting.length ? ` ${lasting.join(', ')} ${lasting.length > 1 ? 'are' : 'is'} held until the next action.` : '')
311
+ + (dropped.length ? `\n[arguments] Not in the current figure's vocabulary, skipped: ${dropped.join(', ')}.` : ''),
312
+
313
+ selfSeen: (width, height, body) => `The picture attached is you as drawn on screen at the time of this call, ${width}×${height} px: the body alone, on a grey backdrop that is not the desktop, with no bubbles in it. Figure and dress: ${body}.`,
314
+ selfFallback: (width, height) => `how you looked then ${width}×${height}`,
315
+ selfNot: (why, seconds) => `[speed_pet_see_self not run] ${{
316
+ tab: 'The pet is shown in a browser page, which gives no picture.',
317
+ hidden: 'The pet window is hidden, so the body is not drawn.',
318
+ 'no-body': 'No figure is on screen yet.',
319
+ capture: 'The pet window gave no picture.',
320
+ timeout: `The pet window did not hand back a picture within ${seconds} seconds.`,
321
+ gone: 'The pet window disconnected.',
322
+ }[why]}`,
323
+
324
+ on: 'on',
325
+ off: 'off',
326
+ settingNames: {
327
+ figure: 'figure', scheme: 'dress (scheme)', roam: 'walking (roam)', snoreSeconds: 'snoring time (snoreSeconds)', sound: 'sound effects (sound)',
328
+ scale: 'size (scale)', bubbleSize: 'bubble size (bubbleSize)', fontSize: 'text size (fontSize)', theme: 'night or day look (theme)', hoverButtons: 'hover buttons (hoverButtons)', user: 'what you call them (user)',
329
+ },
330
+ selfTiers: (user, direct, asked) => (!asked.length ? 'Right now all of these take effect at once.'
331
+ : !direct.length ? `Right now all of these are first asked of ${user} in a bubble.`
332
+ : `Right now these take effect at once: ${direct.join(', ')}; these are first asked of ${user} in a bubble: ${asked.join(', ')}.`),
333
+ selfNone: (user) => `${user} set "Self-adjustment" to "Off" on the Habits page, so right now you can change none of these, and \`speed_pet_quiet\` does not work either.`,
334
+ // the English template puts these right after a sentence, so they start with a space
335
+ chatPage: (user) => ` The app's Chat page lists these bubbles in time order, with what ${user} said and the names of the tools you called between two lines; ${user} can also type and send images there (they arrive as \`[typed]\` events too, images after the text) and answer \`speed_pet_ask\`. The \`images\` of \`speed_pet_say\` show only on the Chat page, not in the bubble.`,
336
+ cuaOff: (user, canOpen) => `## Computer use\n\nComputer use is off: you cannot see the screen or use the mouse and keyboard. When ${user} wants you to look at the screen or help operate the computer, you can suggest turning it on: the Computer use section of the Habits page in the settings window, which explains the risks before it turns on.` +
337
+ (canOpen ? ` If ${user} agrees to turn it on, \`speed_pet_cua_open_settings\` opens the settings window right there.` : ''),
338
+ cuaSettingsOpened: (user) => `The settings window is open at Computer use, showing what it risks; once ${user} clicks to turn it on, the computer-use tools are yours from the next message.`,
339
+ reply: (user, language) => ` Talk to ${user} in ${language}: bubbles, questions and options alike.`,
340
+ };
341
+
342
+ export type ModelText = typeof zh;
343
+
344
+ export const MODEL_TEXT: Record<ModelLanguage, ModelText> = { zh, en };
package/src/moves.ts ADDED
@@ -0,0 +1,101 @@
1
+ /**
2
+ * The targets `speed_pet_move_to` takes. Every figure that walks has the default ones: a share of the width of
3
+ * the screen the pet is on, or left / center / right / cursor. A pack may declare more (`moves` in its
4
+ * figure.json, src/packs.ts): a call to one of them is checked against the declaration here, then goes to
5
+ * the body as it is (`body.move` in web/figure-frame.js), which decides where that is and how it gets there.
6
+ *
7
+ * The tool's parameters stay the same whatever pack is on, so changing figures leaves the tool list as it is;
8
+ * the bot learns a pack's targets from the environment prompt (`moveTable`) and how they changed from the
9
+ * figure events and receipts (`moveChange`).
10
+ */
11
+ import type { ModelLanguage } from './model-text.ts';
12
+ import { nameIn, type MoveParam, type MoveTarget } from './packs.ts';
13
+
14
+ /** Where the default targets are, as a share of the screen's width; `cursor` is the mouse pointer's x. */
15
+ const NAMED: Record<string, number | 'cursor'> = { left: .05, center: .5, right: .95, cursor: 'cursor' };
16
+
17
+ export type MoveOrder =
18
+ /** A default target: the page walks the body there. */
19
+ | { kind: 'walk'; to: number | 'cursor'; run: boolean }
20
+ /** One of the pack's targets: what the body gets, the params named by their ids. */
21
+ | { kind: 'move'; target: MoveTarget; to: string; run: boolean; params: Record<string, number> }
22
+ /** `noTarget`: no `to`; `badTarget`: neither a default target nor one of the pack's; `badParams`: params the target does not take. */
23
+ | { kind: 'noTarget' }
24
+ | { kind: 'badTarget'; got: string }
25
+ | { kind: 'badParams'; target: MoveTarget | null; got: string };
26
+
27
+ /** A `speed_pet_move_to` call read against the targets `moves` of the pack on screen. */
28
+ export function readMove(args: Record<string, unknown>, moves: readonly MoveTarget[]): MoveOrder {
29
+ const run = args.run === true;
30
+ const { to, params } = args;
31
+ const none = params === undefined || params === null || (Array.isArray(params) && params.length === 0);
32
+ if (typeof to === 'number' && Number.isFinite(to)) return none ? { kind: 'walk', to: Math.max(0, Math.min(1, to)), run } : { kind: 'badParams', target: null, got: JSON.stringify(params) };
33
+ if (typeof to !== 'string') return { kind: 'noTarget' };
34
+ const n = Number(to);
35
+ if (to in NAMED || (to.trim() !== '' && Number.isFinite(n))) {
36
+ if (!none) return { kind: 'badParams', target: null, got: JSON.stringify(params) };
37
+ return { kind: 'walk', to: to in NAMED ? NAMED[to]! : Math.max(0, Math.min(1, n)), run };
38
+ }
39
+ const target = moves.find((m) => m.id === to || Object.values(m.name).includes(to));
40
+ if (!target) return { kind: 'badTarget', got: JSON.stringify(to) };
41
+ const named = paramsOf(params, target.params);
42
+ return named ? { kind: 'move', target, to: target.id, run, params: named } : { kind: 'badParams', target, got: JSON.stringify(params) };
43
+ }
44
+
45
+ /**
46
+ * `raw` as the target's numbers by id, or null when it gives one the target does not take or one out of its range.
47
+ * The tool takes them in the declared order; an object keyed by the ids is read too. Numbers left out stay out.
48
+ */
49
+ function paramsOf(raw: unknown, spec: readonly MoveParam[]): Record<string, number> | null {
50
+ if (raw === undefined || raw === null) return {};
51
+ const pairs: Array<[MoveParam | undefined, unknown]> = Array.isArray(raw) ? raw.map((v, i) => [spec[i], v])
52
+ : typeof raw === 'object' ? Object.entries(raw).map(([k, v]) => [spec.find((p) => p.id === k), v]) : [[undefined, raw]];
53
+ const out: Record<string, number> = {};
54
+ for (const [p, v] of pairs) {
55
+ if (!p || typeof v !== 'number' || !(v >= p.min && v <= p.max)) return null;
56
+ out[p.id] = v;
57
+ }
58
+ return out;
59
+ }
60
+
61
+ const MOVE_TEXT = {
62
+ zh: {
63
+ intro: '现在的形象还能去下面这些地方:`to` 写目标,带数值的按顺序写进 `params`,不写的由形象自己定。',
64
+ head: '| 目标 | 去哪、怎么去 | params |\n|---|---|---|\n',
65
+ row: (m: MoveTarget) => `| ${m.id}(${nameIn(m.name, 'zh')}) | ${nameIn(m.about, 'zh')} | ${m.params.map((p) => `${p.id}:${p.min}–${p.max},${nameIn(p.about, 'zh')}`).join(';') || '无'} |`,
66
+ changed: '能去的地方变了。',
67
+ gone: (list: readonly MoveTarget[]) => `这些去不了了:${list.map((m) => `${m.id}(${nameIn(m.name, 'zh')})`).join('、')}。`,
68
+ fresh: '新增或说明变了的:',
69
+ },
70
+ en: {
71
+ intro: 'The current figure can also go to these places: give the target as `to` and its numbers, in order, as `params`; the figure picks any left out.',
72
+ head: '| target | where and how | params |\n|---|---|---|\n',
73
+ row: (m: MoveTarget) => `| ${[m.id, ...(m.name.en ? [m.name.en] : [])].join(' / ')} | ${nameIn(m.about, 'en')} | ${m.params.map((p) => `${p.id}: ${p.min}–${p.max}, ${nameIn(p.about, 'en')}`).join('; ') || '—'} |`,
74
+ changed: 'The places you can go changed.',
75
+ gone: (list: readonly MoveTarget[]) => ` These no longer work: ${list.map((m) => m.id).join(', ')}.`,
76
+ fresh: ' New or changed:',
77
+ },
78
+ } satisfies Record<ModelLanguage, unknown>;
79
+
80
+ /** The pack's targets as the bot's prompt shows them, or '' when it declares none. */
81
+ export function moveTable(moves: readonly MoveTarget[], language: ModelLanguage = 'zh'): string {
82
+ const t = MOVE_TEXT[language];
83
+ return moves.length ? `${t.intro}\n\n${t.head}${moves.map(t.row).join('\n')}` : '';
84
+ }
85
+
86
+ /**
87
+ * How the targets went from `before` to `after`, for the bot, as `vocabChange` tells the words: the whole table
88
+ * when there were none before, '' when the bot would see the same table.
89
+ */
90
+ export function moveChange(before: readonly MoveTarget[], after: readonly MoveTarget[], language: ModelLanguage = 'zh'): string {
91
+ if (!before.length) return moveTable(after, language);
92
+ const t = MOVE_TEXT[language];
93
+ const told = new Map(before.map((m) => [m.id, t.row(m)]));
94
+ const gone = before.filter((m) => !after.some((a) => a.id === m.id));
95
+ const fresh = after.filter((m) => told.get(m.id) !== t.row(m));
96
+ if (!gone.length && !fresh.length) return '';
97
+ let line = t.changed;
98
+ if (gone.length) line += t.gone(gone);
99
+ if (!fresh.length) return line;
100
+ return `${line}${t.fresh}\n\n${t.head}${fresh.map(t.row).join('\n')}`;
101
+ }