@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zbruceli/openclaw-dchat",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "OpenClaw D-Chat/nMobile channel plugin — decentralized E2E encrypted messaging over the NKN relay network",
5
5
  "type": "module",
6
6
  "main": "index.ts",
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
- accountId: DEFAULT_ACCOUNT_ID,
267
- running: false,
268
- lastStartAt: null,
269
- lastStopAt: null,
270
- lastError: null,
271
+ ...createDefaultChannelRuntimeState(DEFAULT_ACCOUNT_ID),
272
+ connected: false,
273
+ lastConnectedAt: null,
271
274
  },
272
275
  buildChannelSummary: ({ snapshot }) => ({
273
- configured: snapshot.configured ?? false,
274
- running: snapshot.running ?? false,
275
- nknAddress: snapshot.baseUrl ?? null,
276
- lastStartAt: snapshot.lastStartAt ?? null,
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
- accountId: account.accountId,
282
- name: account.name,
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,
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
  });
@@ -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 hasSeed = Boolean(accountConfig.seed?.trim());
108
- const hasKeystore = Boolean(accountConfig.keystoreJson?.trim());
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: accountConfig.seed?.trim(),
127
+ seed,
128
+ nknAddress,
117
129
  numSubClients: accountConfig.numSubClients ?? 4,
118
130
  ipfsGateway: accountConfig.ipfsGateway ?? "64.225.88.71:80",
119
131
  config: accountConfig,
package/src/types.ts CHANGED
@@ -128,6 +128,7 @@ export interface ResolvedDchatAccount {
128
128
  enabled: boolean;
129
129
  configured: boolean;
130
130
  seed?: string;
131
+ nknAddress?: string;
131
132
  numSubClients: number;
132
133
  ipfsGateway: string;
133
134
  config: DchatAccountConfig;