@zbruceli/openclaw-dchat 0.1.7 → 0.1.8
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 +11 -36
- package/src/config-schema.ts +15 -3
- package/src/types.ts +1 -0
package/package.json
CHANGED
package/src/channel.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
applyAccountNameToChannelSection,
|
|
3
|
+
buildBaseAccountStatusSnapshot,
|
|
4
|
+
buildBaseChannelStatusSummary,
|
|
3
5
|
buildChannelConfigSchema,
|
|
6
|
+
collectStatusIssuesFromLastError,
|
|
7
|
+
createDefaultChannelRuntimeState,
|
|
4
8
|
createScopedPairingAccess,
|
|
5
9
|
DEFAULT_ACCOUNT_ID,
|
|
6
10
|
deleteAccountFromConfigSection,
|
|
@@ -103,6 +107,7 @@ export const dchatPlugin: ChannelPlugin<ResolvedDchatAccount> = {
|
|
|
103
107
|
name: account.name,
|
|
104
108
|
enabled: account.enabled,
|
|
105
109
|
configured: account.configured,
|
|
110
|
+
nknAddress: account.nknAddress ?? null,
|
|
106
111
|
}),
|
|
107
112
|
resolveAllowFrom: ({ cfg, accountId }) => {
|
|
108
113
|
const dchatConfig = resolveDchatAccountConfig({ cfg: cfg as CoreConfig, accountId });
|
|
@@ -262,46 +267,16 @@ export const dchatPlugin: ChannelPlugin<ResolvedDchatAccount> = {
|
|
|
262
267
|
},
|
|
263
268
|
},
|
|
264
269
|
status: {
|
|
265
|
-
defaultRuntime:
|
|
266
|
-
accountId: DEFAULT_ACCOUNT_ID,
|
|
267
|
-
running: false,
|
|
268
|
-
lastStartAt: null,
|
|
269
|
-
lastStopAt: null,
|
|
270
|
-
lastError: null,
|
|
271
|
-
},
|
|
270
|
+
defaultRuntime: createDefaultChannelRuntimeState(DEFAULT_ACCOUNT_ID),
|
|
272
271
|
buildChannelSummary: ({ snapshot }) => ({
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
nknAddress: snapshot.baseUrl ?? null,
|
|
276
|
-
lastStartAt: snapshot.lastStartAt ?? null,
|
|
277
|
-
lastStopAt: snapshot.lastStopAt ?? null,
|
|
278
|
-
lastError: snapshot.lastError ?? null,
|
|
272
|
+
...buildBaseChannelStatusSummary(snapshot),
|
|
273
|
+
nknAddress: snapshot.nknAddress ?? null,
|
|
279
274
|
}),
|
|
280
275
|
buildAccountSnapshot: ({ account, runtime }) => ({
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
enabled: account.enabled,
|
|
284
|
-
configured: account.configured,
|
|
285
|
-
running: runtime?.running ?? false,
|
|
286
|
-
lastStartAt: runtime?.lastStartAt ?? null,
|
|
287
|
-
lastStopAt: runtime?.lastStopAt ?? null,
|
|
288
|
-
lastError: runtime?.lastError ?? null,
|
|
289
|
-
lastInboundAt: runtime?.lastInboundAt ?? null,
|
|
290
|
-
lastOutboundAt: runtime?.lastOutboundAt ?? null,
|
|
276
|
+
...buildBaseAccountStatusSnapshot({ account, runtime }),
|
|
277
|
+
nknAddress: account.nknAddress ?? null,
|
|
291
278
|
}),
|
|
292
|
-
collectStatusIssues: (accounts) =>
|
|
293
|
-
accounts.flatMap((account) => {
|
|
294
|
-
const lastError = typeof account.lastError === "string" ? account.lastError.trim() : "";
|
|
295
|
-
if (!lastError) return [];
|
|
296
|
-
return [
|
|
297
|
-
{
|
|
298
|
-
channel: "dchat",
|
|
299
|
-
accountId: account.accountId,
|
|
300
|
-
kind: "runtime",
|
|
301
|
-
message: `Channel error: ${lastError}`,
|
|
302
|
-
},
|
|
303
|
-
];
|
|
304
|
-
}),
|
|
279
|
+
collectStatusIssues: (accounts) => collectStatusIssuesFromLastError("dchat", accounts),
|
|
305
280
|
},
|
|
306
281
|
gateway: {
|
|
307
282
|
startAccount: async (ctx) => {
|
package/src/config-schema.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import nkn from "nkn-sdk";
|
|
1
2
|
import type { OpenClawConfig } from "openclaw/plugin-sdk";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
import type { DchatAccountConfig, ResolvedDchatAccount } from "./types.js";
|
|
@@ -104,8 +105,18 @@ export function resolveDchatAccount(params: {
|
|
|
104
105
|
const accountId = rawAccountId || DEFAULT_ACCOUNT_ID;
|
|
105
106
|
const accountConfig = resolveDchatAccountConfig({ cfg, accountId });
|
|
106
107
|
|
|
107
|
-
const
|
|
108
|
-
const
|
|
108
|
+
const seed = accountConfig.seed?.trim();
|
|
109
|
+
const hasSeed = Boolean(seed);
|
|
110
|
+
|
|
111
|
+
let nknAddress: string | undefined;
|
|
112
|
+
if (hasSeed && seed) {
|
|
113
|
+
try {
|
|
114
|
+
const wallet = new nkn.Wallet({ seed });
|
|
115
|
+
nknAddress = wallet.getPublicKey();
|
|
116
|
+
} catch {
|
|
117
|
+
// seed may be invalid
|
|
118
|
+
}
|
|
119
|
+
}
|
|
109
120
|
|
|
110
121
|
const baseEnabled = cfg.channels?.dchat?.enabled !== false;
|
|
111
122
|
return {
|
|
@@ -113,7 +124,8 @@ export function resolveDchatAccount(params: {
|
|
|
113
124
|
name: accountConfig.name || accountId,
|
|
114
125
|
enabled: baseEnabled && accountConfig.enabled !== false,
|
|
115
126
|
configured: hasSeed,
|
|
116
|
-
seed
|
|
127
|
+
seed,
|
|
128
|
+
nknAddress,
|
|
117
129
|
numSubClients: accountConfig.numSubClients ?? 4,
|
|
118
130
|
ipfsGateway: accountConfig.ipfsGateway ?? "64.225.88.71:80",
|
|
119
131
|
config: accountConfig,
|