|
2 | 2 | import { rm } from "node:fs/promises"; |
3 | 3 | import os from "node:os"; |
4 | 4 | import path from "node:path"; |
| 5 | +import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime"; |
5 | 6 | import { definePluginEntry, type OpenClawPluginApi } from "openclaw/plugin-sdk/plugin-entry"; |
6 | 7 | import { |
7 | 8 | normalizeLowercaseStringOrEmpty, |
8 | 9 | normalizeOptionalString, |
9 | 10 | } from "openclaw/plugin-sdk/string-coerce-runtime"; |
10 | 11 | import { buildDevicePairPairingQrChannelData } from "./pairing-qr-channel-data.js"; |
11 | | - |
12 | | -type DevicePairApiModule = typeof import("./api.js"); |
13 | 12 | type NotifyModule = typeof import("./notify.js"); |
14 | | -type PairCommandApproveModule = typeof import("./pair-command-approve.js"); |
15 | | -type PairCommandAuthModule = typeof import("./pair-command-auth.js"); |
16 | | - |
17 | | -let devicePairApiModulePromise: Promise<DevicePairApiModule> | undefined; |
18 | | -let notifyModulePromise: Promise<NotifyModule> | undefined; |
19 | | -let pairCommandApproveModulePromise: Promise<PairCommandApproveModule> | undefined; |
20 | | -let pairCommandAuthModulePromise: Promise<PairCommandAuthModule> | undefined; |
21 | 13 |
|
22 | | -function loadDevicePairApiModule(): Promise<DevicePairApiModule> { |
23 | | - devicePairApiModulePromise ??= import("./api.js"); |
24 | | - return devicePairApiModulePromise; |
25 | | -} |
| 14 | +const loadDevicePairApiModule = createLazyRuntimeModule(() => import("./api.js")); |
26 | 15 |
|
27 | | -function loadNotifyModule(): Promise<NotifyModule> { |
28 | | - notifyModulePromise ??= import("./notify.js"); |
29 | | - return notifyModulePromise; |
30 | | -} |
| 16 | +const loadNotifyModule = createLazyRuntimeModule(() => import("./notify.js")); |
31 | 17 |
|
32 | | -function loadPairCommandApproveModule(): Promise<PairCommandApproveModule> { |
33 | | - pairCommandApproveModulePromise ??= import("./pair-command-approve.js"); |
34 | | - return pairCommandApproveModulePromise; |
35 | | -} |
| 18 | +const loadPairCommandApproveModule = createLazyRuntimeModule( |
| 19 | + () => import("./pair-command-approve.js"), |
| 20 | +); |
36 | 21 |
|
37 | | -function loadPairCommandAuthModule(): Promise<PairCommandAuthModule> { |
38 | | - pairCommandAuthModulePromise ??= import("./pair-command-auth.js"); |
39 | | - return pairCommandAuthModulePromise; |
40 | | -} |
| 22 | +const loadPairCommandAuthModule = createLazyRuntimeModule(() => import("./pair-command-auth.js")); |
41 | 23 |
|
42 | 24 | function formatDurationMinutes(expiresAtMs: number): string { |
43 | 25 | const msRemaining = Math.max(0, expiresAtMs - Date.now()); |
|
0 commit comments