@bolloon/bolloon-agent 0.4.8 → 0.4.9

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/dist/index.js CHANGED
@@ -831,6 +831,41 @@ async function processInput(input, comm) {
831
831
  }
832
832
  catch { /* DID 生成失败不阻塞创建 */ }
833
833
  const channels = await updateChannels((chs) => [...chs, ch]);
834
+ // 2026-08-12 (TaskFix): CLI 创建的 agent 同步写 agents.json + 关联 channelId —
835
+ // 与 server 创建 channel 逻辑对齐. 否则 CLI 创建的 agent 不在 agents.json,
836
+ // 重启后 server 的 healMissingChannels 只能从 agents.json 恢复 → 该 agent 永远消失.
837
+ try {
838
+ const agentsPath = path.join(process.env.HOME || '/tmp', '.bolloon', 'agents', 'agents.json');
839
+ await fs.mkdir(path.dirname(agentsPath), { recursive: true });
840
+ let arr = [];
841
+ try {
842
+ arr = JSON.parse(await fs.readFile(agentsPath, 'utf-8'));
843
+ }
844
+ catch { }
845
+ if (!Array.isArray(arr))
846
+ arr = [];
847
+ const exists = arr.find((a) => a && a.id === agentId);
848
+ if (exists) {
849
+ exists.channelId = id;
850
+ exists.name = name.trim();
851
+ exists.lastActive = new Date().toISOString();
852
+ }
853
+ else {
854
+ arr.push({
855
+ id: agentId,
856
+ name: name.trim(),
857
+ did: `did:local:${id}`,
858
+ description: `Agent ${name} (auto-registered from channel ${id})`,
859
+ status: 'active',
860
+ createdAt: new Date().toISOString(),
861
+ lastActive: new Date().toISOString(),
862
+ channelId: id,
863
+ });
864
+ }
865
+ await fs.writeFile(agentsPath, JSON.stringify(arr, null, 2), 'utf-8');
866
+ console.log(`[创建频道] agent 同步进 agents.json: ${agentId} → channel ${id}`);
867
+ }
868
+ catch { /* agents.json 写失败不阻塞创建 */ }
834
869
  // 刷新 store 缓存 (updateChannels 走了 server-storage, store 内存还是旧的)
835
870
  await store.load();
836
871
  await store.setActive(id);
@@ -1731,7 +1731,6 @@ export async function createWebServer(port = 3000, options = {}) {
1731
1731
  const { existsSync } = await import('fs');
1732
1732
  const { readFile } = await import('fs/promises');
1733
1733
  const agentsFile = `${process.env.HOME || '/tmp'}/.bolloon/agents/agents.json`;
1734
- const sessionsDir = `${process.env.HOME || '/tmp'}/.bolloon/sessions/cache`;
1735
1734
  if (!existsSync(agentsFile))
1736
1735
  return 0;
1737
1736
  const agentsRaw = await readFile(agentsFile, 'utf-8');
@@ -1744,14 +1743,11 @@ export async function createWebServer(port = 3000, options = {}) {
1744
1743
  const cid = a && a.channelId;
1745
1744
  if (!cid || knownIds.has(cid))
1746
1745
  continue;
1747
- // session 文件才算可恢复 (说明确实创建过)
1748
- // 2026-08-12 fix: SessionStore 保存到 cache/<channelId>__default.json (冒号被 filenameEscape __),
1749
- // 之前用 `${sessionsDir}/${cid}:default.json` ( escape + 硬拼冒号) 查不到 → 会话已存在也被判为
1750
- // "无 session" 永不恢复, session/channel 路径与创建智能体 channel 的路径不一致 (bug 修复)
1751
- const { getSessionCacheFile } = await import('../bootstrap/memory-compressor.js');
1752
- const hasSession = existsSync(getSessionCacheFile(cid, 'default')) || existsSync(`${sessionsDir}/${cid}.json`);
1753
- if (!hasSession)
1754
- continue;
1746
+ // 2026-08-12 (TaskFix): 放宽恢复条件 — 只要 agents.json 里 agent 关联了 channelId (非空),
1747
+ // channels.json 缺失该 channel, 就恢复 channel stub.
1748
+ // 之前强制要求 session cache 文件存在, 导致"刚创建还没对话"的 agent (CLI /new agent 同步 agents.json 后)
1749
+ // 重启时 session 文件不存在 永不恢复 "以前创建的智能体消失" bug.
1750
+ // 空 channelId (旧数据无关联 channel) 仍跳过, 避免给无关 agent 乱建 channel.
1755
1751
  const restored = {
1756
1752
  id: cid,
1757
1753
  name: a.name || `Agent-${String(cid).slice(-6)}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bolloon/bolloon-agent",
3
- "version": "0.4.8",
3
+ "version": "0.4.9",
4
4
  "type": "module",
5
5
  "description": "P2P AI Document Agent - 全局安装后执行 `bolloon` 启动产品",
6
6
  "main": "dist/cli-entry.js",