@zbruceli/openclaw-dchat 0.1.2 → 0.1.4
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/package.json +1 -1
- package/src/channel.ts +10 -10
- package/src/config-schema.ts +5 -8
- package/src/onboarding.ts +9 -15
- package/src/types.ts +2 -4
package/package.json
CHANGED
package/src/channel.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from "openclaw/plugin-sdk";
|
|
13
13
|
import {
|
|
14
14
|
type CoreConfig,
|
|
15
|
-
|
|
15
|
+
dchatAccountSchema,
|
|
16
16
|
listDchatAccountIds,
|
|
17
17
|
resolveDchatAccount,
|
|
18
18
|
resolveDchatAccountConfig,
|
|
@@ -66,7 +66,7 @@ export const dchatPlugin: ChannelPlugin<ResolvedDchatAccount> = {
|
|
|
66
66
|
polls: false,
|
|
67
67
|
},
|
|
68
68
|
reload: { configPrefixes: ["channels.dchat"] },
|
|
69
|
-
configSchema: buildChannelConfigSchema(
|
|
69
|
+
configSchema: buildChannelConfigSchema(dchatAccountSchema),
|
|
70
70
|
pairing: {
|
|
71
71
|
idLabel: "nknAddress",
|
|
72
72
|
normalizeAllowEntry: (entry) => entry.replace(/^dchat:/i, ""),
|
|
@@ -106,7 +106,7 @@ export const dchatPlugin: ChannelPlugin<ResolvedDchatAccount> = {
|
|
|
106
106
|
}),
|
|
107
107
|
resolveAllowFrom: ({ cfg, accountId }) => {
|
|
108
108
|
const dchatConfig = resolveDchatAccountConfig({ cfg: cfg as CoreConfig, accountId });
|
|
109
|
-
return (dchatConfig.
|
|
109
|
+
return (dchatConfig.allowFrom ?? []).map((entry) => String(entry));
|
|
110
110
|
},
|
|
111
111
|
formatAllowFrom: ({ allowFrom }) =>
|
|
112
112
|
allowFrom.map((entry) => String(entry).replace(/^dchat:/i, "")),
|
|
@@ -116,12 +116,12 @@ export const dchatPlugin: ChannelPlugin<ResolvedDchatAccount> = {
|
|
|
116
116
|
const accountId = account.accountId;
|
|
117
117
|
const prefix =
|
|
118
118
|
accountId && accountId !== "default"
|
|
119
|
-
? `channels.dchat.accounts.${accountId}
|
|
120
|
-
: "channels.dchat
|
|
119
|
+
? `channels.dchat.accounts.${accountId}`
|
|
120
|
+
: "channels.dchat";
|
|
121
121
|
return {
|
|
122
|
-
policy: account.config.
|
|
123
|
-
allowFrom: account.config.
|
|
124
|
-
policyPath: `${prefix}.
|
|
122
|
+
policy: account.config.dmPolicy ?? "pairing",
|
|
123
|
+
allowFrom: account.config.allowFrom ?? [],
|
|
124
|
+
policyPath: `${prefix}.dmPolicy`,
|
|
125
125
|
allowFromPath: `${prefix}.allowFrom`,
|
|
126
126
|
approveHint: formatPairingApproveHint("dchat"),
|
|
127
127
|
normalizeEntry: (raw: string) => raw.replace(/^dchat:/i, ""),
|
|
@@ -383,8 +383,8 @@ export const dchatPlugin: ChannelPlugin<ResolvedDchatAccount> = {
|
|
|
383
383
|
|
|
384
384
|
// Resolve command authorization for slash commands (/status, /stop, etc.)
|
|
385
385
|
const isGroup = inbound.chatType === "group";
|
|
386
|
-
const dmPolicy = account.config.
|
|
387
|
-
const configAllowFrom = (account.config.
|
|
386
|
+
const dmPolicy = account.config.dmPolicy ?? "pairing";
|
|
387
|
+
const configAllowFrom = (account.config.allowFrom ?? []).map((v) => String(v));
|
|
388
388
|
|
|
389
389
|
const isSenderAllowed = (senderId: string, allowFrom: string[]) => {
|
|
390
390
|
const lower = senderId.toLowerCase();
|
package/src/config-schema.ts
CHANGED
|
@@ -17,7 +17,7 @@ const DEFAULT_ACCOUNT_ID = "default";
|
|
|
17
17
|
|
|
18
18
|
/* ── Zod config schema (powers web UI form via buildChannelConfigSchema) ── */
|
|
19
19
|
|
|
20
|
-
const dchatAccountSchema = z.object({
|
|
20
|
+
export const dchatAccountSchema = z.object({
|
|
21
21
|
name: z.string().optional(),
|
|
22
22
|
enabled: z.boolean().optional(),
|
|
23
23
|
seed: z.string().optional(),
|
|
@@ -25,12 +25,8 @@ const dchatAccountSchema = z.object({
|
|
|
25
25
|
keystorePassword: z.string().optional(),
|
|
26
26
|
numSubClients: z.number().optional(),
|
|
27
27
|
ipfsGateway: z.string().optional(),
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
policy: z.enum(["pairing", "allowlist", "open", "disabled"]).optional(),
|
|
31
|
-
allowFrom: z.array(z.string()).optional(),
|
|
32
|
-
})
|
|
33
|
-
.optional(),
|
|
28
|
+
dmPolicy: z.enum(["pairing", "allowlist", "open", "disabled"]).optional(),
|
|
29
|
+
allowFrom: z.array(z.string()).optional(),
|
|
34
30
|
});
|
|
35
31
|
|
|
36
32
|
export const DchatConfigSchema = dchatAccountSchema.extend({
|
|
@@ -91,7 +87,8 @@ export function resolveDchatAccountConfig(params: {
|
|
|
91
87
|
return {
|
|
92
88
|
...dchatConfig,
|
|
93
89
|
...acct,
|
|
94
|
-
|
|
90
|
+
dmPolicy: acct.dmPolicy ?? dchatConfig.dmPolicy,
|
|
91
|
+
allowFrom: acct.allowFrom ?? dchatConfig.allowFrom,
|
|
95
92
|
};
|
|
96
93
|
}
|
|
97
94
|
|
package/src/onboarding.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { listDchatAccountIds, resolveDchatAccount, type CoreConfig } from "./con
|
|
|
12
12
|
const channel = "dchat" as const;
|
|
13
13
|
|
|
14
14
|
function setDchatDmPolicy(cfg: CoreConfig, policy: DmPolicy) {
|
|
15
|
-
const existingAllowFrom = cfg.channels?.dchat?.
|
|
15
|
+
const existingAllowFrom = cfg.channels?.dchat?.allowFrom ?? [];
|
|
16
16
|
const allowFrom =
|
|
17
17
|
policy === "open"
|
|
18
18
|
? addWildcardAllowFrom(existingAllowFrom)
|
|
@@ -23,11 +23,8 @@ function setDchatDmPolicy(cfg: CoreConfig, policy: DmPolicy) {
|
|
|
23
23
|
...cfg.channels,
|
|
24
24
|
dchat: {
|
|
25
25
|
...cfg.channels?.dchat,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
policy,
|
|
29
|
-
allowFrom,
|
|
30
|
-
},
|
|
26
|
+
dmPolicy: policy,
|
|
27
|
+
allowFrom,
|
|
31
28
|
},
|
|
32
29
|
},
|
|
33
30
|
};
|
|
@@ -38,7 +35,7 @@ async function promptDchatAllowFrom(params: {
|
|
|
38
35
|
prompter: WizardPrompter;
|
|
39
36
|
}): Promise<CoreConfig> {
|
|
40
37
|
const { cfg, prompter } = params;
|
|
41
|
-
const existingAllowFrom = cfg.channels?.dchat?.
|
|
38
|
+
const existingAllowFrom = cfg.channels?.dchat?.allowFrom ?? [];
|
|
42
39
|
|
|
43
40
|
const entry = await prompter.text({
|
|
44
41
|
message: "NKN address to allow (full public key hex)",
|
|
@@ -60,11 +57,8 @@ async function promptDchatAllowFrom(params: {
|
|
|
60
57
|
dchat: {
|
|
61
58
|
...cfg.channels?.dchat,
|
|
62
59
|
enabled: true,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
policy: "allowlist",
|
|
66
|
-
allowFrom: unique,
|
|
67
|
-
},
|
|
60
|
+
dmPolicy: "allowlist",
|
|
61
|
+
allowFrom: unique,
|
|
68
62
|
},
|
|
69
63
|
},
|
|
70
64
|
};
|
|
@@ -73,9 +67,9 @@ async function promptDchatAllowFrom(params: {
|
|
|
73
67
|
const dmPolicy: ChannelOnboardingDmPolicy = {
|
|
74
68
|
label: "D-Chat",
|
|
75
69
|
channel,
|
|
76
|
-
policyKey: "channels.dchat.
|
|
77
|
-
allowFromKey: "channels.dchat.
|
|
78
|
-
getCurrent: (cfg) => ((cfg as CoreConfig).channels?.dchat?.
|
|
70
|
+
policyKey: "channels.dchat.dmPolicy",
|
|
71
|
+
allowFromKey: "channels.dchat.allowFrom",
|
|
72
|
+
getCurrent: (cfg) => ((cfg as CoreConfig).channels?.dchat?.dmPolicy as DmPolicy) ?? "pairing",
|
|
79
73
|
setPolicy: (cfg, policy) => setDchatDmPolicy(cfg as CoreConfig, policy),
|
|
80
74
|
promptAllowFrom: promptDchatAllowFrom,
|
|
81
75
|
};
|
package/src/types.ts
CHANGED
|
@@ -118,10 +118,8 @@ export interface DchatAccountConfig {
|
|
|
118
118
|
ipfsGateway?: string; // default: "64.225.88.71:80"
|
|
119
119
|
enabled?: boolean;
|
|
120
120
|
name?: string;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
policy?: string;
|
|
124
|
-
};
|
|
121
|
+
dmPolicy?: string;
|
|
122
|
+
allowFrom?: string[];
|
|
125
123
|
}
|
|
126
124
|
|
|
127
125
|
export interface ResolvedDchatAccount {
|