mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
perf(config): trim web search config helper imports
This commit is contained in:
44
src/config/plugin-web-search-config.test.ts
Normal file
44
src/config/plugin-web-search-config.test.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolvePluginWebSearchConfig } from "./plugin-web-search-config.js";
|
||||
|
||||
describe("resolvePluginWebSearchConfig", () => {
|
||||
it("returns the nested plugin webSearch object when present", () => {
|
||||
expect(
|
||||
resolvePluginWebSearchConfig(
|
||||
{
|
||||
plugins: {
|
||||
entries: {
|
||||
brave: {
|
||||
config: {
|
||||
webSearch: {
|
||||
apiKey: "brave-key",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"brave",
|
||||
),
|
||||
).toEqual({
|
||||
apiKey: "brave-key",
|
||||
});
|
||||
});
|
||||
|
||||
it("ignores non-record plugin config values", () => {
|
||||
expect(
|
||||
resolvePluginWebSearchConfig(
|
||||
{
|
||||
plugins: {
|
||||
entries: {
|
||||
brave: {
|
||||
config: "nope",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"brave",
|
||||
),
|
||||
).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,3 @@
|
||||
import { isRecord } from "../utils.js";
|
||||
|
||||
type PluginWebSearchConfigCarrier = {
|
||||
plugins?: {
|
||||
entries?: Record<
|
||||
@@ -11,6 +9,10 @@ type PluginWebSearchConfigCarrier = {
|
||||
};
|
||||
};
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
export function resolvePluginWebSearchConfig(
|
||||
config: PluginWebSearchConfigCarrier | undefined,
|
||||
pluginId: string,
|
||||
|
||||
Reference in New Issue
Block a user