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.
- package/CHANGELOG.md +64 -0
- package/LICENSE +0 -14
- package/README.md +29 -11
- package/THIRD_PARTY_NOTICES.md +69 -0
- package/activity.d.ts +15 -0
- package/activity.js +88 -3
- package/describe.json +806 -0
- package/dist/webui.css +2 -0
- package/dist/webui.css.map +7 -0
- package/dist/webui.js +2 -0
- package/dist/webui.js.map +7 -0
- package/host/app-store.cjs +68 -0
- package/host/cursor.cjs +67 -0
- package/host/electron-main.cjs +666 -0
- package/host/input-shape.cjs +63 -0
- package/host/mouse-lease.cjs +77 -0
- package/host/overlay.cjs +139 -0
- package/host/portrait.cjs +52 -0
- package/host/preload.cjs +60 -14
- package/host/renderer-gone.cjs +24 -0
- package/host/windows.cjs +251 -0
- package/package.json +27 -7
- package/scripts/build-webui.mjs +40 -0
- package/scripts/speech-bank/build.py +166 -0
- package/scripts/speech-bank/dicts.py +76 -0
- package/src/ENV_PROMPT.en.md +51 -0
- package/src/ENV_PROMPT.md +51 -0
- package/src/asr/address.ts +25 -0
- package/src/asr/hotkey.ts +335 -0
- package/src/asr/result.ts +51 -0
- package/src/asr/segmenter.ts +269 -0
- package/src/asr/sherpa.ts +280 -0
- package/src/asr/simplify.ts +38 -0
- package/src/asr/system-recognizer.ts +292 -0
- package/src/asr/system-sapi.ps1 +173 -0
- package/src/asr/transcription-api.ts +176 -0
- package/src/chat.ts +212 -0
- package/src/config.ts +481 -0
- package/src/cua/ENV_PROMPT.en.md +29 -0
- package/src/cua/ENV_PROMPT.md +29 -0
- package/src/cua/config.ts +88 -0
- package/src/cua/cua.ts +712 -0
- package/src/cua/engine/darwin.ts +410 -0
- package/src/cua/engine/display.ts +55 -0
- package/src/cua/engine/fail.ts +15 -0
- package/src/cua/engine/foreground.ts +8 -0
- package/src/cua/engine/image.ts +57 -0
- package/src/cua/engine/keys.ts +70 -0
- package/src/cua/engine/linux-keys.ts +29 -0
- package/src/cua/engine/linux.ts +343 -0
- package/src/cua/engine/mac-keys.ts +57 -0
- package/src/cua/engine/user-activity.ts +54 -0
- package/src/cua/engine/wait-idle.ts +31 -0
- package/src/cua/engine/win32.ts +299 -0
- package/src/cua/engine-child.ts +274 -0
- package/src/cua/engine-ipc.ts +140 -0
- package/src/cua/i18n/de.ts +53 -0
- package/src/cua/i18n/en.ts +63 -0
- package/src/cua/i18n/es-419.ts +53 -0
- package/src/cua/i18n/fr.ts +53 -0
- package/src/cua/i18n/index.ts +26 -0
- package/src/cua/i18n/it.ts +53 -0
- package/src/cua/i18n/ja.ts +53 -0
- package/src/cua/i18n/ko.ts +53 -0
- package/src/cua/i18n/pt-BR.ts +53 -0
- package/src/cua/i18n/ru.ts +59 -0
- package/src/cua/i18n/zh-Hant.ts +53 -0
- package/src/cua/i18n/zh.ts +59 -0
- package/src/cua/model-text.ts +252 -0
- package/src/cua/terminal.ts +31 -0
- package/src/cua/tools.ts +153 -0
- package/src/definition.ts +146 -0
- package/src/host-reason.ts +32 -0
- package/src/i18n/de.ts +409 -0
- package/src/i18n/en.ts +443 -0
- package/src/i18n/es-419.ts +409 -0
- package/src/i18n/fr.ts +409 -0
- package/src/i18n/index.ts +56 -0
- package/src/i18n/it.ts +409 -0
- package/src/i18n/ja.ts +409 -0
- package/src/i18n/ko.ts +409 -0
- package/src/i18n/pt-BR.ts +409 -0
- package/src/i18n/ru.ts +415 -0
- package/src/i18n/zh-Hant.ts +409 -0
- package/src/i18n/zh.ts +440 -0
- package/src/index.ts +15 -0
- package/src/model-text.ts +344 -0
- package/src/moves.ts +101 -0
- package/src/pack-import.ts +361 -0
- package/src/packs.ts +449 -0
- package/src/runtime/download.ts +29 -0
- package/src/runtime/store.ts +293 -0
- package/src/script.ts +202 -0
- package/src/self.ts +247 -0
- package/src/server.ts +479 -0
- package/src/speech/data/CMUDICT-LICENSE +33 -0
- package/src/speech/data/IPADIC-COPYING +71 -0
- package/src/speech/data/UNICODE-LICENSE +39 -0
- package/src/speech/data/en.tsv.gz +0 -0
- package/src/speech/data/ja-ipadic.tsv.gz +0 -0
- package/src/speech/data/ja-unihan.tsv.gz +0 -0
- package/src/speech/data/zh.json +1 -0
- package/src/speech/index.ts +204 -0
- package/src/speech/ipa.ts +83 -0
- package/src/speech/japanese.ts +105 -0
- package/src/speech/jukujikun.ts +22 -0
- package/src/speech/korean.ts +35 -0
- package/src/speech/lang.ts +151 -0
- package/src/speech/rules.ts +72 -0
- package/src/speech/syllable.ts +76 -0
- package/src/status.ts +164 -0
- package/src/tools.ts +110 -0
- package/src/webui/api-rows.css +2 -0
- package/src/webui/api-rows.ts +44 -0
- package/src/webui/client.ts +451 -0
- package/src/webui/dress-dialog.css +14 -0
- package/src/webui/dress-dialog.ts +117 -0
- package/src/webui/dress-panel.ts +160 -0
- package/src/webui/key-capture.ts +60 -0
- package/src/webui/shared/modal.css +13 -0
- package/src/webui/shared/modal.ts +77 -0
- package/src/webui/shared/problem.css +15 -0
- package/src/webui/shared/problem.ts +217 -0
- package/src/webui/shared/strings.ts +5 -0
- package/src/webui/style.css +50 -0
- package/src/window-host.ts +116 -0
- package/src/world.ts +2926 -0
- package/web/activity-motion.js +117 -0
- package/web/appearance.js +60 -0
- package/web/body-host.js +257 -0
- package/web/coo/coo.js +384 -0
- package/web/coo/figure.js +15 -0
- package/web/coo/figure.json +1224 -0
- package/web/dist/dress-dialog.css +1 -0
- package/web/dist/dress-dialog.js +1 -0
- package/web/drag-row.js +49 -0
- package/web/drag.js +149 -0
- package/web/dress.css +170 -0
- package/web/dress.html +37 -0
- package/web/dress.js +786 -0
- package/web/figure-frame.html +16 -0
- package/web/figure-frame.js +128 -0
- package/web/frame-loop.js +55 -0
- package/web/hints.js +77 -0
- package/web/i18n/de.js +170 -0
- package/web/i18n/en.js +177 -0
- package/web/i18n/es-419.js +170 -0
- package/web/i18n/fr.js +170 -0
- package/web/i18n/it.js +170 -0
- package/web/i18n/ja.js +170 -0
- package/web/i18n/ko.js +170 -0
- package/web/i18n/pt-BR.js +170 -0
- package/web/i18n/ru.js +170 -0
- package/web/i18n/zh-Hant.js +170 -0
- package/web/i18n/zh.js +175 -0
- package/web/i18n.js +54 -0
- package/{renderer/vendor → web}/kit/body.js +31 -58
- package/web/looks.js +70 -0
- package/web/mic-worklet.js +36 -0
- package/web/mic.js +117 -0
- package/web/motion-frames.js +80 -0
- package/web/motion-level.js +40 -0
- package/web/new-year-2027.svg +238 -0
- package/web/overlay.html +16 -0
- package/web/overlay.js +100 -0
- package/web/pet-app.js +3000 -0
- package/web/pet.css +642 -0
- package/web/pet.html +21 -0
- package/web/scale-slider.js +259 -0
- package/web/show-hide.js +49 -0
- package/web/sound.js +245 -0
- package/web/speech/zh.json +1 -0
- package/web/speech/zh.ogg +0 -0
- package/web/speech.js +197 -0
- package/web/stage.js +160 -0
- package/web/swap-motion.js +119 -0
- package/web/ui.js +195 -0
- package/host/launch.js +0 -187
- package/host/library.cjs +0 -638
- package/host/main.cjs +0 -389
- package/index.js +0 -93
- package/renderer/index.html +0 -22
- package/renderer/pet-sandbox.html +0 -11
- package/renderer/pet.css +0 -38
- package/renderer/pet.js +0 -251
- package/renderer/vendor/activity-motion.js +0 -101
- package/renderer/vendor/figure-frame.js +0 -115
- package/renderer/vendor/pack.css +0 -2
- /package/{renderer/vendor → web}/kit/rig.js +0 -0
package/src/chat.ts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chat page's side of the pet: what the person said (typed in the bubble or the page, spoken,
|
|
3
|
+
* answered, touches) and what the pet said (`speed_pet_say` beats, `speed_pet_ask` questions) and did (tool
|
|
4
|
+
* steps), rebuilt from this World's own events.
|
|
5
|
+
*
|
|
6
|
+
* The person's input is the events delivered to the bot. The pet's side is recorded as
|
|
7
|
+
* `agent-speed.self` events that are stored and never delivered: `say`, `ask`, `activity` (the tool
|
|
8
|
+
* steps between two lines), `delivered` (where messages that waited reached the bot), `withdrawn`
|
|
9
|
+
* (a message taken back before delivery, left out of the history) and `transcript` (the text recognized
|
|
10
|
+
* for a recording delivered before it, shown in the recording's place). A touch is stored as its kind and
|
|
11
|
+
* counts, a figure the person switched to (`agent-speed.figure`) as the kind of switch and the figure's names;
|
|
12
|
+
* the page tells both in its own language.
|
|
13
|
+
*/
|
|
14
|
+
import type { EventEnvelope, RunPhase, WorldStreamSocket } from 'cortico/core/types.ts';
|
|
15
|
+
|
|
16
|
+
export const SELF_TYPE = 'agent-speed.self';
|
|
17
|
+
|
|
18
|
+
/** Event types the chat shows. */
|
|
19
|
+
const CHAT_TYPES = new Set(['agent-speed.message', 'agent-speed.speech', 'agent-speed.answer', 'agent-speed.touch', 'agent-speed.figure', SELF_TYPE]);
|
|
20
|
+
|
|
21
|
+
/** Tools whose work shows as the pet's own lines, not as steps. */
|
|
22
|
+
const SPOKEN_TOOLS = new Set(['speed_pet_say', 'speed_pet_ask']);
|
|
23
|
+
|
|
24
|
+
/** One image of a message: `ref` is the attachment handle; the page fetches its bytes from the console's `/api/blob`. */
|
|
25
|
+
export interface WireImage { ref: string; mime: string; name?: string }
|
|
26
|
+
|
|
27
|
+
/** A touch as the chat page tells it: `poke`, `pet`, `throw`, `drop` or `crash`, how many times, and whether it woke the pet or the pet crashed. */
|
|
28
|
+
export interface ChatTouch { kind: string; count: number; woke: boolean; crashed: boolean }
|
|
29
|
+
|
|
30
|
+
/** A figure switch: to another figure, to another dress of the same one, or a figure that did not load (Coo shows instead) with the page's `reason`; `name` by language, with its `id`. */
|
|
31
|
+
export interface ChatFigure { kind: 'figure' | 'dress' | 'failed'; name: Record<string, string>; reason?: string }
|
|
32
|
+
|
|
33
|
+
/** One beat of a `speed_pet_say`: its text and the first expression played in it, by its id and its name in each language. */
|
|
34
|
+
export interface SayBeat { text: string; mood?: Record<string, string> }
|
|
35
|
+
|
|
36
|
+
export type ChatItem =
|
|
37
|
+
| { kind: 'user'; cursor: number; ts: string; via: 'chat' | 'bubble' | 'voice'; text: string; images?: WireImage[]; at?: number }
|
|
38
|
+
| { kind: 'answer'; cursor: number; ts: string; askId: string; index?: number; text?: string; dismissed?: true }
|
|
39
|
+
/** `text` for touches stored before they were stored as `touch`. */
|
|
40
|
+
| { kind: 'touch'; cursor: number; ts: string; touch?: ChatTouch; text?: string }
|
|
41
|
+
| { kind: 'figure'; cursor: number; ts: string; figure: ChatFigure }
|
|
42
|
+
| { kind: 'say'; cursor: number; ts: string; beats: SayBeat[]; images?: WireImage[] }
|
|
43
|
+
| { kind: 'ask'; cursor: number; ts: string; askId: string; question: string; options: string[]; own: boolean }
|
|
44
|
+
| { kind: 'activity'; cursor: number; ts: string; steps: string[]; ms: number };
|
|
45
|
+
|
|
46
|
+
type Meta = Record<string, unknown>;
|
|
47
|
+
const str = (v: unknown): string | undefined => (typeof v === 'string' ? v : undefined);
|
|
48
|
+
|
|
49
|
+
const wireImages = (e: EventEnvelope): WireImage[] => (e.blobs ?? []).filter((b) => b.mime.startsWith('image/'))
|
|
50
|
+
.map((b) => ({ ref: b.handle, mime: b.mime, ...(b.name ? { name: b.name } : {}) }));
|
|
51
|
+
|
|
52
|
+
/** A stored event as the chat shows it; null for events the chat leaves out. */
|
|
53
|
+
export function chatItem(e: EventEnvelope): ChatItem | null {
|
|
54
|
+
if (!CHAT_TYPES.has(e.type)) return null;
|
|
55
|
+
const m = (e.meta ?? {}) as Meta;
|
|
56
|
+
const base = { cursor: e.cursor, ts: e.ts };
|
|
57
|
+
switch (e.type) {
|
|
58
|
+
case 'agent-speed.message':
|
|
59
|
+
case 'agent-speed.speech': {
|
|
60
|
+
const text = str(m.text);
|
|
61
|
+
if (text === undefined) return null;
|
|
62
|
+
const images = wireImages(e);
|
|
63
|
+
const via = e.type === 'agent-speed.speech' ? 'voice' : m.via === 'chat' ? 'chat' : 'bubble';
|
|
64
|
+
return { kind: 'user', ...base, via, text, ...(images.length ? { images } : {}) };
|
|
65
|
+
}
|
|
66
|
+
case 'agent-speed.answer': {
|
|
67
|
+
const askId = str(m.askId);
|
|
68
|
+
if (!askId) return null;
|
|
69
|
+
return {
|
|
70
|
+
kind: 'answer', ...base, askId,
|
|
71
|
+
...(typeof m.index === 'number' ? { index: m.index } : {}),
|
|
72
|
+
...(str(m.text) !== undefined ? { text: str(m.text) } : {}),
|
|
73
|
+
...(m.dismissed === true ? { dismissed: true as const } : {}),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
case 'agent-speed.touch': {
|
|
77
|
+
const t = (m.touch ?? null) as Meta | null;
|
|
78
|
+
if (t && typeof t.kind === 'string') {
|
|
79
|
+
return { kind: 'touch', ...base, touch: { kind: t.kind, count: typeof t.count === 'number' ? t.count : 1, woke: t.woke === true, crashed: t.crashed === true } };
|
|
80
|
+
}
|
|
81
|
+
const text = str(m.chat);
|
|
82
|
+
return text ? { kind: 'touch', ...base, text } : null;
|
|
83
|
+
}
|
|
84
|
+
case 'agent-speed.figure': {
|
|
85
|
+
const f = (m.figure ?? null) as Meta | null;
|
|
86
|
+
if (!f || !['figure', 'dress', 'failed'].includes(f.kind as string) || !f.name || typeof f.name !== 'object') return null;
|
|
87
|
+
return { kind: 'figure', ...base, figure: { kind: f.kind as ChatFigure['kind'], name: f.name as Record<string, string>, ...(typeof f.reason === 'string' ? { reason: f.reason } : {}) } };
|
|
88
|
+
}
|
|
89
|
+
default: {
|
|
90
|
+
if (m.kind === 'say' && Array.isArray(m.beats)) {
|
|
91
|
+
const beats = (m.beats as Meta[]).flatMap((b) => (typeof b.text === 'string' && b.text ? [{ text: b.text, ...(b.mood && typeof b.mood === 'object' ? { mood: b.mood as Record<string, string> } : {}) }] : []));
|
|
92
|
+
const images = wireImages(e);
|
|
93
|
+
return beats.length || images.length ? { kind: 'say', ...base, beats, ...(images.length ? { images } : {}) } : null;
|
|
94
|
+
}
|
|
95
|
+
if (m.kind === 'ask' && str(m.askId) && str(m.question)) {
|
|
96
|
+
const options = Array.isArray(m.options) ? m.options.filter((o): o is string => typeof o === 'string') : [];
|
|
97
|
+
return { kind: 'ask', ...base, askId: str(m.askId)!, question: str(m.question)!, options, own: m.own !== false };
|
|
98
|
+
}
|
|
99
|
+
if (m.kind === 'activity' && Array.isArray(m.steps)) {
|
|
100
|
+
const steps = m.steps.filter((s): s is string => typeof s === 'string');
|
|
101
|
+
return steps.length ? { kind: 'activity', ...base, steps, ms: typeof m.ms === 'number' ? m.ms : 0 } : null;
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Messages recorded as withdrawn, where messages that waited were delivered (message cursor → record cursor), and transcripts of recordings (message cursor → text). */
|
|
109
|
+
export interface ChatRefs { withdrawn: number[]; delivered: Array<[number, number]>; transcripts: Array<[number, string]> }
|
|
110
|
+
|
|
111
|
+
/** The `withdrawn` and `delivered` records among `events`. */
|
|
112
|
+
export function chatRefs(events: readonly EventEnvelope[]): ChatRefs {
|
|
113
|
+
const refs: ChatRefs = { withdrawn: [], delivered: [], transcripts: [] };
|
|
114
|
+
for (const e of events) {
|
|
115
|
+
const m = (e.meta ?? {}) as Meta;
|
|
116
|
+
if (e.type !== SELF_TYPE) continue;
|
|
117
|
+
if (m.kind === 'withdrawn' && typeof m.cursor === 'number') refs.withdrawn.push(m.cursor);
|
|
118
|
+
if (m.kind === 'delivered' && Array.isArray(m.cursors)) for (const c of m.cursors) if (typeof c === 'number') refs.delivered.push([c, e.cursor]);
|
|
119
|
+
if (m.kind === 'transcript' && typeof m.cursor === 'number' && typeof m.text === 'string') refs.transcripts.push([m.cursor, m.text]);
|
|
120
|
+
}
|
|
121
|
+
return refs;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The chat items among `events`, in the order the bot met them: a message that waited stands where
|
|
126
|
+
* its `delivered` record is, with `at` set to that record's cursor. Messages later recorded as
|
|
127
|
+
* withdrawn are left out; a recording later transcribed shows its transcript.
|
|
128
|
+
*/
|
|
129
|
+
export function chatHistory(events: readonly EventEnvelope[]): ChatItem[] {
|
|
130
|
+
const refs = chatRefs(events);
|
|
131
|
+
const withdrawn = new Set(refs.withdrawn);
|
|
132
|
+
const deliveredAt = new Map(refs.delivered);
|
|
133
|
+
const transcripts = new Map(refs.transcripts);
|
|
134
|
+
const waiting = new Map<number, ChatItem[]>();
|
|
135
|
+
const out: ChatItem[] = [];
|
|
136
|
+
for (const e of events) {
|
|
137
|
+
out.push(...waiting.get(e.cursor) ?? []);
|
|
138
|
+
if (withdrawn.has(e.cursor)) continue;
|
|
139
|
+
const found = chatItem(e);
|
|
140
|
+
if (!found) continue;
|
|
141
|
+
const transcript = transcripts.get(e.cursor);
|
|
142
|
+
const item = found.kind === 'user' && transcript !== undefined ? { ...found, text: transcript } : found;
|
|
143
|
+
const at = deliveredAt.get(e.cursor);
|
|
144
|
+
if (at === undefined || item.kind !== 'user') { out.push(item); continue; }
|
|
145
|
+
waiting.set(at, [...waiting.get(at) ?? [], { ...item, at }]);
|
|
146
|
+
}
|
|
147
|
+
return out;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** The tool steps between two of the pet's lines: names in start order, from the first start. */
|
|
151
|
+
export class ActivityGroup {
|
|
152
|
+
steps: string[] = [];
|
|
153
|
+
startedAt = 0;
|
|
154
|
+
private running: string[] = [];
|
|
155
|
+
|
|
156
|
+
/** Takes a new phase; returns true when a step was added. */
|
|
157
|
+
observe(phase: RunPhase, now: number): boolean {
|
|
158
|
+
const before = [...this.running];
|
|
159
|
+
this.running = [...phase.running];
|
|
160
|
+
let added = false;
|
|
161
|
+
for (const name of phase.running) {
|
|
162
|
+
const i = before.indexOf(name);
|
|
163
|
+
if (i >= 0) { before.splice(i, 1); continue; }
|
|
164
|
+
if (SPOKEN_TOOLS.has(name)) continue;
|
|
165
|
+
if (this.steps.length === 0) this.startedAt = now;
|
|
166
|
+
this.steps.push(name);
|
|
167
|
+
added = true;
|
|
168
|
+
}
|
|
169
|
+
return added;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** The steps so far, and empties the group. */
|
|
173
|
+
take(now: number): { steps: string[]; ms: number } | null {
|
|
174
|
+
if (this.steps.length === 0) return null;
|
|
175
|
+
const out = { steps: this.steps, ms: Math.max(0, now - this.startedAt) };
|
|
176
|
+
this.steps = [];
|
|
177
|
+
return out;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Open chat pages: frames go to every one. */
|
|
182
|
+
export class ChatSockets {
|
|
183
|
+
private readonly sockets = new Set<WorldStreamSocket>();
|
|
184
|
+
|
|
185
|
+
get size(): number {
|
|
186
|
+
return [...this.sockets].filter((s) => s.open).length;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
add(socket: WorldStreamSocket, onMessage: (msg: Meta, socket: WorldStreamSocket) => void): void {
|
|
190
|
+
this.sockets.add(socket);
|
|
191
|
+
socket.onClose(() => this.sockets.delete(socket));
|
|
192
|
+
socket.onMessage((raw) => {
|
|
193
|
+
let msg: unknown;
|
|
194
|
+
try { msg = JSON.parse(raw); } catch { return; }
|
|
195
|
+
if (msg && typeof msg === 'object') onMessage(msg as Meta, socket);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
send(socket: WorldStreamSocket, frame: Meta): void {
|
|
200
|
+
socket.send(JSON.stringify(frame));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
broadcast(frame: Meta): void {
|
|
204
|
+
const text = JSON.stringify(frame);
|
|
205
|
+
for (const s of this.sockets) if (s.open) s.send(text);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
closeAll(reason: string): void {
|
|
209
|
+
for (const s of this.sockets) s.close(reason);
|
|
210
|
+
this.sockets.clear();
|
|
211
|
+
}
|
|
212
|
+
}
|