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/renderer/pet.js DELETED
@@ -1,251 +0,0 @@
1
- const api = window.agentSpeed;
2
- const stage = document.querySelector('#stage');
3
- const card = document.querySelector('#card');
4
- const title = document.querySelector('#card-title');
5
- const notice = document.querySelector('#notice');
6
- const importButton = document.querySelector('#import');
7
- const menuButton = document.querySelector('#menu');
8
- const dark = matchMedia('(prefers-color-scheme: dark)');
9
- const reducedMotion = matchMedia('(prefers-reduced-motion: reduce)');
10
- const FRESH_MS = 5000;
11
- const loadTime = 20_000;
12
- const noSample = { kind: 'idle', rate: 0, deadline: 0 };
13
- const finite = Number.isFinite;
14
- const clamp = (value, low, high) => Math.min(high, Math.max(low, value));
15
- let currentPack = null, mounted = null, movingUntil = 0, localHold = 0;
16
- let activity = noSample, sampledAt = 0, haveActivity = false;
17
-
18
- function bounds() {
19
- const W = stage.clientWidth, H = stage.clientHeight;
20
- return { W, H, floorY: Math.max(0, H - 18), S: Math.min(W * .60, H * .59) / 256 };
21
- }
22
-
23
- function chooseScheme({ axes, presets }) {
24
- return presets?.[0]?.id ?? (axes ?? []).map((axis) => axis.options[0].id).join('-');
25
- }
26
-
27
- function readLayout(raw, size) {
28
- const b = raw?.box;
29
- if (!b || ![b.x, b.y, b.w, b.h].every(finite)) return null;
30
- const maxSide = size.S * 256 * 1.5 * Math.SQRT2;
31
- const x = clamp(b.x, 0, size.W), y = clamp(b.y, 0, size.H);
32
- const right = clamp(b.x + clamp(b.w, 0, maxSide), x, size.W);
33
- const bottom = clamp(b.y + clamp(b.h, 0, maxSide), y, size.H);
34
- const hit = Array.isArray(raw.hit) ? raw.hit.slice(0, 32).filter((c) => c &&
35
- [c.x, c.y, c.r].every(finite) && c.r > 0 && c.r <= maxSide) : [];
36
- return { x, y, right, bottom, hit, cursor: raw.cursor === 'grabbing' ? 'grabbing' : 'grab' };
37
- }
38
-
39
- function hit(layout, point) {
40
- return layout && point.x >= layout.x && point.x < layout.right && point.y >= layout.y && point.y < layout.bottom &&
41
- (layout.hit.length === 0 || layout.hit.some((circle) => Math.hypot(point.x - circle.x, point.y - circle.y) <= circle.r));
42
- }
43
-
44
- function showCard(heading, message, button = 'Import figure pack…') {
45
- title.textContent = heading;
46
- notice.textContent = message;
47
- importButton.textContent = button;
48
- card.hidden = false;
49
- }
50
-
51
- function mount(pack) {
52
- const { manifest } = pack;
53
- const iframe = document.createElement('iframe');
54
- iframe.className = 'figure-frame';
55
- iframe.setAttribute('sandbox', 'allow-scripts');
56
- iframe.setAttribute('aria-hidden', 'true');
57
- iframe.tabIndex = -1;
58
- iframe.src = pack.frameUrl;
59
- const base = new URL('./files/', pack.frameUrl).href;
60
- let closed = false, initialized = false, ready = false, pendingTick = false, visible = false;
61
- let size = bounds(), layout = null, request = 0, lastTick = 0;
62
- let pointerId = null, lastPoint = null, tracking = false;
63
- let windowX = window.screenX, windowY = window.screenY;
64
- const post = (m) => { if (!closed) iframe.contentWindow?.postMessage(m, '*'); };
65
- const listeners = new AbortController();
66
- const { signal } = listeners;
67
- const sendActivity = (value, finish = false) => post({
68
- t: 'activity', value: { ...value, finish, reduced: reducedMotion.matches },
69
- });
70
- const timer = setTimeout(() => fail('The figure did not draw. Check that the pack contains its scripts and model assets.'), loadTime);
71
- const observer = new ResizeObserver(() => {
72
- size = bounds();
73
- if (initialized) post({ t: 'set', state: { bounds: size } });
74
- });
75
-
76
- function close() {
77
- if (closed) return;
78
- closed = true;
79
- releaseCapture();
80
- stage.style.cursor = '';
81
- listeners.abort();
82
- observer.disconnect();
83
- clearTimeout(timer);
84
- cancelAnimationFrame(request);
85
- iframe.remove();
86
- }
87
-
88
- function fail(message) {
89
- close();
90
- showCard('Could not load this figure', message, 'Choose a figure pack…');
91
- }
92
-
93
- function render(now) {
94
- request = requestAnimationFrame(render);
95
- if (pendingTick || !ready) return;
96
- const dt = lastTick ? Math.min((now - lastTick) / 1000, .05) : 1 / 60;
97
- lastTick = now;
98
- pendingTick = true;
99
- if (window.screenX !== windowX || window.screenY !== windowY) {
100
- windowX = window.screenX;
101
- windowY = window.screenY;
102
- localHold = Math.max(localHold, now + 250);
103
- }
104
- post({ t: 'tick', dt, draw: true, windowMoving: Date.now() < movingUntil || now < localHold });
105
- }
106
-
107
- function onMessage(event) {
108
- if (event.source !== iframe.contentWindow || event.origin !== 'null') return;
109
- const m = event.data;
110
- if (m?.t === 'loaded' && !initialized) {
111
- initialized = true;
112
- const modelPath = manifest.model?.split('/').map(encodeURIComponent).join('/');
113
- post({
114
- t: 'init', entry: pack.entryUrl, export: manifest.export, base, modelPath,
115
- scheme: chooseScheme(manifest), start: { x: size.W / 2, facing: 1 },
116
- theme: dark.matches ? 'dark' : 'light', bounds: size,
117
- vocabulary: { vocab: manifest.vocab, canWalk: manifest.can?.walk },
118
- });
119
- } else if (m?.t === 'ready' && initialized && !ready) {
120
- ready = true;
121
- sendActivity(activity);
122
- request = requestAnimationFrame(render);
123
- } else if (m?.t === 'frame' && pendingTick) {
124
- pendingTick = false;
125
- layout = readLayout(m.layout, size);
126
- if (!visible) {
127
- visible = true;
128
- clearTimeout(timer);
129
- card.hidden = true;
130
- }
131
- } else if (m?.t === 'error') {
132
- fail(typeof m.message === 'string' && m.message.trim() ? m.message.slice(0, 300) : 'The figure pack stopped before it could draw.');
133
- }
134
- }
135
-
136
- function position(event) {
137
- const rect = stage.getBoundingClientRect();
138
- // During carry allow the input to follow the pointer outside the pet's immediate outline.
139
- return { x: clamp(event.clientX - rect.left, -size.W, 2 * size.W),
140
- y: clamp(event.clientY - rect.top, -size.H, 2 * size.H), t: performance.now() };
141
- }
142
- function pointer(type, p) { post({ t: 'pointer', type, p }); }
143
- function leave() {
144
- if (tracking) pointer('leave', lastPoint);
145
- tracking = false;
146
- stage.style.cursor = '';
147
- }
148
- function releaseCapture() {
149
- const id = pointerId;
150
- pointerId = null;
151
- if (id !== null && stage.hasPointerCapture(id)) stage.releasePointerCapture(id);
152
- }
153
- function endPointer(event) {
154
- if (!event.isTrusted || pointerId !== event.pointerId) return;
155
- if (event.type === 'pointerup') lastPoint = position(event);
156
- pointer(event.type === 'pointerup' ? 'up' : 'cancel', lastPoint);
157
- releaseCapture();
158
- if (!hit(layout, lastPoint)) leave();
159
- }
160
-
161
- addEventListener('message', onMessage, { signal });
162
- dark.addEventListener('change', () => post({ t: 'set', state: { theme: dark.matches ? 'dark' : 'light' } }), { signal });
163
- reducedMotion.addEventListener('change', () => { if (ready) sendActivity(activity); }, { signal });
164
- stage.addEventListener('pointerdown', (event) => {
165
- if (!event.isTrusted || event.button !== 0 || pointerId !== null || !ready) return;
166
- const p = position(event);
167
- if (!hit(layout, p)) return;
168
- tracking = true;
169
- lastPoint = p;
170
- pointerId = event.pointerId;
171
- stage.setPointerCapture(pointerId);
172
- pointer('down', p);
173
- }, { signal });
174
- stage.addEventListener('pointermove', (event) => {
175
- if (!event.isTrusted || !ready || (pointerId !== null && pointerId !== event.pointerId)) return;
176
- const p = position(event);
177
- if (pointerId === null && !hit(layout, p)) { leave(); return; }
178
- tracking = true;
179
- lastPoint = p;
180
- stage.style.cursor = pointerId === null ? layout.cursor : 'grabbing';
181
- pointer('move', p);
182
- }, { signal });
183
- for (const type of ['pointerup', 'pointercancel', 'lostpointercapture']) stage.addEventListener(type, endPointer, { signal });
184
- stage.addEventListener('pointerleave', () => { if (pointerId === null) leave(); }, { signal });
185
- addEventListener('blur', () => {
186
- if (pointerId !== null) pointer('cancel', lastPoint);
187
- releaseCapture();
188
- leave();
189
- }, { signal });
190
- observer.observe(stage);
191
- stage.append(iframe);
192
- return { close, activity: (value, finish) => { if (ready) sendActivity(value, finish); } };
193
- }
194
-
195
- function applySnapshot(snapshot) {
196
- const now = Date.now();
197
- const stamped = snapshot?.updatedAtMs;
198
- const valid = snapshot?.version === 1 && Number.isSafeInteger(stamped) && stamped <= now && now - stamped < FRESH_MS &&
199
- Number.isSafeInteger(snapshot.generating) && snapshot.generating >= 0 && Number.isSafeInteger(snapshot.tools) && snapshot.tools >= 0 &&
200
- finite(snapshot.outputPerSecond) && snapshot.outputPerSecond >= 0;
201
- if (valid && haveActivity && stamped <= sampledAt) return;
202
- if (!valid && !haveActivity) return;
203
- const previous = activity;
204
- haveActivity = valid;
205
- sampledAt = valid ? stamped : 0;
206
- activity = valid ? {
207
- kind: snapshot.generating ? 'output' : snapshot.tools ? 'tools' : 'idle',
208
- rate: snapshot.outputPerSecond, deadline: stamped + FRESH_MS,
209
- } : noSample;
210
- const finish = previous.kind !== 'idle' && previous.deadline >= now && activity.kind === 'idle' &&
211
- valid && snapshot.complete === true;
212
- mounted?.activity(activity, finish);
213
- }
214
-
215
- function applyState({ pack = null, snapshot = null, movingUntil: moving = 0 } = {}) {
216
- movingUntil = finite(moving) ? moving : 0;
217
- applySnapshot(snapshot);
218
- if (pack?.id === currentPack?.id) return;
219
- mounted?.close();
220
- mounted = null;
221
- currentPack = pack;
222
- if (!pack) {
223
- showCard('Bring a desktop pet', 'Import a Coopanion API 2 figure pack to get started.');
224
- return;
225
- }
226
- showCard('Loading figure…', `${pack.name} is getting ready.`, 'Choose a figure pack…');
227
- mounted = mount(pack);
228
- }
229
-
230
- async function openMenu() {
231
- localHold = performance.now() + 800;
232
- try { await api.openMenu(); }
233
- catch {
234
- if (currentPack && !card.hidden) showCard('Could not open figure packs', 'Try opening the Packs menu again.', 'Choose a figure pack…');
235
- else if (!currentPack) showCard('Bring a desktop pet', 'Could not open the import menu. Try again.');
236
- }
237
- }
238
-
239
- if (api) {
240
- importButton.addEventListener('click', openMenu);
241
- menuButton.addEventListener('click', openMenu);
242
- let received = false;
243
- const unsubscribe = api.onState((state) => { received = true; applyState(state); });
244
- api.getState().then((state) => { if (!received) applyState(state); }).catch(() => {
245
- if (!received) showCard('Could not load figure packs', 'Open the import menu to select a figure pack.');
246
- });
247
- addEventListener('pagehide', () => { unsubscribe?.(); mounted?.close(); }, { once: true });
248
- } else {
249
- showCard('Desktop host unavailable', 'Open this pet from the Agent Speed plugin.');
250
- importButton.disabled = menuButton.disabled = true;
251
- }
@@ -1,101 +0,0 @@
1
- // Agent Speed: translate one live speed target into an additive animation layer.
2
- const clamp = (value, low, high) => Math.min(high, Math.max(low, value));
3
- const TAU = 2 * Math.PI;
4
- const TIERS = [
5
- { face: ['thinking', 'curious', 'content', 'focused', 'smile'], gesture: ['nod', 'look', 'sway'] },
6
- { face: ['happy', 'smile', 'content', 'focused', 'thinking'], gesture: ['nod', 'wave', 'look', 'sway'] },
7
- { face: ['excited', 'happy', 'grin', 'surprised', 'content'], gesture: ['wave', 'dance', 'cheer', 'nod'] },
8
- ];
9
- const FOCUS = { face: ['thinking', 'focused', 'curious', 'content'], gesture: ['look', 'nod'] };
10
- const FINISH = { face: ['happy', 'content', 'wink'], gesture: ['bow', 'nod', 'wave'] };
11
- const INTERACTION_MODES = new Set(['drag', 'air', 'land', 'crouch', 'dizzy']);
12
-
13
- function selectWords(vocab, reported, canWalk) {
14
- const runtime = Array.isArray(reported) ? new Set(reported) : null;
15
- const words = vocab.filter((word) => word && typeof word.id === 'string' && (!runtime || runtime.has(word.id)) &&
16
- !(canWalk === false && (word.id === 'walk' || word.id === 'run')));
17
- const aliases = new Map(words.map((word) => [word, [word.id, ...(word.names?.en ?? [])]
18
- .map((label) => String(label).toLowerCase().replace(/[^a-z0-9]/g, ''))]));
19
- const pick = (kind, choices) => {
20
- for (const choice of choices) {
21
- // Canonical IDs win over names, and indefinite words are not safe ambient cues.
22
- const match = words.find((word) => !word.lasting && word.kind === kind && word.id === choice) ??
23
- words.find((word) => !word.lasting && word.kind === kind && aliases.get(word).includes(choice));
24
- if (match) return match;
25
- }
26
- return null;
27
- };
28
- const profile = (p) => ({ face: pick('expression', p.face), gesture: pick('motion', p.gesture) });
29
- return { tiers: TIERS.map(profile), focus: profile(FOCUS), finish: profile(FINISH) };
30
- }
31
-
32
- export function createActivityMotion(manifest, reported, kitBody) {
33
- const words = selectWords(manifest.vocab, reported, manifest.canWalk);
34
- let kind = 'idle', target = 0, energy = 0, focus = 0, phase = 0, gesturePhase = 0, tier = 0;
35
- let nextCue = 0, cueUntil = 0, cueCount = 0, heldUntil = 0, clock = 0, grabbed = false, gestureWord = null;
36
- let finish = false, deadline = 0, initialized = false;
37
- let reduced = false;
38
- return {
39
- sample(packet) {
40
- const next = packet?.kind === 'output' || packet?.kind === 'tools' || packet?.kind === 'idle' ? packet.kind : 'idle';
41
- // Edges only: no gesture queues, and a disconnect/stale sample is never a completion.
42
- finish = next === 'idle' && Boolean(packet?.finish);
43
- if (next !== kind) nextCue = clock + .2;
44
- kind = next;
45
- deadline = Number.isFinite(packet?.deadline) ? packet.deadline : 0;
46
- reduced = packet?.reduced === true;
47
- const rate = Number.isFinite(packet?.rate) ? clamp(packet.rate, 0, 240) : 0;
48
- target = kind === 'output' ? .18 + .82 * Math.log1p(rate / 45) / Math.log1p(240 / 45) : 0;
49
- },
50
- pointer(type) {
51
- if (type === 'down') grabbed = true;
52
- if (type === 'up' || type === 'cancel') grabbed = false;
53
- if (type !== 'leave') heldUntil = clock + (type === 'move' && !grabbed ? .20 : .65);
54
- },
55
- advance(dt, layout, moving, body) {
56
- if (Date.now() > deadline) { kind = 'idle'; target = 0; finish = false; }
57
- clock += dt;
58
- const interaction = moving || grabbed || clock < heldUntil || layout?.pressing === true || layout?.busy === true ||
59
- INTERACTION_MODES.has(layout?.mode);
60
- const effort = interaction || reduced ? 0 : target;
61
- const attention = kind === 'tools' && !interaction ? 1 : 0;
62
- energy += (effort - energy) * (1 - Math.exp(-dt * (effort > energy ? 5.2 : 3.8)));
63
- focus += (attention - focus) * (1 - Math.exp(-dt * 5));
64
- if (energy < .002) energy = 0;
65
- if (focus < .002) focus = 0;
66
- phase = (phase + dt * TAU * (.85 + 2.35 * energy)) % TAU;
67
- if (energy > (tier === 0 ? .49 : .73) && tier < 2) tier++;
68
- else if (energy < (tier === 2 ? .66 : .42) && tier > 0) tier--;
69
- const nextPhase = gesturePhase + dt * (.21 + .33 * energy);
70
- if (nextPhase >= 1) gestureWord = kind === 'output' && energy > .35 ? words.tiers[tier].gesture : null;
71
- gesturePhase = nextPhase % 1;
72
- const profile = kind === 'tools' ? words.focus : words.tiers[tier];
73
- const talking = !interaction && (kind === 'output' || kind === 'tools');
74
- const isResting = !layout?.moving && !layout?.busy;
75
- if (interaction || reduced || kind !== 'output') gestureWord = null;
76
- const gesture = gestureWord && gesturePhase < .65 ? { kind: gestureWord.id, k: gesturePhase / .65 } : null;
77
- // Kit bodies consume continuous pose/gaze channels; independent bodies can use their own
78
- // finite words. Both contracts receive a smoothly integrated clock, never a restarted clip.
79
- if (!interaction && isResting && initialized) {
80
- if (finish && !reduced) {
81
- const word = words.finish.gesture ?? words.finish.face;
82
- if (word) body.do(word.id);
83
- } else if (!kitBody && talking && !reduced && clock >= Math.max(nextCue, cueUntil)) {
84
- const prefersGesture = kind === 'output' && energy > .35 && cueCount++ % 2 === 1;
85
- const candidates = prefersGesture ? [profile.gesture, profile.face] : [profile.face, profile.gesture];
86
- const word = candidates.find((entry) => entry && entry.seconds <= 4.8);
87
- if (word) body.do(word.id);
88
- cueUntil = clock + (word?.seconds ?? 0);
89
- nextCue = clock + 3.1 - energy * .8;
90
- }
91
- }
92
- finish = false;
93
- initialized = true;
94
- return {
95
- kind, phase, energy: interaction ? 0 : energy, focus: interaction ? 0 : focus, gesture,
96
- face: talking ? profile.face?.id ?? null : null,
97
- tempo: interaction ? 1 : 1 + 1.06 * energy,
98
- };
99
- },
100
- };
101
- }
@@ -1,115 +0,0 @@
1
- // SPDX-License-Identifier: AGPL-3.0-or-later
2
- // Modified for Agent Speed (2026-11-26): standalone opaque pack frame, local model loading and activity drive.
3
- /**
4
- * Inside the opaque sandbox: load the selected API 2 module and call its factory as
5
- * `factory(base, { model, scheme, kit, loadImage, asset, host })`. Model JSON and
6
- * other assets come from the pack's own root, under the host's CSP.
7
- *
8
- * The body owns its drawing and exposes `step(dt, draw)`, `layout()` and `do(word)`;
9
- * kit bodies add movement, expressions, pointer interactions and lifecycle calls.
10
- * The shell drives this frame by postMessage, with at most one tick in flight.
11
- * No workstation, network or model/chat API is passed into the factory.
12
- */
13
- import * as kit from './kit/body.js';
14
- import { createActivityMotion } from './activity-motion.js';
15
-
16
- const root = document.getElementById('root');
17
- let body = null, dead = false, bounds = { W: 0, H: 0, floorY: 0, S: .42 }, desk = null;
18
- let loading = false, motion = null, layout = null;
19
- /** The stage's size from the page, with the windows when there are any. */
20
- const setBounds = (b) => { bounds = desk ? { ...b, ...desk } : { ...b }; };
21
- let events = [], sounds = [];
22
- const post = (m) => parent.postMessage(m, '*');
23
- function fail(err) {
24
- if (dead) return;
25
- dead = true;
26
- post({ t: 'error', message: String(err?.message ?? err).slice(0, 300) });
27
- }
28
- addEventListener('error', (e) => fail(e.error ?? e.message));
29
- addEventListener('unhandledrejection', (e) => fail(e.reason));
30
-
31
- function loadImage(url) {
32
- return new Promise((ok, bad) => {
33
- const im = new Image();
34
- im.crossOrigin = 'anonymous';
35
- im.onload = () => ok(im);
36
- im.onerror = () => bad(new Error(`An image did not load: ${url}`));
37
- im.src = String(url);
38
- });
39
- }
40
-
41
- const host = {
42
- root,
43
- bounds: () => bounds,
44
- emit: (kind, detail) => { if (events.length < 32) events.push({ kind, detail }); },
45
- sound: (name, kind, ...args) => { if (sounds.length < 32) sounds.push({ name, kind, args }); },
46
- };
47
-
48
- addEventListener('message', async (e) => {
49
- if (e.source !== parent || dead) return;
50
- const m = e.data || {};
51
- try {
52
- if (m.t === 'windows') {
53
- desk = Array.isArray(m.ledges) && Array.isArray(m.windows) ? { ledges: m.ledges, windows: m.windows } : null;
54
- const { ledges: _l, windows: _w, ...b } = bounds;
55
- setBounds(b);
56
- } else if (m.t === 'init' && !loading) {
57
- loading = true;
58
- setBounds(m.bounds);
59
- document.documentElement.dataset.theme = m.theme;
60
- const base = new URL(m.base);
61
- let model;
62
- if (m.modelPath) {
63
- const response = await fetch(new URL(m.modelPath, base), { credentials: 'omit' });
64
- if (!response.ok) throw new Error(`The pack model could not be read (${response.status}).`);
65
- model = await response.json();
66
- }
67
- const mod = await import(m.entry);
68
- const make = mod[m.export];
69
- if (typeof make !== 'function') throw new Error(`The pack export ${m.export} is not a function.`);
70
- body = await make(base, { model, scheme: m.scheme, kit, loadImage, asset: (p) => new URL(p, base), host: { ...host, start: m.start } });
71
- for (const fn of ['step', 'layout', 'do']) if (typeof body?.[fn] !== 'function') throw new Error(`The figure has no ${fn} method.`);
72
- const words = Array.isArray(body.words) ? body.words.filter((w) => typeof w === 'string') : null;
73
- motion = createActivityMotion(m.vocabulary, words, typeof body[kit.activityLayer] === 'function');
74
- post({ t: 'ready', z: body.z ?? null, words });
75
- } else if (!body) {
76
- // calls that come before the body is ready have nothing to act on
77
- } else if (m.t === 'activity') motion.sample(m.value);
78
- else if (m.t === 'tick') {
79
- const dt = Math.max(0, Math.min(.05, m.dt || 0));
80
- const activity = motion.advance(dt, layout, m.windowMoving === true, body);
81
- body[kit.activityLayer]?.(activity);
82
- const simDt = dt * activity.tempo;
83
- // Keep the official springs stable after scheduling gaps and at high tempos.
84
- const steps = Math.max(1, Math.ceil(simDt / (1 / 45)));
85
- for (let i = 1; i <= steps; i++) body.step(simDt / steps, i === steps && m.draw);
86
- layout = body.layout();
87
- post({ t: 'frame', layout, events, sounds, z: body.z ?? null });
88
- events = []; sounds = [];
89
- } else if (m.t === 'scheme') {
90
- // the fade starts at the body's next frame: the page's clock is not the body's
91
- await body.setScheme?.(m.id, { fade: m.fade });
92
- post({ t: 'scheme', seq: m.seq, z: body.z ?? null });
93
- } else if (m.t === 'do') body.do(m.word);
94
- else if (m.t === 'walk') { if (!body.walk?.(m.x, m.run, m.id)) events.push({ kind: 'interrupted', detail: { walkId: m.id, by: 'busy' } }); }
95
- else if (m.t === 'move') { if (!body.move?.(m.args, m.id)) events.push({ kind: 'interrupted', detail: { walkId: m.id, by: 'busy' } }); }
96
- else if (m.t === 'stop-walk') body.stopWalk?.(m.id);
97
- else if (m.t === 'pointer') {
98
- motion.pointer(m.type);
99
- body.pointer?.(m.type, m.p);
100
- }
101
- else if (m.t === 'drop') body.drop?.(m.p);
102
- else if (m.t === 'shift') body.shift?.(m.dx, m.dy);
103
- else if (m.t === 'place') body.place?.(m.x, m.facing, m.y);
104
- else if (m.t === 'set') {
105
- if (m.state?.bounds) { setBounds(m.state.bounds); body.resize?.(); }
106
- body.set?.(m.state);
107
- }
108
- else if (m.t === 'cue') body.cue?.(m.kind);
109
- else if (m.t === 'talk') body.talk?.();
110
- } catch (err) {
111
- fail(err);
112
- }
113
- });
114
- addEventListener('pagehide', () => body?.dispose?.(), { once: true });
115
- post({ t: 'loaded' });
@@ -1,2 +0,0 @@
1
- html, body { margin: 0; height: 100%; background: transparent; overflow: hidden; }
2
- #root { position: absolute; inset: 0; }
File without changes