@aiyiran/myclaw 1.1.197 → 1.1.199
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 +141 -73
- package/index.js +1 -1
- package/package.json +1 -1
package/assets/myclaw-inject.js
CHANGED
|
@@ -1492,12 +1492,16 @@ btn.addEventListener("click", function () {
|
|
|
1492
1492
|
return (b.lastUpdated || 0) > (a.lastUpdated || 0) ? b : a;
|
|
1493
1493
|
});
|
|
1494
1494
|
// 记下"新项目建好后要自动创建的会话",靠 localStorage 把意图带过整页跳转。
|
|
1495
|
-
// 跳转后的新页面加载时,processPendingSessions()
|
|
1495
|
+
// 跳转后的新页面加载时,processPendingSessions() 会读取;全部完成后才清除。
|
|
1496
1496
|
try {
|
|
1497
|
-
|
|
1497
|
+
var pendingSessions = {
|
|
1498
1498
|
agentId: newest.id,
|
|
1499
|
-
names: ["程序", "美术", "策划"]
|
|
1500
|
-
|
|
1499
|
+
names: ["程序", "美术", "策划"],
|
|
1500
|
+
createdAt: new Date().toISOString(),
|
|
1501
|
+
myclawVersion: MYCLAW_VERSION
|
|
1502
|
+
};
|
|
1503
|
+
localStorage.setItem(PENDING_SESSIONS_KEY, JSON.stringify(pendingSessions));
|
|
1504
|
+
logNewSession("pending_saved", pendingSessions);
|
|
1501
1505
|
} catch (e) {}
|
|
1502
1506
|
window.location.href = window.location.origin + '/chat?session=' + encodeURIComponent('agent:' + newest.id + ':main');
|
|
1503
1507
|
})
|
|
@@ -1570,60 +1574,105 @@ btn.addEventListener("click", function () {
|
|
|
1570
1574
|
return null;
|
|
1571
1575
|
}
|
|
1572
1576
|
|
|
1573
|
-
// 轮询等待 sessionKey 变化(原生按钮创建+切换后,key 会变成新会话)
|
|
1574
|
-
function waitForSessionChange(app, prevKey, timeoutMs) {
|
|
1575
|
-
return new Promise(function (resolve) {
|
|
1576
|
-
var start = Date.now();
|
|
1577
|
-
(function poll() {
|
|
1578
|
-
if (app.sessionKey && app.sessionKey !== prevKey) { resolve(app.sessionKey); return; }
|
|
1579
|
-
if (Date.now() - start > timeoutMs) { resolve(null); return; }
|
|
1580
|
-
setTimeout(poll, 80);
|
|
1581
|
-
})();
|
|
1582
|
-
});
|
|
1583
|
-
}
|
|
1584
|
-
|
|
1585
1577
|
// localStorage 键:跨"新项目跳转"传递"待自动创建的会话"意图
|
|
1586
1578
|
var PENDING_SESSIONS_KEY = "myclaw_pending_sessions";
|
|
1579
|
+
var NEWSESSION_LOG_KEY = "myclaw_newsession_logs";
|
|
1580
|
+
var AUTO_SESSION_WAIT_MS = 120000;
|
|
1581
|
+
var pendingSessionsProcessing = false;
|
|
1582
|
+
|
|
1583
|
+
// 同时写浏览器控制台和 localStorage,便于页面跳转后保留诊断证据。
|
|
1584
|
+
// 日志只记录创建状态,不记录 token、消息内容等敏感信息。
|
|
1585
|
+
function logNewSession(event, details) {
|
|
1586
|
+
var entry = {
|
|
1587
|
+
time: new Date().toISOString(),
|
|
1588
|
+
event: event,
|
|
1589
|
+
details: details || {}
|
|
1590
|
+
};
|
|
1591
|
+
console.log("[myclaw-newsession]", event, entry.details);
|
|
1592
|
+
try {
|
|
1593
|
+
var logs = JSON.parse(localStorage.getItem(NEWSESSION_LOG_KEY) || "[]");
|
|
1594
|
+
if (!Array.isArray(logs)) logs = [];
|
|
1595
|
+
logs.push(entry);
|
|
1596
|
+
if (logs.length > 100) logs = logs.slice(logs.length - 100);
|
|
1597
|
+
localStorage.setItem(NEWSESSION_LOG_KEY, JSON.stringify(logs));
|
|
1598
|
+
} catch (e) {}
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
function pendingSessionState(pending, startedAt) {
|
|
1602
|
+
var app = getOpenclawApp();
|
|
1603
|
+
var btn = findNativeNewSessionBtn();
|
|
1604
|
+
var sessionKey = app && app.sessionKey ? app.sessionKey : null;
|
|
1605
|
+
return {
|
|
1606
|
+
elapsedMs: Date.now() - startedAt,
|
|
1607
|
+
targetAgentId: pending.agentId || null,
|
|
1608
|
+
currentAgentId: deriveAgentId(sessionKey),
|
|
1609
|
+
sessionKey: sessionKey,
|
|
1610
|
+
appReady: !!app,
|
|
1611
|
+
clientReady: !!(app && app.client),
|
|
1612
|
+
connected: !!(app && app.connected),
|
|
1613
|
+
buttonFound: !!btn,
|
|
1614
|
+
buttonDisabled: btn ? !!btn.disabled : null
|
|
1615
|
+
};
|
|
1616
|
+
}
|
|
1587
1617
|
|
|
1588
|
-
//
|
|
1589
|
-
function
|
|
1618
|
+
// 等待项目页面和网关真正可用。按钮状态仍记入日志,但自动创建不再依赖 UI 按钮。
|
|
1619
|
+
function waitForPendingSessionReady(pending, timeoutMs) {
|
|
1590
1620
|
return new Promise(function (resolve) {
|
|
1591
|
-
var
|
|
1621
|
+
var startedAt = Date.now();
|
|
1622
|
+
var lastSignature = "";
|
|
1623
|
+
var lastLogAt = 0;
|
|
1592
1624
|
(function poll() {
|
|
1593
|
-
var
|
|
1594
|
-
|
|
1595
|
-
if (
|
|
1596
|
-
|
|
1597
|
-
|
|
1625
|
+
var state = pendingSessionState(pending, startedAt);
|
|
1626
|
+
var signature = [state.currentAgentId, state.appReady, state.clientReady, state.connected, state.buttonFound, state.buttonDisabled].join("|");
|
|
1627
|
+
if (signature !== lastSignature || Date.now() - lastLogAt >= 5000) {
|
|
1628
|
+
logNewSession("waiting", state);
|
|
1629
|
+
lastSignature = signature;
|
|
1630
|
+
lastLogAt = Date.now();
|
|
1631
|
+
}
|
|
1632
|
+
var app = getOpenclawApp();
|
|
1633
|
+
var targetMatches = !pending.agentId || state.currentAgentId === pending.agentId;
|
|
1634
|
+
if (app && app.client && app.connected && targetMatches) {
|
|
1635
|
+
logNewSession("ready", state);
|
|
1636
|
+
resolve(app);
|
|
1637
|
+
return;
|
|
1638
|
+
}
|
|
1639
|
+
if (Date.now() - startedAt > timeoutMs) {
|
|
1640
|
+
logNewSession("ready_timeout", state);
|
|
1641
|
+
resolve(null);
|
|
1642
|
+
return;
|
|
1643
|
+
}
|
|
1644
|
+
setTimeout(poll, 250);
|
|
1598
1645
|
})();
|
|
1599
1646
|
});
|
|
1600
1647
|
}
|
|
1601
1648
|
|
|
1602
|
-
//
|
|
1603
|
-
//
|
|
1604
|
-
function
|
|
1649
|
+
// 自动批量创建使用 Gateway 官方 sessions.create RPC,不再模拟点击 UI。
|
|
1650
|
+
// 新版 Control UI 点击按钮后不一定立刻更新 app.sessionKey,以页面切换判断成功会误报超时。
|
|
1651
|
+
function createNamedSessionDirectAsync(label, agentId) {
|
|
1605
1652
|
return new Promise(function (resolve, reject) {
|
|
1606
1653
|
var app = getOpenclawApp();
|
|
1607
|
-
if (!app
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
if (
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1654
|
+
if (!app || !app.client || !app.connected) {
|
|
1655
|
+
reject(new Error("网关未连接"));
|
|
1656
|
+
return;
|
|
1657
|
+
}
|
|
1658
|
+
var params = { label: label };
|
|
1659
|
+
if (agentId) params.agentId = agentId;
|
|
1660
|
+
logNewSession("rpc_create_request", params);
|
|
1661
|
+
app.client.request("sessions.create", params).then(function (result) {
|
|
1662
|
+
var newKey = result && typeof result.key === "string" ? result.key.trim() : "";
|
|
1663
|
+
if (!newKey) {
|
|
1664
|
+
logNewSession("rpc_create_invalid_response", { label: label, result: result || null });
|
|
1665
|
+
reject(new Error("sessions.create 未返回会话 key"));
|
|
1666
|
+
return;
|
|
1667
|
+
}
|
|
1668
|
+
logNewSession("rpc_create_success", { label: label, sessionKey: newKey });
|
|
1669
|
+
resolve(newKey);
|
|
1670
|
+
}).catch(function (err) {
|
|
1671
|
+
logNewSession("rpc_create_failed", {
|
|
1672
|
+
label: label,
|
|
1673
|
+
error: err && err.message ? err.message : String(err)
|
|
1674
|
+
});
|
|
1675
|
+
reject(err);
|
|
1627
1676
|
});
|
|
1628
1677
|
});
|
|
1629
1678
|
}
|
|
@@ -1631,32 +1680,35 @@ btn.addEventListener("click", function () {
|
|
|
1631
1680
|
// 手动"💬 新会话"按钮走这里(带 toast 反馈)
|
|
1632
1681
|
function createNamedSession(label) {
|
|
1633
1682
|
showToast("正在创建:" + label);
|
|
1634
|
-
|
|
1683
|
+
var app = getOpenclawApp();
|
|
1684
|
+
var agentId = deriveAgentId(app && app.sessionKey);
|
|
1685
|
+
createNamedSessionDirectAsync(label, agentId).then(function (newKey) {
|
|
1635
1686
|
showToast("已创建:" + label, "success");
|
|
1687
|
+
setTimeout(function () {
|
|
1688
|
+
window.location.href = window.location.origin + "/chat?session=" + encodeURIComponent(newKey);
|
|
1689
|
+
}, 300);
|
|
1636
1690
|
}).catch(function (err) {
|
|
1637
1691
|
showToast(err && err.message ? err.message : String(err), "error");
|
|
1638
1692
|
console.error("[myclaw-newsession] 创建失败:", err);
|
|
1639
1693
|
});
|
|
1640
1694
|
}
|
|
1641
1695
|
|
|
1642
|
-
//
|
|
1643
|
-
function createSessionsSequential(names) {
|
|
1696
|
+
// 顺序创建多个会话;每个 RPC 完成后再创建下一个。
|
|
1697
|
+
function createSessionsSequential(names, agentId, onCreated) {
|
|
1644
1698
|
return names.reduce(function (chain, name) {
|
|
1645
1699
|
return chain.then(function () {
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
return (b && !b.disabled) ? b : null;
|
|
1650
|
-
}, 8000, 150).then(function () {
|
|
1651
|
-
return createNamedSessionAsync(name);
|
|
1700
|
+
return createNamedSessionDirectAsync(name, agentId).then(function (newKey) {
|
|
1701
|
+
if (onCreated) onCreated(name, newKey);
|
|
1702
|
+
return newKey;
|
|
1652
1703
|
});
|
|
1653
1704
|
});
|
|
1654
1705
|
}, Promise.resolve());
|
|
1655
1706
|
}
|
|
1656
1707
|
|
|
1657
1708
|
// 页面加载后调用一次:若存在"待创建会话"意图,且当前正处于目标项目,就自动依次建好。
|
|
1658
|
-
//
|
|
1709
|
+
// 等待或批量创建失败时保留剩余任务;全部完成后才清除标记。
|
|
1659
1710
|
function processPendingSessions() {
|
|
1711
|
+
if (pendingSessionsProcessing) return;
|
|
1660
1712
|
var raw = null;
|
|
1661
1713
|
try { raw = localStorage.getItem(PENDING_SESSIONS_KEY); } catch (e) { return; }
|
|
1662
1714
|
if (!raw) return;
|
|
@@ -1664,31 +1716,47 @@ btn.addEventListener("click", function () {
|
|
|
1664
1716
|
var pending = null;
|
|
1665
1717
|
try { pending = JSON.parse(raw); } catch (e) {}
|
|
1666
1718
|
if (!pending || !Array.isArray(pending.names) || !pending.names.length) {
|
|
1719
|
+
logNewSession("pending_invalid", { raw: raw });
|
|
1667
1720
|
try { localStorage.removeItem(PENDING_SESSIONS_KEY); } catch (e) {}
|
|
1668
1721
|
return;
|
|
1669
1722
|
}
|
|
1723
|
+
pendingSessionsProcessing = true;
|
|
1724
|
+
logNewSession("pending_loaded", pending);
|
|
1670
1725
|
|
|
1671
|
-
// 等 app + client + sessionKey
|
|
1672
|
-
|
|
1673
|
-
var app = getOpenclawApp();
|
|
1674
|
-
if (!app || !app.client || !app.sessionKey) return null;
|
|
1675
|
-
if (pending.agentId && deriveAgentId(app.sessionKey) !== pending.agentId) return null;
|
|
1676
|
-
var btn = findNativeNewSessionBtn();
|
|
1677
|
-
if (!btn || btn.disabled) return null;
|
|
1678
|
-
return app;
|
|
1679
|
-
}, 20000, 250).then(function (app) {
|
|
1680
|
-
// 就绪判定完成即清标记:成功不重复、失败也不再纠缠
|
|
1681
|
-
try { localStorage.removeItem(PENDING_SESSIONS_KEY); } catch (e) {}
|
|
1726
|
+
// 等 app + client + sessionKey 就绪,并确认当前确实停在目标项目上。
|
|
1727
|
+
waitForPendingSessionReady(pending, AUTO_SESSION_WAIT_MS).then(function (app) {
|
|
1682
1728
|
if (!app) {
|
|
1683
|
-
|
|
1729
|
+
pendingSessionsProcessing = false;
|
|
1730
|
+
console.warn("[myclaw-newsession] 目标项目等待超时;保留标记,刷新后可重试");
|
|
1731
|
+
showToast("自动创建等待超时,刷新页面后会重试", "error");
|
|
1684
1732
|
return;
|
|
1685
1733
|
}
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1734
|
+
var originalNames = pending.names.slice();
|
|
1735
|
+
logNewSession("batch_start", { agentId: pending.agentId, names: originalNames });
|
|
1736
|
+
showToast("正在为新项目创建 " + originalNames.length + " 个对话…");
|
|
1737
|
+
createSessionsSequential(originalNames, pending.agentId, function (createdName, newKey) {
|
|
1738
|
+
// 每成功一个就保存剩余任务;中途失败或刷新时只重试尚未完成的名称。
|
|
1739
|
+
pending.names = pending.names.filter(function (name) { return name !== createdName; });
|
|
1740
|
+
try { localStorage.setItem(PENDING_SESSIONS_KEY, JSON.stringify(pending)); } catch (e) {}
|
|
1741
|
+
logNewSession("pending_progress_saved", {
|
|
1742
|
+
createdName: createdName,
|
|
1743
|
+
sessionKey: newKey,
|
|
1744
|
+
remainingNames: pending.names.slice()
|
|
1745
|
+
});
|
|
1746
|
+
}).then(function () {
|
|
1747
|
+
pendingSessionsProcessing = false;
|
|
1748
|
+
try { localStorage.removeItem(PENDING_SESSIONS_KEY); } catch (e) {}
|
|
1749
|
+
logNewSession("batch_success", { agentId: pending.agentId, names: originalNames });
|
|
1750
|
+
showToast("已创建:" + originalNames.join(" / "), "success");
|
|
1689
1751
|
}).catch(function (err) {
|
|
1752
|
+
pendingSessionsProcessing = false;
|
|
1690
1753
|
console.error("[myclaw-newsession] 批量创建失败:", err);
|
|
1691
|
-
|
|
1754
|
+
logNewSession("batch_failed", {
|
|
1755
|
+
agentId: pending.agentId,
|
|
1756
|
+
remainingNames: pending.names.slice(),
|
|
1757
|
+
error: err && err.message ? err.message : String(err)
|
|
1758
|
+
});
|
|
1759
|
+
showToast("批量创建部分失败,刷新后会重试:" + (err && err.message ? err.message : err), "error");
|
|
1692
1760
|
});
|
|
1693
1761
|
});
|
|
1694
1762
|
}
|
package/index.js
CHANGED
|
@@ -1596,7 +1596,7 @@ const MACHINE_CONFIG = [
|
|
|
1596
1596
|
{ name: '伊伊', claw: 'claw6', desc: '伊伊 的机器' },
|
|
1597
1597
|
{ name: '梓浩', claw: 'claw7', desc: '梓浩 的机器' },
|
|
1598
1598
|
{ name: '刘泓毅', claw: 'claw8', desc: '刘泓毅 的机器' },
|
|
1599
|
-
{ name: '
|
|
1599
|
+
{ name: '袁驿博', claw: 'claw9', desc: '袁驿博 的机器' },
|
|
1600
1600
|
{ name: '雨熙', claw: 'claw10', desc: '雨熙 的机器' },
|
|
1601
1601
|
{ name: '绍博', claw: 'claw11', desc: '绍博 的机器' },
|
|
1602
1602
|
{ name: '黄玺澄', claw: 'claw12', desc: '玺澄 的机器' },
|