cicy-desktop 2.1.169 → 2.1.170
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/package.json +1 -1
- package/src/backends/sidecar-ipc.js +16 -37
- package/src/cloud/cloud-client.js +29 -0
package/package.json
CHANGED
|
@@ -63,47 +63,26 @@ function readDockerTeams() { try { return JSON.parse(fs.readFileSync(DOCKER_TEAM
|
|
|
63
63
|
function writeDockerTeams(obj) { try { fs.mkdirSync(path.dirname(DOCKER_TEAMS_FILE), { recursive: true }); fs.writeFileSync(DOCKER_TEAMS_FILE, JSON.stringify(obj, null, 2)); } catch {} }
|
|
64
64
|
let dockerTeamReg = null; // { teamId, title, apiKey } — 缓存,appOpts 读它
|
|
65
65
|
|
|
66
|
-
//
|
|
66
|
+
// docker 团队的权威来源 = cloud(w-10122 #197):POST /api/team/docker/register 按
|
|
67
|
+
// (deviceId, port) get-or-create。幂等;失效/换设备/丢本机缓存都不会建重复 team;kind='docker';
|
|
68
|
+
// 软删后同 (device,port) 可重建;title 云端缺省 'Docker :<port>'(不回退 owner 名)。
|
|
69
|
+
// 本机 docker-teams.json 只当 cloud 不可达时的 offline fallback(缓存 teamId+key)。
|
|
70
|
+
// mac(colima)/ windows(WSL)同一套(这里平台无关,只有 appDocker 分平台)。
|
|
67
71
|
async function ensureDockerTeam() {
|
|
68
|
-
if (!cc || !cc.loginToken || !cc.loginToken()) return null; // 未登录 → 先不带 key,登录后重建容器再补
|
|
72
|
+
if (!cc || !cc.loginToken || !cc.loginToken()) return null; // 未登录 → 先不带 key,登录后重建容器再补
|
|
73
|
+
const cachedFallback = () => {
|
|
74
|
+
try { const c = readDockerTeams()[APP_VOLUME]; if (c && c.apiKey) { dockerTeamReg = { teamId: c.teamId, title: c.title, apiKey: c.apiKey }; return dockerTeamReg; } } catch {}
|
|
75
|
+
return null;
|
|
76
|
+
};
|
|
69
77
|
try {
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
if (!created || !created.ok) return null;
|
|
75
|
-
// 强制把云端标题设成 "Docker 团队":POST /api/teams 常忽略我们传的 title、
|
|
76
|
-
// 回退成 owner/device 名(= 8008 的标题),卡片就显示成 8008 的了。PATCH 一下盖掉。
|
|
77
|
-
try { await cc.renameTeam(created.teamId, "Docker 团队"); } catch {}
|
|
78
|
-
store[APP_VOLUME] = { teamId: created.teamId, title: "Docker 团队", titleForced: true };
|
|
79
|
-
writeDockerTeams(store);
|
|
80
|
-
dockerTeamReg = { teamId: created.teamId, title: "Docker 团队", apiKey: created.apiKey };
|
|
78
|
+
const r = await cc.registerDockerTeam({ port: APP_PORT });
|
|
79
|
+
if (r && r.ok && r.apiKey) {
|
|
80
|
+
dockerTeamReg = { teamId: r.teamId, title: r.title || `Docker :${APP_PORT}`, apiKey: r.apiKey };
|
|
81
|
+
try { const store = readDockerTeams(); store[APP_VOLUME] = { teamId: r.teamId, title: dockerTeamReg.title, apiKey: r.apiKey }; writeDockerTeams(store); } catch {}
|
|
81
82
|
return dockerTeamReg;
|
|
82
83
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (!rec.titleForced) {
|
|
86
|
-
try { await cc.renameTeam(rec.teamId, "Docker 团队"); } catch {}
|
|
87
|
-
rec.title = "Docker 团队"; rec.titleForced = true;
|
|
88
|
-
store[APP_VOLUME] = rec; writeDockerTeams(store);
|
|
89
|
-
}
|
|
90
|
-
// 「如果没有就 create,有就直接用」(主人)。本机记了 teamId,但云端拿不到它的 key
|
|
91
|
-
// (team 被删 / 换了账号 / 设备重置 —— 等于实际上没有了)→ 视同没有,重新 create 一个
|
|
92
|
-
// 存回本机。这就是手动「清 docker-teams.json + 重建」做的事,自动化掉。
|
|
93
|
-
const apiKey = await cc.getTeamApiKey(rec.teamId);
|
|
94
|
-
if (!apiKey) {
|
|
95
|
-
const created = await cc.createTeam({ title: "Docker 团队", kind: "cloud" });
|
|
96
|
-
if (created && created.ok) {
|
|
97
|
-
try { await cc.renameTeam(created.teamId, "Docker 团队"); } catch {}
|
|
98
|
-
store[APP_VOLUME] = { teamId: created.teamId, title: "Docker 团队", titleForced: true };
|
|
99
|
-
writeDockerTeams(store);
|
|
100
|
-
dockerTeamReg = { teamId: created.teamId, title: "Docker 团队", apiKey: created.apiKey };
|
|
101
|
-
return dockerTeamReg;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
dockerTeamReg = { teamId: rec.teamId, title: rec.title, apiKey };
|
|
105
|
-
return dockerTeamReg;
|
|
106
|
-
} catch (e) { return null; }
|
|
84
|
+
return cachedFallback(); // cloud 返回异常 → offline 兜底
|
|
85
|
+
} catch (e) { return cachedFallback(); } // cloud 不可达 → offline 兜底
|
|
107
86
|
}
|
|
108
87
|
|
|
109
88
|
let registered = false;
|
|
@@ -358,6 +358,34 @@ async function createTeam({ title = "", kind = "cloud" } = {}) {
|
|
|
358
358
|
return { ok: false, status: res.status, reason: res.reason };
|
|
359
359
|
}
|
|
360
360
|
|
|
361
|
+
// Docker 团队的权威来源(w-10122 #197):POST /api/team/docker/register —— cloud 按
|
|
362
|
+
// (deviceId, port) get-or-create。一机一 port 一 team(8009/8010…),幂等:同 (device,port)
|
|
363
|
+
// 返同一 key;不同 port 不同 team;kind='docker';软删后同 (device,port) 可重建。title 传了
|
|
364
|
+
// 就用桌面的,没传云端缺省 'Docker :<port>'(不回退 owner 名)。替代 createTeam + 本机缓存。
|
|
365
|
+
async function registerDockerTeam({ port, title = "" } = {}) {
|
|
366
|
+
const token = loginToken();
|
|
367
|
+
if (!token) return { ok: false, reason: "not_logged_in" };
|
|
368
|
+
if (!port) return { ok: false, reason: "port_required" };
|
|
369
|
+
const body = { deviceId: getDeviceId(), port: Number(port) };
|
|
370
|
+
if (title) body.title = title;
|
|
371
|
+
const res = await cloudFetch("/api/team/docker/register", { method: "POST", body });
|
|
372
|
+
if (res.ok && res.json && (res.json.success || res.json.teamId)) {
|
|
373
|
+
return {
|
|
374
|
+
ok: true,
|
|
375
|
+
teamId: res.json.teamId,
|
|
376
|
+
apiKey: res.json.apiKey,
|
|
377
|
+
title: res.json.title,
|
|
378
|
+
titleVersion: Number(res.json.titleVersion) || 0,
|
|
379
|
+
kind: res.json.kind || "docker",
|
|
380
|
+
port: res.json.port,
|
|
381
|
+
gatewayUrl: res.json.gatewayUrl || GATEWAY_URL,
|
|
382
|
+
protocols: res.json.protocols || ["anthropic", "openai"],
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
log.warn(`[cloud] docker team register failed status=${res.status} reason=${res.reason || ""}`);
|
|
386
|
+
return { ok: false, status: res.status, reason: res.reason, json: res.json };
|
|
387
|
+
}
|
|
388
|
+
|
|
361
389
|
// 改某 team 的标题(PATCH /api/teams/:id {title})——和 DockerCard 改名同一个端点。
|
|
362
390
|
// 用途:建完 docker 独立 team 后**强制**把云端标题设成 "Docker 团队"(POST /api/teams
|
|
363
391
|
// 不保证用我们传的 title,常回退成 owner/device 名 = 8008 的标题,卡片就显示错了)。
|
|
@@ -466,6 +494,7 @@ module.exports = {
|
|
|
466
494
|
registerTeam,
|
|
467
495
|
listTeams,
|
|
468
496
|
createTeam,
|
|
497
|
+
registerDockerTeam,
|
|
469
498
|
renameTeam,
|
|
470
499
|
getTeamApiKey,
|
|
471
500
|
injectGatewayKey,
|