import { resolveFeishuAccount } from "../state/accounts.js";
import { createFeishuClient } from "../transport/client/client.js";
//#region extensions/feishu/src/tools/tools.ts
async function feishuWhoAmI(params) {
	const account = resolveFeishuAccount(params.cfg, params.accountId ?? "default");
	if (!account.configured) throw new Error("Feishu account not configured");
	const { api } = createFeishuClient(account);
	const res = await api.auth.tenantAccessToken.internal({ data: {
		app_id: account.appId,
		app_secret: account.appSecret
	} });
	const token = res?.tenant_access_token || res?.data?.tenant_access_token || "";
	const probes = {};
	const tryProbe = async (name, fn) => {
		try {
			await fn();
			probes[name] = { ok: true };
		} catch (err) {
			probes[name] = {
				ok: false,
				error: err instanceof Error ? err.message : String(err)
			};
		}
	};
	await tryProbe("im.message.read", async () => {
		await api.im.v1.chat.list({ params: { page_size: 1 } });
	});
	await tryProbe("drive.files.list", async () => {
		await api.drive.v1.file.list({ params: { page_size: 1 } });
	});
	await tryProbe("wiki.spaces.list", async () => {
		await api.wiki.v2.space.list({ params: { page_size: 1 } });
	});
	await tryProbe("bitable.apps.list", async () => {
		await api.bitable.v1.app.list({ params: { page_size: 1 } });
	});
	return {
		ok: true,
		tenantAccessToken: Boolean(token),
		probes
	};
}
//#endregion
export { feishuWhoAmI };

//# sourceMappingURL=tools.js.map