@elizaos/plugin-elizacloud 2.0.3-beta.6 → 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/README.md +2 -2
- package/dist/cjs/index.node.cjs +155 -76
- package/dist/cjs/index.node.js.map +4 -4
- package/dist/cloud-providers/cloud-status.d.ts.map +1 -1
- package/dist/cloud-providers/cloud-status.js +4 -1
- package/dist/cloud-providers/cloud-status.js.map +3 -3
- package/dist/index.js +94 -16
- package/dist/index.js.map +4 -4
- package/dist/node/index.node.js +95 -16
- package/dist/node/index.node.js.map +4 -4
- package/dist/services/cloud-auth.d.ts +61 -1
- package/dist/services/cloud-auth.d.ts.map +1 -1
- package/dist/services/cloud-auth.js +93 -16
- package/dist/services/cloud-auth.js.map +3 -3
- package/package.json +5 -5
- package/src/cloud-providers/cloud-status.ts +6 -0
- package/src/services/cloud-auth.ts +180 -26
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cloud-status.d.ts","sourceRoot":"","sources":["../../src/cloud-providers/cloud-status.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAyB,QAAQ,EAAyB,MAAM,eAAe,CAAC;AAO5F,eAAO,MAAM,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"cloud-status.d.ts","sourceRoot":"","sources":["../../src/cloud-providers/cloud-status.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAyB,QAAQ,EAAyB,MAAM,eAAe,CAAC;AAO5F,eAAO,MAAM,mBAAmB,EAAE,QAqEjC,CAAC"}
|
|
@@ -41,6 +41,7 @@ var cloudStatusProvider = {
|
|
|
41
41
|
const bridgeSvc = runtime.getService("CLOUD_BRIDGE");
|
|
42
42
|
const containers = containerSvc?.getTrackedContainers() ?? [];
|
|
43
43
|
const connected = bridgeSvc?.getConnectedContainerIds() ?? [];
|
|
44
|
+
const apiKeyInvalid = auth.isApiKeyInvalid();
|
|
44
45
|
const running = containers.filter((c) => c.status === "running").length;
|
|
45
46
|
const deploying = containers.filter((c) => c.status === "pending" || c.status === "building" || c.status === "deploying").length;
|
|
46
47
|
const summaries = containers.slice(0, MAX_CONTAINER_SUMMARIES).map((c) => ({
|
|
@@ -53,6 +54,7 @@ var cloudStatusProvider = {
|
|
|
53
54
|
}));
|
|
54
55
|
const lines = [
|
|
55
56
|
`ElizaCloud: ${containers.length} container(s), ${running} running, ${connected.length} bridged`,
|
|
57
|
+
...apiKeyInvalid ? [" - WARNING: Eliza Cloud API key REVOKED/INVALID — model calls will 401 until re-provisioned"] : [],
|
|
56
58
|
...summaries.map((c) => ` - ${c.name} [${c.status}]${c.url ? ` @ ${c.url}` : ""}${c.bridged ? " (bridged)" : ""}`)
|
|
57
59
|
];
|
|
58
60
|
return {
|
|
@@ -60,6 +62,7 @@ var cloudStatusProvider = {
|
|
|
60
62
|
`),
|
|
61
63
|
values: {
|
|
62
64
|
cloudAuthenticated: true,
|
|
65
|
+
cloudApiKeyInvalid: apiKeyInvalid,
|
|
63
66
|
totalContainers: containers.length,
|
|
64
67
|
runningContainers: running,
|
|
65
68
|
deployingContainers: deploying
|
|
@@ -75,4 +78,4 @@ export {
|
|
|
75
78
|
cloudStatusProvider
|
|
76
79
|
};
|
|
77
80
|
|
|
78
|
-
//# debugId=
|
|
81
|
+
//# debugId=0127A3606A2CD9C564756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/cloud-providers/cloud-status.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * cloudStatusProvider — Container and connection status in agent state.\n */\n\nimport type { IAgentRuntime, Memory, Provider, ProviderResult, State } from \"@elizaos/core\";\nimport type { CloudAuthService } from \"../services/cloud-auth\";\nimport type { CloudBridgeService } from \"../services/cloud-bridge\";\nimport type { CloudContainerService } from \"../services/cloud-container\";\n\nconst MAX_CONTAINER_SUMMARIES = 10;\n\nexport const cloudStatusProvider: Provider = {\n name: \"elizacloud_status\",\n description: \"ElizaCloud container and connection status\",\n descriptionCompressed: \"ElizaCloud container/connection status.\",\n dynamic: true,\n position: 90,\n contexts: [\"settings\", \"finance\"],\n contextGate: { anyOf: [\"settings\", \"finance\"] },\n cacheStable: false,\n cacheScope: \"turn\",\n async get(runtime: IAgentRuntime, _message: Memory, _state: State): Promise<ProviderResult> {\n try {\n const auth = runtime.getService(\"CLOUD_AUTH\") as CloudAuthService | undefined;\n if (!auth?.isAuthenticated()) {\n return {\n text: \"ElizaCloud: Not authenticated\",\n values: { cloudAuthenticated: false },\n };\n }\n\n const containerSvc = runtime.getService(\"CLOUD_CONTAINER\") as\n | CloudContainerService\n | undefined;\n const bridgeSvc = runtime.getService(\"CLOUD_BRIDGE\") as CloudBridgeService | undefined;\n const containers = containerSvc?.getTrackedContainers() ?? [];\n const connected = bridgeSvc?.getConnectedContainerIds() ?? [];\n\n const running = containers.filter((c) => c.status === \"running\").length;\n const deploying = containers.filter(\n (c) => c.status === \"pending\" || c.status === \"building\" || c.status === \"deploying\"\n ).length;\n\n const summaries = containers.slice(0, MAX_CONTAINER_SUMMARIES).map((c) => ({\n id: c.id,\n name: c.name,\n status: c.status,\n url: c.load_balancer_url,\n billing: c.billing_status,\n bridged: connected.includes(c.id),\n }));\n\n const lines = [\n `ElizaCloud: ${containers.length} container(s), ${running} running, ${connected.length} bridged`,\n ...summaries.map(\n (c) =>\n ` - ${c.name} [${c.status}]${c.url ? ` @ ${c.url}` : \"\"}${c.bridged ? \" (bridged)\" : \"\"}`\n ),\n ];\n\n return {\n text: lines.join(\"\\n\"),\n values: {\n cloudAuthenticated: true,\n totalContainers: containers.length,\n runningContainers: running,\n deployingContainers: deploying,\n },\n data: { containers: summaries, truncated: containers.length > summaries.length },\n };\n } catch {\n return { text: \"\", values: {}, data: {} };\n }\n },\n};\n"
|
|
5
|
+
"/**\n * cloudStatusProvider — Container and connection status in agent state.\n */\n\nimport type { IAgentRuntime, Memory, Provider, ProviderResult, State } from \"@elizaos/core\";\nimport type { CloudAuthService } from \"../services/cloud-auth\";\nimport type { CloudBridgeService } from \"../services/cloud-bridge\";\nimport type { CloudContainerService } from \"../services/cloud-container\";\n\nconst MAX_CONTAINER_SUMMARIES = 10;\n\nexport const cloudStatusProvider: Provider = {\n name: \"elizacloud_status\",\n description: \"ElizaCloud container and connection status\",\n descriptionCompressed: \"ElizaCloud container/connection status.\",\n dynamic: true,\n position: 90,\n contexts: [\"settings\", \"finance\"],\n contextGate: { anyOf: [\"settings\", \"finance\"] },\n cacheStable: false,\n cacheScope: \"turn\",\n async get(runtime: IAgentRuntime, _message: Memory, _state: State): Promise<ProviderResult> {\n try {\n const auth = runtime.getService(\"CLOUD_AUTH\") as CloudAuthService | undefined;\n if (!auth?.isAuthenticated()) {\n return {\n text: \"ElizaCloud: Not authenticated\",\n values: { cloudAuthenticated: false },\n };\n }\n\n const containerSvc = runtime.getService(\"CLOUD_CONTAINER\") as\n | CloudContainerService\n | undefined;\n const bridgeSvc = runtime.getService(\"CLOUD_BRIDGE\") as CloudBridgeService | undefined;\n const containers = containerSvc?.getTrackedContainers() ?? [];\n const connected = bridgeSvc?.getConnectedContainerIds() ?? [];\n\n const apiKeyInvalid = auth.isApiKeyInvalid();\n\n const running = containers.filter((c) => c.status === \"running\").length;\n const deploying = containers.filter(\n (c) => c.status === \"pending\" || c.status === \"building\" || c.status === \"deploying\"\n ).length;\n\n const summaries = containers.slice(0, MAX_CONTAINER_SUMMARIES).map((c) => ({\n id: c.id,\n name: c.name,\n status: c.status,\n url: c.load_balancer_url,\n billing: c.billing_status,\n bridged: connected.includes(c.id),\n }));\n\n const lines = [\n `ElizaCloud: ${containers.length} container(s), ${running} running, ${connected.length} bridged`,\n ...(apiKeyInvalid\n ? [\" - WARNING: Eliza Cloud API key REVOKED/INVALID — model calls will 401 until re-provisioned\"]\n : []),\n ...summaries.map(\n (c) =>\n ` - ${c.name} [${c.status}]${c.url ? ` @ ${c.url}` : \"\"}${c.bridged ? \" (bridged)\" : \"\"}`\n ),\n ];\n\n return {\n text: lines.join(\"\\n\"),\n values: {\n cloudAuthenticated: true,\n cloudApiKeyInvalid: apiKeyInvalid,\n totalContainers: containers.length,\n runningContainers: running,\n deployingContainers: deploying,\n },\n data: { containers: summaries, truncated: containers.length > summaries.length },\n };\n } catch {\n return { text: \"\", values: {}, data: {} };\n }\n },\n};\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AASA,IAAM,0BAA0B;AAEzB,IAAM,sBAAgC;AAAA,EAC3C,MAAM;AAAA,EACN,aAAa;AAAA,EACb,uBAAuB;AAAA,EACvB,SAAS;AAAA,EACT,UAAU;AAAA,EACV,UAAU,CAAC,YAAY,SAAS;AAAA,EAChC,aAAa,EAAE,OAAO,CAAC,YAAY,SAAS,EAAE;AAAA,EAC9C,aAAa;AAAA,EACb,YAAY;AAAA,OACN,IAAG,CAAC,SAAwB,UAAkB,QAAwC;AAAA,IAC1F,IAAI;AAAA,MACF,MAAM,OAAO,QAAQ,WAAW,YAAY;AAAA,MAC5C,IAAI,CAAC,MAAM,gBAAgB,GAAG;AAAA,QAC5B,OAAO;AAAA,UACL,MAAM;AAAA,UACN,QAAQ,EAAE,oBAAoB,MAAM;AAAA,QACtC;AAAA,MACF;AAAA,MAEA,MAAM,eAAe,QAAQ,WAAW,iBAAiB;AAAA,MAGzD,MAAM,YAAY,QAAQ,WAAW,cAAc;AAAA,MACnD,MAAM,aAAa,cAAc,qBAAqB,KAAK,CAAC;AAAA,MAC5D,MAAM,YAAY,WAAW,yBAAyB,KAAK,CAAC;AAAA,MAE5D,MAAM,UAAU,WAAW,OAAO,CAAC,MAAM,EAAE,WAAW,SAAS,EAAE;AAAA,MACjE,MAAM,YAAY,WAAW,OAC3B,CAAC,MAAM,EAAE,WAAW,aAAa,EAAE,WAAW,cAAc,EAAE,WAAW,WAC3E,EAAE;AAAA,MAEF,MAAM,YAAY,WAAW,MAAM,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AAAA,UACnB,qBAAqB;AAAA,QACvB;AAAA,QACA,MAAM,EAAE,YAAY,WAAW,WAAW,WAAW,SAAS,UAAU,OAAO;AAAA,MACjF;AAAA,MACA,MAAM;AAAA,MACN,OAAO,EAAE,MAAM,IAAI,QAAQ,CAAC,GAAG,MAAM,CAAC,EAAE;AAAA;AAAA;AAG9C;",
|
|
8
|
+
"debugId": "0127A3606A2CD9C564756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/index.js
CHANGED
|
@@ -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
|
|
@@ -7221,7 +7224,6 @@ import {
|
|
|
7221
7224
|
resolveApiSecurityConfig,
|
|
7222
7225
|
resolveDesktopApiPort
|
|
7223
7226
|
} from "@elizaos/core";
|
|
7224
|
-
import { isCloudReachable } from "@elizaos/shared";
|
|
7225
7227
|
import { createRemoteJWKSet, jwtVerify } from "jose";
|
|
7226
7228
|
async function deriveDeviceId() {
|
|
7227
7229
|
const os = await import("node:os");
|
|
@@ -7393,12 +7395,57 @@ async function exchangeCodeForSession(args) {
|
|
|
7393
7395
|
claims
|
|
7394
7396
|
};
|
|
7395
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
|
+
}
|
|
7396
7438
|
|
|
7397
7439
|
class CloudAuthService extends Service {
|
|
7398
7440
|
static serviceType = "CLOUD_AUTH";
|
|
7399
7441
|
capabilityDescription = "Eliza Cloud device authentication and SSO session helpers";
|
|
7400
7442
|
client;
|
|
7401
7443
|
credentials = null;
|
|
7444
|
+
revalidationTimer = null;
|
|
7445
|
+
revalidationState = {
|
|
7446
|
+
keyState: "unknown",
|
|
7447
|
+
consecutiveInvalid: 0
|
|
7448
|
+
};
|
|
7402
7449
|
constructor(runtime) {
|
|
7403
7450
|
super(runtime);
|
|
7404
7451
|
this.client = new CloudApiClient2(DEFAULT_CLOUD_CONFIG.baseUrl);
|
|
@@ -7409,6 +7456,11 @@ class CloudAuthService extends Service {
|
|
|
7409
7456
|
return service;
|
|
7410
7457
|
}
|
|
7411
7458
|
async stop() {
|
|
7459
|
+
if (this.revalidationTimer) {
|
|
7460
|
+
clearTimeout(this.revalidationTimer);
|
|
7461
|
+
this.revalidationTimer = null;
|
|
7462
|
+
}
|
|
7463
|
+
this.revalidationState = { keyState: "unknown", consecutiveInvalid: 0 };
|
|
7412
7464
|
this.credentials = null;
|
|
7413
7465
|
}
|
|
7414
7466
|
async initialize() {
|
|
@@ -7425,11 +7477,7 @@ class CloudAuthService extends Service {
|
|
|
7425
7477
|
authenticatedAt: Date.now()
|
|
7426
7478
|
};
|
|
7427
7479
|
logger19.info("[CloudAuth] Authenticated with saved API key");
|
|
7428
|
-
this.
|
|
7429
|
-
if (!valid) {
|
|
7430
|
-
logger19.warn("[CloudAuth] Saved API key could not be validated (cloud may be unreachable or key revoked) — model calls will use the key anyway");
|
|
7431
|
-
}
|
|
7432
|
-
}).catch(() => {});
|
|
7480
|
+
this.scheduleRevalidation(0);
|
|
7433
7481
|
return;
|
|
7434
7482
|
}
|
|
7435
7483
|
const enabled = this.runtime.getSetting("ELIZAOS_CLOUD_ENABLED");
|
|
@@ -7445,20 +7493,50 @@ class CloudAuthService extends Service {
|
|
|
7445
7493
|
logger19.info("[CloudAuth] Cloud not enabled (set ELIZAOS_CLOUD_ENABLED=true)");
|
|
7446
7494
|
}
|
|
7447
7495
|
}
|
|
7448
|
-
async
|
|
7449
|
-
if (!await isCloudReachable()) {
|
|
7450
|
-
logger19.warn("[CloudAuth] Cloud unreachable at boot — skipping API key validation; key will be used as-is");
|
|
7451
|
-
return false;
|
|
7452
|
-
}
|
|
7496
|
+
async probeApiKey(key) {
|
|
7453
7497
|
try {
|
|
7454
7498
|
const validationClient = new CloudApiClient2(this.client.getBaseUrl(), key);
|
|
7455
7499
|
await validationClient.get("/models", { timeoutMs: 2500 });
|
|
7456
|
-
return
|
|
7500
|
+
return "valid";
|
|
7457
7501
|
} catch (err) {
|
|
7458
|
-
|
|
7459
|
-
|
|
7460
|
-
|
|
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);
|
|
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;
|
|
7461
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";
|
|
7462
7540
|
}
|
|
7463
7541
|
async authenticateWithDevice() {
|
|
7464
7542
|
const deviceId = await deriveDeviceId();
|
|
@@ -9910,4 +9988,4 @@ export {
|
|
|
9910
9988
|
BackupScheduler
|
|
9911
9989
|
};
|
|
9912
9990
|
|
|
9913
|
-
//# debugId=
|
|
9991
|
+
//# debugId=188CBE4719CE804364756E2164756E21
|