refactor: trim matrix helper exports

This commit is contained in:
Peter Steinberger
2026-05-01 17:35:57 +01:00
parent a301df0668
commit d47055aa92
30 changed files with 70 additions and 93 deletions

View File

@@ -6,7 +6,7 @@ import { resolveStateDir } from "openclaw/plugin-sdk/state-paths";
import { resolveLegacyMatrixFlatStoreTarget } from "./migration-config.js";
import { resolveMatrixLegacyFlatStoragePaths } from "./storage-paths.js";
export type MatrixLegacyStateMigrationResult = {
type MatrixLegacyStateMigrationResult = {
migrated: boolean;
changes: string[];
warnings: string[];

View File

@@ -1,4 +1,4 @@
export type MatrixRoomKeyBackupStatusLike = {
type MatrixRoomKeyBackupStatusLike = {
serverVersion: string | null;
activeVersion: string | null;
trusted: boolean | null;
@@ -8,7 +8,7 @@ export type MatrixRoomKeyBackupStatusLike = {
keyLoadError: string | null;
};
export type MatrixRoomKeyBackupIssueCode =
type MatrixRoomKeyBackupIssueCode =
| "missing-server-backup"
| "key-load-failed"
| "key-not-loaded"
@@ -18,7 +18,7 @@ export type MatrixRoomKeyBackupIssueCode =
| "indeterminate"
| "ok";
export type MatrixRoomKeyBackupIssue = {
type MatrixRoomKeyBackupIssue = {
code: MatrixRoomKeyBackupIssueCode;
summary: string;
message: string | null;

View File

@@ -32,7 +32,6 @@ import {
resolveGlobalMatrixEnvConfig,
resolveMatrixEnvAuthReadiness,
resolveScopedMatrixEnvConfig,
type MatrixEnvConfig,
} from "./env-auth.js";
import { repairCurrentTokenStorageMetaDeviceId } from "./storage.js";
import type { MatrixAuth, MatrixResolvedConfig } from "./types.js";
@@ -449,10 +448,8 @@ function buildMatrixNetworkFields(params: {
export { getMatrixScopedEnvVarNames } from "../../env-vars.js";
export {
hasReadyMatrixEnvAuth,
resolveGlobalMatrixEnvConfig,
resolveMatrixEnvAuthReadiness,
resolveScopedMatrixEnvConfig,
type MatrixEnvConfig,
} from "./env-auth.js";
export {
resolveValidatedMatrixHomeserverUrl,

View File

@@ -1,7 +1,7 @@
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
import { getMatrixScopedEnvVarNames } from "../../env-vars.js";
export type MatrixEnvConfig = {
type MatrixEnvConfig = {
homeserver: string;
userId: string;
accessToken?: string;

View File

@@ -15,7 +15,7 @@ import {
import type { MatrixAuth } from "./types.js";
import type { MatrixStoragePaths } from "./types.js";
export const DEFAULT_ACCOUNT_KEY = "default";
const DEFAULT_ACCOUNT_KEY = "default";
const STORAGE_META_FILENAME = "storage-meta.json";
const THREAD_BINDINGS_FILENAME = "thread-bindings.json";
const LEGACY_CRYPTO_MIGRATION_FILENAME = "legacy-crypto-migration.json";

View File

@@ -3,10 +3,7 @@ import { resolveMatrixDefaultOrOnlyAccountId } from "../account-selection.js";
import type { CoreConfig } from "../types.js";
import { resolveMatrixConfigFieldPath } from "./config-paths.js";
export function resolveMatrixEncryptionConfigPath(
cfg: CoreConfig,
accountId?: string | null,
): string {
function resolveMatrixEncryptionConfigPath(cfg: CoreConfig, accountId?: string | null): string {
const effectiveAccountId =
normalizeOptionalAccountId(accountId) ?? resolveMatrixDefaultOrOnlyAccountId(cfg);
return resolveMatrixConfigFieldPath(cfg, effectiveAccountId, "encryption");

View File

@@ -1,4 +1,4 @@
export const MATRIX_MEDIA_SIZE_LIMIT_ERROR_MESSAGE = "Matrix media exceeds configured size limit";
const MATRIX_MEDIA_SIZE_LIMIT_ERROR_MESSAGE = "Matrix media exceeds configured size limit";
export class MatrixMediaSizeLimitError extends Error {
readonly code = "MATRIX_MEDIA_SIZE_LIMIT" as const;

View File

@@ -35,7 +35,7 @@ function formatMatrixAttachmentMarker(params: {
return params.unavailable ? `[matrix ${label} unavailable]` : `[matrix ${label}]`;
}
export function isLikelyBareFilename(text: string): boolean {
function isLikelyBareFilename(text: string): boolean {
const trimmed = text.trim();
if (!trimmed || trimmed.includes("\n") || /\s/.test(trimmed)) {
return false;
@@ -97,7 +97,7 @@ export function resolveMatrixMessageBody(params: {
return attachment.caption;
}
export function formatMatrixAttachmentText(params: {
function formatMatrixAttachmentText(params: {
attachment?: MatrixMessageAttachmentSummary;
tooLarge?: boolean;
unavailable?: boolean;

View File

@@ -12,7 +12,7 @@ type MatrixMonitorAllowListMatch = {
matchSource?: "wildcard" | "id" | "prefixed-id" | "prefixed-user";
};
export type MatrixMonitorAccessState = {
type MatrixMonitorAccessState = {
effectiveAllowFrom: string[];
effectiveGroupAllowFrom: string[];
effectiveRoomUsers: string[];

View File

@@ -67,9 +67,7 @@ export function normalizeMatrixAllowList(list?: Array<string | number>) {
return normalizeAllowList(list).map((entry) => normalizeMatrixAllowListEntry(entry));
}
export type MatrixAllowListMatch = AllowlistMatch<
"wildcard" | "id" | "prefixed-id" | "prefixed-user"
>;
type MatrixAllowListMatch = AllowlistMatch<"wildcard" | "id" | "prefixed-id" | "prefixed-user">;
type MatrixAllowListMatchSource = NonNullable<MatrixAllowListMatch["matchSource"]>;

View File

@@ -5,7 +5,7 @@ import type { MatrixRawEvent } from "./types.js";
const MAX_CACHED_REPLY_CONTEXTS = 256;
const MAX_REPLY_BODY_LENGTH = 500;
export type MatrixReplyContext = {
type MatrixReplyContext = {
replyToBody?: string;
replyToSender?: string;
replyToSenderId?: string;

View File

@@ -26,16 +26,16 @@ const MAX_PREPARED_TRIGGER_ENTRIES = 500;
export type { HistoryEntry };
export type HistorySnapshotToken = {
type HistorySnapshotToken = {
snapshotIdx: number;
queueGeneration: number;
};
export type PreparedTriggerResult = {
type PreparedTriggerResult = {
history: HistoryEntry[];
} & HistorySnapshotToken;
export type RoomHistoryTracker = {
type RoomHistoryTracker = {
/**
* Record a non-trigger message for future context.
* Call this when a room message arrives but does not mention the bot.
@@ -66,7 +66,7 @@ export type RoomHistoryTracker = {
) => void;
};
export type RoomHistoryTrackerTestApi = RoomHistoryTracker & {
type RoomHistoryTrackerTestApi = RoomHistoryTracker & {
/**
* Test-only helper for inspecting pending room history directly.
*/

View File

@@ -1,7 +1,7 @@
import type { MatrixRoomConfig } from "../../types.js";
import { buildChannelKeyCandidates, resolveChannelEntryMatch } from "./runtime-api.js";
export type MatrixRoomConfigResolved = {
type MatrixRoomConfigResolved = {
allowed: boolean;
allowlistConfigured: boolean;
config?: MatrixRoomConfig;

View File

@@ -2,9 +2,9 @@ import { resolveThreadSessionKeys } from "openclaw/plugin-sdk/routing";
import type { MatrixRawEvent, RoomMessageEventContent } from "./types.js";
import { RelationType } from "./types.js";
export type MatrixThreadReplies = "off" | "inbound" | "always";
type MatrixThreadReplies = "off" | "inbound" | "always";
export type MatrixThreadRouting = {
type MatrixThreadRouting = {
threadId?: string;
};

View File

@@ -11,14 +11,14 @@ import { normalizePollInput, type PollInput } from "openclaw/plugin-sdk/poll-run
import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
export const M_POLL_START = "m.poll.start" as const;
export const M_POLL_RESPONSE = "m.poll.response" as const;
export const M_POLL_END = "m.poll.end" as const;
const M_POLL_RESPONSE = "m.poll.response" as const;
const M_POLL_END = "m.poll.end" as const;
export const ORG_POLL_START = "org.matrix.msc3381.poll.start" as const;
export const ORG_POLL_RESPONSE = "org.matrix.msc3381.poll.response" as const;
export const ORG_POLL_END = "org.matrix.msc3381.poll.end" as const;
const ORG_POLL_START = "org.matrix.msc3381.poll.start" as const;
const ORG_POLL_RESPONSE = "org.matrix.msc3381.poll.response" as const;
const ORG_POLL_END = "org.matrix.msc3381.poll.end" as const;
export const POLL_EVENT_TYPES = [
const POLL_EVENT_TYPES = [
M_POLL_START,
M_POLL_RESPONSE,
M_POLL_END,
@@ -27,28 +27,28 @@ export const POLL_EVENT_TYPES = [
ORG_POLL_END,
];
export const POLL_START_TYPES = [M_POLL_START, ORG_POLL_START];
export const POLL_RESPONSE_TYPES = [M_POLL_RESPONSE, ORG_POLL_RESPONSE];
export const POLL_END_TYPES = [M_POLL_END, ORG_POLL_END];
const POLL_START_TYPES = [M_POLL_START, ORG_POLL_START];
const POLL_RESPONSE_TYPES = [M_POLL_RESPONSE, ORG_POLL_RESPONSE];
const POLL_END_TYPES = [M_POLL_END, ORG_POLL_END];
export type PollKind = "m.poll.disclosed" | "m.poll.undisclosed";
type PollKind = "m.poll.disclosed" | "m.poll.undisclosed";
export type TextContent = {
type TextContent = {
"m.text"?: string;
"org.matrix.msc1767.text"?: string;
body?: string;
};
export type PollAnswer = {
type PollAnswer = {
id: string;
} & TextContent;
export type PollParsedAnswer = {
type PollParsedAnswer = {
id: string;
text: string;
};
export type PollStartSubtype = {
type PollStartSubtype = {
question: TextContent;
kind?: PollKind;
max_selections?: number;
@@ -63,7 +63,7 @@ export type PollStartContent = {
"org.matrix.msc1767.text"?: string;
};
export type PollSummary = {
type PollSummary = {
eventId: string;
roomId: string;
sender: string;
@@ -74,7 +74,7 @@ export type PollSummary = {
maxSelections: number;
};
export type PollResultsSummary = PollSummary & {
type PollResultsSummary = PollSummary & {
entries: Array<{
id: string;
text: string;
@@ -84,18 +84,18 @@ export type PollResultsSummary = PollSummary & {
closed: boolean;
};
export type ParsedPollStart = {
type ParsedPollStart = {
question: string;
answers: PollParsedAnswer[];
kind: PollKind;
maxSelections: number;
};
export type PollResponseSubtype = {
type PollResponseSubtype = {
answers: string[];
};
export type PollResponseContent = {
type PollResponseContent = {
[M_POLL_RESPONSE]?: PollResponseSubtype;
[ORG_POLL_RESPONSE]?: PollResponseSubtype;
"m.relates_to": {
@@ -108,11 +108,11 @@ export function isPollStartType(eventType: string): boolean {
return (POLL_START_TYPES as readonly string[]).includes(eventType);
}
export function isPollResponseType(eventType: string): boolean {
function isPollResponseType(eventType: string): boolean {
return (POLL_RESPONSE_TYPES as readonly string[]).includes(eventType);
}
export function isPollEndType(eventType: string): boolean {
function isPollEndType(eventType: string): boolean {
return (POLL_END_TYPES as readonly string[]).includes(eventType);
}
@@ -120,7 +120,7 @@ export function isPollEventType(eventType: string): boolean {
return (POLL_EVENT_TYPES as readonly string[]).includes(eventType);
}
export function getTextContent(text?: TextContent): string {
function getTextContent(text?: TextContent): string {
if (!text) {
return "";
}

View File

@@ -3,7 +3,7 @@ import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runti
export const MATRIX_ANNOTATION_RELATION_TYPE = "m.annotation";
export const MATRIX_REACTION_EVENT_TYPE = "m.reaction";
export type MatrixReactionEventContent = {
type MatrixReactionEventContent = {
"m.relates_to": {
rel_type: typeof MATRIX_ANNOTATION_RELATION_TYPE;
event_id: string;
@@ -17,7 +17,7 @@ export type MatrixReactionSummary = {
users: string[];
};
export type MatrixReactionAnnotation = {
type MatrixReactionAnnotation = {
key: string;
eventId?: string;
};
@@ -28,7 +28,7 @@ type MatrixReactionEventLike = {
event_id?: string | null;
};
export function normalizeMatrixReactionMessageId(messageId: string): string {
function normalizeMatrixReactionMessageId(messageId: string): string {
const normalized = messageId.trim();
if (!normalized) {
throw new Error("Matrix reaction requires a messageId");
@@ -36,7 +36,7 @@ export function normalizeMatrixReactionMessageId(messageId: string): string {
return normalized;
}
export function normalizeMatrixReactionEmoji(emoji: string): string {
function normalizeMatrixReactionEmoji(emoji: string): string {
const normalized = emoji.trim();
if (!normalized) {
throw new Error("Matrix reaction requires an emoji");
@@ -96,7 +96,7 @@ export function extractMatrixReactionAnnotation(
};
}
export function extractMatrixReactionKey(content: unknown): string | undefined {
function extractMatrixReactionKey(content: unknown): string | undefined {
return extractMatrixReactionAnnotation(content)?.key;
}

View File

@@ -1,7 +1,7 @@
import type { MatrixEvent } from "matrix-js-sdk/lib/matrix.js";
import type { MatrixRawEvent } from "./types.js";
export type MatrixEventContentMode = "current" | "original";
type MatrixEventContentMode = "current" | "original";
export function matrixEventToRaw(
event: MatrixEvent,

View File

@@ -3,7 +3,7 @@ import { redactSensitiveText } from "openclaw/plugin-sdk/logging-core";
import type { RuntimeLogger } from "openclaw/plugin-sdk/plugin-runtime";
import { getMatrixRuntime } from "../../runtime.js";
export type Logger = {
type Logger = {
trace: (module: string, ...messageOrObject: unknown[]) => void;
debug: (module: string, ...messageOrObject: unknown[]) => void;
info: (module: string, ...messageOrObject: unknown[]) => void;

View File

@@ -1,7 +1,4 @@
import {
fetchWithRuntimeDispatcherOrMockedGlobal,
isMockedFetch,
} from "openclaw/plugin-sdk/runtime-fetch";
import { fetchWithRuntimeDispatcherOrMockedGlobal } from "openclaw/plugin-sdk/runtime-fetch";
import {
closeDispatcher,
createPinnedDispatcher,
@@ -15,7 +12,6 @@ export {
closeDispatcher,
createPinnedDispatcher,
fetchWithRuntimeDispatcherOrMockedGlobal,
isMockedFetch,
resolvePinnedHostnameWithPolicy,
type PinnedDispatcherPolicy,
type SsrFPolicy,

View File

@@ -130,7 +130,7 @@ export type MatrixDeviceVerificationStatusLike = {
signedByOwner?: boolean;
};
export type MatrixKeyBackupInfo = {
type MatrixKeyBackupInfo = {
algorithm: string;
auth_data: Record<string, unknown>;
count?: number;
@@ -138,24 +138,24 @@ export type MatrixKeyBackupInfo = {
version?: string;
};
export type MatrixKeyBackupTrustInfo = {
type MatrixKeyBackupTrustInfo = {
trusted: boolean;
matchesDecryptionKey: boolean;
};
export type MatrixRoomKeyBackupRestoreResult = {
type MatrixRoomKeyBackupRestoreResult = {
total: number;
imported: number;
};
export type MatrixImportRoomKeyProgress = {
type MatrixImportRoomKeyProgress = {
stage: string;
successes?: number;
failures?: number;
total?: number;
};
export type MatrixSecretStorageKeyDescription = {
type MatrixSecretStorageKeyDescription = {
passphrase?: unknown;
name?: string;
[key: string]: unknown;

View File

@@ -1,6 +1,6 @@
import type { MatrixDeviceVerificationStatusLike } from "./types.js";
export function isMatrixDeviceLocallyVerified(
function isMatrixDeviceLocallyVerified(
status: MatrixDeviceVerificationStatusLike | null | undefined,
): boolean {
return status?.localVerified === true;

View File

@@ -18,7 +18,7 @@ import {
const getCore = () => getMatrixRuntime();
export function buildMatrixMediaInfo(params: {
function buildMatrixMediaInfo(params: {
size: number;
mimetype?: string;
durationMs?: number;

View File

@@ -51,7 +51,7 @@ export type MatrixThreadRelation = {
export type MatrixRelation = MatrixReplyRelation | MatrixThreadRelation;
export type MatrixReplyMeta = {
type MatrixReplyMeta = {
"m.relates_to"?: MatrixRelation;
};

View File

@@ -1,7 +1,7 @@
import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
import { resolveMatrixDirectUserId, resolveMatrixTargetIdentity } from "./target-ids.js";
export function trimMaybeString(value: unknown): string | undefined {
function trimMaybeString(value: unknown): string | undefined {
if (typeof value !== "string") {
return undefined;
}
@@ -18,12 +18,12 @@ function resolveMatrixRoomTargetId(value: unknown): string | undefined {
return target?.kind === "room" && target.id.startsWith("!") ? target.id : undefined;
}
export function resolveMatrixSessionAccountId(value: unknown): string | undefined {
function resolveMatrixSessionAccountId(value: unknown): string | undefined {
const trimmed = trimMaybeString(value);
return trimmed ? normalizeAccountId(trimmed) : undefined;
}
export function resolveMatrixStoredRoomId(params: {
function resolveMatrixStoredRoomId(params: {
deliveryTo?: unknown;
lastTo?: unknown;
originNativeChannelId?: unknown;

View File

@@ -4,7 +4,7 @@ import type {
} from "openclaw/plugin-sdk/thread-bindings-session-runtime";
import { resolveThreadBindingLifecycle } from "openclaw/plugin-sdk/thread-bindings-session-runtime";
export type MatrixThreadBindingTargetKind = "subagent" | "acp";
type MatrixThreadBindingTargetKind = "subagent" | "acp";
export type MatrixThreadBindingRecord = {
accountId: string;
@@ -44,7 +44,7 @@ export type MatrixThreadBindingManager = {
stop: () => void;
};
export type MatrixThreadBindingManagerCacheEntry = {
type MatrixThreadBindingManagerCacheEntry = {
filePath: string;
manager: MatrixThreadBindingManager;
};

View File

@@ -14,7 +14,7 @@ type MatrixMigrationSnapshotMarker = {
includeWorkspace: boolean;
};
export type MatrixMigrationSnapshotResult = {
type MatrixMigrationSnapshotResult = {
created: boolean;
archivePath: string;
markerPath: string;

View File

@@ -5,7 +5,6 @@ import {
maybeCreateMatrixMigrationSnapshot,
resolveMatrixMigrationSnapshotMarkerPath,
resolveMatrixMigrationSnapshotOutputDir,
type MatrixMigrationSnapshotResult,
} from "./migration-snapshot-backup.js";
export type MatrixMigrationStatus = {
@@ -52,4 +51,3 @@ export {
resolveMatrixMigrationSnapshotMarkerPath,
resolveMatrixMigrationSnapshotOutputDir,
};
export type { MatrixMigrationSnapshotResult };

View File

@@ -15,13 +15,6 @@ function sendError(respond: (ok: boolean, payload?: unknown) => void, err: unkno
respond(false, { error: formatMatrixErrorMessage(err) });
}
export async function ensureMatrixCryptoRuntime(
...args: Parameters<typeof import("./matrix/deps.js").ensureMatrixCryptoRuntime>
): Promise<void> {
const { ensureMatrixCryptoRuntime: ensureRuntime } = await import("./matrix/deps.js");
await ensureRuntime(...args);
}
export async function handleVerifyRecoveryKey({
params,
respond,

View File

@@ -7,7 +7,6 @@ import {
normalizeSecretStringValue,
type ResolverContext,
type SecretDefaults,
type SecretTargetRegistryEntry,
} from "openclaw/plugin-sdk/channel-secret-basic-runtime";
import { getMatrixScopedEnvVarNames } from "./env-vars.js";
@@ -56,7 +55,7 @@ export const secretTargetRegistryEntries = [
includeInConfigure: true,
includeInAudit: true,
},
] satisfies SecretTargetRegistryEntry[];
] satisfies import("openclaw/plugin-sdk/channel-secret-basic-runtime").SecretTargetRegistryEntry[];
export function collectRuntimeConfigAssignments(params: {
config: { channels?: Record<string, unknown> };

View File

@@ -5,11 +5,10 @@ import type {
OpenClawConfig,
SecretInput,
} from "./runtime-api.js";
export type { ContextVisibilityMode, DmPolicy, GroupPolicy };
export type ReplyToMode = "off" | "first" | "all" | "batched";
export type MatrixDmConfig = {
type MatrixDmConfig = {
/** If false, ignore all incoming Matrix DMs. Default: true. */
enabled?: boolean;
/** Direct message access policy (default: pairing). */
@@ -50,7 +49,7 @@ export type MatrixRoomConfig = {
systemPrompt?: string;
};
export type MatrixActionConfig = {
type MatrixActionConfig = {
reactions?: boolean;
messages?: boolean;
pins?: boolean;
@@ -60,7 +59,7 @@ export type MatrixActionConfig = {
verification?: boolean;
};
export type MatrixThreadBindingsConfig = {
type MatrixThreadBindingsConfig = {
enabled?: boolean;
idleHours?: number;
maxAgeHours?: number;
@@ -68,7 +67,7 @@ export type MatrixThreadBindingsConfig = {
spawnAcpSessions?: boolean;
};
export type MatrixExecApprovalTarget = "dm" | "channel" | "both";
type MatrixExecApprovalTarget = "dm" | "channel" | "both";
export type MatrixExecApprovalConfig = {
/** If true, deliver exec approvals through Matrix-native prompts. */
@@ -94,7 +93,7 @@ export type MatrixStreamingConfig = {
};
};
export type MatrixNetworkConfig = {
type MatrixNetworkConfig = {
/** Dangerous opt-in for trusted private/internal Matrix homeservers. */
dangerouslyAllowPrivateNetwork?: boolean;
};