mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
refactor: dedupe legacy config record helpers
This commit is contained in:
25
src/commands/doctor/shared/legacy-config-record-shared.ts
Normal file
25
src/commands/doctor/shared/legacy-config-record-shared.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
type JsonRecord = Record<string, unknown>;
|
||||
|
||||
export type { JsonRecord };
|
||||
|
||||
export function isRecord(value: unknown): value is JsonRecord {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
export function cloneRecord<T extends JsonRecord>(value: T | undefined): T {
|
||||
return { ...value } as T;
|
||||
}
|
||||
|
||||
export function ensureRecord(target: JsonRecord, key: string): JsonRecord {
|
||||
const current = target[key];
|
||||
if (isRecord(current)) {
|
||||
return current;
|
||||
}
|
||||
const next: JsonRecord = {};
|
||||
target[key] = next;
|
||||
return next;
|
||||
}
|
||||
|
||||
export function hasOwnKey(target: JsonRecord, key: string): boolean {
|
||||
return Object.prototype.hasOwnProperty.call(target, key);
|
||||
}
|
||||
@@ -1,27 +1,14 @@
|
||||
import type { OpenClawConfig } from "../../../config/config.js";
|
||||
import { mergeMissing } from "../../../config/legacy.shared.js";
|
||||
|
||||
type JsonRecord = Record<string, unknown>;
|
||||
import {
|
||||
cloneRecord,
|
||||
ensureRecord,
|
||||
hasOwnKey,
|
||||
isRecord,
|
||||
type JsonRecord,
|
||||
} from "./legacy-config-record-shared.js";
|
||||
const DANGEROUS_RECORD_KEYS = new Set(["__proto__", "prototype", "constructor"]);
|
||||
|
||||
function isRecord(value: unknown): value is JsonRecord {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function cloneRecord<T extends JsonRecord>(value: T | undefined): T {
|
||||
return { ...value } as T;
|
||||
}
|
||||
|
||||
function ensureRecord(target: JsonRecord, key: string): JsonRecord {
|
||||
const current = target[key];
|
||||
if (isRecord(current)) {
|
||||
return current;
|
||||
}
|
||||
const next: JsonRecord = {};
|
||||
target[key] = next;
|
||||
return next;
|
||||
}
|
||||
|
||||
function resolveLegacyFetchConfig(raw: unknown): JsonRecord | undefined {
|
||||
if (!isRecord(raw)) {
|
||||
return undefined;
|
||||
@@ -31,10 +18,6 @@ function resolveLegacyFetchConfig(raw: unknown): JsonRecord | undefined {
|
||||
return isRecord(web?.fetch) ? web.fetch : undefined;
|
||||
}
|
||||
|
||||
function hasOwnKey(target: JsonRecord, key: string): boolean {
|
||||
return Object.prototype.hasOwnProperty.call(target, key);
|
||||
}
|
||||
|
||||
function copyLegacyFirecrawlFetchConfig(fetch: JsonRecord): JsonRecord | undefined {
|
||||
const current = fetch.firecrawl;
|
||||
if (!isRecord(current)) {
|
||||
|
||||
@@ -4,8 +4,13 @@ import {
|
||||
loadPluginManifestRegistry,
|
||||
resolveManifestContractOwnerPluginId,
|
||||
} from "../../../plugins/manifest-registry.js";
|
||||
|
||||
type JsonRecord = Record<string, unknown>;
|
||||
import {
|
||||
cloneRecord,
|
||||
ensureRecord,
|
||||
hasOwnKey,
|
||||
isRecord,
|
||||
type JsonRecord,
|
||||
} from "./legacy-config-record-shared.js";
|
||||
|
||||
const MODERN_SCOPED_WEB_SEARCH_KEYS = new Set(["openaiCodex"]);
|
||||
|
||||
@@ -20,24 +25,6 @@ const LEGACY_WEB_SEARCH_PROVIDER_IDS = loadPluginManifestRegistry({ cache: true
|
||||
const LEGACY_WEB_SEARCH_PROVIDER_ID_SET = new Set(LEGACY_WEB_SEARCH_PROVIDER_IDS);
|
||||
const LEGACY_GLOBAL_WEB_SEARCH_PROVIDER_ID = "brave";
|
||||
|
||||
function isRecord(value: unknown): value is JsonRecord {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function cloneRecord<T extends JsonRecord>(value: T | undefined): T {
|
||||
return { ...value } as T;
|
||||
}
|
||||
|
||||
function ensureRecord(target: JsonRecord, key: string): JsonRecord {
|
||||
const current = target[key];
|
||||
if (isRecord(current)) {
|
||||
return current;
|
||||
}
|
||||
const next: JsonRecord = {};
|
||||
target[key] = next;
|
||||
return next;
|
||||
}
|
||||
|
||||
function resolveLegacySearchConfig(raw: unknown): JsonRecord | undefined {
|
||||
if (!isRecord(raw)) {
|
||||
return undefined;
|
||||
@@ -52,10 +39,6 @@ function copyLegacyProviderConfig(search: JsonRecord, providerKey: string): Json
|
||||
return isRecord(current) ? cloneRecord(current) : undefined;
|
||||
}
|
||||
|
||||
function hasOwnKey(target: JsonRecord, key: string): boolean {
|
||||
return Object.prototype.hasOwnProperty.call(target, key);
|
||||
}
|
||||
|
||||
function hasMappedLegacyWebSearchConfig(raw: unknown): boolean {
|
||||
const search = resolveLegacySearchConfig(raw);
|
||||
if (!search) {
|
||||
|
||||
Reference in New Issue
Block a user