UNPKG

n8n-bookstack-agent-tool

Version:

Comprehensive BookStack API integration tool for n8n AI Agent with MCP framework compatibility

96 lines 4.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BookStack = void 0; const tools_1 = require("@langchain/core/tools"); const zod_1 = require("zod"); const index_js_1 = require("../../src/index.js"); class BookStack { constructor() { this.description = { displayName: 'BookStack', name: 'bookStack', icon: 'file:bookstack.svg', group: ['transform'], version: 1, description: 'BookStack API integration tool for AI Agent', defaults: { name: 'BookStack', }, codex: { categories: ['AI'], subcategories: { AI: ['Tools'], }, resources: { primaryDocumentation: [ { url: 'https://demo.bookstackapp.com/api/docs', }, ], }, }, inputs: [], outputs: ["ai_tool" /* NodeConnectionType.AiTool */], outputNames: ['tool'], credentials: [ { name: 'bookStackApi', required: true, }, ], properties: [ { displayName: 'Name', name: 'name', type: 'string', default: 'bookstack_tool', description: 'The name of the tool', }, { displayName: 'Description', name: 'description', type: 'string', default: 'Tool for interacting with BookStack API to manage documentation', description: 'Description of what the tool does', }, ], }; } async supplyData(itemIndex) { const credentials = await this.getCredentials('bookStackApi'); const name = this.getNodeParameter('name', itemIndex); const description = this.getNodeParameter('description', itemIndex); const config = { baseUrl: credentials.baseUrl, authType: 'bearer', token: credentials.token, tokenSecret: credentials.tokenSecret, timeout: 30000, retryAttempts: 3, retryDelay: 1000, }; const bookStackTool = new index_js_1.BookStackN8nTool(config); const tool = new tools_1.DynamicStructuredTool({ name, description, schema: zod_1.z.object({ command: zod_1.z.string().describe('The BookStack API command to execute (e.g., listBooks, getBook, createBook, updateBook, deleteBook, listPages, getPage, createPage, updatePage, deletePage, listChapters, getChapter, createChapter, updateChapter, deleteChapter, listShelves, getShelf, createShelf, updateShelf, deleteShelf, listUsers, getUser, createUser, updateUser, deleteUser, listRoles, getRole, listAttachments, getAttachment, createAttachment, updateAttachment, deleteAttachment, listTags, getTag, createTag, updateTag, deleteTag, exportBookHtml, exportBookPdf, exportBookMarkdown, exportBookPlainText, exportPageHtml, exportPagePdf, exportPageMarkdown, exportPagePlainText, exportChapterHtml, exportChapterPdf, exportChapterMarkdown, exportChapterPlainText)'), parameters: zod_1.z.record(zod_1.z.any()).optional().describe('Parameters for the command (e.g., {id: "123", name: "My Book", description: "Book description"})'), }), func: async ({ command, parameters = {} }) => { try { const result = await bookStackTool.execCommand(command, parameters); return JSON.stringify(result, null, 2); } catch (error) { return `Error: ${error.message}`; } }, }); return { response: tool, }; } } exports.BookStack = BookStack; //# sourceMappingURL=BookStack.node.js.map