@buz-extensions/buz 1.0.0-beta.2 → 1.0.0-beta.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/index.ts +42 -67
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -1,57 +1,24 @@
|
|
|
1
1
|
import type { ChannelPlugin, OpenClawPluginApi } from "openclaw/plugin-sdk/line";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
buildChannelConfigSchema,
|
|
5
|
-
emptyPluginConfigSchema,
|
|
6
|
-
} from "openclaw/plugin-sdk/line";
|
|
2
|
+
import { emptyPluginConfigSchema } from "openclaw/plugin-sdk/line";
|
|
3
|
+
import { buildChannelConfigSchema } from "openclaw/plugin-sdk/line";
|
|
7
4
|
import { z } from "zod";
|
|
8
5
|
|
|
9
|
-
const BuzAccountSchema = z
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
})
|
|
6
|
+
const BuzAccountSchema = z
|
|
7
|
+
.object({
|
|
8
|
+
enabled: z.boolean().optional(),
|
|
9
|
+
serverAddress: z.string().optional(),
|
|
10
|
+
secretKey: z.string().optional(),
|
|
11
|
+
})
|
|
12
|
+
.partial();
|
|
15
13
|
|
|
16
|
-
const BuzConfigSchema =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
buzChannelConfigSchema.uiHints = {
|
|
25
|
-
enabled: { label: "Enabled" },
|
|
26
|
-
name: { label: "Name" },
|
|
27
|
-
serverAddress: {
|
|
28
|
-
label: "Host Address",
|
|
29
|
-
placeholder: "grpc.buz.ai:443",
|
|
30
|
-
help: "buz gRPC server host:port",
|
|
31
|
-
},
|
|
32
|
-
secretKey: {
|
|
33
|
-
label: "Secret Key",
|
|
34
|
-
sensitive: true,
|
|
35
|
-
help: "IM secret key used to authenticate with buz",
|
|
36
|
-
},
|
|
37
|
-
defaultAccount: {
|
|
38
|
-
label: "Default Account",
|
|
39
|
-
advanced: true,
|
|
40
|
-
},
|
|
41
|
-
accounts: {
|
|
42
|
-
label: "Custom entries",
|
|
43
|
-
},
|
|
44
|
-
"accounts.*.enabled": { label: "Enabled" },
|
|
45
|
-
"accounts.*.name": { label: "Name" },
|
|
46
|
-
"accounts.*.serverAddress": {
|
|
47
|
-
label: "Host Address",
|
|
48
|
-
placeholder: "grpc.buz.ai:443",
|
|
49
|
-
},
|
|
50
|
-
"accounts.*.secretKey": {
|
|
51
|
-
label: "Secret Key",
|
|
52
|
-
sensitive: true,
|
|
53
|
-
},
|
|
54
|
-
};
|
|
14
|
+
const BuzConfigSchema = z
|
|
15
|
+
.object({
|
|
16
|
+
enabled: z.boolean().optional(),
|
|
17
|
+
serverAddress: z.string().optional(),
|
|
18
|
+
secretKey: z.string().optional(),
|
|
19
|
+
accounts: z.record(z.string(), BuzAccountSchema.optional()).optional(),
|
|
20
|
+
})
|
|
21
|
+
.partial();
|
|
55
22
|
|
|
56
23
|
export const buzChannelPlugin = {
|
|
57
24
|
id: "buz",
|
|
@@ -68,7 +35,7 @@ export const buzChannelPlugin = {
|
|
|
68
35
|
threads: true,
|
|
69
36
|
media: false,
|
|
70
37
|
},
|
|
71
|
-
configSchema:
|
|
38
|
+
configSchema: buildChannelConfigSchema(BuzConfigSchema),
|
|
72
39
|
config: {
|
|
73
40
|
listAccountIds: (cfg: any) => {
|
|
74
41
|
const accounts = cfg?.channels?.["buz"]?.accounts || {};
|
|
@@ -83,7 +50,6 @@ export const buzChannelPlugin = {
|
|
|
83
50
|
id === "default"
|
|
84
51
|
? {
|
|
85
52
|
enabled: channelConfig.enabled,
|
|
86
|
-
name: channelConfig.name,
|
|
87
53
|
serverAddress: channelConfig.serverAddress,
|
|
88
54
|
secretKey: channelConfig.secretKey,
|
|
89
55
|
}
|
|
@@ -94,7 +60,7 @@ export const buzChannelPlugin = {
|
|
|
94
60
|
|
|
95
61
|
return {
|
|
96
62
|
accountId: id,
|
|
97
|
-
name:
|
|
63
|
+
name: `buz (${id})`,
|
|
98
64
|
enabled: accountConfig.enabled !== false,
|
|
99
65
|
serverAddress: accountConfig.serverAddress,
|
|
100
66
|
secretKey: accountConfig.secretKey,
|
|
@@ -108,7 +74,6 @@ export const buzChannelPlugin = {
|
|
|
108
74
|
name: account.name,
|
|
109
75
|
enabled: account.enabled,
|
|
110
76
|
configured: Boolean(account.configured),
|
|
111
|
-
serverAddress: account.serverAddress,
|
|
112
77
|
}),
|
|
113
78
|
},
|
|
114
79
|
messaging: {
|
|
@@ -120,20 +85,31 @@ export const buzChannelPlugin = {
|
|
|
120
85
|
resolveSessionTarget: ({ id }: any) => id,
|
|
121
86
|
},
|
|
122
87
|
setupWizard: {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
88
|
+
channel: "buz",
|
|
89
|
+
status: {
|
|
90
|
+
configuredLabel: "configured",
|
|
91
|
+
unconfiguredLabel: "needs server + secret",
|
|
92
|
+
configuredHint: "configured",
|
|
93
|
+
unconfiguredHint: "needs server + secret",
|
|
94
|
+
configuredScore: 1,
|
|
95
|
+
unconfiguredScore: 0,
|
|
96
|
+
resolveConfigured: ({ cfg }: any) => {
|
|
97
|
+
const channelConfig = cfg?.channels?.["buz"];
|
|
98
|
+
const accounts = channelConfig?.accounts || {};
|
|
99
|
+
return Object.values(accounts).some((acc: any) =>
|
|
100
|
+
acc?.serverAddress && acc?.secretKey
|
|
101
|
+
) || (channelConfig?.serverAddress && channelConfig?.secretKey);
|
|
129
102
|
},
|
|
130
|
-
{
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
label: "Secret Key",
|
|
134
|
-
placeholder: "Enter your IM Secret Key",
|
|
103
|
+
resolveStatusLines: ({ cfg, configured }: any) => {
|
|
104
|
+
const accountCount = Object.keys(cfg?.channels?.["buz"]?.accounts || {}).length;
|
|
105
|
+
return [`buz: ${configured ? "configured" : "needs server + secret"}`, `Accounts: ${accountCount || 0}`];
|
|
135
106
|
},
|
|
136
|
-
|
|
107
|
+
},
|
|
108
|
+
credentials: [],
|
|
109
|
+
finalize: async ({ cfg, accountId, credentialValues, prompter }: any) => {
|
|
110
|
+
// buz uses setup adapter for configuration
|
|
111
|
+
return { cfg };
|
|
112
|
+
},
|
|
137
113
|
},
|
|
138
114
|
setup: {
|
|
139
115
|
validateInput: async (params: any) => {
|
|
@@ -187,7 +163,6 @@ export const buzChannelPlugin = {
|
|
|
187
163
|
lastStartAt: runtime?.lastStartAt ?? null,
|
|
188
164
|
lastStopAt: runtime?.lastStopAt ?? null,
|
|
189
165
|
mode: "grpc",
|
|
190
|
-
serverAddress: account.serverAddress,
|
|
191
166
|
...(runtime?.lastError ? { lastError: runtime.lastError } : {}),
|
|
192
167
|
...(runtime?.lastInboundAt ? { lastInboundAt: runtime.lastInboundAt } : {}),
|
|
193
168
|
...(runtime?.lastOutboundAt ? { lastOutboundAt: runtime.lastOutboundAt } : {}),
|