mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 13:26:04 -06:00
refactor: consolidate remaining coercion helpers (#122020)
This commit is contained in:
committed by
GitHub
parent
24bbb416b5
commit
cad77fb39c
@@ -1,6 +1,7 @@
|
||||
// Bundles MCP metadata exposed by plugins for package output.
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { isStringRecord } from "@openclaw/normalization-core/record-coerce";
|
||||
import { resolveMcpTransportConfig } from "../agents/mcp-transport-config.js";
|
||||
import { applyMergePatch } from "../config/merge-patch.js";
|
||||
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
||||
@@ -239,10 +240,6 @@ function hasOnlyKeys(raw: Record<string, unknown>, allowed: ReadonlySet<string>)
|
||||
return Object.keys(raw).every((key) => allowed.has(key));
|
||||
}
|
||||
|
||||
function isStringRecord(raw: unknown): raw is Record<string, string> {
|
||||
return isRecord(raw) && Object.values(raw).every((value) => typeof value === "string");
|
||||
}
|
||||
|
||||
function isPathWithin(baseDir: string, targetPath: string): boolean {
|
||||
const relative = path.relative(baseDir, targetPath);
|
||||
return (
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { toErrorObject as toLintErrorObject } from "@openclaw/normalization-core/error-coercion";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import { expectNoReaddirSyncDuring } from "../test-utils/fs-scan-assertions.js";
|
||||
import { listGitTrackedFiles, toRepoRelativePath } from "../test-utils/repo-files.js";
|
||||
@@ -1119,17 +1120,4 @@ describe("bundled plugin metadata", () => {
|
||||
});
|
||||
});
|
||||
|
||||
function toLintErrorObject(value: unknown, fallbackMessage: string): Error {
|
||||
if (value instanceof Error) {
|
||||
return value;
|
||||
}
|
||||
if (typeof value === "string") {
|
||||
return new Error(value);
|
||||
}
|
||||
const error = new Error(fallbackMessage, { cause: value });
|
||||
if ((typeof value === "object" && value !== null) || typeof value === "function") {
|
||||
Object.assign(error, value);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
/* oxlint-disable max-lines -- TODO: split this grandfathered oversized file. */
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Builds OpenAI-compatible embedding provider entries for plugins.
|
||||
import { normalizeProviderId } from "@openclaw/model-catalog-core/provider-id";
|
||||
import { asOptionalRecord as asRecord } from "@openclaw/normalization-core/record-coerce";
|
||||
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
|
||||
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
|
||||
import { readProviderJsonResponse } from "../agents/provider-http-errors.js";
|
||||
import type {
|
||||
@@ -112,11 +113,6 @@ function normalizeOptionalInputType(value: string | undefined): string | undefin
|
||||
return inputType ? inputType : undefined;
|
||||
}
|
||||
|
||||
function normalizeOptionalString(value: string | undefined): string | undefined {
|
||||
const normalized = value?.trim();
|
||||
return normalized ? normalized : undefined;
|
||||
}
|
||||
|
||||
function chooseSecretInputOverride<T>(
|
||||
override: T | undefined,
|
||||
fallback: T | undefined,
|
||||
|
||||
Reference in New Issue
Block a user