mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 11:58:38 +00:00
refactor: unify account list/default scaffolding
This commit is contained in:
@@ -1,9 +1,5 @@
|
|||||||
import {
|
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
||||||
DEFAULT_ACCOUNT_ID,
|
import { createAccountListHelpers, type OpenClawConfig } from "openclaw/plugin-sdk/bluebubbles";
|
||||||
normalizeAccountId,
|
|
||||||
normalizeOptionalAccountId,
|
|
||||||
} from "openclaw/plugin-sdk/account-id";
|
|
||||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/bluebubbles";
|
|
||||||
import { hasConfiguredSecretInput, normalizeSecretInputString } from "./secret-input.js";
|
import { hasConfiguredSecretInput, normalizeSecretInputString } from "./secret-input.js";
|
||||||
import { normalizeBlueBubblesServerUrl, type BlueBubblesAccountConfig } from "./types.js";
|
import { normalizeBlueBubblesServerUrl, type BlueBubblesAccountConfig } from "./types.js";
|
||||||
|
|
||||||
@@ -16,36 +12,11 @@ export type ResolvedBlueBubblesAccount = {
|
|||||||
baseUrl?: string;
|
baseUrl?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
function listConfiguredAccountIds(cfg: OpenClawConfig): string[] {
|
const {
|
||||||
const accounts = cfg.channels?.bluebubbles?.accounts;
|
listAccountIds: listBlueBubblesAccountIds,
|
||||||
if (!accounts || typeof accounts !== "object") {
|
resolveDefaultAccountId: resolveDefaultBlueBubblesAccountId,
|
||||||
return [];
|
} = createAccountListHelpers("bluebubbles");
|
||||||
}
|
export { listBlueBubblesAccountIds, resolveDefaultBlueBubblesAccountId };
|
||||||
return Object.keys(accounts).filter(Boolean);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function listBlueBubblesAccountIds(cfg: OpenClawConfig): string[] {
|
|
||||||
const ids = listConfiguredAccountIds(cfg);
|
|
||||||
if (ids.length === 0) {
|
|
||||||
return [DEFAULT_ACCOUNT_ID];
|
|
||||||
}
|
|
||||||
return ids.toSorted((a, b) => a.localeCompare(b));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resolveDefaultBlueBubblesAccountId(cfg: OpenClawConfig): string {
|
|
||||||
const preferred = normalizeOptionalAccountId(cfg.channels?.bluebubbles?.defaultAccount);
|
|
||||||
if (
|
|
||||||
preferred &&
|
|
||||||
listBlueBubblesAccountIds(cfg).some((accountId) => normalizeAccountId(accountId) === preferred)
|
|
||||||
) {
|
|
||||||
return preferred;
|
|
||||||
}
|
|
||||||
const ids = listBlueBubblesAccountIds(cfg);
|
|
||||||
if (ids.includes(DEFAULT_ACCOUNT_ID)) {
|
|
||||||
return DEFAULT_ACCOUNT_ID;
|
|
||||||
}
|
|
||||||
return ids[0] ?? DEFAULT_ACCOUNT_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveAccountConfig(
|
function resolveAccountConfig(
|
||||||
cfg: OpenClawConfig,
|
cfg: OpenClawConfig,
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
import {
|
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
||||||
DEFAULT_ACCOUNT_ID,
|
|
||||||
normalizeAccountId,
|
|
||||||
normalizeOptionalAccountId,
|
|
||||||
} from "openclaw/plugin-sdk/account-id";
|
|
||||||
import { isSecretRef } from "openclaw/plugin-sdk/googlechat";
|
import { isSecretRef } from "openclaw/plugin-sdk/googlechat";
|
||||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/googlechat";
|
import { createAccountListHelpers, type OpenClawConfig } from "openclaw/plugin-sdk/googlechat";
|
||||||
import type { GoogleChatAccountConfig } from "./types.config.js";
|
import type { GoogleChatAccountConfig } from "./types.config.js";
|
||||||
|
|
||||||
export type GoogleChatCredentialSource = "file" | "inline" | "env" | "none";
|
export type GoogleChatCredentialSource = "file" | "inline" | "env" | "none";
|
||||||
@@ -22,37 +18,11 @@ export type ResolvedGoogleChatAccount = {
|
|||||||
const ENV_SERVICE_ACCOUNT = "GOOGLE_CHAT_SERVICE_ACCOUNT";
|
const ENV_SERVICE_ACCOUNT = "GOOGLE_CHAT_SERVICE_ACCOUNT";
|
||||||
const ENV_SERVICE_ACCOUNT_FILE = "GOOGLE_CHAT_SERVICE_ACCOUNT_FILE";
|
const ENV_SERVICE_ACCOUNT_FILE = "GOOGLE_CHAT_SERVICE_ACCOUNT_FILE";
|
||||||
|
|
||||||
function listConfiguredAccountIds(cfg: OpenClawConfig): string[] {
|
const {
|
||||||
const accounts = cfg.channels?.["googlechat"]?.accounts;
|
listAccountIds: listGoogleChatAccountIds,
|
||||||
if (!accounts || typeof accounts !== "object") {
|
resolveDefaultAccountId: resolveDefaultGoogleChatAccountId,
|
||||||
return [];
|
} = createAccountListHelpers("googlechat");
|
||||||
}
|
export { listGoogleChatAccountIds, resolveDefaultGoogleChatAccountId };
|
||||||
return Object.keys(accounts).filter(Boolean);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function listGoogleChatAccountIds(cfg: OpenClawConfig): string[] {
|
|
||||||
const ids = listConfiguredAccountIds(cfg);
|
|
||||||
if (ids.length === 0) {
|
|
||||||
return [DEFAULT_ACCOUNT_ID];
|
|
||||||
}
|
|
||||||
return ids.toSorted((a, b) => a.localeCompare(b));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resolveDefaultGoogleChatAccountId(cfg: OpenClawConfig): string {
|
|
||||||
const channel = cfg.channels?.["googlechat"];
|
|
||||||
const preferred = normalizeOptionalAccountId(channel?.defaultAccount);
|
|
||||||
if (
|
|
||||||
preferred &&
|
|
||||||
listGoogleChatAccountIds(cfg).some((accountId) => normalizeAccountId(accountId) === preferred)
|
|
||||||
) {
|
|
||||||
return preferred;
|
|
||||||
}
|
|
||||||
const ids = listGoogleChatAccountIds(cfg);
|
|
||||||
if (ids.includes(DEFAULT_ACCOUNT_ID)) {
|
|
||||||
return DEFAULT_ACCOUNT_ID;
|
|
||||||
}
|
|
||||||
return ids[0] ?? DEFAULT_ACCOUNT_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveAccountConfig(
|
function resolveAccountConfig(
|
||||||
cfg: OpenClawConfig,
|
cfg: OpenClawConfig,
|
||||||
|
|||||||
78
extensions/irc/src/accounts.test.ts
Normal file
78
extensions/irc/src/accounts.test.ts
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { listIrcAccountIds, resolveDefaultIrcAccountId } from "./accounts.js";
|
||||||
|
import type { CoreConfig } from "./types.js";
|
||||||
|
|
||||||
|
function asConfig(value: unknown): CoreConfig {
|
||||||
|
return value as CoreConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("listIrcAccountIds", () => {
|
||||||
|
it("returns default when no accounts are configured", () => {
|
||||||
|
expect(listIrcAccountIds(asConfig({}))).toEqual(["default"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("normalizes, deduplicates, and sorts configured account ids", () => {
|
||||||
|
const cfg = asConfig({
|
||||||
|
channels: {
|
||||||
|
irc: {
|
||||||
|
accounts: {
|
||||||
|
"Ops Team": {},
|
||||||
|
"ops-team": {},
|
||||||
|
Work: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(listIrcAccountIds(cfg)).toEqual(["ops-team", "work"]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("resolveDefaultIrcAccountId", () => {
|
||||||
|
it("prefers configured defaultAccount when it matches", () => {
|
||||||
|
const cfg = asConfig({
|
||||||
|
channels: {
|
||||||
|
irc: {
|
||||||
|
defaultAccount: "Ops Team",
|
||||||
|
accounts: {
|
||||||
|
default: {},
|
||||||
|
"ops-team": {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(resolveDefaultIrcAccountId(cfg)).toBe("ops-team");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("falls back to default when configured defaultAccount is missing", () => {
|
||||||
|
const cfg = asConfig({
|
||||||
|
channels: {
|
||||||
|
irc: {
|
||||||
|
defaultAccount: "missing",
|
||||||
|
accounts: {
|
||||||
|
default: {},
|
||||||
|
work: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(resolveDefaultIrcAccountId(cfg)).toBe("default");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("falls back to first sorted account when default is absent", () => {
|
||||||
|
const cfg = asConfig({
|
||||||
|
channels: {
|
||||||
|
irc: {
|
||||||
|
accounts: {
|
||||||
|
zzz: {},
|
||||||
|
aaa: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(resolveDefaultIrcAccountId(cfg)).toBe("aaa");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
import { readFileSync } from "node:fs";
|
import { readFileSync } from "node:fs";
|
||||||
|
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
||||||
import {
|
import {
|
||||||
DEFAULT_ACCOUNT_ID,
|
createAccountListHelpers,
|
||||||
normalizeAccountId,
|
normalizeResolvedSecretInputString,
|
||||||
normalizeOptionalAccountId,
|
} from "openclaw/plugin-sdk/irc";
|
||||||
} from "openclaw/plugin-sdk/account-id";
|
|
||||||
import { normalizeResolvedSecretInputString } from "openclaw/plugin-sdk/irc";
|
|
||||||
import type { CoreConfig, IrcAccountConfig, IrcNickServConfig } from "./types.js";
|
import type { CoreConfig, IrcAccountConfig, IrcNickServConfig } from "./types.js";
|
||||||
|
|
||||||
const TRUTHY_ENV = new Set(["true", "1", "yes", "on"]);
|
const TRUTHY_ENV = new Set(["true", "1", "yes", "on"]);
|
||||||
@@ -54,19 +53,9 @@ function parseListEnv(value?: string): string[] | undefined {
|
|||||||
return parsed.length > 0 ? parsed : undefined;
|
return parsed.length > 0 ? parsed : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function listConfiguredAccountIds(cfg: CoreConfig): string[] {
|
const { listAccountIds: listIrcAccountIds, resolveDefaultAccountId: resolveDefaultIrcAccountId } =
|
||||||
const accounts = cfg.channels?.irc?.accounts;
|
createAccountListHelpers("irc", { normalizeAccountId });
|
||||||
if (!accounts || typeof accounts !== "object") {
|
export { listIrcAccountIds, resolveDefaultIrcAccountId };
|
||||||
return [];
|
|
||||||
}
|
|
||||||
const ids = new Set<string>();
|
|
||||||
for (const key of Object.keys(accounts)) {
|
|
||||||
if (key.trim()) {
|
|
||||||
ids.add(normalizeAccountId(key));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return [...ids];
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveAccountConfig(cfg: CoreConfig, accountId: string): IrcAccountConfig | undefined {
|
function resolveAccountConfig(cfg: CoreConfig, accountId: string): IrcAccountConfig | undefined {
|
||||||
const accounts = cfg.channels?.irc?.accounts;
|
const accounts = cfg.channels?.irc?.accounts;
|
||||||
@@ -165,29 +154,6 @@ function resolveNickServConfig(accountId: string, nickserv?: IrcNickServConfig):
|
|||||||
return merged;
|
return merged;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function listIrcAccountIds(cfg: CoreConfig): string[] {
|
|
||||||
const ids = listConfiguredAccountIds(cfg);
|
|
||||||
if (ids.length === 0) {
|
|
||||||
return [DEFAULT_ACCOUNT_ID];
|
|
||||||
}
|
|
||||||
return ids.toSorted((a, b) => a.localeCompare(b));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resolveDefaultIrcAccountId(cfg: CoreConfig): string {
|
|
||||||
const preferred = normalizeOptionalAccountId(cfg.channels?.irc?.defaultAccount);
|
|
||||||
if (
|
|
||||||
preferred &&
|
|
||||||
listIrcAccountIds(cfg).some((accountId) => normalizeAccountId(accountId) === preferred)
|
|
||||||
) {
|
|
||||||
return preferred;
|
|
||||||
}
|
|
||||||
const ids = listIrcAccountIds(cfg);
|
|
||||||
if (ids.includes(DEFAULT_ACCOUNT_ID)) {
|
|
||||||
return DEFAULT_ACCOUNT_ID;
|
|
||||||
}
|
|
||||||
return ids[0] ?? DEFAULT_ACCOUNT_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resolveIrcAccount(params: {
|
export function resolveIrcAccount(params: {
|
||||||
cfg: CoreConfig;
|
cfg: CoreConfig;
|
||||||
accountId?: string | null;
|
accountId?: string | null;
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import {
|
import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
||||||
DEFAULT_ACCOUNT_ID,
|
import { createAccountListHelpers } from "openclaw/plugin-sdk/matrix";
|
||||||
normalizeAccountId,
|
|
||||||
normalizeOptionalAccountId,
|
|
||||||
} from "openclaw/plugin-sdk/account-id";
|
|
||||||
import { hasConfiguredSecretInput } from "../secret-input.js";
|
import { hasConfiguredSecretInput } from "../secret-input.js";
|
||||||
import type { CoreConfig, MatrixConfig } from "../types.js";
|
import type { CoreConfig, MatrixConfig } from "../types.js";
|
||||||
import { resolveMatrixConfigForAccount } from "./client.js";
|
import { resolveMatrixConfigForAccount } from "./client.js";
|
||||||
@@ -35,44 +32,11 @@ export type ResolvedMatrixAccount = {
|
|||||||
config: MatrixConfig;
|
config: MatrixConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
function listConfiguredAccountIds(cfg: CoreConfig): string[] {
|
const {
|
||||||
const accounts = cfg.channels?.matrix?.accounts;
|
listAccountIds: listMatrixAccountIds,
|
||||||
if (!accounts || typeof accounts !== "object") {
|
resolveDefaultAccountId: resolveDefaultMatrixAccountId,
|
||||||
return [];
|
} = createAccountListHelpers("matrix", { normalizeAccountId });
|
||||||
}
|
export { listMatrixAccountIds, resolveDefaultMatrixAccountId };
|
||||||
// Normalize and de-duplicate keys so listing and resolution use the same semantics
|
|
||||||
return [
|
|
||||||
...new Set(
|
|
||||||
Object.keys(accounts)
|
|
||||||
.filter(Boolean)
|
|
||||||
.map((id) => normalizeAccountId(id)),
|
|
||||||
),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function listMatrixAccountIds(cfg: CoreConfig): string[] {
|
|
||||||
const ids = listConfiguredAccountIds(cfg);
|
|
||||||
if (ids.length === 0) {
|
|
||||||
// Fall back to default if no accounts configured (legacy top-level config)
|
|
||||||
return [DEFAULT_ACCOUNT_ID];
|
|
||||||
}
|
|
||||||
return ids.toSorted((a, b) => a.localeCompare(b));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resolveDefaultMatrixAccountId(cfg: CoreConfig): string {
|
|
||||||
const preferred = normalizeOptionalAccountId(cfg.channels?.matrix?.defaultAccount);
|
|
||||||
if (
|
|
||||||
preferred &&
|
|
||||||
listMatrixAccountIds(cfg).some((accountId) => normalizeAccountId(accountId) === preferred)
|
|
||||||
) {
|
|
||||||
return preferred;
|
|
||||||
}
|
|
||||||
const ids = listMatrixAccountIds(cfg);
|
|
||||||
if (ids.includes(DEFAULT_ACCOUNT_ID)) {
|
|
||||||
return DEFAULT_ACCOUNT_ID;
|
|
||||||
}
|
|
||||||
return ids[0] ?? DEFAULT_ACCOUNT_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveAccountConfig(cfg: CoreConfig, accountId: string): MatrixConfig | undefined {
|
function resolveAccountConfig(cfg: CoreConfig, accountId: string): MatrixConfig | undefined {
|
||||||
const accounts = cfg.channels?.matrix?.accounts;
|
const accounts = cfg.channels?.matrix?.accounts;
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
import {
|
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
||||||
DEFAULT_ACCOUNT_ID,
|
import { createAccountListHelpers, type OpenClawConfig } from "openclaw/plugin-sdk/mattermost";
|
||||||
normalizeAccountId,
|
|
||||||
normalizeOptionalAccountId,
|
|
||||||
} from "openclaw/plugin-sdk/account-id";
|
|
||||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/mattermost";
|
|
||||||
import { normalizeResolvedSecretInputString, normalizeSecretInputString } from "../secret-input.js";
|
import { normalizeResolvedSecretInputString, normalizeSecretInputString } from "../secret-input.js";
|
||||||
import type { MattermostAccountConfig, MattermostChatMode } from "../types.js";
|
import type { MattermostAccountConfig, MattermostChatMode } from "../types.js";
|
||||||
import { normalizeMattermostBaseUrl } from "./client.js";
|
import { normalizeMattermostBaseUrl } from "./client.js";
|
||||||
@@ -28,36 +24,11 @@ export type ResolvedMattermostAccount = {
|
|||||||
blockStreamingCoalesce?: MattermostAccountConfig["blockStreamingCoalesce"];
|
blockStreamingCoalesce?: MattermostAccountConfig["blockStreamingCoalesce"];
|
||||||
};
|
};
|
||||||
|
|
||||||
function listConfiguredAccountIds(cfg: OpenClawConfig): string[] {
|
const {
|
||||||
const accounts = cfg.channels?.mattermost?.accounts;
|
listAccountIds: listMattermostAccountIds,
|
||||||
if (!accounts || typeof accounts !== "object") {
|
resolveDefaultAccountId: resolveDefaultMattermostAccountId,
|
||||||
return [];
|
} = createAccountListHelpers("mattermost");
|
||||||
}
|
export { listMattermostAccountIds, resolveDefaultMattermostAccountId };
|
||||||
return Object.keys(accounts).filter(Boolean);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function listMattermostAccountIds(cfg: OpenClawConfig): string[] {
|
|
||||||
const ids = listConfiguredAccountIds(cfg);
|
|
||||||
if (ids.length === 0) {
|
|
||||||
return [DEFAULT_ACCOUNT_ID];
|
|
||||||
}
|
|
||||||
return ids.toSorted((a, b) => a.localeCompare(b));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resolveDefaultMattermostAccountId(cfg: OpenClawConfig): string {
|
|
||||||
const preferred = normalizeOptionalAccountId(cfg.channels?.mattermost?.defaultAccount);
|
|
||||||
if (
|
|
||||||
preferred &&
|
|
||||||
listMattermostAccountIds(cfg).some((accountId) => normalizeAccountId(accountId) === preferred)
|
|
||||||
) {
|
|
||||||
return preferred;
|
|
||||||
}
|
|
||||||
const ids = listMattermostAccountIds(cfg);
|
|
||||||
if (ids.includes(DEFAULT_ACCOUNT_ID)) {
|
|
||||||
return DEFAULT_ACCOUNT_ID;
|
|
||||||
}
|
|
||||||
return ids[0] ?? DEFAULT_ACCOUNT_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveAccountConfig(
|
function resolveAccountConfig(
|
||||||
cfg: OpenClawConfig,
|
cfg: OpenClawConfig,
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
import { readFileSync } from "node:fs";
|
import { readFileSync } from "node:fs";
|
||||||
import {
|
import {
|
||||||
|
createAccountListHelpers,
|
||||||
DEFAULT_ACCOUNT_ID,
|
DEFAULT_ACCOUNT_ID,
|
||||||
normalizeAccountId,
|
normalizeAccountId,
|
||||||
normalizeOptionalAccountId,
|
|
||||||
} from "openclaw/plugin-sdk/account-id";
|
|
||||||
import {
|
|
||||||
listConfiguredAccountIds as listConfiguredAccountIdsFromSection,
|
|
||||||
resolveAccountWithDefaultFallback,
|
resolveAccountWithDefaultFallback,
|
||||||
} from "openclaw/plugin-sdk/nextcloud-talk";
|
} from "openclaw/plugin-sdk/nextcloud-talk";
|
||||||
import { normalizeResolvedSecretInputString } from "./secret-input.js";
|
import { normalizeResolvedSecretInputString } from "./secret-input.js";
|
||||||
@@ -32,37 +29,18 @@ export type ResolvedNextcloudTalkAccount = {
|
|||||||
config: NextcloudTalkAccountConfig;
|
config: NextcloudTalkAccountConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
function listConfiguredAccountIds(cfg: CoreConfig): string[] {
|
const {
|
||||||
return listConfiguredAccountIdsFromSection({
|
listAccountIds: listNextcloudTalkAccountIdsInternal,
|
||||||
accounts: cfg.channels?.["nextcloud-talk"]?.accounts as Record<string, unknown> | undefined,
|
resolveDefaultAccountId: resolveDefaultNextcloudTalkAccountId,
|
||||||
normalizeAccountId,
|
} = createAccountListHelpers("nextcloud-talk", {
|
||||||
});
|
normalizeAccountId,
|
||||||
}
|
});
|
||||||
|
export { resolveDefaultNextcloudTalkAccountId };
|
||||||
|
|
||||||
export function listNextcloudTalkAccountIds(cfg: CoreConfig): string[] {
|
export function listNextcloudTalkAccountIds(cfg: CoreConfig): string[] {
|
||||||
const ids = listConfiguredAccountIds(cfg);
|
const ids = listNextcloudTalkAccountIdsInternal(cfg);
|
||||||
debugAccounts("listNextcloudTalkAccountIds", ids);
|
debugAccounts("listNextcloudTalkAccountIds", ids);
|
||||||
if (ids.length === 0) {
|
return ids;
|
||||||
return [DEFAULT_ACCOUNT_ID];
|
|
||||||
}
|
|
||||||
return ids.toSorted((a, b) => a.localeCompare(b));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resolveDefaultNextcloudTalkAccountId(cfg: CoreConfig): string {
|
|
||||||
const preferred = normalizeOptionalAccountId(cfg.channels?.["nextcloud-talk"]?.defaultAccount);
|
|
||||||
if (
|
|
||||||
preferred &&
|
|
||||||
listNextcloudTalkAccountIds(cfg).some(
|
|
||||||
(accountId) => normalizeAccountId(accountId) === preferred,
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return preferred;
|
|
||||||
}
|
|
||||||
const ids = listNextcloudTalkAccountIds(cfg);
|
|
||||||
if (ids.includes(DEFAULT_ACCOUNT_ID)) {
|
|
||||||
return DEFAULT_ACCOUNT_ID;
|
|
||||||
}
|
|
||||||
return ids[0] ?? DEFAULT_ACCOUNT_ID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveAccountConfig(
|
function resolveAccountConfig(
|
||||||
|
|||||||
@@ -1,45 +1,13 @@
|
|||||||
import {
|
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
||||||
DEFAULT_ACCOUNT_ID,
|
import { createAccountListHelpers, type OpenClawConfig } from "openclaw/plugin-sdk/zalo";
|
||||||
normalizeAccountId,
|
|
||||||
normalizeOptionalAccountId,
|
|
||||||
} from "openclaw/plugin-sdk/account-id";
|
|
||||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/zalo";
|
|
||||||
import { resolveZaloToken } from "./token.js";
|
import { resolveZaloToken } from "./token.js";
|
||||||
import type { ResolvedZaloAccount, ZaloAccountConfig, ZaloConfig } from "./types.js";
|
import type { ResolvedZaloAccount, ZaloAccountConfig, ZaloConfig } from "./types.js";
|
||||||
|
|
||||||
export type { ResolvedZaloAccount };
|
export type { ResolvedZaloAccount };
|
||||||
|
|
||||||
function listConfiguredAccountIds(cfg: OpenClawConfig): string[] {
|
const { listAccountIds: listZaloAccountIds, resolveDefaultAccountId: resolveDefaultZaloAccountId } =
|
||||||
const accounts = (cfg.channels?.zalo as ZaloConfig | undefined)?.accounts;
|
createAccountListHelpers("zalo");
|
||||||
if (!accounts || typeof accounts !== "object") {
|
export { listZaloAccountIds, resolveDefaultZaloAccountId };
|
||||||
return [];
|
|
||||||
}
|
|
||||||
return Object.keys(accounts).filter(Boolean);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function listZaloAccountIds(cfg: OpenClawConfig): string[] {
|
|
||||||
const ids = listConfiguredAccountIds(cfg);
|
|
||||||
if (ids.length === 0) {
|
|
||||||
return [DEFAULT_ACCOUNT_ID];
|
|
||||||
}
|
|
||||||
return ids.toSorted((a, b) => a.localeCompare(b));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resolveDefaultZaloAccountId(cfg: OpenClawConfig): string {
|
|
||||||
const zaloConfig = cfg.channels?.zalo as ZaloConfig | undefined;
|
|
||||||
const preferred = normalizeOptionalAccountId(zaloConfig?.defaultAccount);
|
|
||||||
if (
|
|
||||||
preferred &&
|
|
||||||
listZaloAccountIds(cfg).some((accountId) => normalizeAccountId(accountId) === preferred)
|
|
||||||
) {
|
|
||||||
return preferred;
|
|
||||||
}
|
|
||||||
const ids = listZaloAccountIds(cfg);
|
|
||||||
if (ids.includes(DEFAULT_ACCOUNT_ID)) {
|
|
||||||
return DEFAULT_ACCOUNT_ID;
|
|
||||||
}
|
|
||||||
return ids[0] ?? DEFAULT_ACCOUNT_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveAccountConfig(
|
function resolveAccountConfig(
|
||||||
cfg: OpenClawConfig,
|
cfg: OpenClawConfig,
|
||||||
|
|||||||
@@ -1,43 +1,13 @@
|
|||||||
import {
|
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
||||||
DEFAULT_ACCOUNT_ID,
|
import { createAccountListHelpers, type OpenClawConfig } from "openclaw/plugin-sdk/zalouser";
|
||||||
normalizeAccountId,
|
|
||||||
normalizeOptionalAccountId,
|
|
||||||
} from "openclaw/plugin-sdk/account-id";
|
|
||||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/zalouser";
|
|
||||||
import type { ResolvedZalouserAccount, ZalouserAccountConfig, ZalouserConfig } from "./types.js";
|
import type { ResolvedZalouserAccount, ZalouserAccountConfig, ZalouserConfig } from "./types.js";
|
||||||
import { checkZaloAuthenticated, getZaloUserInfo } from "./zalo-js.js";
|
import { checkZaloAuthenticated, getZaloUserInfo } from "./zalo-js.js";
|
||||||
|
|
||||||
function listConfiguredAccountIds(cfg: OpenClawConfig): string[] {
|
const {
|
||||||
const accounts = (cfg.channels?.zalouser as ZalouserConfig | undefined)?.accounts;
|
listAccountIds: listZalouserAccountIds,
|
||||||
if (!accounts || typeof accounts !== "object") {
|
resolveDefaultAccountId: resolveDefaultZalouserAccountId,
|
||||||
return [];
|
} = createAccountListHelpers("zalouser");
|
||||||
}
|
export { listZalouserAccountIds, resolveDefaultZalouserAccountId };
|
||||||
return Object.keys(accounts).filter(Boolean);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function listZalouserAccountIds(cfg: OpenClawConfig): string[] {
|
|
||||||
const ids = listConfiguredAccountIds(cfg);
|
|
||||||
if (ids.length === 0) {
|
|
||||||
return [DEFAULT_ACCOUNT_ID];
|
|
||||||
}
|
|
||||||
return ids.toSorted((a, b) => a.localeCompare(b));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resolveDefaultZalouserAccountId(cfg: OpenClawConfig): string {
|
|
||||||
const zalouserConfig = cfg.channels?.zalouser as ZalouserConfig | undefined;
|
|
||||||
const preferred = normalizeOptionalAccountId(zalouserConfig?.defaultAccount);
|
|
||||||
if (
|
|
||||||
preferred &&
|
|
||||||
listZalouserAccountIds(cfg).some((accountId) => normalizeAccountId(accountId) === preferred)
|
|
||||||
) {
|
|
||||||
return preferred;
|
|
||||||
}
|
|
||||||
const ids = listZalouserAccountIds(cfg);
|
|
||||||
if (ids.includes(DEFAULT_ACCOUNT_ID)) {
|
|
||||||
return DEFAULT_ACCOUNT_ID;
|
|
||||||
}
|
|
||||||
return ids[0] ?? DEFAULT_ACCOUNT_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveAccountConfig(
|
function resolveAccountConfig(
|
||||||
cfg: OpenClawConfig,
|
cfg: OpenClawConfig,
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ export {
|
|||||||
applyAccountNameToChannelSection,
|
applyAccountNameToChannelSection,
|
||||||
migrateBaseNameToDefaultAccount,
|
migrateBaseNameToDefaultAccount,
|
||||||
} from "../channels/plugins/setup-helpers.js";
|
} from "../channels/plugins/setup-helpers.js";
|
||||||
|
export { createAccountListHelpers } from "../channels/plugins/account-helpers.js";
|
||||||
export { collectBlueBubblesStatusIssues } from "../channels/plugins/status-issues/bluebubbles.js";
|
export { collectBlueBubblesStatusIssues } from "../channels/plugins/status-issues/bluebubbles.js";
|
||||||
export type {
|
export type {
|
||||||
BaseProbeResult,
|
BaseProbeResult,
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ export {
|
|||||||
applyAccountNameToChannelSection,
|
applyAccountNameToChannelSection,
|
||||||
migrateBaseNameToDefaultAccount,
|
migrateBaseNameToDefaultAccount,
|
||||||
} from "../channels/plugins/setup-helpers.js";
|
} from "../channels/plugins/setup-helpers.js";
|
||||||
|
export { createAccountListHelpers } from "../channels/plugins/account-helpers.js";
|
||||||
export type {
|
export type {
|
||||||
ChannelAccountSnapshot,
|
ChannelAccountSnapshot,
|
||||||
ChannelMessageActionAdapter,
|
ChannelMessageActionAdapter,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export {
|
|||||||
deleteAccountFromConfigSection,
|
deleteAccountFromConfigSection,
|
||||||
setAccountEnabledInConfigSection,
|
setAccountEnabledInConfigSection,
|
||||||
} from "../channels/plugins/config-helpers.js";
|
} from "../channels/plugins/config-helpers.js";
|
||||||
|
export { createAccountListHelpers } from "../channels/plugins/account-helpers.js";
|
||||||
export { buildChannelConfigSchema } from "../channels/plugins/config-schema.js";
|
export { buildChannelConfigSchema } from "../channels/plugins/config-schema.js";
|
||||||
export { formatPairingApproveHint } from "../channels/plugins/helpers.js";
|
export { formatPairingApproveHint } from "../channels/plugins/helpers.js";
|
||||||
export type {
|
export type {
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ export {
|
|||||||
} from "../channels/plugins/onboarding/helpers.js";
|
} from "../channels/plugins/onboarding/helpers.js";
|
||||||
export { PAIRING_APPROVED_MESSAGE } from "../channels/plugins/pairing-message.js";
|
export { PAIRING_APPROVED_MESSAGE } from "../channels/plugins/pairing-message.js";
|
||||||
export { applyAccountNameToChannelSection } from "../channels/plugins/setup-helpers.js";
|
export { applyAccountNameToChannelSection } from "../channels/plugins/setup-helpers.js";
|
||||||
|
export { createAccountListHelpers } from "../channels/plugins/account-helpers.js";
|
||||||
export type {
|
export type {
|
||||||
BaseProbeResult,
|
BaseProbeResult,
|
||||||
ChannelDirectoryEntry,
|
ChannelDirectoryEntry,
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ export {
|
|||||||
applyAccountNameToChannelSection,
|
applyAccountNameToChannelSection,
|
||||||
migrateBaseNameToDefaultAccount,
|
migrateBaseNameToDefaultAccount,
|
||||||
} from "../channels/plugins/setup-helpers.js";
|
} from "../channels/plugins/setup-helpers.js";
|
||||||
|
export { createAccountListHelpers } from "../channels/plugins/account-helpers.js";
|
||||||
export type {
|
export type {
|
||||||
BaseProbeResult,
|
BaseProbeResult,
|
||||||
ChannelAccountSnapshot,
|
ChannelAccountSnapshot,
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ export {
|
|||||||
promptSingleChannelSecretInput,
|
promptSingleChannelSecretInput,
|
||||||
} from "../channels/plugins/onboarding/helpers.js";
|
} from "../channels/plugins/onboarding/helpers.js";
|
||||||
export { applyAccountNameToChannelSection } from "../channels/plugins/setup-helpers.js";
|
export { applyAccountNameToChannelSection } from "../channels/plugins/setup-helpers.js";
|
||||||
|
export { createAccountListHelpers } from "../channels/plugins/account-helpers.js";
|
||||||
export type { ChannelGroupContext, ChannelSetupInput } from "../channels/plugins/types.js";
|
export type { ChannelGroupContext, ChannelSetupInput } from "../channels/plugins/types.js";
|
||||||
export type { ChannelPlugin } from "../channels/plugins/types.plugin.js";
|
export type { ChannelPlugin } from "../channels/plugins/types.plugin.js";
|
||||||
export { createReplyPrefixOptions } from "../channels/reply-prefix.js";
|
export { createReplyPrefixOptions } from "../channels/reply-prefix.js";
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export {
|
|||||||
applyAccountNameToChannelSection,
|
applyAccountNameToChannelSection,
|
||||||
migrateBaseNameToDefaultAccount,
|
migrateBaseNameToDefaultAccount,
|
||||||
} from "../channels/plugins/setup-helpers.js";
|
} from "../channels/plugins/setup-helpers.js";
|
||||||
|
export { createAccountListHelpers } from "../channels/plugins/account-helpers.js";
|
||||||
export type {
|
export type {
|
||||||
BaseProbeResult,
|
BaseProbeResult,
|
||||||
BaseTokenResolution,
|
BaseTokenResolution,
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export {
|
|||||||
applyAccountNameToChannelSection,
|
applyAccountNameToChannelSection,
|
||||||
migrateBaseNameToDefaultAccount,
|
migrateBaseNameToDefaultAccount,
|
||||||
} from "../channels/plugins/setup-helpers.js";
|
} from "../channels/plugins/setup-helpers.js";
|
||||||
|
export { createAccountListHelpers } from "../channels/plugins/account-helpers.js";
|
||||||
export type {
|
export type {
|
||||||
BaseProbeResult,
|
BaseProbeResult,
|
||||||
ChannelAccountSnapshot,
|
ChannelAccountSnapshot,
|
||||||
|
|||||||
Reference in New Issue
Block a user