@aiyiran/myclaw 1.0.198 → 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,15 +178,21 @@
181
178
  }
182
179
 
183
180
  // ═══ 请求数据 ═══
181
+ function getArtifactsUrl() {
182
+ var agentName = getAgentName();
183
+ var wsPrefix = agentName === 'main' ? 'workspace' : 'workspace-' + agentName;
184
+ return window.location.origin + '/cmd/api/preview?path=' + wsPrefix + '/.myclaw/__MY_ARTIFACTS__.json';
185
+ }
186
+
184
187
  function fetchArtifacts(contentEl) {
185
- var url = window.location.origin + '/cmd/api/preview?path=.myclaw/__MY_ARTIFACTS__.json';
186
- fetch(url)
188
+ fetch(getArtifactsUrl())
187
189
  .then(function (res) {
188
190
  if (!res.ok) throw new Error('HTTP ' + res.status);
189
191
  return res.json();
190
192
  })
191
193
  .then(function (data) {
192
194
  cachedData = data;
195
+ if (!contentEl) return;
193
196
  if (!data || !data.assets || !data.assets.length) {
194
197
  contentEl.innerHTML = '<div style="text-align:center;padding:32px;color:#888;">暂无作品</div>';
195
198
  return;
@@ -198,10 +201,23 @@
198
201
  })
199
202
  .catch(function (err) {
200
203
  console.error('[myclaw-artifacts] 加载失败:', err);
201
- 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
+ }
202
207
  });
203
208
  }
204
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
+
205
221
  // ═══ 渲染列表 ═══
206
222
  function renderArtifactsList(container, data) {
207
223
  container.innerHTML = '';
@@ -385,6 +401,7 @@
385
401
  function init() {
386
402
  injectStyles();
387
403
  createArtifactsButton();
404
+ startPolling();
388
405
  console.log('[myclaw-artifacts] ✅ 初始化完成');
389
406
  }
390
407
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiyiran/myclaw",
3
- "version": "1.0.198",
3
+ "version": "1.0.200",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {