@qihoo/tuitui-openclaw-channel 1.0.16 → 1.0.17

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": "@qihoo/tuitui-openclaw-channel",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "maintainers": [
5
5
  {
6
6
  "name": "huzunjie",
package/src/channel.ts CHANGED
@@ -24,8 +24,27 @@ const isConfigured = (account: any)=> !!(account?.appId && account?.appSecret);
24
24
 
25
25
  const wsReadyStates = ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED'] as const;
26
26
  let wsNumber = 0;
27
+ const checkTuiTuiConfig = async (apiRuntime: any) => {
28
+ const cfg = await apiRuntime.config.loadConfig();
29
+ const channels = cfg?.channels || {};
30
+ const currChannel = channels?.[CHANNEL_ID] || {};
31
+ if (currChannel?.appId === undefined && !currChannel.accounts) {
32
+ await apiRuntime.config.writeConfigFile({
33
+ ...cfg,
34
+ channels: {
35
+ ...channels,
36
+ [CHANNEL_ID]: {
37
+ ...currChannel,
38
+ ...baseFildsDefault,
39
+ appSecret: undefined,
40
+ }
41
+ }
42
+ });
43
+ }
44
+ };
27
45
 
28
46
  export function createTuiTuiChannelPlugin(apiRuntime: any) {
47
+ checkTuiTuiConfig(apiRuntime);
29
48
  return {
30
49
  id: CHANNEL_ID,
31
50
  meta: {
@@ -44,16 +63,15 @@ export function createTuiTuiChannelPlugin(apiRuntime: any) {
44
63
  config: {
45
64
  listAccountIds: (cfg: any) => {
46
65
  const base = cfg?.channels?.[CHANNEL_ID];
47
- if (!base) return [];
48
66
  const ids = new Set<string>();
49
- if (isEnabled(base.enabled)) ids.add(DEFAULT_ACCOUNT_ID);
50
- if (base.accounts) for (const k in base.accounts) ids.add(k);
67
+ ids.add(DEFAULT_ACCOUNT_ID);
68
+ if (base?.accounts) for (const k in base.accounts) ids.add(k);
51
69
  return Array.from(ids);
52
70
  },
53
71
 
54
72
  resolveAccount,
55
73
 
56
- defaultAccountId: (_cfg: any) => DEFAULT_ACCOUNT_ID,
74
+ defaultAccountId: () => DEFAULT_ACCOUNT_ID,
57
75
 
58
76
  isEnabled,
59
77
 
@@ -102,11 +120,18 @@ export function createTuiTuiChannelPlugin(apiRuntime: any) {
102
120
  },
103
121
 
104
122
  status: {
123
+ defaultRuntime: {
124
+ accountId: DEFAULT_ACCOUNT_ID,
125
+ running: false,
126
+ lastStartAt: null,
127
+ lastStopAt: null,
128
+ lastError: null,
129
+ },
105
130
  buildAccountSnapshot: (params: any) => {
106
131
  const account = params.account;
107
132
  return {
108
133
  ...params.runtime,
109
- accountId: params.accountId ?? account?.accountId ?? DEFAULT_ACCOUNT_ID,
134
+ accountId: params.accountId || account?.accountId || DEFAULT_ACCOUNT_ID,
110
135
  enabled: isEnabled(account?.enabled),
111
136
  configured: isConfigured(account),
112
137
  };
@@ -220,7 +245,7 @@ export function createTuiTuiChannelPlugin(apiRuntime: any) {
220
245
  wsNumber++;
221
246
  const wsId = `${wsNumber}-${Date.now()}`;
222
247
  const wsEvtIds = new Set<string>();
223
- let wsRetryTimerId = 0;
248
+ let wsRetryTimerId: any = 0;
224
249
 
225
250
  const wsUrl = `wss://im.live.360.cn:8282/robot/callback/ws?auth=${account.appId}.${account.appSecret}`;
226
251
  const defSendMsg = (msg: any) => {
package/src/confs.ts CHANGED
@@ -13,8 +13,8 @@ export const capabilities = {
13
13
 
14
14
  /*** 一些配置字段设定信息 ***/
15
15
  const baseFields = {
16
- appId: { type: 'string' } ,
17
- appSecret: { type: 'string' },
16
+ appId: { type: 'string', default: '' } ,
17
+ appSecret: { type: 'string', default: '' },
18
18
  dmPolicy: {
19
19
  type: 'string',
20
20
  default: 'pairing',
@@ -22,6 +22,7 @@ const baseFields = {
22
22
  },
23
23
  allowFrom: {
24
24
  type: 'array',
25
+ default: [],
25
26
  items: { type: 'string' }
26
27
  },
27
28
  groupPolicy: {
@@ -35,6 +36,7 @@ const baseFields = {
35
36
  },
36
37
  groupAllowFrom: {
37
38
  type: 'array',
39
+ default: [],
38
40
  items: { type: 'string' }
39
41
  },
40
42
  channelContext: {
package/src/outbound.ts CHANGED
@@ -376,7 +376,7 @@ function getTargets(chatId: string, chatType: ChatType): TuiTuiToTargets {
376
376
 
377
377
  function replaceSingleNewlines(content: string): string {
378
378
  // 匹配单个换行符,前后都不是换行符
379
- return content.replace(/([^\n])\n([^\n])/g, '$1\n\n$2');
379
+ return content.replace(/([^\n|])\n([^\n|])/g, '$1\n\n$2');
380
380
  }
381
381
 
382
382
  /*