@zbruceli/openclaw-dchat 0.1.7 → 0.1.9
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 +20 -34
- 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 });
|
|
@@ -263,45 +268,23 @@ export const dchatPlugin: ChannelPlugin<ResolvedDchatAccount> = {
|
|
|
263
268
|
},
|
|
264
269
|
status: {
|
|
265
270
|
defaultRuntime: {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
lastStopAt: null,
|
|
270
|
-
lastError: null,
|
|
271
|
+
...createDefaultChannelRuntimeState(DEFAULT_ACCOUNT_ID),
|
|
272
|
+
connected: false,
|
|
273
|
+
lastConnectedAt: null,
|
|
271
274
|
},
|
|
272
275
|
buildChannelSummary: ({ snapshot }) => ({
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
lastStopAt: snapshot.lastStopAt ?? null,
|
|
278
|
-
lastError: snapshot.lastError ?? null,
|
|
276
|
+
...buildBaseChannelStatusSummary(snapshot),
|
|
277
|
+
nknAddress: snapshot.nknAddress ?? null,
|
|
278
|
+
connected: snapshot.connected ?? false,
|
|
279
|
+
lastConnectedAt: snapshot.lastConnectedAt ?? null,
|
|
279
280
|
}),
|
|
280
281
|
buildAccountSnapshot: ({ account, runtime }) => ({
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
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,
|
|
282
|
+
...buildBaseAccountStatusSnapshot({ account, runtime }),
|
|
283
|
+
nknAddress: account.nknAddress ?? null,
|
|
284
|
+
connected: (runtime as Record<string, unknown>)?.connected ?? false,
|
|
285
|
+
lastConnectedAt: (runtime as Record<string, unknown>)?.lastConnectedAt ?? null,
|
|
291
286
|
}),
|
|
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
|
-
}),
|
|
287
|
+
collectStatusIssues: (accounts) => collectStatusIssuesFromLastError("dchat", accounts),
|
|
305
288
|
},
|
|
306
289
|
gateway: {
|
|
307
290
|
startAccount: async (ctx) => {
|
|
@@ -332,7 +315,9 @@ export const dchatPlugin: ChannelPlugin<ResolvedDchatAccount> = {
|
|
|
332
315
|
accountId: account.accountId,
|
|
333
316
|
baseUrl: address,
|
|
334
317
|
running: true,
|
|
318
|
+
connected: true,
|
|
335
319
|
lastStartAt: Date.now(),
|
|
320
|
+
lastConnectedAt: Date.now(),
|
|
336
321
|
});
|
|
337
322
|
logger.info(`[${account.accountId}] connected as ${address}`);
|
|
338
323
|
|
|
@@ -619,6 +604,7 @@ export const dchatPlugin: ChannelPlugin<ResolvedDchatAccount> = {
|
|
|
619
604
|
const errMsg = err instanceof Error ? err.message : String(err);
|
|
620
605
|
ctx.setStatus({
|
|
621
606
|
accountId: account.accountId,
|
|
607
|
+
connected: false,
|
|
622
608
|
lastError: errMsg,
|
|
623
609
|
lastStopAt: Date.now(),
|
|
624
610
|
});
|
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,
|