import z from "zod/v3";
import { getDoc, getDocBySlug, getDocMetadataRecord, getDocsKeys } from "@intlayer/docs";

//#region src/tools/docs.ts
const loadDocsTools = async (server) => {
	const docsKeys = getDocsKeys();
	server.tool("get-doc-list", "Get the list of docs names and their metadata to get more details about what doc to retrieve", {}, async () => {
		try {
			const docsMetadataRecord = await getDocMetadataRecord();
			return { content: [{
				type: "text",
				text: JSON.stringify(docsMetadataRecord, null, 2)
			}] };
		} catch (error) {
			return { content: [{
				type: "text",
				text: `Get doc list failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
			}] };
		}
	});
	server.tool("get-doc", "Get a doc by his key. Example: `./docs/en/getting-started.md`. List all docs metadata first to get more details about what doc key to retrieve.", { docKey: z.enum(docsKeys) }, async ({ docKey }) => {
		try {
			return { content: [{
				type: "text",
				text: await getDoc(docKey)
			}] };
		} catch (error) {
			return { content: [{
				type: "text",
				text: `Get doc failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
			}] };
		}
	});
	server.tool("get-doc-by-slug", "Get an array of docs by their slugs. If not slug is provided, return all docs (1.2Mb). List all docs metadata first to get more details about what doc to retrieve.", {
		slug: z.union([z.string(), z.array(z.string())]).optional().describe("Slug of the docs. If not provided, return all docs. If not provided, return all docs."),
		strict: z.boolean().optional().describe("Strict mode - only return docs that match all slugs, by excluding additional slugs"),
		description: "Get an array of docs by their slugs"
	}, async ({ slug, strict }) => {
		try {
			return { content: (await getDocBySlug(slug, void 0, strict)).map((d) => ({
				type: "text",
				text: d
			})) };
		} catch (error) {
			return { content: [{
				type: "text",
				text: `Get doc by slug failed: ${error instanceof Error ? error.message : "An unknown error occurred"}`
			}] };
		}
	});
};

//#endregion
export { loadDocsTools };
//# sourceMappingURL=docs.mjs.map