//#region extensions/feishu/src/state/accounts.ts
function asFeishuSection(cfg) {
	return cfg.channels?.feishu;
}
function listFeishuAccountIds(cfg) {
	const section = asFeishuSection(cfg);
	if (!section) return [];
	const accounts = section.accounts ?? {};
	const keys = Object.keys(accounts);
	if (keys.length > 0) return keys;
	return ["default"];
}
function resolveRootAccount(section) {
	return {
		enabled: section.enabled,
		name: "Default Account",
		appId: section.appId,
		appSecret: section.appSecret,
		domain: section.domain,
		connectionMode: section.connectionMode,
		webhookHost: section.webhookHost,
		webhookPort: section.webhookPort,
		webhookPath: section.webhookPath,
		verificationToken: section.verificationToken,
		encryptKey: section.encryptKey,
		dmPolicy: section.dmPolicy,
		groupPolicy: section.groupPolicy,
		allowFrom: section.allowFrom,
		groupAllowFrom: section.groupAllowFrom,
		requireMention: section.requireMention,
		historyLimit: section.historyLimit,
		textChunkLimit: section.textChunkLimit,
		renderMode: section.renderMode,
		reactionNotifications: section.reactionNotifications,
		inboundDebounceMs: section.inboundDebounceMs,
		streaming: section.streaming,
		blockStreamingCoalesce: section.blockStreamingCoalesce,
		tools: section.tools,
		actions: section.actions,
		dynamicAgentCreation: section.dynamicAgentCreation
	};
}
function mergeAccount(section, account) {
	const root = resolveRootAccount(section);
	if (!account) return root;
	return {
		...root,
		...account,
		allowFrom: account.allowFrom ?? root.allowFrom,
		groupAllowFrom: account.groupAllowFrom ?? root.groupAllowFrom
	};
}
function resolveFeishuAccount(cfg, accountId) {
	const section = asFeishuSection(cfg) ?? { enabled: false };
	const requested = (accountId ?? "").trim();
	const accounts = section.accounts ?? {};
	const hasNamedAccounts = Object.keys(accounts).length > 0;
	const effectiveAccountId = requested || section.defaultAccount || (hasNamedAccounts ? Object.keys(accounts)[0] : "default");
	const merged = mergeAccount(section, hasNamedAccounts ? accounts[effectiveAccountId] : resolveRootAccount(section));
	const enabled = merged.enabled !== false && section.enabled !== false;
	const appId = merged.appId?.trim() || void 0;
	const appSecret = merged.appSecret?.trim() || void 0;
	const configured = Boolean(appId && appSecret);
	return {
		accountId: effectiveAccountId,
		name: merged.name,
		enabled,
		configured,
		appId,
		appSecret,
		domain: merged.domain ?? "feishu",
		connectionMode: merged.connectionMode ?? "websocket",
		webhookHost: merged.webhookHost,
		webhookPort: merged.webhookPort,
		webhookPath: merged.webhookPath,
		verificationToken: merged.verificationToken,
		encryptKey: merged.encryptKey,
		dmPolicy: merged.dmPolicy ?? "open",
		groupPolicy: merged.groupPolicy ?? "allowlist",
		allowFrom: merged.allowFrom,
		groupAllowFrom: merged.groupAllowFrom,
		requireMention: merged.requireMention,
		historyLimit: typeof merged.historyLimit === "number" ? merged.historyLimit : 50,
		textChunkLimit: typeof merged.textChunkLimit === "number" ? merged.textChunkLimit : 4e3,
		renderMode: merged.renderMode,
		reactionNotifications: merged.reactionNotifications,
		inboundDebounceMs: merged.inboundDebounceMs,
		streaming: merged.streaming === true,
		blockStreamingCoalesce: merged.blockStreamingCoalesce,
		tools: merged.tools,
		actions: merged.actions,
		dynamicAgentCreation: merged.dynamicAgentCreation
	};
}
//#endregion
export { listFeishuAccountIds, resolveFeishuAccount };

//# sourceMappingURL=accounts.js.map