@agy-daddy/plugin-pet 1.1.1 → 1.1.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/agy-plugin.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "schemaVersion": 1,
3
3
  "id": "agy-daddy.pet",
4
4
  "publisher": "agy-daddy",
5
- "version": "1.1.1",
5
+ "version": "1.1.2",
6
6
  "license": "MIT",
7
7
  "displayName": {
8
8
  "zh-CN": "桌面与网页伴侣宠",
@@ -19,19 +19,30 @@
19
19
  "main": "./src/node.js",
20
20
  "renderer": "./src/renderer.js",
21
21
  "world": "isolated",
22
- "activationEvents": ["onStartup"],
23
- "requires": {
24
- "anchors": ["topbar.rightCluster"]
25
- },
22
+ "activationEvents": [
23
+ "onStartup"
24
+ ],
26
25
  "provides": {
27
26
  "services": {
28
- "pet": { "version": "1.0.0", "realm": "node" }
27
+ "pet": {
28
+ "version": "1.0.0",
29
+ "realm": "node"
30
+ }
29
31
  },
30
- "events": ["pet:focus-session@1", "pet:theme-changed@1"],
31
- "states": ["state:pet.state@1", "state:session.active@1"]
32
+ "events": [
33
+ "pet:focus-session@1",
34
+ "pet:theme-changed@1"
35
+ ],
36
+ "states": [
37
+ "state:pet.state@1",
38
+ "state:session.active@1"
39
+ ]
32
40
  },
33
41
  "consumes": {
34
- "context": { "version": "^1.0.0", "optional": true }
42
+ "context": {
43
+ "version": "^1.0.0",
44
+ "optional": true
45
+ }
35
46
  },
36
47
  "permissions": [
37
48
  "dom:read",
@@ -41,16 +52,50 @@
41
52
  "ui:desktop-overlay"
42
53
  ],
43
54
  "contributes": {
44
- "topbar.units": [{ "id": "pet-chip", "order": 35 }],
45
- "topbar.popovers": [{ "id": "pet-panel", "anchorId": "pet-chip" }],
46
- "desktop.overlay": { "id": "pet-companion", "defaultWidth": 220, "defaultHeight": 200 },
47
- "settings": { "schema": "./settings.schema.json" },
55
+ "desktop.overlay": {
56
+ "id": "pet-companion",
57
+ "defaultWidth": 220,
58
+ "defaultHeight": 200
59
+ },
60
+ "settings": {
61
+ "schema": "./settings.schema.json"
62
+ },
48
63
  "commands": [
49
- { "id": "pet.toggleDesktop", "title": { "zh-CN": "切换桌面置顶桌宠", "en": "Toggle Desktop Pet" } },
50
- { "id": "pet.toggleWeb", "title": { "zh-CN": "切换 PC-Web 悬浮桌宠", "en": "Toggle PC-Web Pet" } },
51
- { "id": "pet.listThemes", "title": { "zh-CN": "列出可用桌宠主题", "en": "List Pet Themes" } },
52
- { "id": "pet.listProjectOptions", "title": { "zh-CN": "列出可监听项目", "en": "List Watchable Projects" } },
53
- { "id": "pet.listGroupOptions", "title": { "zh-CN": "列出可监听分组", "en": "List Watchable Groups" } }
64
+ {
65
+ "id": "pet.toggleDesktop",
66
+ "title": {
67
+ "zh-CN": "切换桌面置顶桌宠",
68
+ "en": "Toggle Desktop Pet"
69
+ }
70
+ },
71
+ {
72
+ "id": "pet.toggleWeb",
73
+ "title": {
74
+ "zh-CN": "切换 PC-Web 悬浮桌宠",
75
+ "en": "Toggle PC-Web Pet"
76
+ }
77
+ },
78
+ {
79
+ "id": "pet.listThemes",
80
+ "title": {
81
+ "zh-CN": "列出可用桌宠主题",
82
+ "en": "List Pet Themes"
83
+ }
84
+ },
85
+ {
86
+ "id": "pet.listProjectOptions",
87
+ "title": {
88
+ "zh-CN": "列出可监听项目",
89
+ "en": "List Watchable Projects"
90
+ }
91
+ },
92
+ {
93
+ "id": "pet.listGroupOptions",
94
+ "title": {
95
+ "zh-CN": "列出可监听分组",
96
+ "en": "List Watchable Groups"
97
+ }
98
+ }
54
99
  ],
55
100
  "locales": "./locales"
56
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agy-daddy/plugin-pet",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "MIT clean-room desktop and PC-Web companion pet plugin with 12 vector themes, custom pack sandbox, TPS speed linkage, and 4D session watch filtering",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/renderer.js CHANGED
@@ -1,166 +1,12 @@
1
1
  'use strict';
2
2
 
3
- const { createPetCanvasStage } = require('./shared/pet-canvas-stage');
4
- const { getBuiltinThemes, getBuiltinThemeById } = require('./shared/themes');
5
-
6
3
  let disposers = [];
7
4
 
8
5
  async function mount(ctx) {
9
6
  dispose();
10
7
 
11
- const doc = globalThis.document;
12
- let latestSnapshot = null;
13
- let panelEl = null;
14
- let canvasStage = null;
15
8
  let lastSessionKey = '';
16
9
 
17
- const stopStyles = ctx.styles.inject(`
18
- #agy-pet-panel {
19
- display: flex;
20
- flex-direction: column;
21
- gap: 10px;
22
- padding: 10px 12px;
23
- color: var(--ag-text-primary, #e4e4e7);
24
- font-size: 12px;
25
- }
26
- .ag-pet-preview-row {
27
- display: flex;
28
- align-items: center;
29
- gap: 12px;
30
- padding: 8px;
31
- border-radius: 10px;
32
- background: rgba(167, 139, 250, 0.08);
33
- border: 1px solid rgba(167, 139, 250, 0.22);
34
- }
35
- .ag-pet-btn-row {
36
- display: flex;
37
- flex-wrap: wrap;
38
- gap: 6px;
39
- }
40
- .ag-pet-btn {
41
- padding: 5px 10px;
42
- border-radius: 8px;
43
- border: 1px solid var(--ag-custom-token-accent, var(--ag-token-accent-default, #a78bfa));
44
- background: rgba(167, 139, 250, 0.14);
45
- color: inherit;
46
- cursor: pointer;
47
- font-size: 11px;
48
- }
49
- .ag-pet-themes {
50
- display: grid;
51
- grid-template-columns: repeat(3, minmax(0, 1fr));
52
- gap: 6px;
53
- }
54
- .ag-pet-theme-btn {
55
- padding: 5px 6px;
56
- border-radius: 7px;
57
- border: 1px solid rgba(161, 161, 170, 0.25);
58
- background: transparent;
59
- color: inherit;
60
- cursor: pointer;
61
- font-size: 11px;
62
- text-align: left;
63
- overflow: hidden;
64
- text-overflow: ellipsis;
65
- white-space: nowrap;
66
- }
67
- .ag-pet-theme-btn[data-active="true"] {
68
- border-color: var(--ag-custom-token-accent, var(--ag-token-accent-default, #a78bfa));
69
- background: rgba(167, 139, 250, 0.18);
70
- }
71
- `, { scope: 'shadow', id: 'pet-panel-styles' });
72
-
73
- function renderPanel() {
74
- if (!panelEl) return;
75
- panelEl.textContent = '';
76
-
77
- const petState = latestSnapshot?.state || {};
78
- const curThemeId = petState.themeId || ctx.settings?.get?.()?.themeId || 'daddy-orb';
79
- const curTheme = getBuiltinThemeById(curThemeId);
80
- const themes = Array.isArray(latestSnapshot?.themes) && latestSnapshot.themes.length > 0
81
- ? latestSnapshot.themes
82
- : getBuiltinThemes();
83
-
84
- const previewRow = doc.createElement('div');
85
- previewRow.className = 'ag-pet-preview-row';
86
-
87
- if (typeof doc.createElement === 'function') {
88
- const canvas = doc.createElement('canvas');
89
- canvas.width = 96;
90
- canvas.height = 96;
91
- previewRow.appendChild(canvas);
92
- if (canvasStage) canvasStage.dispose();
93
- canvasStage = createPetCanvasStage(canvas, {
94
- width: 96,
95
- height: 96,
96
- scene: latestSnapshot?.scene || curTheme.scene,
97
- state: {
98
- animState: petState.motion?.animState || 'idle',
99
- speedFactor: petState.motion?.speedFactor || 1.0
100
- }
101
- });
102
- canvasStage.start();
103
- }
104
-
105
- const meta = doc.createElement('div');
106
- const title = doc.createElement('div');
107
- title.textContent = `${curTheme.name?.['zh-CN'] || curThemeId}`;
108
- const sub = doc.createElement('div');
109
- const tpsStr = petState.motion?.tps != null ? ` · ${petState.motion.tps} tok/s` : '';
110
- sub.textContent = `状态:${petState.motion?.animState || 'idle'}${tpsStr}`;
111
- meta.appendChild(title);
112
- meta.appendChild(sub);
113
- previewRow.appendChild(meta);
114
- panelEl.appendChild(previewRow);
115
-
116
- const btnRow = doc.createElement('div');
117
- btnRow.className = 'ag-pet-btn-row';
118
-
119
- const toggleDeskBtn = doc.createElement('button');
120
- toggleDeskBtn.type = 'button';
121
- toggleDeskBtn.className = 'ag-pet-btn';
122
- toggleDeskBtn.textContent = petState.desktopVisible !== false ? '桌面置顶:开' : '桌面置顶:关';
123
- toggleDeskBtn.addEventListener('click', () => {
124
- void ctx.commands?.execute?.('pet.toggleDesktop');
125
- });
126
-
127
- const toggleWebBtn = doc.createElement('button');
128
- toggleWebBtn.type = 'button';
129
- toggleWebBtn.className = 'ag-pet-btn';
130
- toggleWebBtn.textContent = petState.webVisible !== false ? 'PC-Web:开' : 'PC-Web:关';
131
- toggleWebBtn.addEventListener('click', () => {
132
- void ctx.commands?.execute?.('pet.toggleWeb');
133
- });
134
-
135
- const openSettingsBtn = doc.createElement('button');
136
- openSettingsBtn.type = 'button';
137
- openSettingsBtn.className = 'ag-pet-btn';
138
- openSettingsBtn.textContent = '完整设置与白名单';
139
- openSettingsBtn.addEventListener('click', () => {
140
- void ctx.settings?.open?.({ pluginId: ctx.pluginId });
141
- });
142
-
143
- btnRow.appendChild(toggleDeskBtn);
144
- btnRow.appendChild(toggleWebBtn);
145
- btnRow.appendChild(openSettingsBtn);
146
- panelEl.appendChild(btnRow);
147
-
148
- const grid = doc.createElement('div');
149
- grid.className = 'ag-pet-themes';
150
- for (const th of themes.slice(0, 15)) {
151
- const b = doc.createElement('button');
152
- b.type = 'button';
153
- b.className = 'ag-pet-theme-btn';
154
- b.setAttribute('data-active', th.id === curThemeId ? 'true' : 'false');
155
- b.textContent = th.name?.['zh-CN'] || th.name?.en || th.id;
156
- b.addEventListener('click', () => {
157
- void ctx.settings?.update?.({ themeId: th.id });
158
- });
159
- grid.appendChild(b);
160
- }
161
- panelEl.appendChild(grid);
162
- }
163
-
164
10
  function syncActiveSession() {
165
11
  const cascadeId = ctx.hostDom?.getSessionId?.() || null;
166
12
  const busy = Boolean(ctx.hostDom?.isAssistantBusy?.());
@@ -170,52 +16,14 @@ async function mount(ctx) {
170
16
  Promise.resolve(ctx.bridge?.post?.('/active-session', { cascadeId, busy })).catch(() => {});
171
17
  }
172
18
 
173
- const stopUnit = ctx.topbar.registerUnit({
174
- id: 'pet-chip',
175
- order: 35,
176
- label: '桌宠',
177
- iconSvg: '<svg viewBox="0 0 16 16" width="14" height="14" fill="currentColor"><circle cx="8" cy="8" r="5"/></svg>',
178
- title: '桌面与 PC-Web 伴侣宠物'
179
- });
180
-
181
- const popoverHandle = ctx.topbar.registerPopover({
182
- id: 'pet-panel',
183
- anchorId: 'pet-chip',
184
- title: '伴侣宠物控制台',
185
- render(node) {
186
- panelEl = node;
187
- panelEl.id = 'agy-pet-panel';
188
- renderPanel();
189
- }
190
- });
191
-
192
- const stopStateSub = ctx.state?.subscribe?.('state:pet.state@1', () => {
193
- void Promise.resolve(ctx.bridge?.post?.('/state', {}))
194
- .then((snap) => {
195
- if (snap && snap.ok) {
196
- latestSnapshot = snap;
197
- renderPanel();
198
- }
199
- })
200
- .catch(() => {});
201
- });
202
-
203
19
  const stopActivePoll = ctx.schedule.every(1000, () => {
204
20
  syncActiveSession();
205
21
  });
206
22
 
207
23
  syncActiveSession();
208
- try {
209
- latestSnapshot = await ctx.bridge.post('/state', {});
210
- } catch {}
211
24
 
212
25
  disposers.push(
213
- stopStyles,
214
- stopUnit,
215
- () => popoverHandle?.dispose?.(),
216
- () => { if (typeof stopStateSub === 'function') stopStateSub(); },
217
- () => { if (typeof stopActivePoll === 'function') stopActivePoll(); },
218
- () => { if (canvasStage) { canvasStage.dispose(); canvasStage = null; } }
26
+ () => { if (typeof stopActivePoll === 'function') stopActivePoll(); }
219
27
  );
220
28
  }
221
29