@kodelyth/matrix 2026.5.39 → 2026.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/dist/account-selection-Y50DNJ2l.js +158 -0
  2. package/dist/active-client-CmFdvPdO.js +20 -0
  3. package/dist/api.js +12 -0
  4. package/dist/approval-handler.runtime-BIi4fL0R.js +377 -0
  5. package/dist/approval-ids-BGHK7PnZ.js +7 -0
  6. package/dist/approval-reaction-auth-CL0-nCNV.js +27 -0
  7. package/dist/approval-reactions-nDm2x-K5.js +162 -0
  8. package/dist/async-lock-SsmtFXtt.js +19 -0
  9. package/dist/auth-presence.js +26 -0
  10. package/dist/backup-health-3BHbHxyd.js +60 -0
  11. package/dist/channel-C0kCyTNB.js +1380 -0
  12. package/dist/channel-plugin-api.js +2 -0
  13. package/dist/channel.runtime-CdrdEN-0.js +250 -0
  14. package/dist/cli-FtY6Nuzw.js +1338 -0
  15. package/dist/cli-metadata-Dkwua7CB.js +22 -0
  16. package/dist/cli-metadata.js +2 -0
  17. package/dist/client-BnohYygh.js +25 -0
  18. package/dist/client-PhrTwuC4.js +30 -0
  19. package/dist/client-bootstrap-Mcj8ChJ5.js +114 -0
  20. package/dist/config-paths-DVvt6vM3.js +114 -0
  21. package/dist/config-schema-BMGOlhdI.js +308 -0
  22. package/dist/config-secret-input.runtime-Dv_4Br_f.js +2 -0
  23. package/dist/contract-api.js +8 -0
  24. package/dist/create-client-J0htTaRj.js +64 -0
  25. package/dist/credentials-B7GsBbgQ.js +56 -0
  26. package/dist/credentials-read-8fE4qoWs.js +112 -0
  27. package/dist/credentials-write.runtime-BibplB4Y.js +17 -0
  28. package/dist/crypto-node.runtime-D9qxgRPa.js +12 -0
  29. package/dist/crypto-runtime-1pKW4O2F.js +1214 -0
  30. package/dist/deps-DVpDS81G.js +208 -0
  31. package/dist/device-health-Ct2wDSPG.js +16 -0
  32. package/dist/directory-live-i3T8uORc.js +150 -0
  33. package/dist/doctor-contract-BLzYHl_9.js +246 -0
  34. package/dist/doctor-contract-api.js +2 -0
  35. package/dist/doctor-diR5gE7D.js +153 -0
  36. package/dist/draft-stream-HpPJ_VJt.js +143 -0
  37. package/dist/encryption-guidance-BNEgckrZ.js +15 -0
  38. package/dist/env-auth-UFiTGkDM.js +63 -0
  39. package/dist/env-vars-EQKQv-FE.js +63 -0
  40. package/dist/errors-BETj3zr9.js +17 -0
  41. package/dist/exec-approval-resolver-BxPorU_t.js +15 -0
  42. package/dist/helper-api.js +4 -0
  43. package/dist/http-client-DoQgbQsU.js +331 -0
  44. package/dist/index.js +46 -0
  45. package/dist/legacy-crypto-inspector-zK0hDCbt.js +41 -0
  46. package/dist/legacy-crypto-restore-DSFIXuDo.js +85 -0
  47. package/dist/logging-Df7aPD1z.js +99 -0
  48. package/dist/matrix-migration.runtime-BNoT1Prt.js +525 -0
  49. package/dist/media-text-ZhGA8Pcs.js +146 -0
  50. package/dist/messages-CRA9WGg0.js +140 -0
  51. package/dist/migration-snapshot-backup-BR-xD7Ew.js +69 -0
  52. package/dist/migration-snapshot.runtime-BLcy_Nvw.js +2 -0
  53. package/dist/monitor-DQm7_13y.js +4331 -0
  54. package/dist/plugin-entry.handlers.runtime.js +51 -0
  55. package/dist/probe.runtime-CjJS53Kz.js +3 -0
  56. package/dist/profile-update-DqkPgZ1P.js +68 -0
  57. package/dist/reaction-common-CmVLzP-u.js +71 -0
  58. package/dist/reaction-events-D0nUJuZV.js +121 -0
  59. package/dist/record-shared-DGvSFn5M.js +2 -0
  60. package/dist/resolve-targets-ChECUzD2.js +140 -0
  61. package/dist/resolver.runtime-hdY3n0GO.js +5 -0
  62. package/dist/rolldown-runtime-DUslC3ob.js +14 -0
  63. package/dist/route-xRKj_ESW.js +161 -0
  64. package/dist/runtime-B-Fyrmxo.js +8 -0
  65. package/dist/runtime-api-BYXXkxq2.js +24 -0
  66. package/dist/runtime-api.js +25 -0
  67. package/dist/runtime-heavy-api.js +3 -0
  68. package/dist/runtime-lwTSy9Yt.js +6 -0
  69. package/dist/runtime-setter-api.js +2 -0
  70. package/dist/sdk-Jhq7mLtD.js +1704 -0
  71. package/dist/secret-contract-DEMcDsjl.js +120 -0
  72. package/dist/secret-contract-api.js +2 -0
  73. package/dist/send-CJunc6QM.js +1517 -0
  74. package/dist/setup-bootstrap-rJ0qZWPe.js +62 -0
  75. package/dist/setup-core-BEYoXF3J.js +677 -0
  76. package/dist/setup-entry.js +19 -0
  77. package/dist/setup-plugin-api.js +43 -0
  78. package/dist/setup-surface-c28ON6jq.js +537 -0
  79. package/dist/shared-D6MFMnpG.js +642 -0
  80. package/dist/startup-abort-B2J3MU_h.js +109 -0
  81. package/dist/startup-verification-CkD4Cwce.js +132 -0
  82. package/dist/storage-nyO0DOFE.js +281 -0
  83. package/dist/storage-paths-BTAketfg.js +52 -0
  84. package/dist/subagent-hooks-api-Dr_xnMRG.js +170 -0
  85. package/dist/subagent-hooks-api.js +2 -0
  86. package/dist/sync-state-Bx0gPaGA.js +12 -0
  87. package/dist/target-ids-Bsazo8si.js +77 -0
  88. package/dist/test-api.js +4 -0
  89. package/dist/thread-binding-api-IGU0-L70.js +17 -0
  90. package/dist/thread-binding-api.js +2 -0
  91. package/dist/thread-bindings-FjAZmDUP.js +352 -0
  92. package/dist/thread-bindings-runtime.js +2 -0
  93. package/dist/thread-bindings-shared-fvfP7jVs.js +97 -0
  94. package/dist/timeout-abort-signal-DpSHDHhR.js +2 -0
  95. package/dist/tool-actions.runtime-Cbo7YcYZ.js +532 -0
  96. package/dist/url-validation-DlrXNjAE.js +36 -0
  97. package/dist/verification-7tDPRpJU.js +345 -0
  98. package/package.json +19 -7
  99. package/api.js +0 -7
  100. package/auth-presence.js +0 -7
  101. package/channel-plugin-api.js +0 -7
  102. package/cli-metadata.js +0 -7
  103. package/contract-api.js +0 -7
  104. package/doctor-contract-api.js +0 -7
  105. package/helper-api.js +0 -7
  106. package/index.js +0 -7
  107. package/plugin-entry.handlers.runtime.js +0 -7
  108. package/runtime-api.js +0 -7
  109. package/runtime-heavy-api.js +0 -7
  110. package/runtime-setter-api.js +0 -7
  111. package/secret-contract-api.js +0 -7
  112. package/setup-entry.js +0 -7
  113. package/setup-plugin-api.js +0 -7
  114. package/subagent-hooks-api.js +0 -7
  115. package/test-api.js +0 -7
  116. package/thread-binding-api.js +0 -7
  117. package/thread-bindings-runtime.js +0 -7
@@ -0,0 +1,64 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-DUslC3ob.js";
2
+ import { t as resolveValidatedMatrixHomeserverUrl } from "./url-validation-DlrXNjAE.js";
3
+ import { a as resolveMatrixStoragePaths, n as maybeMigrateLegacyStorage, o as writeStorageMeta } from "./storage-nyO0DOFE.js";
4
+ import "./shared-D6MFMnpG.js";
5
+ import { normalizeOptionalString } from "klaw/plugin-sdk/string-coerce-runtime";
6
+ import fs from "node:fs";
7
+ import { ssrfPolicyFromDangerouslyAllowPrivateNetwork } from "klaw/plugin-sdk/ssrf-runtime";
8
+ //#region extensions/matrix/src/matrix/client/create-client.ts
9
+ var create_client_exports = /* @__PURE__ */ __exportAll({ createMatrixClient: () => createMatrixClient });
10
+ let matrixCreateClientRuntimeDepsPromise;
11
+ async function loadMatrixCreateClientRuntimeDeps() {
12
+ matrixCreateClientRuntimeDepsPromise ??= Promise.all([import("./sdk-Jhq7mLtD.js").then((n) => n.n), import("./logging-Df7aPD1z.js").then((n) => n.n)]).then(([sdkModule, loggingModule]) => ({
13
+ MatrixClient: sdkModule.MatrixClient,
14
+ ensureMatrixSdkLoggingConfigured: loggingModule.ensureMatrixSdkLoggingConfigured
15
+ }));
16
+ return await matrixCreateClientRuntimeDepsPromise;
17
+ }
18
+ async function createMatrixClient(params) {
19
+ const { MatrixClient, ensureMatrixSdkLoggingConfigured } = await loadMatrixCreateClientRuntimeDeps();
20
+ ensureMatrixSdkLoggingConfigured();
21
+ const homeserver = await resolveValidatedMatrixHomeserverUrl(params.homeserver, { dangerouslyAllowPrivateNetwork: params.allowPrivateNetwork });
22
+ const matrixClientUserId = normalizeOptionalString(params.userId);
23
+ const userId = matrixClientUserId ?? "unknown";
24
+ const storagePaths = params.persistStorage !== false ? resolveMatrixStoragePaths({
25
+ homeserver,
26
+ userId,
27
+ accessToken: params.accessToken,
28
+ accountId: params.accountId,
29
+ deviceId: params.deviceId,
30
+ env: process.env
31
+ }) : null;
32
+ if (storagePaths) {
33
+ await maybeMigrateLegacyStorage({
34
+ storagePaths,
35
+ env: process.env
36
+ });
37
+ fs.mkdirSync(storagePaths.rootDir, { recursive: true });
38
+ writeStorageMeta({
39
+ storagePaths,
40
+ homeserver,
41
+ userId,
42
+ accountId: params.accountId,
43
+ deviceId: params.deviceId
44
+ });
45
+ }
46
+ const cryptoDatabasePrefix = storagePaths ? `klaw-matrix-${storagePaths.accountKey}-${storagePaths.tokenHash}` : void 0;
47
+ return new MatrixClient(homeserver, params.accessToken, {
48
+ userId: matrixClientUserId,
49
+ password: params.password,
50
+ deviceId: params.deviceId,
51
+ encryption: params.encryption,
52
+ localTimeoutMs: params.localTimeoutMs,
53
+ initialSyncLimit: params.initialSyncLimit,
54
+ storagePath: storagePaths?.storagePath,
55
+ recoveryKeyPath: storagePaths?.recoveryKeyPath,
56
+ idbSnapshotPath: storagePaths?.idbSnapshotPath,
57
+ cryptoDatabasePrefix,
58
+ autoBootstrapCrypto: params.autoBootstrapCrypto,
59
+ ssrfPolicy: params.ssrfPolicy ?? ssrfPolicyFromDangerouslyAllowPrivateNetwork(params.allowPrivateNetwork),
60
+ dispatcherPolicy: params.dispatcherPolicy
61
+ });
62
+ }
63
+ //#endregion
64
+ export { create_client_exports as n, createMatrixClient as t };
@@ -0,0 +1,56 @@
1
+ import { a as resolveMatrixCredentialsDir, i as loadMatrixCredentials, n as credentialsMatchConfig, o as resolveMatrixCredentialsPath, t as clearMatrixCredentials } from "./credentials-read-8fE4qoWs.js";
2
+ import { t as createAsyncLock } from "./async-lock-SsmtFXtt.js";
3
+ import { writeJsonFileAtomically } from "klaw/plugin-sdk/json-store";
4
+ //#region extensions/matrix/src/matrix/credentials.ts
5
+ const credentialWriteLocks = /* @__PURE__ */ new Map();
6
+ function withCredentialWriteLock(credPath, fn) {
7
+ let withLock = credentialWriteLocks.get(credPath);
8
+ if (!withLock) {
9
+ withLock = createAsyncLock();
10
+ credentialWriteLocks.set(credPath, withLock);
11
+ }
12
+ return withLock(fn);
13
+ }
14
+ async function writeMatrixCredentialsUnlocked(params) {
15
+ const now = (/* @__PURE__ */ new Date()).toISOString();
16
+ const toSave = {
17
+ ...params.credentials,
18
+ createdAt: params.existing?.createdAt ?? now,
19
+ lastUsedAt: now
20
+ };
21
+ await writeJsonFileAtomically(params.credPath, toSave);
22
+ }
23
+ async function saveMatrixCredentials(credentials, env = process.env, accountId) {
24
+ const credPath = resolveMatrixCredentialsPath(env, accountId);
25
+ await withCredentialWriteLock(credPath, async () => {
26
+ await writeMatrixCredentialsUnlocked({
27
+ credPath,
28
+ credentials,
29
+ existing: loadMatrixCredentials(env, accountId)
30
+ });
31
+ });
32
+ }
33
+ async function saveBackfilledMatrixDeviceId(credentials, env = process.env, accountId) {
34
+ const credPath = resolveMatrixCredentialsPath(env, accountId);
35
+ return await withCredentialWriteLock(credPath, async () => {
36
+ const existing = loadMatrixCredentials(env, accountId);
37
+ if (existing && (existing.homeserver !== credentials.homeserver || existing.userId !== credentials.userId || existing.accessToken !== credentials.accessToken)) return "skipped";
38
+ await writeMatrixCredentialsUnlocked({
39
+ credPath,
40
+ credentials,
41
+ existing
42
+ });
43
+ return "saved";
44
+ });
45
+ }
46
+ async function touchMatrixCredentials(env = process.env, accountId) {
47
+ const credPath = resolveMatrixCredentialsPath(env, accountId);
48
+ await withCredentialWriteLock(credPath, async () => {
49
+ const existing = loadMatrixCredentials(env, accountId);
50
+ if (!existing) return;
51
+ existing.lastUsedAt = (/* @__PURE__ */ new Date()).toISOString();
52
+ await writeJsonFileAtomically(credPath, existing);
53
+ });
54
+ }
55
+ //#endregion
56
+ export { clearMatrixCredentials, credentialsMatchConfig, loadMatrixCredentials, resolveMatrixCredentialsDir, resolveMatrixCredentialsPath, saveBackfilledMatrixDeviceId, saveMatrixCredentials, touchMatrixCredentials };
@@ -0,0 +1,112 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-DUslC3ob.js";
2
+ import { a as resolveMatrixDefaultOrOnlyAccountId, n as requiresExplicitMatrixDefaultAccount } from "./account-selection-Y50DNJ2l.js";
3
+ import { t as getMatrixRuntime } from "./runtime-B-Fyrmxo.js";
4
+ import { a as resolveMatrixCredentialsPath$1, r as resolveMatrixCredentialsDir$1 } from "./storage-paths-BTAketfg.js";
5
+ import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "klaw/plugin-sdk/account-id";
6
+ import fs from "node:fs";
7
+ import os from "node:os";
8
+ import path from "node:path";
9
+ //#region extensions/matrix/src/matrix/credentials-read.ts
10
+ var credentials_read_exports = /* @__PURE__ */ __exportAll({
11
+ clearMatrixCredentials: () => clearMatrixCredentials,
12
+ credentialsMatchConfig: () => credentialsMatchConfig,
13
+ loadMatrixCredentials: () => loadMatrixCredentials,
14
+ resolveMatrixCredentialsDir: () => resolveMatrixCredentialsDir,
15
+ resolveMatrixCredentialsPath: () => resolveMatrixCredentialsPath
16
+ });
17
+ function resolveStateDir(env) {
18
+ try {
19
+ return getMatrixRuntime().state.resolveStateDir(env, os.homedir);
20
+ } catch {
21
+ const override = (env.KLAW_STATE_DIR ?? env.KLAW_STATE_DIR)?.trim();
22
+ if (override) return path.resolve(override);
23
+ const homeDir = env.KLAW_HOME?.trim() || env.KLAW_HOME?.trim() || env.HOME?.trim() || os.homedir();
24
+ return path.join(homeDir, ".klaw");
25
+ }
26
+ }
27
+ function resolveLegacyMatrixCredentialsPath(env) {
28
+ return path.join(resolveMatrixCredentialsDir(env), "credentials.json");
29
+ }
30
+ function shouldReadLegacyCredentialsForAccount(accountId) {
31
+ const normalizedAccountId = normalizeAccountId(accountId);
32
+ const cfg = getMatrixRuntime().config.current();
33
+ if (!cfg.channels?.matrix || typeof cfg.channels.matrix !== "object") return normalizedAccountId === DEFAULT_ACCOUNT_ID;
34
+ if (requiresExplicitMatrixDefaultAccount(cfg)) return false;
35
+ return normalizeAccountId(resolveMatrixDefaultOrOnlyAccountId(cfg)) === normalizedAccountId;
36
+ }
37
+ function resolveLegacyMigrationSourcePath(env, accountId) {
38
+ if (!shouldReadLegacyCredentialsForAccount(accountId)) return null;
39
+ const legacyPath = resolveLegacyMatrixCredentialsPath(env);
40
+ return legacyPath === resolveMatrixCredentialsPath(env, accountId) ? null : legacyPath;
41
+ }
42
+ function parseMatrixCredentialsFile(filePath) {
43
+ const raw = fs.readFileSync(filePath, "utf-8");
44
+ const parsed = JSON.parse(raw);
45
+ if (typeof parsed.homeserver !== "string" || typeof parsed.userId !== "string" || typeof parsed.accessToken !== "string") return null;
46
+ return parsed;
47
+ }
48
+ function loadMatrixCredentialsFile(filePath, source) {
49
+ try {
50
+ return {
51
+ kind: "loaded",
52
+ source,
53
+ credentials: parseMatrixCredentialsFile(filePath)
54
+ };
55
+ } catch (error) {
56
+ if (error?.code === "ENOENT") return { kind: "missing" };
57
+ throw error;
58
+ }
59
+ }
60
+ function loadLegacyMatrixCredentialsWithCurrentFallback(params) {
61
+ const legacy = loadMatrixCredentialsFile(params.legacyPath, "legacy");
62
+ if (legacy.kind === "loaded") return legacy;
63
+ return loadMatrixCredentialsFile(params.currentPath, "current");
64
+ }
65
+ function resolveMatrixCredentialsDir(env = process.env, stateDir) {
66
+ return resolveMatrixCredentialsDir$1(stateDir ?? resolveStateDir(env));
67
+ }
68
+ function resolveMatrixCredentialsPath(env = process.env, accountId) {
69
+ return resolveMatrixCredentialsPath$1({
70
+ stateDir: resolveStateDir(env),
71
+ accountId
72
+ });
73
+ }
74
+ function loadMatrixCredentials(env = process.env, accountId) {
75
+ const currentPath = resolveMatrixCredentialsPath(env, accountId);
76
+ try {
77
+ const current = loadMatrixCredentialsFile(currentPath, "current");
78
+ if (current.kind === "loaded") return current.credentials;
79
+ const legacyPath = resolveLegacyMigrationSourcePath(env, accountId);
80
+ if (!legacyPath) return null;
81
+ const loaded = loadLegacyMatrixCredentialsWithCurrentFallback({
82
+ legacyPath,
83
+ currentPath
84
+ });
85
+ if (loaded.kind !== "loaded" || !loaded.credentials) return null;
86
+ if (loaded.source === "legacy") try {
87
+ fs.mkdirSync(path.dirname(currentPath), { recursive: true });
88
+ fs.renameSync(legacyPath, currentPath);
89
+ } catch {}
90
+ return loaded.credentials;
91
+ } catch {
92
+ return null;
93
+ }
94
+ }
95
+ function clearMatrixCredentials(env = process.env, accountId) {
96
+ const paths = [resolveMatrixCredentialsPath(env, accountId), resolveLegacyMigrationSourcePath(env, accountId)];
97
+ for (const filePath of paths) {
98
+ if (!filePath) continue;
99
+ try {
100
+ fs.unlinkSync(filePath);
101
+ } catch {}
102
+ }
103
+ }
104
+ function credentialsMatchConfig(stored, config) {
105
+ if (!config.userId) {
106
+ if (!config.accessToken) return false;
107
+ return stored.homeserver === config.homeserver && stored.accessToken === config.accessToken;
108
+ }
109
+ return stored.homeserver === config.homeserver && stored.userId === config.userId;
110
+ }
111
+ //#endregion
112
+ export { resolveMatrixCredentialsDir as a, loadMatrixCredentials as i, credentialsMatchConfig as n, resolveMatrixCredentialsPath as o, credentials_read_exports as r, clearMatrixCredentials as t };
@@ -0,0 +1,17 @@
1
+ //#region extensions/matrix/src/matrix/credentials-write.runtime.ts
2
+ let matrixCredentialsRuntimePromise;
3
+ function loadMatrixCredentialsRuntime() {
4
+ matrixCredentialsRuntimePromise ??= import("./credentials-B7GsBbgQ.js");
5
+ return matrixCredentialsRuntimePromise;
6
+ }
7
+ async function saveMatrixCredentials(...args) {
8
+ return (await loadMatrixCredentialsRuntime()).saveMatrixCredentials(...args);
9
+ }
10
+ async function saveBackfilledMatrixDeviceId(...args) {
11
+ return (await loadMatrixCredentialsRuntime()).saveBackfilledMatrixDeviceId(...args);
12
+ }
13
+ async function touchMatrixCredentials(...args) {
14
+ return (await loadMatrixCredentialsRuntime()).touchMatrixCredentials(...args);
15
+ }
16
+ //#endregion
17
+ export { saveBackfilledMatrixDeviceId, saveMatrixCredentials, touchMatrixCredentials };
@@ -0,0 +1,12 @@
1
+ import { createRequire } from "node:module";
2
+ //#region extensions/matrix/src/matrix/sdk/crypto-node.runtime.ts
3
+ const require = createRequire(import.meta.url);
4
+ function loadMatrixCryptoNodeBindings() {
5
+ const { Attachment, EncryptedAttachment } = require("@matrix-org/matrix-sdk-crypto-nodejs");
6
+ return {
7
+ Attachment,
8
+ EncryptedAttachment
9
+ };
10
+ }
11
+ //#endregion
12
+ export { loadMatrixCryptoNodeBindings };