@aiyiran/myclaw 1.1.179 → 1.1.180
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/assets/myclaw-inject.js +42 -19
- package/package.json +1 -1
package/assets/myclaw-inject.js
CHANGED
|
@@ -27,8 +27,10 @@
|
|
|
27
27
|
var committedText = ""; // 已经提交到 textarea 的文字(上一轮累积)
|
|
28
28
|
var cursorOffset = 0; // 录音开始时光标在 textarea 中的位置
|
|
29
29
|
var injected = false;
|
|
30
|
-
var stopping = false; // 正在等待最终识别结果(stopVoice
|
|
30
|
+
var stopping = false; // 正在等待最终识别结果(stopVoice 的等待窗口)
|
|
31
31
|
var suppressNextClipboardCopy = false;
|
|
32
|
+
var VOICE_STOP_WAIT_MS = 1000;
|
|
33
|
+
var VOICE_STOP_WAIT_SECONDS = VOICE_STOP_WAIT_MS / 1000;
|
|
32
34
|
|
|
33
35
|
// ═══ 1. 右下角版本入口(打开快捷命令) ═══
|
|
34
36
|
function createVersionBar() {
|
|
@@ -861,7 +863,7 @@ btn.addEventListener("click", function () {
|
|
|
861
863
|
|
|
862
864
|
voice = new window.VoiceInput({
|
|
863
865
|
onResult: function (text) {
|
|
864
|
-
// 完全停止后才忽略;stopping
|
|
866
|
+
// 完全停止后才忽略;stopping 期间仍允许写入
|
|
865
867
|
if (!recording && !stopping) return;
|
|
866
868
|
// 讯飞实时返回识别文字,替换到光标位置
|
|
867
869
|
pendingText = text;
|
|
@@ -931,7 +933,7 @@ btn.addEventListener("click", function () {
|
|
|
931
933
|
|
|
932
934
|
|
|
933
935
|
/**
|
|
934
|
-
*
|
|
936
|
+
* 语音录入结束时,短暂等待后关闭录音资源
|
|
935
937
|
* @param {Function} [onDone] - 等待完成后执行的回调(如发送)
|
|
936
938
|
*/
|
|
937
939
|
var voiceStopTimer = null;
|
|
@@ -943,13 +945,13 @@ btn.addEventListener("click", function () {
|
|
|
943
945
|
return;
|
|
944
946
|
}
|
|
945
947
|
|
|
946
|
-
// 进入 stopping 态:UI 立即更新,但 onResult
|
|
948
|
+
// 进入 stopping 态:UI 立即更新,但 onResult 仍允许在等待窗口内写入文字
|
|
947
949
|
stopping = true;
|
|
948
950
|
recording = false;
|
|
949
951
|
updateButtonUI();
|
|
950
|
-
console.log("[myclaw-voice] stopping=true, UI updated, starting
|
|
952
|
+
console.log("[myclaw-voice] stopping=true, UI updated, starting " + VOICE_STOP_WAIT_SECONDS + "s timer...");
|
|
951
953
|
|
|
952
|
-
//
|
|
954
|
+
// 延迟关闭录音资源(等讯飞把剩余识别结果全部推过来)
|
|
953
955
|
if (voiceStopTimer) {
|
|
954
956
|
console.log("[myclaw-voice] clearing previous timer");
|
|
955
957
|
clearTimeout(voiceStopTimer);
|
|
@@ -958,9 +960,9 @@ btn.addEventListener("click", function () {
|
|
|
958
960
|
voiceStopTimer = null;
|
|
959
961
|
stopping = false;
|
|
960
962
|
updateButtonUI();
|
|
961
|
-
console.log("[myclaw-voice]
|
|
963
|
+
console.log("[myclaw-voice] " + VOICE_STOP_WAIT_SECONDS + "s timer fired, closing resources...");
|
|
962
964
|
|
|
963
|
-
// 快照当前 textarea
|
|
965
|
+
// 快照当前 textarea 值(等待窗口内 onResult 可能已更新)
|
|
964
966
|
var finalText = getTextareaValue();
|
|
965
967
|
console.log("[myclaw-voice] finalText:", JSON.stringify(finalText.substring(0, 50)));
|
|
966
968
|
if (voice) {
|
|
@@ -977,7 +979,7 @@ btn.addEventListener("click", function () {
|
|
|
977
979
|
}
|
|
978
980
|
|
|
979
981
|
console.log("[myclaw-voice] 停止录音完成");
|
|
980
|
-
},
|
|
982
|
+
}, VOICE_STOP_WAIT_MS);
|
|
981
983
|
}
|
|
982
984
|
|
|
983
985
|
// ═══ 5. DOM 注入 ═══
|
|
@@ -1061,7 +1063,7 @@ btn.addEventListener("click", function () {
|
|
|
1061
1063
|
".myclaw-problem-menu-item:hover, .myclaw-problem-menu-item:focus {",
|
|
1062
1064
|
" background: #31314a; color: #fff; outline: none;",
|
|
1063
1065
|
"}",
|
|
1064
|
-
/* 按钮处理中态:半透明 +
|
|
1066
|
+
/* 按钮处理中态:半透明 + 红圈收缩动画 */
|
|
1065
1067
|
".myclaw-voice-stopping {",
|
|
1066
1068
|
" opacity: 0.5 !important;",
|
|
1067
1069
|
" position: relative;",
|
|
@@ -1076,7 +1078,7 @@ btn.addEventListener("click", function () {
|
|
|
1076
1078
|
" border-radius: 50%;",
|
|
1077
1079
|
" border: 2px solid #ff4444;",
|
|
1078
1080
|
" transform: translate(-50%, -50%) scale(1.5);",
|
|
1079
|
-
" animation: myclaw-countdown
|
|
1081
|
+
" animation: myclaw-countdown " + VOICE_STOP_WAIT_SECONDS + "s linear forwards;",
|
|
1080
1082
|
" pointer-events: none;",
|
|
1081
1083
|
"}",
|
|
1082
1084
|
"@keyframes myclaw-countdown {",
|
|
@@ -1215,7 +1217,7 @@ btn.addEventListener("click", function () {
|
|
|
1215
1217
|
}
|
|
1216
1218
|
|
|
1217
1219
|
/**
|
|
1218
|
-
* 拦截 Enter 键:语音态下按回车 →
|
|
1220
|
+
* 拦截 Enter 键:语音态下按回车 → 等待语音收尾后发送
|
|
1219
1221
|
*/
|
|
1220
1222
|
function hookVoiceEnter() {
|
|
1221
1223
|
document.addEventListener("keydown", function (e) {
|
|
@@ -1249,7 +1251,7 @@ btn.addEventListener("click", function () {
|
|
|
1249
1251
|
var text = getTextareaValue();
|
|
1250
1252
|
if (!text || !text.trim()) return; // 空文字不处理
|
|
1251
1253
|
|
|
1252
|
-
// 1)
|
|
1254
|
+
// 1) 停止语音输入(等待语音收尾后关闭,关闭后触发发送)
|
|
1253
1255
|
if (recording) {
|
|
1254
1256
|
e.preventDefault();
|
|
1255
1257
|
e.stopPropagation();
|
|
@@ -1380,7 +1382,7 @@ btn.addEventListener("click", function () {
|
|
|
1380
1382
|
}
|
|
1381
1383
|
|
|
1382
1384
|
// 弹出命令输入小弹框
|
|
1383
|
-
function promptAndRun(title, placeholder, hint, cmdTemplate, btnColor, defaultValue, allowAnyName,
|
|
1385
|
+
function promptAndRun(title, placeholder, hint, cmdTemplate, btnColor, defaultValue, allowAnyName, afterDelay, afterFn) {
|
|
1384
1386
|
var mask = document.createElement("div");
|
|
1385
1387
|
mask.style.cssText = [
|
|
1386
1388
|
"position:fixed",
|
|
@@ -1456,8 +1458,8 @@ btn.addEventListener("click", function () {
|
|
|
1456
1458
|
var cmd = cmdTemplate.replace("{name}", safeName);
|
|
1457
1459
|
runCommand(cmd);
|
|
1458
1460
|
setTimeout(function () { mask.remove(); }, 1000);
|
|
1459
|
-
if (
|
|
1460
|
-
setTimeout(function () { location.reload(); },
|
|
1461
|
+
if (afterDelay) {
|
|
1462
|
+
setTimeout(afterFn || function () { location.reload(); }, afterDelay);
|
|
1461
1463
|
}
|
|
1462
1464
|
}
|
|
1463
1465
|
|
|
@@ -1474,6 +1476,26 @@ btn.addEventListener("click", function () {
|
|
|
1474
1476
|
}
|
|
1475
1477
|
|
|
1476
1478
|
function openNewAgentPrompt() {
|
|
1479
|
+
var apiBase = (function () {
|
|
1480
|
+
var h = window.location.hostname;
|
|
1481
|
+
var isRemote = h === 'claw.yiranlaoshi.com' || h.endsWith('.kekouen.cn');
|
|
1482
|
+
return isRemote ? window.location.origin + '/sync' : 'http://127.0.0.1:18800';
|
|
1483
|
+
})();
|
|
1484
|
+
|
|
1485
|
+
function redirectToNewestAgent() {
|
|
1486
|
+
fetch(apiBase + '/api/agents')
|
|
1487
|
+
.then(function (r) { return r.json(); })
|
|
1488
|
+
.then(function (data) {
|
|
1489
|
+
var agents = (data.agents || []).filter(function (a) { return a && a.id; });
|
|
1490
|
+
if (!agents.length) { location.reload(); return; }
|
|
1491
|
+
var newest = agents.reduce(function (a, b) {
|
|
1492
|
+
return (b.lastUpdated || 0) > (a.lastUpdated || 0) ? b : a;
|
|
1493
|
+
});
|
|
1494
|
+
window.location.href = window.location.origin + '/chat?session=' + encodeURIComponent('agent:' + newest.id + ':main');
|
|
1495
|
+
})
|
|
1496
|
+
.catch(function () { location.reload(); });
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1477
1499
|
promptAndRun(
|
|
1478
1500
|
"\u65B0\u5EFA\u9879\u76EE",
|
|
1479
1501
|
"\u8F93\u5165\u65B0\u9879\u76EE\u540D\u79F0\uFF0C\u5982 my-cat",
|
|
@@ -1482,7 +1504,8 @@ btn.addEventListener("click", function () {
|
|
|
1482
1504
|
"#3b82f6",
|
|
1483
1505
|
"",
|
|
1484
1506
|
true,
|
|
1485
|
-
3000
|
|
1507
|
+
3000,
|
|
1508
|
+
redirectToNewestAgent
|
|
1486
1509
|
);
|
|
1487
1510
|
}
|
|
1488
1511
|
|
|
@@ -1805,7 +1828,7 @@ btn.addEventListener("click", function () {
|
|
|
1805
1828
|
|
|
1806
1829
|
// ── 按钮列表 ──
|
|
1807
1830
|
var btns = [
|
|
1808
|
-
{ label: "\uD83D\uDCC1 \u65B0\u9879\u76EE", desc: "\u521B\u5EFA\u4E00\u4E2A\u65B0\u9879\u76EE", hasInput: true, inputTitle: "\u65B0\u5EFA\u9879\u76EE", placeholder: "\u8F93\u5165\u65B0\u9879\u76EE\u540D\u79F0\uFF0C\u5982 my-cat", hint: "\u7ED9\u4F60\u7684\u65B0\u9879\u76EE\u8D77\u4E2A\u540D\u5B57\uFF08\u4E2D\u6587 / \u82F1\u6587\u5747\u53EF\uFF09\uFF0C\u70B9\u51FB\u540E\u4F1A\u81EA\u52A8\u521B\u5EFA", cmd: "mc new {name}", color: "#3b82f6", allowAnyName: true,
|
|
1831
|
+
{ label: "\uD83D\uDCC1 \u65B0\u9879\u76EE", desc: "\u521B\u5EFA\u4E00\u4E2A\u65B0\u9879\u76EE", hasInput: true, inputTitle: "\u65B0\u5EFA\u9879\u76EE", placeholder: "\u8F93\u5165\u65B0\u9879\u76EE\u540D\u79F0\uFF0C\u5982 my-cat", hint: "\u7ED9\u4F60\u7684\u65B0\u9879\u76EE\u8D77\u4E2A\u540D\u5B57\uFF08\u4E2D\u6587 / \u82F1\u6587\u5747\u53EF\uFF09\uFF0C\u70B9\u51FB\u540E\u4F1A\u81EA\u52A8\u521B\u5EFA", cmd: "mc new {name}", color: "#3b82f6", allowAnyName: true, afterDelay: 3000 },
|
|
1809
1832
|
{ label: "\uD83D\uDCAC \u6DFB\u52A0\u5BF9\u8BDD", desc: "\u6253\u5F00\u5DF2\u6709\u4F19\u4F34\u7684\u5BF9\u8BDD\u7A97\u53E3", hasInput: true, inputTitle: "\u6DFB\u52A0\u5BF9\u8BDD", placeholder: "\u8F93\u5165\u4F19\u4F34\u540D\u79F0\uFF0C\u5982 kakaxi", hint: "\u8F93\u5165\u4F60\u7684\u4F19\u4F34\u7684\u540D\u79F0\uFF08\u82F1\u6587\u5B57\u6BCD\u3001\u6570\u5B57\u3001\u8FDE\u5B57\u7B26\uFF09\uFF0C\u70B9\u51FB\u540E\u4F1A\u6253\u5F00\u5BF9\u8BDD\u7A97\u53E3", cmd: "mc tui {name}", color: "#10b981", getDefault: getCurrentAgentName },
|
|
1810
1833
|
{ label: "\uD83D\uDD04 \u91CD\u542F\u670D\u52A1", desc: "\u91CD\u542F\u6587\u4EF6\u670D\u52A1", hasInput: false, cmd: "mc server", color: "#ef4444" },
|
|
1811
1834
|
{ label: "\uD83E\uDD9E \u91CD\u542F\u9F99\u867E", desc: "\u91CD\u542F OpenClaw \u6838\u5FC3\u670D\u52A1", hasInput: false, cmd: "mc all", color: "#f59e0b" },
|
|
@@ -1854,7 +1877,7 @@ btn.addEventListener("click", function () {
|
|
|
1854
1877
|
|
|
1855
1878
|
row.onclick = function () {
|
|
1856
1879
|
if (item.hasInput) {
|
|
1857
|
-
promptAndRun(item.inputTitle, item.placeholder, item.hint, item.cmd, item.color, item.getDefault ? item.getDefault() : '', item.allowAnyName, item.
|
|
1880
|
+
promptAndRun(item.inputTitle, item.placeholder, item.hint, item.cmd, item.color, item.getDefault ? item.getDefault() : '', item.allowAnyName, item.afterDelay, item.afterFn);
|
|
1858
1881
|
} else {
|
|
1859
1882
|
runCommand(item.cmd);
|
|
1860
1883
|
}
|