openclaw-seatalk 0.3.2 → 0.3.3

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/src/accounts.ts DELETED
@@ -1,96 +0,0 @@
1
- import {
2
- DEFAULT_ACCOUNT_ID,
3
- type OpenClawConfig,
4
- normalizeAccountId,
5
- } from "openclaw/plugin-sdk/core";
6
- import type { ResolvedSeaTalkAccount, SeaTalkAccountConfig, SeaTalkConfig } from "./types.js";
7
-
8
- function listConfiguredAccountIds(cfg: OpenClawConfig): string[] {
9
- const accounts = (cfg.channels?.seatalk as SeaTalkConfig)?.accounts;
10
- if (!accounts || typeof accounts !== "object") {
11
- return [];
12
- }
13
- return Object.keys(accounts).filter(Boolean);
14
- }
15
-
16
- export function listSeaTalkAccountIds(cfg: OpenClawConfig): string[] {
17
- const ids = listConfiguredAccountIds(cfg);
18
- if (ids.length === 0) {
19
- return [DEFAULT_ACCOUNT_ID];
20
- }
21
- return [...ids].toSorted((a, b) => a.localeCompare(b));
22
- }
23
-
24
- export function resolveDefaultSeaTalkAccountId(cfg: OpenClawConfig): string {
25
- const ids = listSeaTalkAccountIds(cfg);
26
- if (ids.includes(DEFAULT_ACCOUNT_ID)) {
27
- return DEFAULT_ACCOUNT_ID;
28
- }
29
- return ids[0] ?? DEFAULT_ACCOUNT_ID;
30
- }
31
-
32
- function resolveAccountConfig(
33
- cfg: OpenClawConfig,
34
- accountId: string,
35
- ): SeaTalkAccountConfig | undefined {
36
- const accounts = (cfg.channels?.seatalk as SeaTalkConfig)?.accounts;
37
- if (!accounts || typeof accounts !== "object") {
38
- return undefined;
39
- }
40
- return accounts[accountId];
41
- }
42
-
43
- function mergeSeaTalkAccountConfig(cfg: OpenClawConfig, accountId: string): SeaTalkConfig {
44
- const seatalkCfg = cfg.channels?.seatalk as SeaTalkConfig | undefined;
45
- const { accounts: _ignored, ...base } = seatalkCfg ?? {};
46
- const account = resolveAccountConfig(cfg, accountId) ?? {};
47
- return { ...base, ...account } as SeaTalkConfig;
48
- }
49
-
50
- export function resolveSeaTalkCredentials(cfg?: SeaTalkConfig): {
51
- appId: string;
52
- appSecret: string;
53
- signingSecret: string;
54
- } | null {
55
- const appId = (cfg?.appId ?? process.env.SEATALK_APP_ID)?.trim();
56
- const appSecret = (cfg?.appSecret ?? process.env.SEATALK_APP_SECRET)?.trim();
57
- const signingSecret = (cfg?.signingSecret ?? process.env.SEATALK_SIGNING_SECRET)?.trim();
58
- if (!appId || !appSecret || !signingSecret) {
59
- return null;
60
- }
61
- return { appId, appSecret, signingSecret };
62
- }
63
-
64
- export function resolveSeaTalkAccount(params: {
65
- cfg: OpenClawConfig;
66
- accountId?: string | null;
67
- }): ResolvedSeaTalkAccount {
68
- const accountId = normalizeAccountId(params.accountId);
69
- const seatalkCfg = params.cfg.channels?.seatalk as SeaTalkConfig | undefined;
70
-
71
- const baseEnabled = seatalkCfg?.enabled !== false;
72
- const merged = mergeSeaTalkAccountConfig(params.cfg, accountId);
73
- const accountEnabled = merged.enabled !== false;
74
- const enabled = baseEnabled && accountEnabled;
75
- const creds = resolveSeaTalkCredentials(merged);
76
-
77
- return {
78
- accountId,
79
- enabled,
80
- configured: Boolean(creds),
81
- appId: creds?.appId,
82
- appSecret: creds?.appSecret,
83
- mode: merged.mode ?? "webhook",
84
- relayUrl: merged.relayUrl,
85
- webhookPort: merged.webhookPort ?? 8080,
86
- webhookPath: merged.webhookPath ?? "/callback",
87
- tools: merged.tools,
88
- config: merged,
89
- };
90
- }
91
-
92
- export function listEnabledSeaTalkAccounts(cfg: OpenClawConfig): ResolvedSeaTalkAccount[] {
93
- return listSeaTalkAccountIds(cfg)
94
- .map((accountId) => resolveSeaTalkAccount({ cfg, accountId }))
95
- .filter((account) => account.enabled && account.configured);
96
- }