|
1 | | -import { |
2 | | - applyAccountNameToChannelSection, |
3 | | - applySetupAccountConfigPatch, |
4 | | - DEFAULT_ACCOUNT_ID, |
5 | | - hasConfiguredSecretInput, |
6 | | - migrateBaseNameToDefaultAccount, |
7 | | - normalizeAccountId, |
8 | | - type OpenClawConfig, |
9 | | -} from "openclaw/plugin-sdk/mattermost"; |
| 1 | +import { DEFAULT_ACCOUNT_ID, hasConfiguredSecretInput } from "openclaw/plugin-sdk/mattermost"; |
10 | 2 | import { type ChannelSetupWizard } from "../../../src/channels/plugins/setup-wizard.js"; |
11 | | -import type { ChannelSetupAdapter } from "../../../src/channels/plugins/types.adapters.js"; |
12 | 3 | import { formatDocsLink } from "../../../src/terminal/links.js"; |
| 4 | +import { listMattermostAccountIds } from "./mattermost/accounts.js"; |
13 | 5 | import { |
14 | | - listMattermostAccountIds, |
15 | | - resolveMattermostAccount, |
16 | | - type ResolvedMattermostAccount, |
17 | | -} from "./mattermost/accounts.js"; |
18 | | -import { normalizeMattermostBaseUrl } from "./mattermost/client.js"; |
| 6 | + isMattermostConfigured, |
| 7 | + mattermostSetupAdapter, |
| 8 | + resolveMattermostAccountWithSecrets, |
| 9 | +} from "./setup-core.js"; |
19 | 10 |
|
20 | 11 | const channel = "mattermost" as const; |
21 | | - |
22 | | -function isMattermostConfigured(account: ResolvedMattermostAccount): boolean { |
23 | | - const tokenConfigured = |
24 | | - Boolean(account.botToken?.trim()) || hasConfiguredSecretInput(account.config.botToken); |
25 | | - return tokenConfigured && Boolean(account.baseUrl); |
26 | | -} |
27 | | - |
28 | | -function resolveMattermostAccountWithSecrets(cfg: OpenClawConfig, accountId: string) { |
29 | | - return resolveMattermostAccount({ |
30 | | - cfg, |
31 | | - accountId, |
32 | | - allowUnresolvedSecretRef: true, |
33 | | - }); |
34 | | -} |
35 | | - |
36 | | -export const mattermostSetupAdapter: ChannelSetupAdapter = { |
37 | | - resolveAccountId: ({ accountId }) => normalizeAccountId(accountId), |
38 | | - applyAccountName: ({ cfg, accountId, name }) => |
39 | | - applyAccountNameToChannelSection({ |
40 | | - cfg, |
41 | | - channelKey: channel, |
42 | | - accountId, |
43 | | - name, |
44 | | - }), |
45 | | - validateInput: ({ accountId, input }) => { |
46 | | - const token = input.botToken ?? input.token; |
47 | | - const baseUrl = normalizeMattermostBaseUrl(input.httpUrl); |
48 | | - if (input.useEnv && accountId !== DEFAULT_ACCOUNT_ID) { |
49 | | - return "Mattermost env vars can only be used for the default account."; |
50 | | - } |
51 | | - if (!input.useEnv && (!token || !baseUrl)) { |
52 | | - return "Mattermost requires --bot-token and --http-url (or --use-env)."; |
53 | | - } |
54 | | - if (input.httpUrl && !baseUrl) { |
55 | | - return "Mattermost --http-url must include a valid base URL."; |
56 | | - } |
57 | | - return null; |
58 | | - }, |
59 | | - applyAccountConfig: ({ cfg, accountId, input }) => { |
60 | | - const token = input.botToken ?? input.token; |
61 | | - const baseUrl = normalizeMattermostBaseUrl(input.httpUrl); |
62 | | - const namedConfig = applyAccountNameToChannelSection({ |
63 | | - cfg, |
64 | | - channelKey: channel, |
65 | | - accountId, |
66 | | - name: input.name, |
67 | | - }); |
68 | | - const next = |
69 | | - accountId !== DEFAULT_ACCOUNT_ID |
70 | | - ? migrateBaseNameToDefaultAccount({ |
71 | | - cfg: namedConfig, |
72 | | - channelKey: channel, |
73 | | - }) |
74 | | - : namedConfig; |
75 | | - return applySetupAccountConfigPatch({ |
76 | | - cfg: next, |
77 | | - channelKey: channel, |
78 | | - accountId, |
79 | | - patch: input.useEnv |
80 | | - ? {} |
81 | | - : { |
82 | | - ...(token ? { botToken: token } : {}), |
83 | | - ...(baseUrl ? { baseUrl } : {}), |
84 | | - }, |
85 | | - }); |
86 | | - }, |
87 | | -}; |
| 12 | +export { mattermostSetupAdapter } from "./setup-core.js"; |
88 | 13 |
|
89 | 14 | export const mattermostSetupWizard: ChannelSetupWizard = { |
90 | 15 | channel, |
|
0 commit comments