openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
170 lines (169 loc) • 7.53 kB
JavaScript
import { y as resolveStateDir } from "./paths-mvMm5bYV.js";
import { t as createLazyImportLoader } from "./lazy-promise-BONnzNfb.js";
import { c as isRecord } from "./utils-CCC-BEJH.js";
import { i as GENERATED_BUNDLED_CHANNEL_CONFIG_METADATA } from "./ids-BVNPk-iM.js";
import { t as resolveMemorySearchConfig } from "./memory-search-CTXTHmj4.js";
import { i as resolveSharedMemoryStatusSnapshot, n as resolveStatusSummaryFromOverview, r as resolveMemoryPluginStatus, t as collectStatusScanOverview } from "./status.scan-overview-BXn7EgEP.js";
import path from "node:path";
import os from "node:os";
//#region src/commands/status.scan-result.ts
/** Flattens overview, gateway, channel, summary, memory, and compatibility inputs into a scan result. */
function buildStatusScanResult(params) {
return {
cfg: params.cfg,
sourceConfig: params.sourceConfig,
secretDiagnostics: params.secretDiagnostics,
osSummary: params.osSummary,
tailscaleMode: params.tailscaleMode,
tailscaleDns: params.tailscaleDns,
tailscaleHttpsUrl: params.tailscaleHttpsUrl,
update: params.update,
gatewayConnection: params.gatewaySnapshot.gatewayConnection,
remoteUrlMissing: params.gatewaySnapshot.remoteUrlMissing,
gatewayMode: params.gatewaySnapshot.gatewayMode,
gatewayProbeAuth: params.gatewaySnapshot.gatewayProbeAuth,
gatewayProbeAuthWarning: params.gatewaySnapshot.gatewayProbeAuthWarning,
gatewayProbe: params.gatewaySnapshot.gatewayProbe,
gatewayReachable: params.gatewaySnapshot.gatewayReachable,
gatewaySelf: params.gatewaySnapshot.gatewaySelf,
channelIssues: params.channelIssues,
agentStatus: params.agentStatus,
channels: params.channels,
summary: params.summary,
memory: params.memory,
memoryPlugin: params.memoryPlugin,
pluginCompatibility: params.pluginCompatibility
};
}
//#endregion
//#region src/commands/status.scan-execute.ts
/** Builds a full status scan result from an overview scan plus channel/plugin compatibility data. */
async function executeStatusScanFromOverview(params) {
const memoryPlugin = resolveMemoryPluginStatus(params.overview.cfg);
const [memory, summary] = await Promise.all([params.resolveMemory({
cfg: params.overview.cfg,
agentStatus: params.overview.agentStatus,
memoryPlugin,
...params.runtime ? { runtime: params.runtime } : {}
}), resolveStatusSummaryFromOverview({
overview: params.overview,
includeChannelSummary: params.summary?.includeChannelSummary
})]);
return buildStatusScanResult({
cfg: params.overview.cfg,
sourceConfig: params.overview.sourceConfig,
secretDiagnostics: params.overview.secretDiagnostics,
osSummary: params.overview.osSummary,
tailscaleMode: params.overview.tailscaleMode,
tailscaleDns: params.overview.tailscaleDns,
tailscaleHttpsUrl: params.overview.tailscaleHttpsUrl,
update: params.overview.update,
gatewaySnapshot: params.overview.gatewaySnapshot,
channelIssues: params.channelIssues,
agentStatus: params.overview.agentStatus,
channels: params.channels,
summary,
memory,
memoryPlugin,
pluginCompatibility: params.pluginCompatibility
});
}
//#endregion
//#region src/commands/status.scan-memory.ts
const statusScanDepsRuntimeModuleLoader = createLazyImportLoader(() => import("./status.scan.deps.runtime.js"));
function loadStatusScanDepsRuntimeModule() {
return statusScanDepsRuntimeModuleLoader.load();
}
/** Returns the default on-disk memory store path for an agent. */
function resolveDefaultMemoryStorePath(agentId) {
return path.join(resolveStateDir(process.env, os.homedir), "memory", `${agentId}.sqlite`);
}
/** Resolves memory index/cache status for the current status scan. */
async function resolveStatusMemoryStatusSnapshot(params) {
const { getMemorySearchManager } = await loadStatusScanDepsRuntimeModule();
return await resolveSharedMemoryStatusSnapshot({
cfg: params.cfg,
agentStatus: params.agentStatus,
memoryPlugin: params.memoryPlugin,
resolveMemoryConfig: resolveMemorySearchConfig,
getMemorySearchManager,
requireDefaultStore: params.requireDefaultStore
});
}
//#endregion
//#region src/commands/status.scan.fast-json.ts
const IGNORED_CHANNEL_CONFIG_KEYS = new Set(["defaults", "modelByChannel"]);
const STATUS_JSON_CHANNEL_ENV_PREFIXES = GENERATED_BUNDLED_CHANNEL_CONFIG_METADATA.filter((entry) => entry.configurable !== false).map((entry) => `${entry.channelId.replace(/[^a-z0-9]+/gi, "_").toUpperCase()}_`);
const STATUS_JSON_CHANNEL_ENV_VARS = new Set(GENERATED_BUNDLED_CHANNEL_CONFIG_METADATA.filter((entry) => entry.configurable !== false).flatMap((entry) => entry.channelEnvVars ?? []));
function hasMeaningfulStatusJsonChannelConfig(value) {
if (!isRecord(value)) return false;
return Object.keys(value).some((key) => key !== "enabled");
}
function hasExplicitStatusJsonChannelConfig(cfg) {
if (!isRecord(cfg.channels)) return false;
for (const [key, value] of Object.entries(cfg.channels)) {
if (IGNORED_CHANNEL_CONFIG_KEYS.has(key)) continue;
if (hasMeaningfulStatusJsonChannelConfig(value)) return true;
}
return false;
}
function hasStatusJsonChannelEnvConfig(env = process.env) {
for (const [key, value] of Object.entries(env)) {
if (typeof value !== "string" || value.trim().length === 0) continue;
if (STATUS_JSON_CHANNEL_ENV_VARS.has(key) || STATUS_JSON_CHANNEL_ENV_PREFIXES.some((prefix) => key.startsWith(prefix))) return true;
}
return false;
}
function hasPotentialConfiguredChannelsForStatusJson(cfg) {
return hasExplicitStatusJsonChannelConfig(cfg) || hasStatusJsonChannelEnvConfig();
}
/** Runs status JSON with an injectable policy for tests and specialized callers. */
async function scanStatusJsonWithPolicy(opts, runtime, policy) {
return await executeStatusScanFromOverview({
overview: await collectStatusScanOverview({
commandName: policy.commandName,
opts,
showSecrets: false,
runtime,
allowMissingConfigFastPath: policy.allowMissingConfigFastPath,
resolveHasConfiguredChannels: policy.resolveHasConfiguredChannels,
includeChannelsData: false,
includeChannelSecretTargets: false,
skipConfigPluginValidation: true,
fetchGitUpdate: policy.fetchGitUpdate,
includeRegistryUpdate: policy.includeRegistryUpdate,
includeLocalStatusRpcFallback: policy.includeLocalStatusRpcFallback,
gatewayProbeTimeoutMs: policy.gatewayProbeTimeoutMs
}),
runtime,
summary: { includeChannelSummary: policy.includeChannelSummary },
resolveMemory: policy.resolveMemory,
channelIssues: [],
channels: {
rows: [],
details: []
},
pluginCompatibility: []
});
}
/** Runs the default fast status JSON scan. */
async function scanStatusJsonFast(opts, runtime) {
return await scanStatusJsonWithPolicy(opts, runtime, {
commandName: "status --json",
allowMissingConfigFastPath: true,
includeChannelSummary: false,
fetchGitUpdate: opts.all === true,
includeRegistryUpdate: opts.all === true,
includeLocalStatusRpcFallback: opts.all === true,
gatewayProbeTimeoutMs: opts.all === true ? void 0 : (cfg) => opts.timeoutMs ?? Math.max(1e3, cfg.gateway?.handshakeTimeoutMs ?? 0),
resolveHasConfiguredChannels: (cfg) => hasPotentialConfiguredChannelsForStatusJson(cfg),
resolveMemory: async ({ cfg, agentStatus, memoryPlugin }) => opts.all ? await resolveStatusMemoryStatusSnapshot({
cfg,
agentStatus,
memoryPlugin,
requireDefaultStore: resolveDefaultMemoryStorePath
}) : null
});
}
//#endregion
export { executeStatusScanFromOverview as i, scanStatusJsonWithPolicy as n, resolveStatusMemoryStatusSnapshot as r, scanStatusJsonFast as t };