@nalvietnam/avatar-cli 1.12.1 → 1.12.2

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
@@ -225,19 +225,25 @@ function spinnerWithElapsed(prefix) {
225
225
  // src/lib/check-claude-code-subscription-and-quota.ts
226
226
  var QUOTA_VERIFY_TIMEOUT_MS = 6e4;
227
227
  var QUOTA_VERIFY_PROMPT = "ok";
228
- function checkClaudeCodeSubscriptionAuth() {
228
+ function readClaudeCodeAuthInfo() {
229
229
  const result = spawnSync("claude", ["auth", "status"], { encoding: "utf8" });
230
- if (result.error || result.status !== 0) return "not-authenticated";
230
+ if (result.error || result.status !== 0) return { state: "not-authenticated" };
231
231
  const stdout = (result.stdout || "").trim();
232
- if (stdout.startsWith("{")) {
233
- try {
234
- const parsed = JSON.parse(stdout);
235
- return parsed.loggedIn === true ? "authenticated" : "not-authenticated";
236
- } catch {
237
- return "authenticated";
238
- }
232
+ if (!stdout.startsWith("{")) {
233
+ return { state: "authenticated" };
234
+ }
235
+ try {
236
+ const parsed = JSON.parse(stdout);
237
+ if (parsed.loggedIn !== true) return { state: "not-authenticated" };
238
+ return {
239
+ state: "authenticated",
240
+ email: parsed.email,
241
+ subscriptionType: parsed.subscriptionType,
242
+ apiProvider: parsed.apiProvider
243
+ };
244
+ } catch {
245
+ return { state: "authenticated" };
239
246
  }
240
- return "authenticated";
241
247
  }
242
248
  function triggerClaudeCodeAuthLogin() {
243
249
  log.info("Kh\u1EDFi \u0111\u1ED9ng \u0111\u0103ng nh\u1EADp Claude Code (browser s\u1EBD m\u1EDF)...");
@@ -807,15 +813,48 @@ async function runAiSetupPhase(args) {
807
813
  const choice = await promptAiProviderChoice(globalInfo);
808
814
  switch (choice) {
809
815
  case "subscription": {
810
- if (checkClaudeCodeSubscriptionAuth() !== "authenticated") {
816
+ let authInfo = readClaudeCodeAuthInfo();
817
+ if (authInfo.state !== "authenticated") {
811
818
  triggerClaudeCodeAuthLogin();
819
+ authInfo = readClaudeCodeAuthInfo();
820
+ }
821
+ if (authInfo.state === "authenticated" && authInfo.subscriptionType) {
822
+ await writeClaudeSettings(args.workspacePath, {
823
+ provider: "subscription",
824
+ model: SUBSCRIPTION_DEFAULT_MODEL
825
+ });
826
+ await appendAuditEntry(
827
+ "ai_setup",
828
+ `provider=subscription,result=ok,plan=${authInfo.subscriptionType},probe=skipped`
829
+ );
830
+ log.success(
831
+ `AI ready \xB7 Subscription (${authInfo.subscriptionType}) \xB7 model=${SUBSCRIPTION_DEFAULT_MODEL}`
832
+ );
833
+ return { ok: true, provider: "subscription", model: SUBSCRIPTION_DEFAULT_MODEL };
812
834
  }
835
+ log.dim("Auth status kh\xF4ng tr\u1EA3 subscriptionType \u2014 verify quota (30-60s)...");
813
836
  let quota = verifyClaudeCodeQuota();
814
837
  if (!quota.ok && quota.reason === "auth-expired") {
815
838
  log.warn("Token Claude Code \u0111\xE3 h\u1EBFt h\u1EA1n. T\u1EF1 \u0111\u1ED9ng re-login...");
816
839
  triggerClaudeCodeAuthLogin();
817
840
  quota = verifyClaudeCodeQuota();
818
841
  }
842
+ if (!quota.ok && (quota.reason === "timeout" || quota.reason === "unknown")) {
843
+ log.warn(`Probe verify ${quota.reason} \u2014 accept trust auth status. Ti\u1EBFp t\u1EE5c.`);
844
+ if (quota.detail?.trim()) log.warn(` Chi ti\u1EBFt: ${quota.detail.slice(0, 200)}`);
845
+ await writeClaudeSettings(args.workspacePath, {
846
+ provider: "subscription",
847
+ model: SUBSCRIPTION_DEFAULT_MODEL
848
+ });
849
+ await appendAuditEntry(
850
+ "ai_setup",
851
+ `provider=subscription,result=ok,probe=${quota.reason}-soft-pass`
852
+ );
853
+ log.success(
854
+ `AI ready \xB7 Subscription (probe ${quota.reason}, soft-pass) \xB7 model=${SUBSCRIPTION_DEFAULT_MODEL}`
855
+ );
856
+ return { ok: true, provider: "subscription", model: SUBSCRIPTION_DEFAULT_MODEL };
857
+ }
819
858
  if (!quota.ok) {
820
859
  const reason = quota.reason ?? "unknown";
821
860
  await appendAuditEntry(
@@ -823,9 +862,7 @@ async function runAiSetupPhase(args) {
823
862
  `provider=subscription,result=no-quota,reason=${reason}`
824
863
  );
825
864
  log.warn(`Subscription verify th\u1EA5t b\u1EA1i (${reason}).`);
826
- if (quota.detail?.trim()) {
827
- log.warn(` Chi ti\u1EBFt: ${quota.detail.slice(0, 200)}`);
828
- }
865
+ if (quota.detail?.trim()) log.warn(` Chi ti\u1EBFt: ${quota.detail.slice(0, 200)}`);
829
866
  log.warn(` \u2192 ${getQuotaErrorHint(reason)}`);
830
867
  return { ok: false, reason: `subscription-${reason}`, phase: "quota" };
831
868
  }