n8n-nodes-berget-mk 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -112,7 +112,6 @@ exports.chatProperties = [
112
112
  },
113
113
  ];
114
114
  async function executeChat(context, itemIndex) {
115
- var _a, _b;
116
115
  const credentials = await context.getCredentials('bergetAiApi');
117
116
  const model = context.getNodeParameter('chatModel', itemIndex);
118
117
  const messages = context.getNodeParameter('chatMessages.values', itemIndex, []);
@@ -130,10 +129,7 @@ async function executeChat(context, itemIndex) {
130
129
  }
131
130
  const { status, data } = await (0, shared_1.bergetRequest)(credentials.apiKey, 'POST', '/chat/completions', body);
132
131
  if (status !== 200) {
133
- const message = (_b = (_a = data === null || data === void 0 ? void 0 : data.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : `HTTP ${status}`;
134
- throw new n8n_workflow_1.NodeOperationError(context.getNode(), `Berget AI chat error: ${message}`, {
135
- itemIndex,
136
- });
132
+ throw new n8n_workflow_1.NodeOperationError(context.getNode(), (0, shared_1.formatBergetError)('chat', status, data), { itemIndex });
137
133
  }
138
134
  return data;
139
135
  }
@@ -30,7 +30,7 @@ exports.ocrProperties = [
30
30
  type: 'string',
31
31
  default: '',
32
32
  required: true,
33
- description: 'URL of the document to process',
33
+ description: "URL of the document to process. Note: Berget AI's server fetches this URL directly, so it must be reachable from Berget's infrastructure (not just from your n8n host). Use public URLs.",
34
34
  displayOptions: {
35
35
  show: {
36
36
  resource: ['ocr'],
@@ -143,7 +143,7 @@ exports.ocrProperties = [
143
143
  },
144
144
  ];
145
145
  async function executeOcr(context, itemIndex) {
146
- var _a, _b, _c, _d, _e, _f, _g;
146
+ var _a, _b, _c, _d, _e;
147
147
  const credentials = await context.getCredentials('bergetAiApi');
148
148
  const documentType = context.getNodeParameter('ocrDocumentType', itemIndex);
149
149
  const asyncMode = context.getNodeParameter('ocrAsync', itemIndex);
@@ -189,8 +189,5 @@ async function executeOcr(context, itemIndex) {
189
189
  message: 'Document processing started. Use the taskId to check status.',
190
190
  };
191
191
  }
192
- const message = (_g = (_f = data === null || data === void 0 ? void 0 : data.error) === null || _f === void 0 ? void 0 : _f.message) !== null && _g !== void 0 ? _g : `HTTP ${status}`;
193
- throw new n8n_workflow_1.NodeOperationError(context.getNode(), `Berget AI OCR error: ${message}`, {
194
- itemIndex,
195
- });
192
+ throw new n8n_workflow_1.NodeOperationError(context.getNode(), (0, shared_1.formatBergetError)('OCR', status, data), { itemIndex });
196
193
  }
@@ -86,7 +86,6 @@ exports.rerankProperties = [
86
86
  },
87
87
  ];
88
88
  async function executeRerank(context, itemIndex) {
89
- var _a, _b;
90
89
  const credentials = await context.getCredentials('bergetAiApi');
91
90
  const model = context.getNodeParameter('rerankModel', itemIndex);
92
91
  const query = context.getNodeParameter('rerankQuery', itemIndex);
@@ -99,10 +98,7 @@ async function executeRerank(context, itemIndex) {
99
98
  ...options,
100
99
  });
101
100
  if (status !== 200) {
102
- const message = (_b = (_a = data === null || data === void 0 ? void 0 : data.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : `HTTP ${status}`;
103
- throw new n8n_workflow_1.NodeOperationError(context.getNode(), `Berget AI rerank error: ${message}`, {
104
- itemIndex,
105
- });
101
+ throw new n8n_workflow_1.NodeOperationError(context.getNode(), (0, shared_1.formatBergetError)('rerank', status, data), { itemIndex });
106
102
  }
107
103
  return data;
108
104
  }
@@ -15,3 +15,11 @@ export declare function bergetRequest(apiKey: string, method: 'GET' | 'POST', pa
15
15
  status: number;
16
16
  data: unknown;
17
17
  }>;
18
+ /**
19
+ * Format a Berget API error response into a human-readable string.
20
+ *
21
+ * Berget's API returns errors in multiple shapes across endpoints, so we
22
+ * handle each possibility defensively. Always includes HTTP status code,
23
+ * and surfaces error code + details when the API provides them.
24
+ */
25
+ export declare function formatBergetError(resourceLabel: string, status: number, data: unknown): string;
@@ -7,6 +7,7 @@ exports.BERGET_API_BASE_URL = void 0;
7
7
  exports.fetchBergetModels = fetchBergetModels;
8
8
  exports.loadModelOptions = loadModelOptions;
9
9
  exports.bergetRequest = bergetRequest;
10
+ exports.formatBergetError = formatBergetError;
10
11
  const axios_1 = __importDefault(require("axios"));
11
12
  exports.BERGET_API_BASE_URL = 'https://api.berget.ai/v1';
12
13
  async function fetchBergetModels(context) {
@@ -44,3 +45,57 @@ async function bergetRequest(apiKey, method, path, body, extraHeaders) {
44
45
  });
45
46
  return { status: response.status, data: response.data };
46
47
  }
48
+ /**
49
+ * Format a Berget API error response into a human-readable string.
50
+ *
51
+ * Berget's API returns errors in multiple shapes across endpoints, so we
52
+ * handle each possibility defensively. Always includes HTTP status code,
53
+ * and surfaces error code + details when the API provides them.
54
+ */
55
+ function formatBergetError(resourceLabel, status, data) {
56
+ const parts = [`Berget AI ${resourceLabel} error (HTTP ${status})`];
57
+ if (data && typeof data === 'object') {
58
+ const d = data;
59
+ // Shape A (OpenAPI-documented): { error: "message string", code: "...", details: ... }
60
+ // Shape B (OpenAI-compatible): { error: { message: "...", type: "...", code: "..." } }
61
+ // Shape C (some endpoints): { message: "..." }
62
+ // Shape D (bare string on some): "error text"
63
+ let messageText;
64
+ let code;
65
+ let details;
66
+ const err = d.error;
67
+ if (typeof err === 'string') {
68
+ messageText = err;
69
+ code = typeof d.code === 'string' ? d.code : undefined;
70
+ details = d.details;
71
+ }
72
+ else if (err && typeof err === 'object') {
73
+ const eo = err;
74
+ if (typeof eo.message === 'string')
75
+ messageText = eo.message;
76
+ if (typeof eo.code === 'string')
77
+ code = eo.code;
78
+ if (eo.type && typeof eo.type === 'string' && !code)
79
+ code = eo.type;
80
+ if (eo.details !== undefined)
81
+ details = eo.details;
82
+ }
83
+ else if (typeof d.message === 'string') {
84
+ messageText = d.message;
85
+ }
86
+ if (messageText)
87
+ parts.push(messageText);
88
+ if (code)
89
+ parts.push(`code: ${code}`);
90
+ if (details !== undefined) {
91
+ const detailsStr = typeof details === 'string' ? details : JSON.stringify(details);
92
+ if (detailsStr && detailsStr !== '{}' && detailsStr !== 'null') {
93
+ parts.push(`details: ${detailsStr}`);
94
+ }
95
+ }
96
+ }
97
+ else if (typeof data === 'string' && data.trim().length > 0) {
98
+ parts.push(data.trim().slice(0, 500));
99
+ }
100
+ return parts.join(' — ');
101
+ }
@@ -76,7 +76,7 @@ exports.speechProperties = [
76
76
  },
77
77
  ];
78
78
  async function executeSpeech(context, itemIndex) {
79
- var _a, _b, _c, _d, _e;
79
+ var _a, _b;
80
80
  const credentials = await context.getCredentials('bergetAiApi');
81
81
  const model = context.getNodeParameter('speechModel', itemIndex);
82
82
  const binaryPropertyName = context.getNodeParameter('speechBinaryProperty', itemIndex);
@@ -107,10 +107,7 @@ async function executeSpeech(context, itemIndex) {
107
107
  maxBodyLength: Infinity,
108
108
  });
109
109
  if (response.status !== 200) {
110
- const message = (_e = (_d = (_c = response.data) === null || _c === void 0 ? void 0 : _c.error) === null || _d === void 0 ? void 0 : _d.message) !== null && _e !== void 0 ? _e : `HTTP ${response.status}`;
111
- throw new n8n_workflow_1.NodeOperationError(context.getNode(), `Berget AI speech error: ${message}`, {
112
- itemIndex,
113
- });
110
+ throw new n8n_workflow_1.NodeOperationError(context.getNode(), (0, shared_1.formatBergetError)('speech', response.status, response.data), { itemIndex });
114
111
  }
115
112
  return response.data;
116
113
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-berget-mk",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "n8n community node for Berget AI. Multi-resource action node (chat, OCR, rerank, speech-to-text) plus Chat Model and Embeddings Model sub-nodes that plug into n8n's built-in AI Agent and Vector Store nodes.",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",