From d5098a03d062cc1856bdbf456561518f982ca511 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Tue, 2 Jul 2024 16:15:01 +0100 Subject: [PATCH 1/5] include nr-assistant in nodesdir --- lib/launcher.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/launcher.js b/lib/launcher.js index 86c492d..04e192f 100644 --- a/lib/launcher.js +++ b/lib/launcher.js @@ -142,6 +142,8 @@ class Launcher { nodesDir.push(path.join(require.main.path, '..', '..', '@flowfuse', 'nr-project-nodes').replace(/\\/g, '/')) nodesDir.push(path.join(require.main.path, 'node_modules', '@flowfuse', 'nr-file-nodes').replace(/\\/g, '/')) nodesDir.push(path.join(require.main.path, '..', '..', '@flowfuse', 'nr-file-nodes').replace(/\\/g, '/')) + nodesDir.push(path.join(require.main.path, 'node_modules', '@flowfuse', 'nr-assistant').replace(/\\/g, '/')) + nodesDir.push(path.join(require.main.path, '..', '..', '@flowfuse', 'nr-assistant').replace(/\\/g, '/')) nodesDir.push(require.main.path) this.settings.nodesDir = nodesDir From 82e9d3e26095a8857159a8a4c74255176477104f Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Tue, 2 Jul 2024 16:16:22 +0100 Subject: [PATCH 2/5] pass assistant runtime settings through --- lib/runtimeSettings.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/runtimeSettings.js b/lib/runtimeSettings.js index 976336c..95a2002 100644 --- a/lib/runtimeSettings.js +++ b/lib/runtimeSettings.js @@ -24,6 +24,7 @@ function getSettingsFile (settings) { }, fileStore: null, projectLink: null, + assistant: null, httpNodeAuth: '', setupAuthMiddleware: '', httpNodeMiddleware: '', @@ -144,6 +145,17 @@ function getSettingsFile (settings) { projectSettings.projectLink.useSharedSubscriptions = true } } + + if (settings.assistant) { + // Enable the nr-assistant nodes when configured + projectSettings.assistant = { + enabled: settings.assistant.enabled, // overall enable/disable + url: `${settings.forgeURL}/api/v1/assistant/`, // URL for the assistant service + token: settings.projectToken, + requestTimeout: settings.requestTimeout || 60000 // timeout for assistant requests + } + } + let contextStorage = '' if (settings.fileStore?.url) { // file nodes settings @@ -327,7 +339,8 @@ module.exports = { projectID: '${settings.projectID}', launcherVersion: '${settings.launcherVersion}', ${projectSettings.fileStore ? 'fileStore: ' + JSON.stringify(projectSettings.fileStore) + ',' : ''} - ${projectSettings.projectLink ? 'projectLink: ' + JSON.stringify(projectSettings.projectLink) : ''} + ${projectSettings.projectLink ? 'projectLink: ' + JSON.stringify(projectSettings.projectLink) + ',' : ''} + ${projectSettings.assistant ? 'assistant: ' + JSON.stringify(projectSettings.assistant) : ''} }, runtimeState: { enabled: true, From 4cf61ce926383e05409582c28824b4e8d7502ee7 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Wed, 3 Jul 2024 12:47:10 +0100 Subject: [PATCH 3/5] add unit test --- test/unit/lib/runtimeSettings_spec.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/unit/lib/runtimeSettings_spec.js b/test/unit/lib/runtimeSettings_spec.js index 1c3da5f..dc3e7cf 100644 --- a/test/unit/lib/runtimeSettings_spec.js +++ b/test/unit/lib/runtimeSettings_spec.js @@ -390,4 +390,28 @@ describe('Runtime Settings', function () { settings.editorTheme.palette.catalogues.should.have.length(1) settings.editorTheme.palette.catalogues[0].should.not.eql('foo') // will be NR default catalogue }) + it('includes assistant settings when enabled', async function () { + const result = runtimeSettings.getSettingsFile({ + settings: { + palette: { + catalogue: ['foo', 'bar', 'baz'] + }, + assistant: { + enabled: true, + service: { + url: 'http://localhost:9876', + token: 'blah', + requestTimeout: 60000 + } + } + } + }) + const settings = await loadSettings(result) + settings.should.have.property('flowforge').and.be.an.Object() + settings.flowforge.should.have.property('assistant') + settings.flowforge.projectLink.should.have.property('enabled', true) + settings.flowforge.projectLink.should.have.property('url', 'http://localhost:9876') + settings.flowforge.projectLink.should.have.property('token', 'blah') + settings.flowforge.projectLink.should.have.property('requestTimeout', 60000) + }) }) From 0963c0d7cff3388bd204d1401eacd714bd3094f7 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Wed, 3 Jul 2024 13:32:23 +0100 Subject: [PATCH 4/5] fix new test --- lib/runtimeSettings.js | 2 +- test/unit/lib/runtimeSettings_spec.js | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/runtimeSettings.js b/lib/runtimeSettings.js index 9dee1d3..f1a537d 100644 --- a/lib/runtimeSettings.js +++ b/lib/runtimeSettings.js @@ -152,7 +152,7 @@ function getSettingsFile (settings) { enabled: settings.assistant.enabled, // overall enable/disable url: `${settings.forgeURL}/api/v1/assistant/`, // URL for the assistant service token: settings.projectToken, - requestTimeout: settings.requestTimeout || 60000 // timeout for assistant requests + requestTimeout: settings.assistant.requestTimeout || 60000 // timeout for assistant requests } } diff --git a/test/unit/lib/runtimeSettings_spec.js b/test/unit/lib/runtimeSettings_spec.js index 6f785a7..ead3ea4 100644 --- a/test/unit/lib/runtimeSettings_spec.js +++ b/test/unit/lib/runtimeSettings_spec.js @@ -411,26 +411,25 @@ describe('Runtime Settings', function () { }) it('includes assistant settings when enabled', async function () { const result = runtimeSettings.getSettingsFile({ + baseURL: 'https://BASEURL', + forgeURL: 'https://FORGEURL', + projectToken: 'ffxxx_1234567890', settings: { palette: { catalogue: ['foo', 'bar', 'baz'] - }, - assistant: { - enabled: true, - service: { - url: 'http://localhost:9876', - token: 'blah', - requestTimeout: 60000 - } } + }, + assistant: { + enabled: true, + requestTimeout: 12345 } }) const settings = await loadSettings(result) settings.should.have.property('flowforge').and.be.an.Object() settings.flowforge.should.have.property('assistant') - settings.flowforge.projectLink.should.have.property('enabled', true) - settings.flowforge.projectLink.should.have.property('url', 'http://localhost:9876') - settings.flowforge.projectLink.should.have.property('token', 'blah') - settings.flowforge.projectLink.should.have.property('requestTimeout', 60000) + settings.flowforge.assistant.should.have.property('enabled', true) + settings.flowforge.assistant.should.have.property('url', 'https://FORGEURL/api/v1/assistant/') + settings.flowforge.assistant.should.have.property('token', 'ffxxx_1234567890') + settings.flowforge.assistant.should.have.property('requestTimeout', 12345) }) }) From b0193243e8ab98a1034c60a02adeb2da92eed605 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Wed, 3 Jul 2024 17:02:54 +0100 Subject: [PATCH 5/5] add nr-assistant to package --- package-lock.json | 30 ++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 31 insertions(+) diff --git a/package-lock.json b/package-lock.json index aa1185f..dc97c5b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "2.5.1", "license": "Apache-2.0", "dependencies": { + "@flowfuse/nr-assistant": "^0.1.0", "@flowfuse/nr-file-nodes": "^0.0.5", "@flowfuse/nr-project-nodes": "^0.6.2", "@node-red/util": "^3.1.0", @@ -43,6 +44,24 @@ "yaml": "^2.1.3" } }, + "../../../nr-assistant": { + "name": "@flowfuse/nr-assistant", + "version": "0.1.0", + "extraneous": true, + "license": "Apache-2.0", + "dependencies": { + "got": "^11.8.6" + }, + "devDependencies": { + "eslint": "^8.48.0", + "eslint-config-standard": "^17.1.0", + "eslint-plugin-html": "7.1.0", + "eslint-plugin-no-only-tests": "^3.1.0" + }, + "engines": { + "node": ">=16.x" + } + }, "node_modules/@aashutoshrathi/word-wrap": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", @@ -1031,6 +1050,17 @@ "node": ">=10" } }, + "node_modules/@flowfuse/nr-assistant": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@flowfuse/nr-assistant/-/nr-assistant-0.1.0.tgz", + "integrity": "sha512-ZzyQS2U7B7Td29j3AEjnw4UQ9UdUwI1McwiIvl8pucZeFJJX67YLIMCtaN97vqXYgIMSr6+H2Uz00e6t/bX1Qw==", + "dependencies": { + "got": "^11.8.6" + }, + "engines": { + "node": ">=16.x" + } + }, "node_modules/@flowfuse/nr-file-nodes": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/@flowfuse/nr-file-nodes/-/nr-file-nodes-0.0.5.tgz", diff --git a/package.json b/package.json index 6e35476..18f055c 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ }, "homepage": "https://github.com/FlowFuse/nr-launcher#readme", "dependencies": { + "@flowfuse/nr-assistant": "^0.1.0", "@flowfuse/nr-file-nodes": "^0.0.5", "@flowfuse/nr-project-nodes": "^0.6.2", "@node-red/util": "^3.1.0",