opencode-copilot-account-switcher 0.14.34 → 0.14.35
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.
- package/dist/wechat/compat/jiti-loader.d.ts +9 -0
- package/dist/wechat/compat/jiti-loader.js +18 -0
- package/dist/wechat/compat/openclaw-account-helpers.js +2 -13
- package/dist/wechat/compat/openclaw-public-entry.js +2 -13
- package/dist/wechat/compat/openclaw-sync-buf.js +4 -15
- package/dist/wechat/compat/openclaw-updates-send.js +3 -15
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@ export type JitiLoader = (path: string) => unknown;
|
|
|
2
2
|
type CreateJiti = (id: string | URL, options?: Record<string, unknown>) => JitiLoader;
|
|
3
3
|
type JitiImport = (specifier: string) => Promise<unknown> | unknown;
|
|
4
4
|
type JitiResolve = (specifier: string) => string;
|
|
5
|
+
type ModuleImport = (specifier: string) => Promise<unknown>;
|
|
5
6
|
type JitiNamespace = {
|
|
6
7
|
createJiti?: unknown;
|
|
7
8
|
default?: unknown;
|
|
@@ -9,8 +10,16 @@ type JitiNamespace = {
|
|
|
9
10
|
};
|
|
10
11
|
export declare function resolveCreateJiti(namespace: JitiNamespace): CreateJiti;
|
|
11
12
|
export declare function resolveJitiEsmEntry(resolveImpl?: JitiResolve): string;
|
|
13
|
+
export declare function hasBunRuntime(bunVersion?: string | undefined): boolean;
|
|
12
14
|
export declare function wrapCreateJiti(createJiti: CreateJiti): CreateJiti;
|
|
13
15
|
export declare function loadJiti(importImpl?: JitiImport, resolveImpl?: JitiResolve): Promise<{
|
|
14
16
|
createJiti: CreateJiti;
|
|
15
17
|
}>;
|
|
18
|
+
export declare function loadModuleWithTsFallback(modulePath: string, options?: {
|
|
19
|
+
bunVersion?: string | undefined;
|
|
20
|
+
importImpl?: ModuleImport;
|
|
21
|
+
loadJitiImpl?: typeof loadJiti;
|
|
22
|
+
parentURL?: string | URL;
|
|
23
|
+
jitiOptions?: Record<string, unknown>;
|
|
24
|
+
}): Promise<unknown>;
|
|
16
25
|
export {};
|
|
@@ -32,6 +32,10 @@ function onJitiError(error) {
|
|
|
32
32
|
throw error;
|
|
33
33
|
}
|
|
34
34
|
const nativeImport = (id) => import(id);
|
|
35
|
+
const DEFAULT_JITI_EXTENSIONS = [".ts", ".tsx", ".mts", ".cts", ".js", ".mjs", ".cjs", ".json"];
|
|
36
|
+
export function hasBunRuntime(bunVersion = process.versions?.bun) {
|
|
37
|
+
return typeof bunVersion === "string" && bunVersion.length > 0;
|
|
38
|
+
}
|
|
35
39
|
export function wrapCreateJiti(createJiti) {
|
|
36
40
|
const requireFromJiti = createRequire(resolveJitiEsmEntry());
|
|
37
41
|
let transformImpl;
|
|
@@ -58,3 +62,17 @@ export async function loadJiti(importImpl = (specifier) => import(specifier), re
|
|
|
58
62
|
createJiti: wrapCreateJiti(resolveCreateJiti(namespace)),
|
|
59
63
|
};
|
|
60
64
|
}
|
|
65
|
+
export async function loadModuleWithTsFallback(modulePath, options = {}) {
|
|
66
|
+
const moduleUrl = pathToFileURL(modulePath).href;
|
|
67
|
+
const importImpl = options.importImpl ?? nativeImport;
|
|
68
|
+
if (hasBunRuntime(options.bunVersion)) {
|
|
69
|
+
return await importImpl(moduleUrl);
|
|
70
|
+
}
|
|
71
|
+
const { createJiti } = await (options.loadJitiImpl ?? loadJiti)();
|
|
72
|
+
const loader = createJiti(options.parentURL ?? import.meta.url, {
|
|
73
|
+
interopDefault: true,
|
|
74
|
+
extensions: DEFAULT_JITI_EXTENSIONS,
|
|
75
|
+
...(options.jitiOptions ?? {}),
|
|
76
|
+
});
|
|
77
|
+
return loader(modulePath);
|
|
78
|
+
}
|
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import {
|
|
2
|
+
import { loadModuleWithTsFallback } from "./jiti-loader.js";
|
|
3
3
|
const OPENCLAW_WEIXIN_ACCOUNTS_MODULE = "@tencent-weixin/openclaw-weixin/src/auth/accounts.ts";
|
|
4
|
-
let accountJitiLoader = null;
|
|
5
|
-
async function getAccountJiti() {
|
|
6
|
-
if (accountJitiLoader) {
|
|
7
|
-
return accountJitiLoader;
|
|
8
|
-
}
|
|
9
|
-
accountJitiLoader = (await loadJiti()).createJiti(import.meta.url, {
|
|
10
|
-
interopDefault: true,
|
|
11
|
-
extensions: [".ts", ".tsx", ".mts", ".cts", ".js", ".mjs", ".cjs", ".json"],
|
|
12
|
-
});
|
|
13
|
-
return accountJitiLoader;
|
|
14
|
-
}
|
|
15
4
|
function asObject(value) {
|
|
16
5
|
return value && typeof value === "object" ? value : {};
|
|
17
6
|
}
|
|
@@ -52,7 +41,7 @@ export function createOpenClawAccountHelpers(input) {
|
|
|
52
41
|
export async function loadOpenClawAccountHelpers(options = {}) {
|
|
53
42
|
const require = createRequire(import.meta.url);
|
|
54
43
|
const accountsModulePath = require.resolve(options.accountsModulePath ?? OPENCLAW_WEIXIN_ACCOUNTS_MODULE);
|
|
55
|
-
const accountsModule =
|
|
44
|
+
const accountsModule = await loadModuleWithTsFallback(accountsModulePath, { parentURL: import.meta.url });
|
|
56
45
|
if (typeof accountsModule.listIndexedWeixinAccountIds !== "function" || typeof accountsModule.loadWeixinAccount !== "function") {
|
|
57
46
|
throw new Error("[wechat-compat] account source helper unavailable");
|
|
58
47
|
}
|
|
@@ -1,23 +1,12 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import {
|
|
5
|
-
let publicJitiLoader = null;
|
|
4
|
+
import { loadModuleWithTsFallback } from "./jiti-loader.js";
|
|
6
5
|
function requireField(condition, message) {
|
|
7
6
|
if (!condition) {
|
|
8
7
|
throw new Error(`[wechat-compat] ${message}`);
|
|
9
8
|
}
|
|
10
9
|
}
|
|
11
|
-
async function getPublicJiti() {
|
|
12
|
-
if (publicJitiLoader) {
|
|
13
|
-
return publicJitiLoader;
|
|
14
|
-
}
|
|
15
|
-
publicJitiLoader = (await loadJiti()).createJiti(import.meta.url, {
|
|
16
|
-
interopDefault: true,
|
|
17
|
-
extensions: [".ts", ".tsx", ".mts", ".cts", ".js", ".mjs", ".cjs", ".json"],
|
|
18
|
-
});
|
|
19
|
-
return publicJitiLoader;
|
|
20
|
-
}
|
|
21
10
|
export async function resolveOpenClawWeixinPublicEntry() {
|
|
22
11
|
const require = createRequire(import.meta.url);
|
|
23
12
|
const packageName = "@tencent-weixin/openclaw-weixin";
|
|
@@ -42,7 +31,7 @@ export async function resolveOpenClawWeixinPublicEntry() {
|
|
|
42
31
|
}
|
|
43
32
|
export async function loadOpenClawWeixinDefaultExport() {
|
|
44
33
|
const entry = await resolveOpenClawWeixinPublicEntry();
|
|
45
|
-
const moduleNamespace =
|
|
34
|
+
const moduleNamespace = await loadModuleWithTsFallback(entry.entryAbsolutePath, { parentURL: import.meta.url });
|
|
46
35
|
const plugin = moduleNamespace.default;
|
|
47
36
|
if (!plugin || typeof plugin !== "object" || typeof plugin.register !== "function") {
|
|
48
37
|
throw new Error("[wechat-compat] @tencent-weixin/openclaw-weixin public entry default export is missing register(api)");
|
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { loadModuleWithTsFallback } from "./jiti-loader.js";
|
|
5
5
|
const OPENCLAW_SYNC_BUF_MODULE = "@tencent-weixin/openclaw-weixin/src/storage/sync-buf.ts";
|
|
6
6
|
const OPENCLAW_STATE_DIR_MODULE = "@tencent-weixin/openclaw-weixin/src/storage/state-dir.ts";
|
|
7
|
-
let syncBufJitiLoader = null;
|
|
8
|
-
async function getSyncBufJiti() {
|
|
9
|
-
if (syncBufJitiLoader) {
|
|
10
|
-
return syncBufJitiLoader;
|
|
11
|
-
}
|
|
12
|
-
syncBufJitiLoader = (await loadJiti()).createJiti(import.meta.url, {
|
|
13
|
-
interopDefault: true,
|
|
14
|
-
extensions: [".ts", ".tsx", ".mts", ".cts", ".js", ".mjs", ".cjs", ".json"],
|
|
15
|
-
});
|
|
16
|
-
return syncBufJitiLoader;
|
|
17
|
-
}
|
|
18
7
|
export function createOpenClawSyncBufHelper(input) {
|
|
19
8
|
return {
|
|
20
9
|
async persistGetUpdatesBuf({ accountId, getUpdatesBuf }) {
|
|
@@ -29,7 +18,7 @@ export function createOpenClawSyncBufHelper(input) {
|
|
|
29
18
|
export async function loadOpenClawSyncBufHelper(options = {}) {
|
|
30
19
|
const require = createRequire(import.meta.url);
|
|
31
20
|
const syncBufModulePath = require.resolve(options.syncBufModulePath ?? OPENCLAW_SYNC_BUF_MODULE);
|
|
32
|
-
const syncBufModule =
|
|
21
|
+
const syncBufModule = await loadModuleWithTsFallback(syncBufModulePath, { parentURL: import.meta.url });
|
|
33
22
|
if (typeof syncBufModule.getSyncBufFilePath !== "function" || typeof syncBufModule.saveGetUpdatesBuf !== "function") {
|
|
34
23
|
throw new Error("[wechat-compat] sync-buf source helper unavailable");
|
|
35
24
|
}
|
|
@@ -41,7 +30,7 @@ export async function loadOpenClawSyncBufHelper(options = {}) {
|
|
|
41
30
|
export async function loadLatestWeixinAccountState(options = {}) {
|
|
42
31
|
const require = createRequire(import.meta.url);
|
|
43
32
|
const stateDirModulePath = require.resolve(options.stateDirModulePath ?? OPENCLAW_STATE_DIR_MODULE);
|
|
44
|
-
const stateDirModule =
|
|
33
|
+
const stateDirModule = await loadModuleWithTsFallback(stateDirModulePath, { parentURL: import.meta.url });
|
|
45
34
|
const stateDir = stateDirModule.resolveStateDir?.();
|
|
46
35
|
if (!stateDir) {
|
|
47
36
|
return null;
|
|
@@ -67,7 +56,7 @@ export async function loadLatestWeixinAccountState(options = {}) {
|
|
|
67
56
|
const accountRaw = await readFile(accountFilePath, "utf8");
|
|
68
57
|
const account = JSON.parse(accountRaw);
|
|
69
58
|
const syncBufModulePath = require.resolve(options.syncBufModulePath ?? OPENCLAW_SYNC_BUF_MODULE);
|
|
70
|
-
const syncBufModule =
|
|
59
|
+
const syncBufModule = await loadModuleWithTsFallback(syncBufModulePath, { parentURL: import.meta.url });
|
|
71
60
|
if (typeof account.token !== "string" || account.token.trim().length === 0) {
|
|
72
61
|
return null;
|
|
73
62
|
}
|
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import {
|
|
2
|
+
import { loadModuleWithTsFallback } from "./jiti-loader.js";
|
|
3
3
|
const OPENCLAW_UPDATES_MODULE = "@tencent-weixin/openclaw-weixin/src/api/api.ts";
|
|
4
4
|
const OPENCLAW_SEND_MODULE = "@tencent-weixin/openclaw-weixin/src/messaging/send.ts";
|
|
5
|
-
let updatesSendJitiLoader = null;
|
|
6
|
-
async function getUpdatesSendJiti() {
|
|
7
|
-
if (updatesSendJitiLoader) {
|
|
8
|
-
return updatesSendJitiLoader;
|
|
9
|
-
}
|
|
10
|
-
updatesSendJitiLoader = (await loadJiti()).createJiti(import.meta.url, {
|
|
11
|
-
interopDefault: true,
|
|
12
|
-
extensions: [".ts", ".tsx", ".mts", ".cts", ".js", ".mjs", ".cjs", ".json"],
|
|
13
|
-
});
|
|
14
|
-
return updatesSendJitiLoader;
|
|
15
|
-
}
|
|
16
5
|
function toObjectInput(input) {
|
|
17
6
|
return input && typeof input === "object" ? input : {};
|
|
18
7
|
}
|
|
@@ -34,9 +23,8 @@ export async function loadOpenClawUpdatesAndSendHelpers(options = {}) {
|
|
|
34
23
|
const require = createRequire(import.meta.url);
|
|
35
24
|
const getUpdatesModulePath = require.resolve(options.getUpdatesModulePath ?? OPENCLAW_UPDATES_MODULE);
|
|
36
25
|
const sendModulePath = require.resolve(options.sendMessageWeixinModulePath ?? OPENCLAW_SEND_MODULE);
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const sendModule = jiti(sendModulePath);
|
|
26
|
+
const getUpdatesModule = await loadModuleWithTsFallback(getUpdatesModulePath, { parentURL: import.meta.url });
|
|
27
|
+
const sendModule = await loadModuleWithTsFallback(sendModulePath, { parentURL: import.meta.url });
|
|
40
28
|
if (typeof getUpdatesModule.getUpdates !== "function") {
|
|
41
29
|
throw new Error("public getUpdates helper unavailable");
|
|
42
30
|
}
|