UNPKG

n8n-nodes-wxai

Version:

A user-friendly WXAI node for n8n, designed to enhance your workflow with Gemini 2.0 Flash model. Supports chat completions with configurable parameters.

34 lines (33 loc) 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sendErrorPostReceive = void 0; const n8n_workflow_1 = require("n8n-workflow"); async function sendErrorPostReceive(data, response) { if (String(response.statusCode).startsWith('4') || String(response.statusCode).startsWith('5')) { throw new n8n_workflow_1.NodeApiError(this.getNode(), response); } // Handle SSE format response from WXAI const contentType = response.headers['content-type']; if (typeof contentType === 'string' && contentType.includes('text/event-stream')) { const body = response.body; const lines = body.split('\n'); for (const line of lines) { if (line.startsWith('data:')) { try { const jsonData = line.substring(5).trim(); if (jsonData && jsonData !== '[DONE]') { const parsedData = JSON.parse(jsonData); // Replace the response body with parsed JSON response.body = parsedData; break; } } catch (error) { // Continue if JSON parsing fails } } } } return data; } exports.sendErrorPostReceive = sendErrorPostReceive;