@flowfuse/nr-assistant
Advanced tools
Comparing version 0.1.1-cc561a2-202407081555.0 to 0.1.1
29
index.js
@@ -30,5 +30,5 @@ module.exports = (RED) => { | ||
RED.httpAdmin.post('/nr-assistant/:method', RED.auth.needsPermission('write'), function (req, res) { | ||
const method = req.params.method || 'fn' | ||
const method = req.params.method | ||
// limit method to prevent path traversal | ||
if (/[^a-zA-Z0-9-_]/.test(method)) { | ||
if (!method || typeof method !== 'string' || /[^a-z0-9-_]/.test(method)) { | ||
res.status(400) | ||
@@ -39,4 +39,3 @@ res.json({ status: 'error', message: 'Invalid method' }) | ||
const input = req.body | ||
const prompt = input.prompt | ||
if (!input.prompt) { | ||
if (!input || !input.prompt || typeof input.prompt !== 'string') { | ||
res.status(400) | ||
@@ -47,3 +46,3 @@ res.json({ status: 'error', message: 'prompt is required' }) | ||
const body = { | ||
prompt, // this is the prompt to the AI | ||
prompt: input.prompt, // this is the prompt to the AI | ||
promptHint: input.promptHint, // this is used to let the AI know what we are generating (`function node? Node JavaScript? flow?) | ||
@@ -70,7 +69,19 @@ context: input.context, // this is used to provide additional context to the AI (e.g. the selected text of the function node) | ||
}).catch((error) => { | ||
const errorData = { status: 'error', message: 'Request to FlowFuse Assistant was unsuccessful', body: error.response?.body } | ||
let body = error.response?.body | ||
if (typeof body === 'string') { | ||
try { | ||
body = JSON.parse(body) | ||
} catch (e) { | ||
// ignore | ||
} | ||
} | ||
let message = 'FlowFuse Assistant request was unsuccessful' | ||
const errorData = { status: 'error', message, body } | ||
const errorCode = error.response?.statusCode || 500 | ||
res.status(errorCode).json({ status: 'error', message: errorData }) | ||
console.warn('nr-assistant error:', error) | ||
RED.log.warn('FlowFuse Assistant request was unsuccessful') | ||
res.status(errorCode).json(errorData) | ||
RED.log.trace('nr-assistant error:', error) | ||
if (body && typeof body === 'object' && body.error) { | ||
message = `${message}: ${body.error}` | ||
} | ||
RED.log.warn(message) | ||
}) | ||
@@ -77,0 +88,0 @@ }) |
{ | ||
"name": "@flowfuse/nr-assistant", | ||
"version": "0.1.1-cc561a2-202407081555.0", | ||
"version": "0.1.1", | ||
"description": "FlowFuse Node-RED assistant plugin", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -28,3 +28,3 @@ # FlowFuse Node-RED Assistant | ||
"assistant": { | ||
"enabled": true | ||
"enabled": true, | ||
"url": "https://", // URL of the AI service | ||
@@ -31,0 +31,0 @@ "token": "", // API token for the AI service |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64641
11
84