@aka_openclaw_plugin/mychat 0.1.19 → 0.2.0

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.
@@ -0,0 +1,28 @@
1
+ import { t as resolveMychatAccount } from "./accounts-BTv5784y.js";
2
+ //#region extensions/mychat/src/account-inspect.ts
3
+ function inspectMychatAccount(params) {
4
+ const account = resolveMychatAccount({
5
+ cfg: params.cfg,
6
+ accountId: params.accountId
7
+ });
8
+ if (!account) return {
9
+ accountId: params.accountId,
10
+ enabled: false,
11
+ baseUrl: "",
12
+ tokenSource: "none",
13
+ tokenStatus: "missing"
14
+ };
15
+ let tokenSource = "none";
16
+ if ((((params.cfg.channels?.mychat)?.accounts)?.[params.accountId])?.token) tokenSource = "config";
17
+ else if (params.envToken) tokenSource = "env";
18
+ return {
19
+ accountId: account.accountId,
20
+ enabled: account.enabled,
21
+ name: account.name,
22
+ baseUrl: account.baseUrl,
23
+ tokenSource,
24
+ tokenStatus: account.token ? "configured" : "missing"
25
+ };
26
+ }
27
+ //#endregion
28
+ export { inspectMychatAccount };
@@ -0,0 +1,96 @@
1
+ import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/channel-plugin-common";
2
+ //#region extensions/mychat/src/accounts.ts
3
+ const DEFAULT_DM_POLICY = "open";
4
+ const DEFAULT_GROUP_POLICY = "open";
5
+ const DEFAULT_HISTORY_LIMIT = 50;
6
+ const DEFAULT_MEDIA_MAX_MB = 10;
7
+ function resolveWsUrl(baseUrl) {
8
+ const url = new URL(baseUrl);
9
+ url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
10
+ url.pathname = url.pathname.replace(/\/+$/, "") + "/ws/bot";
11
+ return url.toString();
12
+ }
13
+ function mergeAccountConfig(channel, account) {
14
+ if (!account) return channel;
15
+ return {
16
+ ...channel,
17
+ ...account,
18
+ actions: {
19
+ messages: account.actions?.messages ?? channel.actions?.messages ?? true,
20
+ threads: account.actions?.threads ?? channel.actions?.threads ?? true,
21
+ reactions: account.actions?.reactions ?? channel.actions?.reactions ?? true
22
+ },
23
+ groups: {
24
+ ...channel.groups ?? {},
25
+ ...account.groups ?? {}
26
+ },
27
+ reconnect: account.reconnect ?? channel.reconnect
28
+ };
29
+ }
30
+ function resolveMychatAccounts(cfg) {
31
+ const mychatConfig = cfg.channels?.mychat;
32
+ if (!mychatConfig) return [];
33
+ const accounts = mychatConfig.accounts ?? {};
34
+ const accountIds = Object.keys(accounts);
35
+ if (accountIds.length === 0) {
36
+ const resolved = resolveSingleAccount({
37
+ accountId: DEFAULT_ACCOUNT_ID,
38
+ config: mychatConfig
39
+ });
40
+ return resolved ? [resolved] : [];
41
+ }
42
+ return accountIds.map((id) => {
43
+ return resolveSingleAccount({
44
+ accountId: id,
45
+ config: mergeAccountConfig(mychatConfig, accounts[id])
46
+ });
47
+ }).filter(Boolean);
48
+ }
49
+ function resolveSingleAccount(params) {
50
+ const { accountId, config } = params;
51
+ const enabled = config.enabled ?? true;
52
+ if (!enabled) return null;
53
+ const token = resolveToken(config);
54
+ if (!token) return null;
55
+ const baseUrl = config.baseUrl.replace(/\/+$/, "");
56
+ const wsUrl = config.wsUrl ?? resolveWsUrl(baseUrl);
57
+ return {
58
+ accountId: normalizeAccountId(accountId),
59
+ enabled,
60
+ name: config.name,
61
+ baseUrl,
62
+ wsUrl,
63
+ token,
64
+ defaultTo: config.defaultTo,
65
+ dmPolicy: config.dmPolicy ?? DEFAULT_DM_POLICY,
66
+ groupPolicy: config.groupPolicy ?? DEFAULT_GROUP_POLICY,
67
+ allowFrom: config.allowFrom ?? [],
68
+ groupAllowFrom: config.groupAllowFrom ?? [],
69
+ requireMention: config.requireMention ?? false,
70
+ historyLimit: config.historyLimit ?? DEFAULT_HISTORY_LIMIT,
71
+ mediaMaxMb: config.mediaMaxMb ?? DEFAULT_MEDIA_MAX_MB,
72
+ actions: {
73
+ messages: config.actions?.messages ?? true,
74
+ threads: config.actions?.threads ?? true,
75
+ reactions: config.actions?.reactions ?? true
76
+ },
77
+ groups: config.groups ?? {},
78
+ reconnect: config.reconnect ?? {}
79
+ };
80
+ }
81
+ function resolveToken(config) {
82
+ if (config.token) return config.token;
83
+ if (typeof process !== "undefined") {
84
+ const envToken = process.env.MYCHAT_BOT_TOKEN;
85
+ if (envToken) return envToken;
86
+ }
87
+ return null;
88
+ }
89
+ function resolveMychatAccount(params) {
90
+ const accounts = resolveMychatAccounts(params.cfg);
91
+ if (accounts.length === 0) return null;
92
+ if (!params.accountId) return accounts[0];
93
+ return accounts.find((a) => a.accountId === params.accountId) ?? accounts[0] ?? null;
94
+ }
95
+ //#endregion
96
+ export { resolveMychatAccounts as n, resolveMychatAccount as t };
package/dist/api.js ADDED
@@ -0,0 +1,6 @@
1
+ import { a as tryGetMychatRuntime, i as setMychatRuntime, n as init_runtime, t as getMychatRuntime } from "./runtime-CkiGSF1r.js";
2
+ import { t as mychatPlugin } from "./channel-BVfWh6jv.js";
3
+ //#region extensions/mychat/api.ts
4
+ init_runtime();
5
+ //#endregion
6
+ export { getMychatRuntime, mychatPlugin, setMychatRuntime, tryGetMychatRuntime };