UNPKG

n8n

Version:

n8n Workflow Automation Tool

29 lines 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildAskCredentialTool = buildAskCredentialTool; const agents_1 = require("@n8n/agents"); const api_types_1 = require("@n8n/api-types"); function buildAskCredentialTool(deps) { return (new agents_1.Tool(api_types_1.ASK_CREDENTIAL_TOOL_NAME) .description('Show a credential picker card in the chat UI and suspend until the user selects ' + 'a credential. Call ONCE per credential slot, BEFORE the write_config / patch_config ' + 'that introduces the node tool. Returns { credentialId, credentialName } on success ' + 'or { skipped: true } if the user skips credential setup so the tool can be added ' + 'without credentials. Auto-resolves without ' + 'rendering a card when the user has exactly one credential of the requested type.') .input(api_types_1.askCredentialInputSchema) .suspend(api_types_1.askCredentialInputSchema) .resume(api_types_1.askCredentialResumeSchema) .handler(async (input, ctx) => { if (ctx.resumeData !== undefined) return ctx.resumeData; const all = await deps.credentialProvider.list(); const matching = all.filter((c) => c.type === input.credentialType); if (matching.length === 1) { return { credentialId: matching[0].id, credentialName: matching[0].name }; } return await ctx.suspend(input); }) .build()); } //# sourceMappingURL=ask-credential.tool.js.map