mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 04:31:10 +00:00
refactor: dedupe extension string helpers
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
|
||||
import { fetchWithSsrFGuard, type SsrFPolicy } from "../../runtime-api.js";
|
||||
import { getMSTeamsRuntime } from "../runtime.js";
|
||||
import { ensureUserAgentHeader } from "../user-agent.js";
|
||||
@@ -46,7 +47,7 @@ function readNestedString(value: unknown, keys: Array<string | number>): string
|
||||
}
|
||||
current = current[key as keyof typeof current];
|
||||
}
|
||||
return typeof current === "string" && current.trim() ? current.trim() : undefined;
|
||||
return normalizeOptionalString(current);
|
||||
}
|
||||
|
||||
export function buildMSTeamsGraphMessageUrls(params: {
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
import { createLazyRuntimeNamedExport } from "openclaw/plugin-sdk/lazy-runtime";
|
||||
import { createRuntimeOutboundDelegates } from "openclaw/plugin-sdk/outbound-runtime";
|
||||
import { createComputedAccountStatusAdapter } from "openclaw/plugin-sdk/status-helpers";
|
||||
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
|
||||
import { msTeamsApprovalAuth } from "./approval-auth.js";
|
||||
import {
|
||||
buildProbeChannelStatusSummary,
|
||||
@@ -207,7 +208,7 @@ function readOptionalTrimmedString(
|
||||
params: Record<string, unknown>,
|
||||
key: string,
|
||||
): string | undefined {
|
||||
return typeof params[key] === "string" ? params[key].trim() || undefined : undefined;
|
||||
return normalizeOptionalString(params[key]);
|
||||
}
|
||||
|
||||
function resolveActionUploadFilePath(params: Record<string, unknown>): string | undefined {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import crypto from "node:crypto";
|
||||
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
|
||||
import { isRecord } from "./attachments/shared.js";
|
||||
import { resolveMSTeamsStorePath } from "./storage.js";
|
||||
import { readJsonFile, withFileLock, writeJsonFile } from "./store-fs.js";
|
||||
@@ -89,7 +90,7 @@ function readNestedValue(value: unknown, keys: Array<string | number>): unknown
|
||||
|
||||
function readNestedString(value: unknown, keys: Array<string | number>): string | undefined {
|
||||
const found = readNestedValue(value, keys);
|
||||
return typeof found === "string" && found.trim() ? found.trim() : undefined;
|
||||
return normalizeOptionalString(found);
|
||||
}
|
||||
|
||||
export function extractMSTeamsPollVote(
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
|
||||
import { createDraftStreamLoop, type DraftStreamLoop } from "openclaw/plugin-sdk/channel-lifecycle";
|
||||
import { readStringValue } from "openclaw/plugin-sdk/text-runtime";
|
||||
|
||||
/** Default throttle interval between stream updates (ms).
|
||||
* Teams docs recommend buffering tokens for 1.5-2s; limit is 1 req/s. */
|
||||
@@ -45,8 +46,7 @@ import { formatUnknownError } from "./errors.js";
|
||||
|
||||
function extractId(response: unknown): string | undefined {
|
||||
if (response && typeof response === "object" && "id" in response) {
|
||||
const id = (response as { id?: unknown }).id;
|
||||
return typeof id === "string" ? id : undefined;
|
||||
return readStringValue((response as { id?: unknown }).id);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export function trimToUndefined(value: unknown): string | undefined {
|
||||
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
||||
}
|
||||
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
|
||||
|
||||
export const trimToUndefined = normalizeOptionalString;
|
||||
|
||||
export function asFiniteNumber(value: unknown): number | undefined {
|
||||
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { WebClient } from "@slack/web-api";
|
||||
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
|
||||
import { isRecord } from "openclaw/plugin-sdk/text-runtime";
|
||||
import { isRecord, normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
|
||||
import { createSlackWebClient } from "./client.js";
|
||||
|
||||
export type SlackScopesResult = {
|
||||
@@ -71,8 +71,7 @@ function readError(payload: unknown): string | undefined {
|
||||
if (!isRecord(payload)) {
|
||||
return undefined;
|
||||
}
|
||||
const error = payload.error;
|
||||
return typeof error === "string" && error.trim() ? error.trim() : undefined;
|
||||
return normalizeOptionalString(payload.error);
|
||||
}
|
||||
|
||||
async function callSlack(
|
||||
|
||||
@@ -6,6 +6,7 @@ import type { Bot } from "grammy";
|
||||
import { logVerbose } from "openclaw/plugin-sdk/runtime-env";
|
||||
import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime-env";
|
||||
import { resolveStateDir } from "openclaw/plugin-sdk/state-paths";
|
||||
import { readStringValue } from "openclaw/plugin-sdk/text-runtime";
|
||||
import { withTelegramApiErrorLogging } from "./api-logging.js";
|
||||
import { normalizeTelegramCommandName, TELEGRAM_COMMAND_NAME_PATTERN } from "./command-config.js";
|
||||
|
||||
@@ -95,8 +96,7 @@ function readErrorTextField(value: unknown, key: "description" | "message"): str
|
||||
if (!value || typeof value !== "object" || !(key in value)) {
|
||||
return undefined;
|
||||
}
|
||||
const text = (value as Record<"description" | "message", unknown>)[key];
|
||||
return typeof text === "string" ? text : undefined;
|
||||
return readStringValue((value as Record<"description" | "message", unknown>)[key]);
|
||||
}
|
||||
|
||||
function isBotCommandsTooMuchError(err: unknown): boolean {
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
fetchWithTimeout,
|
||||
resolveProviderHttpRequestConfig,
|
||||
} from "openclaw/plugin-sdk/provider-http";
|
||||
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
|
||||
|
||||
export const DEFAULT_VYDRA_BASE_URL = "https://www.vydra.ai/api/v1";
|
||||
export const DEFAULT_VYDRA_IMAGE_MODEL = "grok-imagine";
|
||||
@@ -47,9 +48,7 @@ function addUrlValue(value: unknown, urls: Set<string>): void {
|
||||
}
|
||||
}
|
||||
|
||||
export function trimToUndefined(value: unknown): string | undefined {
|
||||
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
||||
}
|
||||
export const trimToUndefined = normalizeOptionalString;
|
||||
|
||||
export function normalizeVydraBaseUrl(value: string | undefined): string {
|
||||
const fallback = DEFAULT_VYDRA_BASE_URL;
|
||||
|
||||
Reference in New Issue
Block a user