mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 21:31:26 +00:00
perf(memory): trim matrix config import graph
This commit is contained in:
12
extensions/matrix/src/matrix/client/config-runtime-api.ts
Normal file
12
extensions/matrix/src/matrix/client/config-runtime-api.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export {
|
||||
DEFAULT_ACCOUNT_ID,
|
||||
normalizeAccountId,
|
||||
normalizeOptionalAccountId,
|
||||
} from "openclaw/plugin-sdk/account-id";
|
||||
export { isPrivateOrLoopbackHost } from "openclaw/plugin-sdk/matrix";
|
||||
export {
|
||||
assertHttpUrlTargetsPrivateNetwork,
|
||||
ssrfPolicyFromAllowPrivateNetwork,
|
||||
type LookupFn,
|
||||
type SsrFPolicy,
|
||||
} from "openclaw/plugin-sdk/ssrf-runtime";
|
||||
@@ -9,16 +9,7 @@ import {
|
||||
} from "../../account-selection.js";
|
||||
import { resolveMatrixAccountStringValues } from "../../auth-precedence.js";
|
||||
import { getMatrixScopedEnvVarNames } from "../../env-vars.js";
|
||||
import {
|
||||
DEFAULT_ACCOUNT_ID,
|
||||
assertHttpUrlTargetsPrivateNetwork,
|
||||
isPrivateOrLoopbackHost,
|
||||
type LookupFn,
|
||||
normalizeAccountId,
|
||||
normalizeOptionalAccountId,
|
||||
normalizeResolvedSecretInputString,
|
||||
ssrfPolicyFromAllowPrivateNetwork,
|
||||
} from "../../runtime-api.js";
|
||||
import { normalizeResolvedSecretInputString } from "../../runtime-api.js";
|
||||
import { getMatrixRuntime } from "../../runtime.js";
|
||||
import type { CoreConfig } from "../../types.js";
|
||||
import {
|
||||
@@ -26,7 +17,16 @@ import {
|
||||
resolveMatrixBaseConfig,
|
||||
listNormalizedMatrixAccountIds,
|
||||
} from "../account-config.js";
|
||||
import { resolveMatrixConfigFieldPath } from "../config-update.js";
|
||||
import { resolveMatrixConfigFieldPath } from "../config-paths.js";
|
||||
import {
|
||||
DEFAULT_ACCOUNT_ID,
|
||||
assertHttpUrlTargetsPrivateNetwork,
|
||||
isPrivateOrLoopbackHost,
|
||||
type LookupFn,
|
||||
normalizeAccountId,
|
||||
normalizeOptionalAccountId,
|
||||
ssrfPolicyFromAllowPrivateNetwork,
|
||||
} from "./config-runtime-api.js";
|
||||
import type { MatrixAuth, MatrixResolvedConfig } from "./types.js";
|
||||
|
||||
type MatrixAuthClientDeps = {
|
||||
@@ -44,10 +44,12 @@ let matrixCredentialsReadDepsPromise: Promise<MatrixCredentialsReadDeps> | undef
|
||||
let matrixAuthClientDepsForTest: MatrixAuthClientDeps | undefined;
|
||||
|
||||
export function setMatrixAuthClientDepsForTest(
|
||||
deps?: {
|
||||
MatrixClient: typeof import("../sdk.js").MatrixClient;
|
||||
ensureMatrixSdkLoggingConfigured: typeof import("./logging.js").ensureMatrixSdkLoggingConfigured;
|
||||
} | undefined,
|
||||
deps?:
|
||||
| {
|
||||
MatrixClient: typeof import("../sdk.js").MatrixClient;
|
||||
ensureMatrixSdkLoggingConfigured: typeof import("./logging.js").ensureMatrixSdkLoggingConfigured;
|
||||
}
|
||||
| undefined,
|
||||
): void {
|
||||
matrixAuthClientDepsForTest = deps;
|
||||
}
|
||||
|
||||
31
extensions/matrix/src/matrix/config-paths.ts
Normal file
31
extensions/matrix/src/matrix/config-paths.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
||||
import type { CoreConfig } from "../types.js";
|
||||
|
||||
export function shouldStoreMatrixAccountAtTopLevel(cfg: CoreConfig, accountId: string): boolean {
|
||||
const normalizedAccountId = normalizeAccountId(accountId);
|
||||
if (normalizedAccountId !== DEFAULT_ACCOUNT_ID) {
|
||||
return false;
|
||||
}
|
||||
const accounts = cfg.channels?.matrix?.accounts;
|
||||
return !accounts || Object.keys(accounts).length === 0;
|
||||
}
|
||||
|
||||
export function resolveMatrixConfigPath(cfg: CoreConfig, accountId: string): string {
|
||||
const normalizedAccountId = normalizeAccountId(accountId);
|
||||
if (shouldStoreMatrixAccountAtTopLevel(cfg, normalizedAccountId)) {
|
||||
return "channels.matrix";
|
||||
}
|
||||
return `channels.matrix.accounts.${normalizedAccountId}`;
|
||||
}
|
||||
|
||||
export function resolveMatrixConfigFieldPath(
|
||||
cfg: CoreConfig,
|
||||
accountId: string,
|
||||
fieldPath: string,
|
||||
): string {
|
||||
const suffix = fieldPath.trim().replace(/^\.+/, "");
|
||||
if (!suffix) {
|
||||
return resolveMatrixConfigPath(cfg, accountId);
|
||||
}
|
||||
return `${resolveMatrixConfigPath(cfg, accountId)}.${suffix}`;
|
||||
}
|
||||
@@ -1,9 +1,19 @@
|
||||
import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-id";
|
||||
import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
||||
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
||||
import { coerceSecretRef } from "openclaw/plugin-sdk/config-runtime";
|
||||
import { normalizeSecretInputString } from "openclaw/plugin-sdk/setup";
|
||||
import type { CoreConfig, MatrixConfig } from "../types.js";
|
||||
import { findMatrixAccountConfig } from "./account-config.js";
|
||||
import {
|
||||
resolveMatrixConfigFieldPath,
|
||||
resolveMatrixConfigPath,
|
||||
shouldStoreMatrixAccountAtTopLevel,
|
||||
} from "./config-paths.js";
|
||||
|
||||
export {
|
||||
resolveMatrixConfigFieldPath,
|
||||
resolveMatrixConfigPath,
|
||||
shouldStoreMatrixAccountAtTopLevel,
|
||||
} from "./config-paths.js";
|
||||
|
||||
export type MatrixAccountPatch = {
|
||||
name?: string | null;
|
||||
@@ -113,35 +123,6 @@ function applyNullableArrayField(
|
||||
target[key] = [...value];
|
||||
}
|
||||
|
||||
export function shouldStoreMatrixAccountAtTopLevel(cfg: CoreConfig, accountId: string): boolean {
|
||||
const normalizedAccountId = normalizeAccountId(accountId);
|
||||
if (normalizedAccountId !== DEFAULT_ACCOUNT_ID) {
|
||||
return false;
|
||||
}
|
||||
const accounts = cfg.channels?.matrix?.accounts;
|
||||
return !accounts || Object.keys(accounts).length === 0;
|
||||
}
|
||||
|
||||
export function resolveMatrixConfigPath(cfg: CoreConfig, accountId: string): string {
|
||||
const normalizedAccountId = normalizeAccountId(accountId);
|
||||
if (shouldStoreMatrixAccountAtTopLevel(cfg, normalizedAccountId)) {
|
||||
return "channels.matrix";
|
||||
}
|
||||
return `channels.matrix.accounts.${normalizedAccountId}`;
|
||||
}
|
||||
|
||||
export function resolveMatrixConfigFieldPath(
|
||||
cfg: CoreConfig,
|
||||
accountId: string,
|
||||
fieldPath: string,
|
||||
): string {
|
||||
const suffix = fieldPath.trim().replace(/^\.+/, "");
|
||||
if (!suffix) {
|
||||
return resolveMatrixConfigPath(cfg, accountId);
|
||||
}
|
||||
return `${resolveMatrixConfigPath(cfg, accountId)}.${suffix}`;
|
||||
}
|
||||
|
||||
export function updateMatrixAccountConfig(
|
||||
cfg: CoreConfig,
|
||||
accountId: string,
|
||||
|
||||
Reference in New Issue
Block a user