refactor(hooks): centralize live plugin config lookup · openclaw/openclaw@db5895f
vincentkoc
·
2026-04-23
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | | -475eafc1885c69203ac690a0ef3c1d1ddf6879d904a6980cf5f172c29ed70868 plugin-sdk-api-baseline.json |
2 | | -906bb0b167b155d2f766bd13f720c8c6ed8f349769d39f57ff5070045b96ef4c plugin-sdk-api-baseline.jsonl |
| 1 | +452cf5257df597bb0062c4478aca3afdbda6909fbaaf9ade214c27e8885935b1 plugin-sdk-api-baseline.json |
| 2 | +30117bdbd814978ad04be54e80b72385cabb0c726de1abcbad319c9d0b3ed101 plugin-sdk-api-baseline.jsonl |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -192,7 +192,7 @@ explicitly promotes one as public.
|
192 | 192 | | `plugin-sdk/process-runtime` | Process exec helpers | |
193 | 193 | | `plugin-sdk/cli-runtime` | CLI formatting, wait, and version helpers | |
194 | 194 | | `plugin-sdk/gateway-runtime` | Gateway client and channel-status patch helpers | |
195 | | -| `plugin-sdk/config-runtime` | Config load/write helpers | |
| 195 | +| `plugin-sdk/config-runtime` | Config load/write helpers and plugin-config lookup helpers | |
196 | 196 | | `plugin-sdk/telegram-command-config` | Telegram command-name/description normalization and duplicate/conflict checks, even when the bundled Telegram contract surface is unavailable | |
197 | 197 | | `plugin-sdk/text-autolink-runtime` | File-reference autolink detection without the broad text-runtime barrel | |
198 | 198 | | `plugin-sdk/approval-runtime` | Exec/plugin approval helpers, approval-capability builders, auth/profile helpers, native routing/runtime helpers | |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -9,6 +9,7 @@ import {
|
9 | 9 | resolveAgentWorkspaceDir, |
10 | 10 | } from "openclaw/plugin-sdk/agent-runtime"; |
11 | 11 | import { |
| 12 | +resolvePluginConfigObject, |
12 | 13 | resolveSessionStoreEntry, |
13 | 14 | updateSessionStore, |
14 | 15 | type OpenClawConfig, |
@@ -573,14 +574,10 @@ function isActiveMemoryGloballyEnabled(cfg: OpenClawConfig): boolean {
|
573 | 574 | if (entry?.enabled === false) { |
574 | 575 | return false; |
575 | 576 | } |
576 | | -const pluginConfig = asRecord(entry?.config); |
| 577 | +const pluginConfig = resolvePluginConfigObject(cfg, "active-memory"); |
577 | 578 | return pluginConfig?.enabled !== false; |
578 | 579 | } |
579 | 580 | |
580 | | -function resolveActiveMemoryPluginConfigFromConfig(cfg: OpenClawConfig): unknown { |
581 | | -return asRecord(cfg.plugins?.entries?.["active-memory"])?.config; |
582 | | -} |
583 | | - |
584 | 581 | function updateActiveMemoryGlobalEnabledInConfig( |
585 | 582 | cfg: OpenClawConfig, |
586 | 583 | enabled: boolean, |
@@ -1887,7 +1884,7 @@ export default definePluginEntry({
|
1887 | 1884 | warnDeprecatedModelFallbackPolicy(api.pluginConfig); |
1888 | 1885 | const refreshLiveConfigFromRuntime = () => { |
1889 | 1886 | const livePluginConfig = |
1890 | | -resolveActiveMemoryPluginConfigFromConfig(api.runtime.config.loadConfig()) ?? |
| 1887 | +resolvePluginConfigObject(api.runtime.config.loadConfig(), "active-memory") ?? |
1891 | 1888 | api.pluginConfig; |
1892 | 1889 | config = normalizePluginConfig(livePluginConfig); |
1893 | 1890 | warnDeprecatedModelFallbackPolicy(livePluginConfig); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -10,6 +10,7 @@ import { randomUUID } from "node:crypto";
|
10 | 10 | import type * as LanceDB from "@lancedb/lancedb"; |
11 | 11 | import { Type } from "@sinclair/typebox"; |
12 | 12 | import OpenAI from "openai"; |
| 13 | +import { resolvePluginConfigObject } from "openclaw/plugin-sdk/config-runtime"; |
13 | 14 | import { ensureGlobalUndiciEnvProxyDispatcher } from "openclaw/plugin-sdk/runtime-env"; |
14 | 15 | import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime"; |
15 | 16 | import { definePluginEntry, type OpenClawPluginApi } from "./api.js"; |
@@ -311,9 +312,7 @@ export default definePluginEntry({
|
311 | 312 | const embeddings = new Embeddings(apiKey, model, baseUrl, dimensions); |
312 | 313 | const resolveCurrentHookConfig = () => { |
313 | 314 | const runtimeConfig = api.runtime.config?.loadConfig?.(); |
314 | | -const runtimePlugins = asRecord(asRecord(runtimeConfig)?.plugins); |
315 | | -const runtimeEntries = asRecord(runtimePlugins?.entries); |
316 | | -const runtimePluginConfig = asRecord(runtimeEntries?.["memory-lancedb"])?.config; |
| 315 | +const runtimePluginConfig = resolvePluginConfigObject(runtimeConfig, "memory-lancedb"); |
317 | 316 | if (!runtimePluginConfig) { |
318 | 317 | return cfg; |
319 | 318 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import { resolvePluginConfigObject } from "openclaw/plugin-sdk/config-runtime"; |
1 | 2 | import { definePluginEntry, resolveDefaultAgentId } from "./api.js"; |
2 | 3 | import { resolveConfig } from "./src/config.js"; |
3 | 4 | import { buildWorkshopGuidance } from "./src/prompt.js"; |
@@ -6,12 +7,6 @@ import { createProposalFromMessages } from "./src/signals.js";
|
6 | 7 | import { createSkillWorkshopTool } from "./src/tool.js"; |
7 | 8 | import { applyOrStoreProposal, createStoreForContext } from "./src/workshop.js"; |
8 | 9 | |
9 | | -function asRecord(value: unknown): Record<string, unknown> | undefined { |
10 | | -return value && typeof value === "object" && !Array.isArray(value) |
11 | | - ? (value as Record<string, unknown>) |
12 | | - : undefined; |
13 | | -} |
14 | | - |
15 | 10 | export default definePluginEntry({ |
16 | 11 | id: "skill-workshop", |
17 | 12 | name: "Skill Workshop", |
@@ -24,10 +19,8 @@ export default definePluginEntry({
|
24 | 19 | } |
25 | 20 | const resolveCurrentConfig = () => { |
26 | 21 | const runtimeConfig = api.runtime.config?.loadConfig?.(); |
27 | | -const runtimePlugins = asRecord(asRecord(runtimeConfig)?.plugins); |
28 | | -const runtimeEntries = asRecord(runtimePlugins?.entries); |
29 | 22 | const runtimePluginConfig = |
30 | | -asRecord(runtimeEntries?.["skill-workshop"])?.config ?? api.pluginConfig; |
| 23 | +resolvePluginConfigObject(runtimeConfig, "skill-workshop") ?? api.pluginConfig; |
31 | 24 | return resolveConfig(runtimePluginConfig); |
32 | 25 | }; |
33 | 26 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import { resolvePluginConfigObject } from "openclaw/plugin-sdk/config-runtime"; |
1 | 2 | import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime"; |
2 | 3 | import { |
3 | 4 | definePluginEntry, |
@@ -72,20 +73,6 @@ function resolveOwnershipAgent(config: OpenClawConfig): { id: string; name: stri
|
72 | 73 | return { id, name }; |
73 | 74 | } |
74 | 75 | |
75 | | -function asRecord(value: unknown): Record<string, unknown> | undefined { |
76 | | -return value && typeof value === "object" && !Array.isArray(value) |
77 | | - ? (value as Record<string, unknown>) |
78 | | - : undefined; |
79 | | -} |
80 | | - |
81 | | -function resolveThreadOwnershipPluginConfigFromConfig( |
82 | | -config: OpenClawConfig, |
83 | | -): ThreadOwnershipConfig | undefined { |
84 | | -return asRecord(asRecord(config.plugins?.entries)?.["thread-ownership"])?.config as |
85 | | -| ThreadOwnershipConfig |
86 | | -| undefined; |
87 | | -} |
88 | | - |
89 | 76 | export default definePluginEntry({ |
90 | 77 | id: "thread-ownership", |
91 | 78 | name: "Thread Ownership", |
@@ -94,7 +81,7 @@ export default definePluginEntry({
|
94 | 81 | const resolveCurrentState = () => { |
95 | 82 | const currentConfig = api.runtime.config?.loadConfig?.() ?? api.config; |
96 | 83 | const pluginCfg = |
97 | | -resolveThreadOwnershipPluginConfigFromConfig(currentConfig) || |
| 84 | +resolvePluginConfigObject(currentConfig, "thread-ownership") || |
98 | 85 | ((api.pluginConfig ?? {}) as ThreadOwnershipConfig); |
99 | 86 | return { |
100 | 87 | currentConfig, |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { resolvePluginConfigObject, type OpenClawConfig } from "./config-runtime.js"; |
| 3 | + |
| 4 | +describe("resolvePluginConfigObject", () => { |
| 5 | +it("returns the plugin config object for a configured plugin entry", () => { |
| 6 | +const config = { |
| 7 | +plugins: { |
| 8 | +entries: { |
| 9 | +"demo-plugin": { |
| 10 | +enabled: true, |
| 11 | +config: { |
| 12 | +enabled: false, |
| 13 | +mode: "strict", |
| 14 | +}, |
| 15 | +}, |
| 16 | +}, |
| 17 | +}, |
| 18 | +} as OpenClawConfig; |
| 19 | + |
| 20 | +expect(resolvePluginConfigObject(config, "demo-plugin")).toEqual({ |
| 21 | +enabled: false, |
| 22 | +mode: "strict", |
| 23 | +}); |
| 24 | +}); |
| 25 | + |
| 26 | +it("returns undefined for missing or non-object plugin configs", () => { |
| 27 | +const config = { |
| 28 | +plugins: { |
| 29 | +entries: { |
| 30 | +"demo-plugin": { |
| 31 | +enabled: true, |
| 32 | +config: "bad-shape", |
| 33 | +}, |
| 34 | +"array-plugin": { |
| 35 | +enabled: true, |
| 36 | +config: ["bad-shape"], |
| 37 | +}, |
| 38 | +}, |
| 39 | +}, |
| 40 | +} as OpenClawConfig; |
| 41 | + |
| 42 | +expect(resolvePluginConfigObject(config, "missing-plugin")).toBeUndefined(); |
| 43 | +expect(resolvePluginConfigObject(config, "demo-plugin")).toBeUndefined(); |
| 44 | +expect(resolvePluginConfigObject(config, "array-plugin")).toBeUndefined(); |
| 45 | +expect(resolvePluginConfigObject(undefined, "demo-plugin")).toBeUndefined(); |
| 46 | +}); |
| 47 | +}); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -12,6 +12,28 @@ export function requireRuntimeConfig(config: OpenClawConfig, context: string): O
|
12 | 12 | ); |
13 | 13 | } |
14 | 14 | |
| 15 | +export function resolvePluginConfigObject( |
| 16 | +config: OpenClawConfig | undefined, |
| 17 | +pluginId: string, |
| 18 | +): Record<string, unknown> | undefined { |
| 19 | +const plugins = |
| 20 | +config?.plugins && typeof config.plugins === "object" && !Array.isArray(config.plugins) |
| 21 | + ? (config.plugins as Record<string, unknown>) |
| 22 | + : undefined; |
| 23 | +const entries = |
| 24 | +plugins?.entries && typeof plugins.entries === "object" && !Array.isArray(plugins.entries) |
| 25 | + ? (plugins.entries as Record<string, unknown>) |
| 26 | + : undefined; |
| 27 | +const entry = entries?.[pluginId]; |
| 28 | +if (!entry || typeof entry !== "object" || Array.isArray(entry)) { |
| 29 | +return undefined; |
| 30 | +} |
| 31 | +const pluginConfig = (entry as { config?: unknown }).config; |
| 32 | +return pluginConfig && typeof pluginConfig === "object" && !Array.isArray(pluginConfig) |
| 33 | + ? (pluginConfig as Record<string, unknown>) |
| 34 | + : undefined; |
| 35 | +} |
| 36 | + |
15 | 37 | export { resolveDefaultAgentId } from "../agents/agent-scope.js"; |
16 | 38 | export { |
17 | 39 | clearRuntimeConfigSnapshot, |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。