Files
n8n/packages/nodes-base/nodes/MistralAI/GenericFunctions.ts
alighasami 3d5eaf9445
Some checks failed
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
first commit
2026-03-17 16:22:57 +03:30

63 lines
1.7 KiB
TypeScript

import type FormData from 'form-data';
import type {
IDataObject,
IExecuteFunctions,
IHttpRequestMethods,
IHttpRequestOptions,
JsonObject,
} from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
import type { Page } from './types';
export async function mistralApiRequest(
this: IExecuteFunctions,
method: IHttpRequestMethods,
resource: string,
body: IDataObject | FormData = {},
qs: IDataObject = {},
): Promise<any> {
const options: IHttpRequestOptions = {
method,
body,
qs,
url: `https://api.mistral.ai${resource}`,
json: true,
};
if (Object.keys(body).length === 0) {
delete options.body;
}
if (Object.keys(qs).length === 0) {
delete options.qs;
}
try {
return await this.helpers.httpRequestWithAuthentication.call(this, 'mistralCloudApi', options);
} catch (error) {
throw new NodeApiError(this.getNode(), error as JsonObject);
}
}
export async function encodeBinaryData(
this: IExecuteFunctions,
itemIndex: number,
): Promise<{ dataUrl: string; fileName: string | undefined }> {
const binaryProperty = this.getNodeParameter('binaryProperty', itemIndex);
const binaryData = this.helpers.assertBinaryData(itemIndex, binaryProperty);
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(itemIndex, binaryProperty);
const base64Data = binaryDataBuffer.toString('base64');
const dataUrl = `data:${binaryData.mimeType};base64,${base64Data}`;
return { dataUrl, fileName: binaryData.fileName };
}
export function processResponseData(response: IDataObject): IDataObject {
const pages = response.pages as Page[];
return {
...response,
extractedText: pages.map((page) => page.markdown).join('\n\n'),
pageCount: pages.length,
};
}