agentosity 0.2.2 → 0.2.3

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +16 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentosity",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Agentosity — AI-native is a number now. Automatic attendance for your AI agents (stdio MCP lifecycle + activity probes) + human clock-out CLI.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/index.js CHANGED
@@ -55,7 +55,20 @@ async function init(companyArg) {
55
55
  }
56
56
 
57
57
  // 2. 公司绑定(统一收口网页;--company 仅供无浏览器环境)
58
- let prof = await get(`/api/profile?device=${cfg.deviceId ?? ""}`);
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
- prof = await get(`/api/profile?device=${cfg.deviceId ?? ""}`);
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");