UNPKG

@n8n/n8n-nodes-langchain

Version:
54 lines • 2.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.makeAzureFoundryFailedAttemptHandler = makeAzureFoundryFailedAttemptHandler; const model_discovery_1 = require("@n8n/ai-utilities/model-discovery"); const is_record_1 = require("@n8n/utils/is-record"); const n8n_workflow_1 = require("n8n-workflow"); function statusOf(error) { if (!(0, is_record_1.isRecord)(error)) return undefined; if (typeof error.status === 'number') return error.status; const response = error.response; return (0, is_record_1.isRecord)(response) && typeof response.status === 'number' ? response.status : undefined; } function messageOf(error) { return (0, is_record_1.isRecord)(error) && typeof error.message === 'string' ? error.message : undefined; } const MODEL_NOT_SUPPORTED = /\bmodels?\b[^.]{0,30}\bnot supported\b/i; const OPERATION_UNSUPPORTED = /\brequested operation is unsupported\b/i; function isDeploymentRejected(error) { const message = messageOf(error); const kind = (0, model_discovery_1.classifyChatModelFailure)(message); if (kind === 'unsupported_parameter') return false; const status = statusOf(error); if (status === 404) return true; if (status !== 400) return false; return (kind === 'capability_mismatch' || kind === 'invalid_model' || MODEL_NOT_SUPPORTED.test(message ?? '') || OPERATION_UNSUPPORTED.test(message ?? '')); } function makeAzureFoundryFailedAttemptHandler(modelName, useResponsesApi, route = 'foundry') { const apiRequested = route === 'anthropic' ? 'the Anthropic Messages API' : useResponsesApi ? 'the Responses API' : 'Chat Completions'; const remedy = route === 'anthropic' ? 'Set Model Family to OpenAI if the deployment is not a Claude model.' : route === 'classic' ? 'Switch the credential to the Microsoft Foundry endpoint type if the deployment serves only the Responses API.' : useResponsesApi ? "Turn off 'Use Responses API' if the deployment serves Chat Completions." : "Turn on 'Use Responses API' if the deployment serves only the Responses API."; return (error) => { if (!isDeploymentRejected(error)) return; throw new n8n_workflow_1.UserError(`Azure did not accept the deployment "${modelName}" on ${apiRequested}. Check the deployment name. ${remedy}`, { cause: error }); }; } //# sourceMappingURL=error-handling.js.map