openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
134 lines (133 loc) • 5.42 kB
JavaScript
import "./src-H3RMXyFL.mjs";
import { t as expectDefined } from "./expect-DDakjvvQ.mjs";
import { t as createDeferredCore } from "./deferred-D0La5CRk.mjs";
import "./fetch-timeout-D62KciOm.mjs";
import { t as resolveActiveManagedProxyTlsOptions } from "./active-managed-proxy-tls-NikAcZOT.mjs";
import "./managed-proxy-undici-DF3sC2Pe.mjs";
import { t as createLoggerBackedRuntime } from "./runtime-logger.internal-BsjqY2kJ.mjs";
import { createAmbientNodeProxyAgent, hasAmbientNodeProxyConfigured } from "@openclaw/proxyline";
//#region src/plugin-sdk/extension-shared.ts
/**
* Builds the standard passive-channel status object used by plugin status surfaces.
* Missing lifecycle fields are normalized to stable defaults so callers can merge
* plugin-specific extras without leaking `undefined` into status responses.
*/
function buildPassiveChannelStatusSummary(e, t) {
return {
configured: e.configured ?? false,
...t ?? {},
running: e.running ?? false,
lastStartAt: e.lastStartAt ?? null,
lastStopAt: e.lastStopAt ?? null,
lastError: e.lastError ?? null
};
}
/** Adds probe state to the standard passive-channel status summary. */
function buildPassiveProbedChannelStatusSummary(e, t) {
return {
...buildPassiveChannelStatusSummary(e, t),
probe: e.probe,
lastProbeAt: e.lastProbeAt ?? null
};
}
/** Normalizes optional traffic timestamps for channel status payloads. */
function buildTrafficStatusSummary(e) {
return {
lastInboundAt: e?.lastInboundAt ?? null,
lastOutboundAt: e?.lastOutboundAt ?? null
};
}
/**
* Returns the provided runtime or creates a logger-backed fallback for monitor-only paths.
* The fallback cannot exit the process, so command/runtime callers should inject a real runtime.
*/
function resolveLoggerBackedRuntime(e, t) {
return e ?? createLoggerBackedRuntime({
logger: t,
exitError: () => /* @__PURE__ */ new Error("Runtime exit not available")
});
}
/** Applies the shared validation rule for open DM policies that require wildcard allowlists. */
function requireChannelOpenAllowFrom(e) {
e.requireOpenAllowFrom({
policy: e.policy,
allowFrom: e.allowFrom,
ctx: e.ctx,
path: ["allowFrom"],
message: `channels.${e.channel}.dmPolicy="open" requires channels.${e.channel}.allowFrom to include "*"`
});
}
/** Extracts a fixed set of fields from unknown status issue payloads without trusting shape. */
function readStatusIssueFields(e, t) {
if (!e || typeof e !== "object") return null;
const n = e;
const r = {};
for (const e of t) r[e] = n[e];
return r;
}
/** Converts string or numeric account identifiers from status issue payloads to strings. */
function coerceStatusIssueAccountId(e) {
return typeof e === "string" ? e : typeof e === "number" ? String(e) : void 0;
}
/** Creates a promise with externally controlled resolve/reject hooks for async handoff code. */
function createDeferred() {
return createDeferredCore();
}
const DEFAULT_PACKAGE_JSON_VERSION_CANDIDATES = [
"../package.json",
"./package.json",
"../../package.json"
];
/** Formats Zod plugin-config issues into stable user-facing status messages. */
function formatPluginConfigIssue(e, t) {
if (!e) return t?.invalidConfigMessage ?? "invalid config";
if (e.code === "unrecognized_keys" && e.keys.length > 0) return t?.unknownKeyMessage?.(expectDefined(e.keys[0], "keys entry at 0")) ?? `unknown config key: ${e.keys[0]}`;
if (e.code === "invalid_type" && e.path.length === 0) return t?.rootInvalidTypeMessage ?? "expected config object";
return e.message;
}
/** Keeps only string/number path segments so config issue paths stay JSON-safe. */
function normalizePluginConfigIssuePath(e) {
return e.filter((e) => {
const t = typeof e;
return t === "string" || t === "number";
});
}
/** Converts raw Zod issues into the plugin status issue shape used by bundled channels. */
function mapPluginConfigIssues(e, t) {
return e.map((e) => ({
path: normalizePluginConfigIssuePath(e.path),
message: formatPluginConfigIssue(e, t)
}));
}
/** Reads plugin package versions across source, bundled, and test layouts with a fallback. */
function readPluginPackageVersion(e) {
for (const t of e.candidates ?? DEFAULT_PACKAGE_JSON_VERSION_CANDIDATES) try {
const n = e.require(t).version;
if (typeof n === "string" && n.trim().length > 0) return n;
} catch {}
return e.fallback ?? "unknown";
}
/**
* Builds an ambient Node proxy agent when proxy env/config is active.
* Managed proxy CA trust is attached when available; creation errors are reported
* through `onError` and otherwise degrade to no agent.
*/
async function resolveAmbientNodeProxyAgent(e) {
const t = e?.protocol ?? "https";
if (!hasAmbientNodeProxyConfigured({ protocol: t })) return;
try {
const n = resolveActiveManagedProxyTlsOptions();
const r = createAmbientNodeProxyAgent({
protocol: t,
...n ? { proxyTls: n } : {}
});
if (r === void 0) return;
e?.onUsingProxy?.();
return r;
} catch (t) {
e?.onError?.(t);
return;
}
}
//#endregion
export { createDeferred as a, normalizePluginConfigIssuePath as c, requireChannelOpenAllowFrom as d, resolveAmbientNodeProxyAgent as f, coerceStatusIssueAccountId as i, readPluginPackageVersion as l, buildPassiveProbedChannelStatusSummary as n, formatPluginConfigIssue as o, resolveLoggerBackedRuntime as p, buildTrafficStatusSummary as r, mapPluginConfigIssues as s, buildPassiveChannelStatusSummary as t, readStatusIssueFields as u };