@aiyiran/myclaw 1.0.194 → 1.0.196

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.
@@ -37,7 +37,7 @@
37
37
  bar.style.cssText = [
38
38
  "position: fixed",
39
39
  "bottom: 8px",
40
- "right: 8px",
40
+ "right: 40px",
41
41
  "padding: 2px 8px",
42
42
  "background: none",
43
43
  "color: rgba(150, 150, 150, 0.4)",
@@ -70,7 +70,7 @@
70
70
  btn.style.cssText = [
71
71
  "position: fixed",
72
72
  "bottom: 8px",
73
- "right: 80px",
73
+ "right: 120px",
74
74
  "padding: 2px 8px",
75
75
  "background: none",
76
76
  "color: rgba(150, 150, 150, 0.4)",
@@ -96,6 +96,7 @@
96
96
 
97
97
  // ═══ 1.2 右下角 CMD 按钮(弹框 iframe) ═══
98
98
  var cmdOpen = false;
99
+ var artifactsOpen = false;
99
100
 
100
101
  function createCmdButton() {
101
102
  if (document.querySelector("#myclaw-cmd-btn")) return;
@@ -105,7 +106,7 @@
105
106
  btn.style.cssText = [
106
107
  "position: fixed",
107
108
  "bottom: 8px",
108
- "right: 130px",
109
+ "right: 190px",
109
110
  "padding: 3px 10px",
110
111
  "background: rgba(59, 130, 246, 0.85)",
111
112
  "color: #fff",
@@ -199,7 +200,7 @@
199
200
 
200
201
  // iframe
201
202
  var iframe = document.createElement("iframe");
202
- iframe.src = window.location.origin + "/cmd";
203
+ iframe.src = window.location.origin + "/cmd/";
203
204
  iframe.style.cssText = [
204
205
  "flex: 1",
205
206
  "width: 100%",
@@ -228,6 +229,225 @@
228
229
  if (btn) btn.style.background = "rgba(59, 130, 246, 0.85)";
229
230
  }
230
231
 
232
+ // ═══ 1.3 学生作品展示 ═══
233
+
234
+ function getAgentName() {
235
+ var params = new URLSearchParams(window.location.search);
236
+ // 优先从 session 参数解析: agent:main:feishu:... → main
237
+ var session = params.get("session");
238
+ if (session) {
239
+ var decoded = decodeURIComponent(session);
240
+ if (decoded.indexOf("agent:") === 0) {
241
+ var parts = decoded.split(":");
242
+ if (parts.length >= 2) return parts[1];
243
+ }
244
+ }
245
+ // fallback: agent 参数
246
+ var agent = params.get("agent");
247
+ if (agent) return agent;
248
+ return "";
249
+ }
250
+
251
+ function createArtifactsButton() {
252
+ if (document.querySelector("#myclaw-artifacts-btn")) return;
253
+
254
+ var btn = document.createElement("div");
255
+ btn.id = "myclaw-artifacts-btn";
256
+ btn.style.cssText = [
257
+ "position: fixed",
258
+ "bottom: 8px",
259
+ "right: 140px",
260
+ "padding: 3px 10px",
261
+ "background: rgba(100, 100, 100, 0.7)",
262
+ "color: #fff",
263
+ "font-size: 11px",
264
+ "font-weight: bold",
265
+ "font-family: monospace",
266
+ "border-radius: 4px",
267
+ "z-index: 99999",
268
+ "user-select: none",
269
+ "cursor: pointer",
270
+ "transition: all 0.2s",
271
+ "letter-spacing: 0.5px",
272
+ ].join(";");
273
+ btn.textContent = "\uD83C\uDFA8 \u4F5C\u54C1";
274
+ btn.title = "\u67E5\u770B\u5B66\u751F\u4F5C\u54C1";
275
+
276
+ btn.onmouseenter = function () { btn.style.background = "rgba(80, 80, 80, 0.95)"; btn.style.transform = "scale(1.05)"; };
277
+ btn.onmouseleave = function () { if (!artifactsOpen) { btn.style.background = "rgba(100, 100, 100, 0.7)"; } btn.style.transform = "scale(1)"; };
278
+ btn.onclick = function (e) {
279
+ e.stopPropagation();
280
+ if (artifactsOpen) {
281
+ closeArtifactsPanel();
282
+ } else {
283
+ openArtifactsPanel();
284
+ }
285
+ };
286
+
287
+ document.body.appendChild(btn);
288
+ }
289
+
290
+ function openArtifactsPanel() {
291
+ if (document.querySelector("#myclaw-artifacts-modal")) return;
292
+ artifactsOpen = true;
293
+
294
+ // 按钮 active 态
295
+ var btn = document.querySelector("#myclaw-artifacts-btn");
296
+ if (btn) btn.style.background = "rgba(80, 80, 80, 0.95)";
297
+
298
+ // 遮罩
299
+ var overlay = document.createElement("div");
300
+ overlay.id = "myclaw-artifacts-modal";
301
+ overlay.style.cssText = [
302
+ "position: fixed",
303
+ "top: 0",
304
+ "left: 0",
305
+ "width: 100vw",
306
+ "height: 100vh",
307
+ "background: rgba(0, 0, 0, 0.3)",
308
+ "z-index: 99998",
309
+ "display: flex",
310
+ "align-items: center",
311
+ "justify-content: center",
312
+ "animation: myclaw-fade-in 0.15s ease",
313
+ ].join(";");
314
+
315
+ // 面板容器
316
+ var box = document.createElement("div");
317
+ box.style.cssText = [
318
+ "width: 480px",
319
+ "max-height: 70vh",
320
+ "background: #1e1e2e",
321
+ "border-radius: 8px",
322
+ "overflow: hidden",
323
+ "display: flex",
324
+ "flex-direction: column",
325
+ "box-shadow: 0 8px 32px rgba(0,0,0,0.4)",
326
+ ].join(";");
327
+
328
+ // 标题栏
329
+ var header = document.createElement("div");
330
+ header.style.cssText = [
331
+ "display: flex",
332
+ "align-items: center",
333
+ "justify-content: space-between",
334
+ "padding: 10px 16px",
335
+ "background: #2d2d3f",
336
+ "color: #cdd6f4",
337
+ "font-size: 14px",
338
+ "font-family: monospace",
339
+ "user-select: none",
340
+ ].join(";");
341
+ header.innerHTML = '<span>\uD83C\uDFA8 \u5B66\u751F\u4F5C\u54C1</span>';
342
+
343
+ var closeBtn = document.createElement("span");
344
+ closeBtn.textContent = "\u2715";
345
+ closeBtn.style.cssText = "cursor:pointer;padding:2px 6px;border-radius:3px;font-size:14px;transition:background 0.15s;";
346
+ closeBtn.onmouseenter = function () { closeBtn.style.background = "rgba(255,255,255,0.1)"; };
347
+ closeBtn.onmouseleave = function () { closeBtn.style.background = "none"; };
348
+ closeBtn.onclick = function () { closeArtifactsPanel(); };
349
+ header.appendChild(closeBtn);
350
+
351
+ // 内容区
352
+ var content = document.createElement("div");
353
+ content.id = "myclaw-artifacts-content";
354
+ content.style.cssText = [
355
+ "flex: 1",
356
+ "overflow-y: auto",
357
+ "padding: 16px",
358
+ "color: #cdd6f4",
359
+ "font-family: monospace",
360
+ "font-size: 13px",
361
+ ].join(";");
362
+
363
+ // 加载中
364
+ content.innerHTML = '<div style="text-align:center;padding:32px;color:#888;">加载中...</div>';
365
+
366
+ box.appendChild(header);
367
+ box.appendChild(content);
368
+ overlay.appendChild(box);
369
+
370
+ // 点击遮罩关闭
371
+ overlay.onclick = function (e) {
372
+ if (e.target === overlay) closeArtifactsPanel();
373
+ };
374
+
375
+ document.body.appendChild(overlay);
376
+
377
+ // 异步请求数据
378
+ fetchArtifacts(content);
379
+ }
380
+
381
+ function fetchArtifacts(contentEl) {
382
+ var url = window.location.origin + "/cmd/api/preview?path=.myclaw/__MY_ARTIFACTS__.json";
383
+ fetch(url)
384
+ .then(function (res) {
385
+ if (!res.ok) throw new Error("HTTP " + res.status);
386
+ return res.json();
387
+ })
388
+ .then(function (data) {
389
+ if (!data || !data.assets || !data.assets.length) {
390
+ contentEl.innerHTML = '<div style="text-align:center;padding:32px;color:#888;">暂无作品</div>';
391
+ return;
392
+ }
393
+ renderArtifactsList(contentEl, data);
394
+ })
395
+ .catch(function (err) {
396
+ console.error("[myclaw-artifacts] 加载失败:", err);
397
+ contentEl.innerHTML = '<div style="text-align:center;padding:32px;color:#ff6b6b;">加载失败,请稍后重试</div>';
398
+ });
399
+ }
400
+
401
+ function renderArtifactsList(container, data) {
402
+ container.innerHTML = "";
403
+ // 拼接: base + workspace前缀 + / + 资源路径
404
+ // main → workspace, 其他 → workspace-{name}
405
+ var wsName = data.workspace_id || "";
406
+ var wsPrefix = wsName === "main" ? "workspace" : "workspace-" + wsName;
407
+ var baseUrl = window.location.origin + "/cmd/api/preview?path=" + wsPrefix + "/";
408
+
409
+ data.assets.forEach(function (asset) {
410
+ var card = document.createElement("a");
411
+ card.href = baseUrl + asset.path;
412
+ card.target = "_blank";
413
+ card.rel = "noopener noreferrer";
414
+ card.style.cssText = [
415
+ "display: block",
416
+ "padding: 12px 14px",
417
+ "margin-bottom: 10px",
418
+ "background: #2d2d3f",
419
+ "border-radius: 6px",
420
+ "color: #cdd6f4",
421
+ "text-decoration: none",
422
+ "transition: background 0.15s",
423
+ "cursor: pointer",
424
+ ].join(";");
425
+ card.onmouseenter = function () { card.style.background = "#3d3d5c"; };
426
+ card.onmouseleave = function () { card.style.background = "#2d2d3f"; };
427
+
428
+ var title = document.createElement("div");
429
+ title.style.cssText = "font-size: 14px; font-weight: bold; margin-bottom: 4px;";
430
+ title.textContent = asset.name || "未命名作品";
431
+
432
+ var meta = document.createElement("div");
433
+ meta.style.cssText = "font-size: 11px; color: #888;";
434
+ meta.textContent = asset.type ? asset.type.toUpperCase() : "";
435
+
436
+ card.appendChild(title);
437
+ card.appendChild(meta);
438
+ container.appendChild(card);
439
+ });
440
+ }
441
+
442
+ function closeArtifactsPanel() {
443
+ var modal = document.querySelector("#myclaw-artifacts-modal");
444
+ if (modal) modal.remove();
445
+ artifactsOpen = false;
446
+
447
+ var btn = document.querySelector("#myclaw-artifacts-btn");
448
+ if (btn) btn.style.background = "rgba(100, 100, 100, 0.7)";
449
+ }
450
+
231
451
  // \u6D4B\u8BD5\u9EA6\u514B\u98CE\u51FD\u6570
232
452
  function testMicrophone() {
233
453
  console.log("[myclaw] \u5F00\u59CB\u6D4B\u8BD5\u9EA6\u514B\u98CE...");
@@ -586,6 +806,7 @@
586
806
  createVersionBar();
587
807
  createDocButton();
588
808
  createCmdButton();
809
+ createArtifactsButton();
589
810
  injectStyles();
590
811
 
591
812
  // 初始化 VoiceInput SDK
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiyiran/myclaw",
3
- "version": "1.0.194",
3
+ "version": "1.0.196",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
package/patch.js CHANGED
@@ -246,51 +246,6 @@ function patch() {
246
246
  console.error('[myclaw-patch] ⚠ Permissions-Policy 修复失败 (非致命): ' + err.message);
247
247
  }
248
248
 
249
- // 8. Patch X-Frame-Options + frame-ancestors(允许同域 iframe 嵌入)
250
- try {
251
- const distParent = path.resolve(uiDir, '..');
252
- const distFiles = fs.readdirSync(distParent);
253
- let framePatched = false;
254
-
255
- for (const f of distFiles) {
256
- if (f.endsWith('.js' + BACKUP_SUFFIX)) continue; // 跳过备份文件
257
- const isTarget = (f.startsWith('gateway-cli-') || f.startsWith('server-')) && f.endsWith('.js');
258
- if (!isTarget) continue;
259
-
260
- const filePath = path.join(distParent, f);
261
- let content = fs.readFileSync(filePath, 'utf8');
262
- let modified = false;
263
-
264
- // X-Frame-Options: DENY → SAMEORIGIN
265
- if (content.includes('"DENY"')) {
266
- const backupFile = filePath + BACKUP_SUFFIX;
267
- if (!fs.existsSync(backupFile)) {
268
- fs.copyFileSync(filePath, backupFile);
269
- }
270
- content = content.replace(/"X-Frame-Options",\s*"DENY"/g, '"X-Frame-Options", "SAMEORIGIN"');
271
- modified = true;
272
- }
273
-
274
- // frame-ancestors 'none' → 'self'
275
- if (content.includes("'none'") && content.includes("frame-ancestors")) {
276
- content = content.replace(/frame-ancestors\s*'none'/g, "frame-ancestors 'self'");
277
- modified = true;
278
- }
279
-
280
- if (modified) {
281
- fs.writeFileSync(filePath, content, 'utf8');
282
- console.log('[myclaw-patch] ✅ 已修复 iframe 安全头 (X-Frame-Options + frame-ancestors): ' + f);
283
- framePatched = true;
284
- }
285
- }
286
-
287
- if (!framePatched) {
288
- console.log('[myclaw-patch] ⚠ 未找到 iframe 安全头配置');
289
- }
290
- } catch (err) {
291
- console.error('[myclaw-patch] ⚠ iframe 安全头修复失败 (非致命): ' + err.message);
292
- }
293
-
294
249
  console.log('[myclaw-patch] ✅ 注入完成,重启 Gateway 后生效');
295
250
  return { success: true, uiDir: uiDir, version: version };
296
251
  }