@topolo/cli 0.1.3 → 0.1.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.
Files changed (2) hide show
  1. package/dist/index.js +34 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -409,6 +409,37 @@ async function resolveCredential() {
409
409
  const config = await readConfig();
410
410
  return config.credential ?? null;
411
411
  }
412
+ var REFRESH_SKEW_SECONDS = 60;
413
+ async function refreshCredentialIfNeeded() {
414
+ if (process.env.TOPOLO_API_KEY || process.env.TOPOLO_ACCESS_TOKEN) {
415
+ return resolveCredential();
416
+ }
417
+ const config = await readConfig();
418
+ const cred = config.credential;
419
+ if (!cred || cred.kind !== "access_token") return cred ?? null;
420
+ if (!cred.refreshToken || !cred.expiresAt || !config.oauthClientId) return cred;
421
+ const now = Math.floor(Date.now() / 1e3);
422
+ if (cred.expiresAt - REFRESH_SKEW_SECONDS > now) return cred;
423
+ try {
424
+ const oauth = new TopoloOAuth({
425
+ serviceUrls: resolveServiceUrls(config.serviceUrls)
426
+ });
427
+ const tokens = await oauth.refreshToken({
428
+ clientId: config.oauthClientId,
429
+ refreshToken: cred.refreshToken
430
+ });
431
+ const refreshed = {
432
+ kind: "access_token",
433
+ accessToken: tokens.access_token,
434
+ ...tokens.refresh_token ? { refreshToken: tokens.refresh_token } : { refreshToken: cred.refreshToken },
435
+ expiresAt: Math.floor(Date.now() / 1e3) + tokens.expires_in
436
+ };
437
+ await writeConfig({ ...config, credential: refreshed });
438
+ return refreshed;
439
+ } catch {
440
+ return cred;
441
+ }
442
+ }
412
443
  function resolveAgentName(configAgentName) {
413
444
  return process.env.TOPOLO_AGENT_NAME ?? configAgentName;
414
445
  }
@@ -585,6 +616,7 @@ async function runDeviceFlow(options) {
585
616
  ...token.refresh_token ? { refreshToken: token.refresh_token } : {},
586
617
  expiresAt: Math.floor(Date.now() / 1e3) + token.expires_in
587
618
  };
619
+ updated.oauthClientId = options.clientId;
588
620
  await writeConfig(updated);
589
621
  emit(
590
622
  {
@@ -664,11 +696,11 @@ function sleep(ms) {
664
696
  }
665
697
 
666
698
  // src/version.ts
667
- var CLI_VERSION = "0.1.3";
699
+ var CLI_VERSION = "0.1.4";
668
700
 
669
701
  // src/client.ts
670
702
  async function buildClient(options) {
671
- const credential = await resolveCredential();
703
+ const credential = await refreshCredentialIfNeeded();
672
704
  if (!credential) return null;
673
705
  const config = await readConfig();
674
706
  const serviceUrls = resolveServiceUrls(config.serviceUrls);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topolo/cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Command-line interface for the Topolo platform. Designed for humans and for agents (Claude, Codex, etc.) that prefer shell invocation.",
5
5
  "type": "module",
6
6
  "bin": {