























@@ -1,3 +1,6 @@
1+// Shared formatting helpers for status overview, gateway summaries, and JSON payloads.
2+// These functions keep text and JSON status surfaces aligned without pulling in command orchestration.
3+14import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
25import { resolveGatewayPort } from "../../config/config.js";
36import type { OpenClawConfig } from "../../config/types.js";
@@ -57,6 +60,7 @@ type StatusManagedService = {
5760} | null;
5861};
596263+/** Resolves the display update channel from config, install kind, and git metadata. */
6064export function resolveStatusUpdateChannelInfo(params: {
6165updateConfigChannel?: string | null;
6266update: {
@@ -76,6 +80,7 @@ export function resolveStatusUpdateChannelInfo(params: {
7680});
7781}
788283+/** Builds the update row fields reused by the overview table and status-all report. */
7984export function buildStatusUpdateSurface(params: {
8085updateConfigChannel?: string | null;
8186update: StatusUpdateLike;
@@ -93,11 +98,13 @@ export function buildStatusUpdateSurface(params: {
9398};
9499}
95100101+/** Formats missing dashboard URLs as disabled instead of leaking empty/null into status rows. */
96102export function formatStatusDashboardValue(value: string | null | undefined): string {
97103const trimmed = normalizeOptionalString(value);
98104return trimmed && trimmed.length > 0 ? trimmed : "disabled";
99105}
100106107+/** Formats Tailscale exposure in a compact, warning-aware status row value. */
101108export function formatStatusTailscaleValue(params: {
102109tailscaleMode: string;
103110dnsName?: string | null;
@@ -112,6 +119,7 @@ export function formatStatusTailscaleValue(params: {
112119const decorateOff = params.decorateOff ?? ((value: string) => value);
113120const decorateWarn = params.decorateWarn ?? ((value: string) => value);
114121if (params.tailscaleMode === "off") {
122+// Off mode can still show daemon/DNS context when the caller wants diagnostic detail.
115123const suffix = [
116124params.includeBackendStateWhenOff && params.backendState
117125 ? `daemon ${params.backendState}`
@@ -139,6 +147,7 @@ export function formatStatusTailscaleValue(params: {
139147return decorateWarn(parts.join(" · "));
140148}
141149150+/** Formats launchd/systemd service state into one row-friendly string. */
142151export function formatStatusServiceValue(params: {
143152label: string;
144153installed: boolean;
@@ -161,6 +170,7 @@ export function formatStatusServiceValue(params: {
161170return `${params.label} ${installedPrefix}${params.loadedText}${runtimeSuffix}`;
162171}
163172173+/** Returns the dashboard URL when the Control UI is enabled for the current gateway binding. */
164174export function resolveStatusDashboardUrl(params: {
165175cfg: Pick<OpenClawConfig, "gateway">;
166176}): string | null {
@@ -176,6 +186,7 @@ export function resolveStatusDashboardUrl(params: {
176186}).httpUrl;
177187}
178188189+/** Builds the ordered overview rows shared by status command variants. */
179190export function buildStatusOverviewRows(params: {
180191prefixRows?: StatusOverviewRow[];
181192dashboardValue: string;
@@ -224,6 +235,7 @@ export function buildStatusOverviewRows(params: {
224235return rows;
225236}
226237238+/** Builds overview rows directly from raw scan/update/gateway inputs. */
227239export function buildStatusOverviewSurfaceRows(params: {
228240cfg: Pick<OpenClawConfig, "update" | "gateway">;
229241update: StatusUpdateLike;
@@ -310,6 +322,7 @@ export function buildStatusOverviewSurfaceRows(params: {
310322});
311323}
312324325+/** Returns which gateway auth material was actually used for the probe. */
313326export function formatGatewayAuthUsed(
314327auth: {
315328token?: string;
@@ -330,6 +343,7 @@ export function formatGatewayAuthUsed(
330343return "none";
331344}
332345346+/** Formats gateway self metadata returned by the health endpoint. */
333347export function formatGatewaySelfSummary(gatewaySelf: StatusGatewaySelf): string | null {
334348return gatewaySelf?.host || gatewaySelf?.ip || gatewaySelf?.version || gatewaySelf?.platform
335349 ? [
@@ -343,6 +357,7 @@ export function formatGatewaySelfSummary(gatewaySelf: StatusGatewaySelf): string
343357 : null;
344358}
345359360+/** Builds gateway target, reachability, auth, and mode strings for text status output. */
346361export function buildGatewayStatusSummaryParts(params: {
347362gatewayMode: "local" | "remote";
348363remoteUrlMissing: boolean;
@@ -383,6 +398,7 @@ export function buildGatewayStatusSummaryParts(params: {
383398};
384399}
385400401+/** Builds gateway/dashboard/service values for overview rows. */
386402export function buildStatusGatewaySurfaceValues(params: {
387403cfg: Pick<OpenClawConfig, "gateway">;
388404gatewayMode: "local" | "remote";
@@ -452,6 +468,7 @@ export function buildStatusGatewaySurfaceValues(params: {
452468};
453469}
454470471+/** Builds the stable gateway object used by `openclaw status --json`. */
455472export function buildGatewayStatusJsonPayload(params: {
456473gatewayMode: "local" | "remote";
457474gatewayConnection: {
@@ -493,12 +510,14 @@ export function buildGatewayStatusJsonPayload(params: {
493510typeof params.gatewayProbe.health === "object" &&
494511"modelPricing" in params.gatewayProbe.health
495512 ? {
513+// Preserve model pricing when the gateway already returned it; do not synthesize pricing locally.
496514modelPricing: (params.gatewayProbe.health as { modelPricing?: unknown }).modelPricing,
497515}
498516 : {}),
499517};
500518}
501519520+/** Redacts common credential shapes before text is printed in status diagnostics. */
502521export function redactSecrets(text: string): string {
503522if (!text) {
504523return text;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。