cortico-world-agent-speed 0.2.3 → 0.2.4

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.
@@ -534,12 +534,6 @@ function runPetHost({ url, parentPid = 0, tray: withTray = true }) {
534
534
  dress.on('closed', () => { dress = null; });
535
535
  dress.loadURL(target);
536
536
  };
537
-
538
- // The World can open its own dressing window without relying on renderer readiness.
539
- process.on('message', (message) => {
540
- if (message === 'open-dress') void app.whenReady().then(() => openDress());
541
- });
542
-
543
537
  onPet('pet:interactive', (_e, on) => { if (!shape) mouse.ask(on); });
544
538
  onPet('pet:inputRects', (_e, rects) => { if (shape && Array.isArray(rects)) mouse.ask(rects); });
545
539
  onPet('pet:focus', () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-agent-speed",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "type": "module",
5
5
  "description": "The Coopanion desktop pet with local Agent Speed activity animation",
6
6
  "main": "./src/index.ts",
@@ -11,12 +11,14 @@ import { petText } from '../i18n/index.ts';
11
11
  import { describeHostReason, type HostReason } from '../host-reason.ts';
12
12
  import { captureKey, PRESSES, splitTaps, withTaps } from './key-capture.ts';
13
13
  import { apiRows, type ApiState } from './api-rows.ts';
14
+ import { hostFrameDressDialogs } from './dress-dialog.ts';
14
15
  import './style.css';
15
16
 
16
17
  interface Artifact { phase: 'absent' | 'working' | 'ready' | 'error'; path: string; done: number; total: number | null; detail: string | null }
17
18
  interface PetState {
18
19
  inWindow: boolean;
19
20
  url: string | null;
21
+ dressUrl: string | null;
20
22
  window: { phase: string; pid: number | null; source: string | null; reason: HostReason | null } | null;
21
23
  electron: Artifact & { supported: boolean };
22
24
  screen: { w: number; h: number } | null;
@@ -112,8 +114,70 @@ const petPanel: WebUiPanel = {
112
114
 
113
115
  const dress = ui.sheet({ title: t.dress, desc: t.dressHint });
114
116
  root.appendChild(dress.el);
115
- const btnDress = ui.button(t.dress, { size: 'sm', variant: 'primary' });
116
- dress.body.append(btnDress);
117
+ const doc = root.ownerDocument;
118
+ const frame = ui.h('iframe', 'pet-dressframe');
119
+ frame.title = t.dress;
120
+ frame.hidden = true;
121
+ const dressStatus = ui.h('div', 'read-feedback');
122
+ dressStatus.setAttribute('role', 'status');
123
+ dress.body.append(dressStatus, frame);
124
+ hostFrameDressDialogs({ doc, host: doc.body, signal: ctx.signal }, frame);
125
+
126
+ const appearance = () => {
127
+ const mode = doc.documentElement.dataset.colorMode;
128
+ return mode === 'dark' || (!mode && matchMedia('(prefers-color-scheme: dark)').matches) ? 'dark' : 'light';
129
+ };
130
+ const syncAppearance = () => {
131
+ if (!frame.dataset.origin) return;
132
+ const accent = getComputedStyle(doc.documentElement).getPropertyValue('--accent').trim();
133
+ frame.contentWindow?.postMessage({ type: 'companion:appearance', mode: appearance(), accent }, frame.dataset.origin);
134
+ };
135
+ const observer = new MutationObserver(syncAppearance);
136
+ observer.observe(doc.documentElement, { attributes: true, attributeFilter: ['data-color-mode', 'data-theme-scheme'] });
137
+ ctx.own({ dispose: () => observer.disconnect() });
138
+ frame.addEventListener('load', syncAppearance, { signal: ctx.signal });
139
+ const zh = ctx.language === 'zh' || ctx.language === 'zh-Hant';
140
+ let pending: { dispose(): void } | undefined;
141
+ doc.defaultView?.addEventListener('message', (event) => {
142
+ if (event.source !== frame.contentWindow || event.origin !== frame.dataset.origin) return;
143
+ if (event.data?.type === 'companion:height') {
144
+ const height = event.data.height;
145
+ if (Number.isFinite(height) && height > 0) frame.style.height = `${height}px`;
146
+ } else if (event.data?.type === 'companion:painted') {
147
+ pending?.dispose();
148
+ dressStatus.hidden = true;
149
+ frame.hidden = false;
150
+ frame.classList.remove('pet-dressframe-pending');
151
+ }
152
+ }, { signal: ctx.signal });
153
+ const showDress = (url: string | null) => {
154
+ if ((frame.dataset.src ?? null) === url) return;
155
+ pending?.dispose();
156
+ dressStatus.hidden = false;
157
+ if (url === null) {
158
+ frame.hidden = true;
159
+ delete frame.dataset.src;
160
+ delete frame.dataset.origin;
161
+ frame.removeAttribute('src');
162
+ dressStatus.textContent = zh ? '装扮服务尚未就绪。' : 'Dressing is not ready yet.';
163
+ return;
164
+ }
165
+ const target = new URL(url);
166
+ frame.dataset.src = url;
167
+ frame.dataset.origin = target.origin;
168
+ target.searchParams.set('appearance', appearance());
169
+ target.searchParams.set('fit', '1');
170
+ frame.classList.add('pet-dressframe-pending');
171
+ frame.hidden = false;
172
+ dressStatus.textContent = zh ? '正在加载装扮…' : 'Loading dressing…';
173
+ pending = ctx.timeout(() => {
174
+ if (!frame.classList.contains('pet-dressframe-pending')) return;
175
+ frame.hidden = true;
176
+ dressStatus.textContent = zh ? '无法加载内嵌装扮。请确认 Coopanion 支持 Agent Speed 内嵌装扮。'
177
+ : 'Could not load inline dressing. Check that this version of Coopanion supports Agent Speed inline dressing.';
178
+ }, 8000);
179
+ frame.src = target.href;
180
+ };
117
181
 
118
182
  s.append(win.row, rt.row);
119
183
  dress.el.hidden = true;
@@ -137,6 +201,7 @@ const petPanel: WebUiPanel = {
137
201
  else rt.set(e.supported ? t.notInstalled : t.noBuild, 'off', e.supported ? t.electronSize : '');
138
202
  btnInstall.hidden = e.phase === 'ready' || !e.supported;
139
203
  btnInstall.disabled = e.phase === 'working';
204
+ showDress(next.dressUrl);
140
205
  };
141
206
  const refresh = async () => { try { render(await ctx.invoke<PetState>('state')); } catch (err) { if (!ctx.signal.aborted) msg.replaceChildren(listProblem(root.ownerDocument, errText(err))); } };
142
207
  const call = (method: string, anchor: HTMLElement) => async () => {
@@ -145,12 +210,6 @@ const petPanel: WebUiPanel = {
145
210
  btnOpen.addEventListener('click', call('openWindow', btnOpen));
146
211
  btnClose.addEventListener('click', call('closeWindow', btnClose));
147
212
  btnInstall.addEventListener('click', call('installElectron', btnInstall));
148
- btnDress.addEventListener('click', async () => {
149
- btnDress.disabled = true;
150
- try { await ctx.invoke('openDress'); }
151
- catch (err) { if (!ctx.signal.aborted) problem(btnDress, errText(err)); }
152
- finally { btnDress.disabled = false; }
153
- });
154
213
  void refresh();
155
214
  ctx.interval(() => void refresh(), 1500);
156
215
  },
@@ -1,3 +1,6 @@
1
+ .pet-dressframe{display:block; width:100%; height:620px; border:0; border-radius:12px}
2
+ .pet-dressframe[hidden]{display:none}
3
+ .pet-dressframe-pending{position:absolute; visibility:hidden; pointer-events:none}
1
4
  /* the meter belongs to how it listens: no rule between them */
2
5
  .pet-voicebody .mountrow.pet-meterrow{border-top:0; padding:4px 0 6px}
3
6
  /* the name's characters sit 1px low in their line box; the bar follows them */
@@ -64,7 +64,7 @@ export class WindowHost {
64
64
  let child: ChildProcess;
65
65
  try {
66
66
  // the window closes by itself if this process dies without stopping it
67
- child = spawn(cmd.command, [...cmd.args, `--parent-pid=${process.pid}`], { env, stdio: ['ignore', 'pipe', 'pipe', 'ipc'], windowsHide: false });
67
+ child = spawn(cmd.command, [...cmd.args, `--parent-pid=${process.pid}`], { env, stdio: ['ignore', 'pipe', 'pipe'], windowsHide: false });
68
68
  } catch (err) {
69
69
  this.st = { phase: 'error', pid: null, source: cmd.source, reason: { kind: 'startFailed', why: (err as Error).message } };
70
70
  return;
@@ -99,15 +99,6 @@ export class WindowHost {
99
99
  this.st = { phase: code === 0 ? 'stopped' : 'error', pid: null, source: cmd.source, reason: code === 0 ? { kind: 'closed' } : { kind: 'exited', code } };
100
100
  });
101
101
  }
102
-
103
- openDress(): Promise<void> {
104
- const child = this.child;
105
- if (!child?.connected) return Promise.reject(new Error('Agent Speed pet window is not running'));
106
- const { promise, resolve, reject } = Promise.withResolvers<void>();
107
- child.send('open-dress', (error) => error ? reject(error) : resolve());
108
- return promise;
109
- }
110
-
111
102
  async stop(): Promise<void> {
112
103
  const child = this.child;
113
104
  this.child = null;
package/src/world.ts CHANGED
@@ -2644,15 +2644,6 @@ export class DesktopPetWorld implements World {
2644
2644
  if (panel === 'pet') {
2645
2645
  switch (method) {
2646
2646
  case 'state': return this.petState();
2647
- case 'openDress': {
2648
- this.openWindow();
2649
- const window = this.windowHost;
2650
- const reason = window?.state().reason;
2651
- if (reason) throw new Error(describeHostReason(petText(language).windowReason, reason));
2652
- if (!window) throw new Error(petText(language).panel.notOpen);
2653
- await window.openDress();
2654
- return this.petState();
2655
- }
2656
2647
  case 'openWindow': this.openWindow(); return this.petState();
2657
2648
  case 'closeWindow': await this.windowHost?.stop(); return this.petState();
2658
2649
  // hides the window as the pet's menu does; it stays connected and comes back with openWindow