agentosity 0.2.2 → 0.2.4
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/index.js +17 -3
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -55,7 +55,20 @@ async function init(companyArg) {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
// 2. 公司绑定(统一收口网页;--company 仅供无浏览器环境)
|
|
58
|
-
|
|
58
|
+
// 拿"明确答复"才做判断:网络抖动/服务瞬时失败(返回 error)一律重试,绝不误判成"未绑定"
|
|
59
|
+
const fetchProfileDefinitive = async (attempts = 5) => {
|
|
60
|
+
for (let i = 0; i < attempts; i++) {
|
|
61
|
+
const p = await get(`/api/profile?device=${cfg.deviceId ?? ""}`);
|
|
62
|
+
if (p && "company" in p) return p;
|
|
63
|
+
await new Promise((r) => setTimeout(r, 2000));
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
};
|
|
67
|
+
let prof = await fetchProfileDefinitive();
|
|
68
|
+
if (prof === null) {
|
|
69
|
+
console.error("服务暂时不可达,稍后重跑 npx agentosity init");
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
59
72
|
if (!prof?.company && companyArg) {
|
|
60
73
|
const created = await post("/api/companies", { name: companyArg });
|
|
61
74
|
if (created?.id) await post("/api/profile", { companyId: created.id }, { method: "PUT" });
|
|
@@ -67,7 +80,8 @@ async function init(companyArg) {
|
|
|
67
80
|
await openBrowser(url);
|
|
68
81
|
for (let i = 0; i < 150 && !prof?.company; i++) {
|
|
69
82
|
await new Promise((r) => setTimeout(r, 2000));
|
|
70
|
-
|
|
83
|
+
const p = await get(`/api/profile?device=${cfg.deviceId ?? ""}`);
|
|
84
|
+
if (p && "company" in p) prof = p; // 错误答复不覆盖,继续等
|
|
71
85
|
}
|
|
72
86
|
if (!prof?.company) {
|
|
73
87
|
console.error("等待超时。在网页上绑定公司后,重新跑 npx agentosity init");
|
|
@@ -163,7 +177,7 @@ async function clockout() {
|
|
|
163
177
|
console.log(`✅ 下班快乐!${r.clocked_local}`);
|
|
164
178
|
if (r.rank_company != null) console.log(` 你是公司今天第 ${r.rank_company} 个下班的 · 全网第 ${r.rank_global} 个`);
|
|
165
179
|
if (r.note) console.log(` ${r.note}`);
|
|
166
|
-
console.log(`
|
|
180
|
+
console.log(` 榜单实时更新:${apiBase()}/me`);
|
|
167
181
|
} else {
|
|
168
182
|
console.error(`打卡失败:${r?.error ?? "网络不可达"}`);
|
|
169
183
|
process.exit(1);
|