@elizaos/plugin-elizacloud 2.0.3-beta.5 → 2.0.3-beta.7

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
@@ -1089,13 +1089,13 @@ var init_cloud_billing_routes = __esm(() => {
1089
1089
  });
1090
1090
 
1091
1091
  // src/routes/home-remote-runner-access-url.ts
1092
- import { normalizeCloudSiteUrl as normalizeCloudSiteUrl3 } from "@elizaos/shared";
1092
+ import { normalizeCloudSiteUrl as normalizeCloudSiteUrl2 } from "@elizaos/shared";
1093
1093
  function buildHomeRemoteRunnerAccessUrl(input) {
1094
1094
  const sessionId = input.sessionId?.trim();
1095
1095
  if (!sessionId)
1096
1096
  return null;
1097
1097
  try {
1098
- const url = new URL(normalizeCloudSiteUrl3(input.cloudBaseUrl ?? undefined));
1098
+ const url = new URL(normalizeCloudSiteUrl2(input.cloudBaseUrl ?? undefined));
1099
1099
  url.pathname = "/dashboard/app";
1100
1100
  url.search = "";
1101
1101
  url.hash = "";
@@ -1859,7 +1859,7 @@ function resolvePersistedCloudIdentity(runtime) {
1859
1859
  userId: normalizeEnvValue(runtimeWithCloud?.getSetting?.("ELIZA_CLOUD_USER_ID")) ?? normalizeEnvValue(runtimeWithCloud?.character?.secrets?.ELIZA_CLOUD_USER_ID)
1860
1860
  };
1861
1861
  }
1862
- function resolveCloudApiBaseUrl4(rawBaseUrl) {
1862
+ function resolveCloudApiBaseUrl3(rawBaseUrl) {
1863
1863
  return resolveCloudApiBaseUrl(rawBaseUrl ?? DEFAULT_CLOUD_API_BASE_URL2) ?? DEFAULT_CLOUD_API_BASE_URL2;
1864
1864
  }
1865
1865
  function resolveCloudApiKey2(config, runtime) {
@@ -1982,7 +1982,7 @@ async function fetchCloudCredits(config, runtime) {
1982
1982
  error: authenticatedFailure ?? (authenticatedUnexpectedResponse ? "unexpected response" : "missing cloud api key")
1983
1983
  };
1984
1984
  }
1985
- const resolvedBaseUrl = resolveCloudApiBaseUrl4(config.cloud?.baseUrl);
1985
+ const resolvedBaseUrl = resolveCloudApiBaseUrl3(config.cloud?.baseUrl);
1986
1986
  const baseUrlRejection = await validateCloudBaseUrl(resolvedBaseUrl);
1987
1987
  if (baseUrlRejection) {
1988
1988
  return {
@@ -2953,6 +2953,7 @@ var cloudStatusProvider = {
2953
2953
  const bridgeSvc = runtime.getService("CLOUD_BRIDGE");
2954
2954
  const containers = containerSvc?.getTrackedContainers() ?? [];
2955
2955
  const connected = bridgeSvc?.getConnectedContainerIds() ?? [];
2956
+ const apiKeyInvalid = auth.isApiKeyInvalid();
2956
2957
  const running = containers.filter((c) => c.status === "running").length;
2957
2958
  const deploying = containers.filter((c) => c.status === "pending" || c.status === "building" || c.status === "deploying").length;
2958
2959
  const summaries = containers.slice(0, MAX_CONTAINER_SUMMARIES).map((c) => ({
@@ -2965,6 +2966,7 @@ var cloudStatusProvider = {
2965
2966
  }));
2966
2967
  const lines = [
2967
2968
  `ElizaCloud: ${containers.length} container(s), ${running} running, ${connected.length} bridged`,
2969
+ ...apiKeyInvalid ? [" - WARNING: Eliza Cloud API key REVOKED/INVALID — model calls will 401 until re-provisioned"] : [],
2968
2970
  ...summaries.map((c) => ` - ${c.name} [${c.status}]${c.url ? ` @ ${c.url}` : ""}${c.bridged ? " (bridged)" : ""}`)
2969
2971
  ];
2970
2972
  return {
@@ -2972,6 +2974,7 @@ var cloudStatusProvider = {
2972
2974
  `),
2973
2975
  values: {
2974
2976
  cloudAuthenticated: true,
2977
+ cloudApiKeyInvalid: apiKeyInvalid,
2975
2978
  totalContainers: containers.length,
2976
2979
  runningContainers: running,
2977
2980
  deployingContainers: deploying
@@ -5351,6 +5354,11 @@ class PaypalManagedClient {
5351
5354
  return readPaypalJson(response);
5352
5355
  }
5353
5356
  }
5357
+
5358
+ // src/cloud/index.ts
5359
+ init_base_url();
5360
+ init_validate_url();
5361
+
5354
5362
  // src/cloud/null-observer.ts
5355
5363
  class NullCloudSetupObserver {
5356
5364
  onAvailabilityChecked(_result) {}
@@ -7216,7 +7224,6 @@ import {
7216
7224
  resolveApiSecurityConfig,
7217
7225
  resolveDesktopApiPort
7218
7226
  } from "@elizaos/core";
7219
- import { isCloudReachable } from "@elizaos/shared";
7220
7227
  import { createRemoteJWKSet, jwtVerify } from "jose";
7221
7228
  async function deriveDeviceId() {
7222
7229
  const os = await import("node:os");
@@ -7388,12 +7395,57 @@ async function exchangeCodeForSession(args) {
7388
7395
  claims
7389
7396
  };
7390
7397
  }
7398
+ var DEFAULT_REVALIDATION_CONFIG = {
7399
+ retryMs: 60000,
7400
+ steadyMs: 1800000,
7401
+ invalidThreshold: 2
7402
+ };
7403
+ function decideRevalidation(prev, probe, cfg = DEFAULT_REVALIDATION_CONFIG) {
7404
+ if (probe === "valid") {
7405
+ const log = prev.keyState !== "valid" ? { level: "info", message: "[CloudAuth] API key validated" } : null;
7406
+ return {
7407
+ state: { keyState: "valid", consecutiveInvalid: 0 },
7408
+ delayMs: cfg.steadyMs,
7409
+ log
7410
+ };
7411
+ }
7412
+ if (probe === "invalid") {
7413
+ const consecutiveInvalid = prev.consecutiveInvalid + 1;
7414
+ const confirmed = consecutiveInvalid >= cfg.invalidThreshold;
7415
+ if (confirmed) {
7416
+ const log = prev.keyState !== "invalid" ? {
7417
+ level: "error",
7418
+ message: "[CloudAuth] Eliza Cloud API key is REVOKED/INVALID (cloud reachable, key rejected). Model calls will fail with 401 until the agent is re-provisioned or a valid ELIZAOS_CLOUD_API_KEY is set."
7419
+ } : null;
7420
+ return {
7421
+ state: { keyState: "invalid", consecutiveInvalid },
7422
+ delayMs: cfg.steadyMs,
7423
+ log
7424
+ };
7425
+ }
7426
+ return {
7427
+ state: { keyState: prev.keyState, consecutiveInvalid },
7428
+ delayMs: cfg.retryMs,
7429
+ log: null
7430
+ };
7431
+ }
7432
+ return {
7433
+ state: { ...prev },
7434
+ delayMs: cfg.retryMs,
7435
+ log: null
7436
+ };
7437
+ }
7391
7438
 
7392
7439
  class CloudAuthService extends Service {
7393
7440
  static serviceType = "CLOUD_AUTH";
7394
7441
  capabilityDescription = "Eliza Cloud device authentication and SSO session helpers";
7395
7442
  client;
7396
7443
  credentials = null;
7444
+ revalidationTimer = null;
7445
+ revalidationState = {
7446
+ keyState: "unknown",
7447
+ consecutiveInvalid: 0
7448
+ };
7397
7449
  constructor(runtime) {
7398
7450
  super(runtime);
7399
7451
  this.client = new CloudApiClient2(DEFAULT_CLOUD_CONFIG.baseUrl);
@@ -7404,6 +7456,11 @@ class CloudAuthService extends Service {
7404
7456
  return service;
7405
7457
  }
7406
7458
  async stop() {
7459
+ if (this.revalidationTimer) {
7460
+ clearTimeout(this.revalidationTimer);
7461
+ this.revalidationTimer = null;
7462
+ }
7463
+ this.revalidationState = { keyState: "unknown", consecutiveInvalid: 0 };
7407
7464
  this.credentials = null;
7408
7465
  }
7409
7466
  async initialize() {
@@ -7420,11 +7477,7 @@ class CloudAuthService extends Service {
7420
7477
  authenticatedAt: Date.now()
7421
7478
  };
7422
7479
  logger19.info("[CloudAuth] Authenticated with saved API key");
7423
- this.validateApiKey(key).then((valid) => {
7424
- if (!valid) {
7425
- logger19.warn("[CloudAuth] Saved API key could not be validated (cloud may be unreachable or key revoked) — model calls will use the key anyway");
7426
- }
7427
- }).catch(() => {});
7480
+ this.scheduleRevalidation(0);
7428
7481
  return;
7429
7482
  }
7430
7483
  const enabled = this.runtime.getSetting("ELIZAOS_CLOUD_ENABLED");
@@ -7440,20 +7493,50 @@ class CloudAuthService extends Service {
7440
7493
  logger19.info("[CloudAuth] Cloud not enabled (set ELIZAOS_CLOUD_ENABLED=true)");
7441
7494
  }
7442
7495
  }
7443
- async validateApiKey(key) {
7444
- if (!await isCloudReachable()) {
7445
- logger19.warn("[CloudAuth] Cloud unreachable at boot — skipping API key validation; key will be used as-is");
7446
- return false;
7447
- }
7496
+ async probeApiKey(key) {
7448
7497
  try {
7449
7498
  const validationClient = new CloudApiClient2(this.client.getBaseUrl(), key);
7450
7499
  await validationClient.get("/models", { timeoutMs: 2500 });
7451
- return true;
7500
+ return "valid";
7452
7501
  } catch (err) {
7453
- const msg = err instanceof Error ? err.message : String(err);
7454
- logger19.warn(`[CloudAuth] Could not reach cloud API to validate key: ${msg}`);
7455
- return false;
7502
+ if (err instanceof CloudApiError2 && (err.statusCode === 401 || err.statusCode === 403)) {
7503
+ return "invalid";
7504
+ }
7505
+ return "unreachable";
7506
+ }
7507
+ }
7508
+ scheduleRevalidation(delayMs) {
7509
+ if (this.revalidationTimer) {
7510
+ clearTimeout(this.revalidationTimer);
7456
7511
  }
7512
+ const timer = setTimeout(() => {
7513
+ this.runRevalidation();
7514
+ }, delayMs);
7515
+ timer.unref?.();
7516
+ this.revalidationTimer = timer;
7517
+ }
7518
+ async runRevalidation() {
7519
+ const key = this.credentials?.apiKey;
7520
+ if (!key) {
7521
+ return;
7522
+ }
7523
+ const probe = await this.probeApiKey(key).catch(() => "unreachable");
7524
+ if (this.credentials?.apiKey !== key) {
7525
+ return;
7526
+ }
7527
+ const decision = decideRevalidation(this.revalidationState, probe);
7528
+ this.revalidationState = decision.state;
7529
+ if (decision.log) {
7530
+ if (decision.log.level === "error") {
7531
+ logger19.error(decision.log.message);
7532
+ } else {
7533
+ logger19.info(decision.log.message);
7534
+ }
7535
+ }
7536
+ this.scheduleRevalidation(decision.delayMs);
7537
+ }
7538
+ isApiKeyInvalid() {
7539
+ return this.revalidationState.keyState === "invalid";
7457
7540
  }
7458
7541
  async authenticateWithDevice() {
7459
7542
  const deviceId = await deriveDeviceId();
@@ -9881,7 +9964,7 @@ export {
9881
9964
  src_default as default,
9882
9965
  createPayment,
9883
9966
  createOrder,
9884
- cloudLogin2 as cloudLogin,
9967
+ cloudLogin,
9885
9968
  clearCloudSecrets,
9886
9969
  __resetCloudBaseUrlCache,
9887
9970
  PlaidManagedClientError,
@@ -9897,12 +9980,12 @@ export {
9897
9980
  LIFEOPS_SCHEDULE_DEVICE_KINDS,
9898
9981
  ElizaCloudClient,
9899
9982
  DuffelConfigError,
9900
- ConnectionMonitor2 as ConnectionMonitor,
9983
+ ConnectionMonitor,
9901
9984
  CloudTtsUnavailableError,
9902
- CloudRuntimeProxy2 as CloudRuntimeProxy,
9985
+ CloudRuntimeProxy,
9903
9986
  CloudManager,
9904
9987
  ClackObserver,
9905
- BackupScheduler2 as BackupScheduler
9988
+ BackupScheduler
9906
9989
  };
9907
9990
 
9908
- //# debugId=BF5678F4013BB32F64756E2164756E21
9991
+ //# debugId=188CBE4719CE804364756E2164756E21