diff --git a/extensions/matrix/package.json b/extensions/matrix/package.json index 03c25bd9def..605751f6ccd 100644 --- a/extensions/matrix/package.json +++ b/extensions/matrix/package.json @@ -18,6 +18,7 @@ "extensions": [ "./index.ts" ], + "setupEntry": "./setup-entry.ts", "channel": { "id": "matrix", "label": "Matrix", diff --git a/extensions/matrix/src/channel.runtime.ts b/extensions/matrix/src/channel.runtime.ts deleted file mode 100644 index 475d53629e1..00000000000 --- a/extensions/matrix/src/channel.runtime.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { - listMatrixDirectoryGroupsLive as listMatrixDirectoryGroupsLiveImpl, - listMatrixDirectoryPeersLive as listMatrixDirectoryPeersLiveImpl, -} from "./directory-live.js"; -import { resolveMatrixAuth as resolveMatrixAuthImpl } from "./matrix/client.js"; -import { probeMatrix as probeMatrixImpl } from "./matrix/probe.js"; -import { sendMessageMatrix as sendMessageMatrixImpl } from "./matrix/send.js"; -import { matrixOutbound as matrixOutboundImpl } from "./outbound.js"; -import { resolveMatrixTargets as resolveMatrixTargetsImpl } from "./resolve-targets.js"; -export const matrixChannelRuntime = { - listMatrixDirectoryGroupsLive: listMatrixDirectoryGroupsLiveImpl, - listMatrixDirectoryPeersLive: listMatrixDirectoryPeersLiveImpl, - resolveMatrixAuth: resolveMatrixAuthImpl, - probeMatrix: probeMatrixImpl, - sendMessageMatrix: sendMessageMatrixImpl, - resolveMatrixTargets: resolveMatrixTargetsImpl, - matrixOutbound: { ...matrixOutboundImpl }, -}; diff --git a/extensions/matrix/src/matrix/client.ts b/extensions/matrix/src/matrix/client.ts index 3d6a9f4ff92..c6b4f9ef653 100644 --- a/extensions/matrix/src/matrix/client.ts +++ b/extensions/matrix/src/matrix/client.ts @@ -1,7 +1,7 @@ export type { MatrixAuth } from "./client/types.js"; export { isBunRuntime } from "./client/runtime.js"; +export { getMatrixScopedEnvVarNames } from "openclaw/plugin-sdk/matrix"; export { - getMatrixScopedEnvVarNames, hasReadyMatrixEnvAuth, resolveMatrixConfigForAccount, resolveScopedMatrixEnvConfig, diff --git a/extensions/matrix/src/matrix/client/config.ts b/extensions/matrix/src/matrix/client/config.ts index 9d4dbc734fd..2f3d11c7711 100644 --- a/extensions/matrix/src/matrix/client/config.ts +++ b/extensions/matrix/src/matrix/client/config.ts @@ -1,5 +1,6 @@ import { DEFAULT_ACCOUNT_ID, + getMatrixScopedEnvVarNames, isPrivateOrLoopbackHost, normalizeAccountId, normalizeOptionalAccountId, @@ -7,7 +8,6 @@ import { requiresExplicitMatrixDefaultAccount, resolveMatrixDefaultOrOnlyAccountId, } from "openclaw/plugin-sdk/matrix"; -import { getMatrixScopedEnvVarNames } from "../../../../../src/infra/matrix-env-vars.js"; import { getMatrixRuntime } from "../../runtime.js"; import type { CoreConfig } from "../../types.js"; import { @@ -92,7 +92,7 @@ function resolveGlobalMatrixEnvConfig(env: NodeJS.ProcessEnv): MatrixEnvConfig { }; } -export { getMatrixScopedEnvVarNames } from "../../../../../src/infra/matrix-env-vars.js"; +export { getMatrixScopedEnvVarNames } from "openclaw/plugin-sdk/matrix"; export function resolveScopedMatrixEnvConfig( accountId: string, diff --git a/extensions/matrix/src/matrix/client/file-sync-store.ts b/extensions/matrix/src/matrix/client/file-sync-store.ts index 25a2d4e07f8..70c6ea5831a 100644 --- a/extensions/matrix/src/matrix/client/file-sync-store.ts +++ b/extensions/matrix/src/matrix/client/file-sync-store.ts @@ -7,7 +7,7 @@ import { type ISyncResponse, type IStoredClientOpts, } from "matrix-js-sdk"; -import { createAsyncLock, writeJsonAtomic } from "../../../../../src/infra/json-files.js"; +import { writeJsonFileAtomically } from "openclaw/plugin-sdk/matrix"; import { LogService } from "../sdk/logger.js"; const STORE_VERSION = 1; @@ -19,6 +19,23 @@ type PersistedMatrixSyncStore = { clientOptions?: IStoredClientOpts; }; +function createAsyncLock() { + let lock: Promise = Promise.resolve(); + return async function withLock(fn: () => Promise): Promise { + const previous = lock; + let release: (() => void) | undefined; + lock = new Promise((resolve) => { + release = resolve; + }); + await previous; + try { + return await fn(); + } finally { + release?.(); + } + }; +} + function isRecord(value: unknown): value is Record { return typeof value === "object" && value !== null; } @@ -229,11 +246,7 @@ export class FileBackedMatrixSyncStore extends MemoryStore { }; try { await this.persistLock(async () => { - await writeJsonAtomic(this.storagePath, payload, { - mode: 0o600, - trailingNewline: true, - ensureDirMode: 0o700, - }); + await writeJsonFileAtomically(this.storagePath, payload); }); } catch (err) { this.dirty = true; diff --git a/extensions/matrix/src/matrix/sdk/logger.ts b/extensions/matrix/src/matrix/sdk/logger.ts index 9e663bf69b1..f3f08fe7cdc 100644 --- a/extensions/matrix/src/matrix/sdk/logger.ts +++ b/extensions/matrix/src/matrix/sdk/logger.ts @@ -1,6 +1,5 @@ import { format } from "node:util"; -import { redactSensitiveText } from "../../../../../src/logging/redact.js"; -import type { RuntimeLogger } from "../../../../../src/plugins/runtime/types.js"; +import { redactSensitiveText, type RuntimeLogger } from "openclaw/plugin-sdk/matrix"; import { getMatrixRuntime } from "../../runtime.js"; export type Logger = { diff --git a/src/plugin-sdk/matrix.ts b/src/plugin-sdk/matrix.ts index 5a5f0d3b7f4..51799e4d07d 100644 --- a/src/plugin-sdk/matrix.ts +++ b/src/plugin-sdk/matrix.ts @@ -105,6 +105,7 @@ export { resolveMatrixCredentialsPath, resolveMatrixLegacyFlatStoragePaths, } from "../infra/matrix-storage-paths.js"; +export { getMatrixScopedEnvVarNames } from "../infra/matrix-env-vars.js"; export { requiresExplicitMatrixDefaultAccount, resolveMatrixDefaultOrOnlyAccountId, @@ -147,6 +148,4 @@ export { buildProbeChannelStatusSummary, collectStatusIssuesFromLastError, } from "./status-helpers.js"; -export { matrixSetupWizard } from "../../extensions/matrix/api.js"; -export { matrixSetupAdapter } from "../../extensions/matrix/api.js"; export type { GatewayRequestHandlerOptions } from "../gateway/server-methods/types.js"; diff --git a/src/plugin-sdk/subpaths.test.ts b/src/plugin-sdk/subpaths.test.ts index 4e73ce9c26e..46c01d3deaa 100644 --- a/src/plugin-sdk/subpaths.test.ts +++ b/src/plugin-sdk/subpaths.test.ts @@ -260,8 +260,7 @@ describe("plugin-sdk subpath exports", () => { it("keeps the newly added bundled plugin-sdk contracts available", async () => { expect(typeof bluebubblesSdk.parseFiniteNumber).toBe("function"); - expect(typeof matrixSdk.matrixSetupWizard).toBe("object"); - expect(typeof matrixSdk.matrixSetupAdapter).toBe("object"); + expect(typeof matrixSdk.getMatrixScopedEnvVarNames).toBe("function"); expect(typeof mattermostSdk.parseStrictPositiveInteger).toBe("function"); expect(typeof nextcloudTalkSdk.waitForAbortSignal).toBe("function"); expect(typeof twitchSdk.DEFAULT_ACCOUNT_ID).toBe("string");