@aiyiran/myclaw 1.0.199 → 1.0.200

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.
@@ -29,6 +29,7 @@
29
29
  // ═══ 状态 ═══
30
30
  var panelVisible = false;
31
31
  var cachedData = null;
32
+ var pollTimer = null;
32
33
 
33
34
  // ═══ 工具:从 URL 解析 agent 名称 ═══
34
35
  function getAgentName() {
@@ -61,8 +62,8 @@
61
62
  btn.id = 'myclaw-artifacts-btn';
62
63
  btn.style.cssText = [
63
64
  'position: fixed',
64
- 'bottom: 8px',
65
- 'right: 140px',
65
+ 'top: 370px',
66
+ 'right: 0',
66
67
  'padding: 3px 10px',
67
68
  'background: rgba(100, 100, 100, 0.7)',
68
69
  'color: #fff',
@@ -162,12 +163,8 @@
162
163
  panel.appendChild(content);
163
164
  document.body.appendChild(panel);
164
165
 
165
- // 请求数据
166
- if (cachedData) {
167
- renderArtifactsList(content, cachedData);
168
- } else {
169
- fetchArtifacts(content);
170
- }
166
+ // 立即拉一次,后续由轮询更新
167
+ fetchArtifacts(content);
171
168
  }
172
169
 
173
170
  // ═══ 关闭右侧面板 ═══
@@ -181,17 +178,21 @@
181
178
  }
182
179
 
183
180
  // ═══ 请求数据 ═══
184
- function fetchArtifacts(contentEl) {
181
+ function getArtifactsUrl() {
185
182
  var agentName = getAgentName();
186
183
  var wsPrefix = agentName === 'main' ? 'workspace' : 'workspace-' + agentName;
187
- var url = window.location.origin + '/cmd/api/preview?path=' + wsPrefix + '/.myclaw/__MY_ARTIFACTS__.json';
188
- fetch(url)
184
+ return window.location.origin + '/cmd/api/preview?path=' + wsPrefix + '/.myclaw/__MY_ARTIFACTS__.json';
185
+ }
186
+
187
+ function fetchArtifacts(contentEl) {
188
+ fetch(getArtifactsUrl())
189
189
  .then(function (res) {
190
190
  if (!res.ok) throw new Error('HTTP ' + res.status);
191
191
  return res.json();
192
192
  })
193
193
  .then(function (data) {
194
194
  cachedData = data;
195
+ if (!contentEl) return;
195
196
  if (!data || !data.assets || !data.assets.length) {
196
197
  contentEl.innerHTML = '<div style="text-align:center;padding:32px;color:#888;">暂无作品</div>';
197
198
  return;
@@ -200,10 +201,23 @@
200
201
  })
201
202
  .catch(function (err) {
202
203
  console.error('[myclaw-artifacts] 加载失败:', err);
203
- contentEl.innerHTML = '<div style="text-align:center;padding:32px;color:#ff6b6b;">加载失败,请稍后重试</div>';
204
+ if (contentEl) {
205
+ contentEl.innerHTML = '<div style="text-align:center;padding:32px;color:#ff6b6b;">加载失败,请稍后重试</div>';
206
+ }
204
207
  });
205
208
  }
206
209
 
210
+ function startPolling() {
211
+ if (pollTimer) return;
212
+ // 立即拉一次
213
+ fetchArtifacts(null);
214
+ // 每秒轮询
215
+ pollTimer = setInterval(function () {
216
+ var contentEl = document.querySelector('#myclaw-artifacts-content');
217
+ fetchArtifacts(contentEl);
218
+ }, 1000);
219
+ }
220
+
207
221
  // ═══ 渲染列表 ═══
208
222
  function renderArtifactsList(container, data) {
209
223
  container.innerHTML = '';
@@ -387,6 +401,7 @@
387
401
  function init() {
388
402
  injectStyles();
389
403
  createArtifactsButton();
404
+ startPolling();
390
405
  console.log('[myclaw-artifacts] ✅ 初始化完成');
391
406
  }
392
407
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiyiran/myclaw",
3
- "version": "1.0.199",
3
+ "version": "1.0.200",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {