Skip to content

Commit

Permalink
Merge pull request #256 from FlowFuse/255-nr-assistant-settings
Browse files Browse the repository at this point in the history
Map runtime settings for nr-assistant
  • Loading branch information
Steve-Mcl authored Jul 3, 2024
2 parents 41924f9 + b019324 commit b205186
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion lib/runtimeSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function getSettingsFile (settings) {
},
fileStore: null,
projectLink: null,
assistant: null,
httpNodeAuth: '',
setupAuthMiddleware: '',
httpNodeMiddleware: '',
Expand Down Expand Up @@ -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.assistant.requestTimeout || 60000 // timeout for assistant requests
}
}

let contextStorage = ''
if (settings.fileStore?.url) {
// file nodes settings
Expand Down Expand Up @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 23 additions & 0 deletions test/unit/lib/runtimeSettings_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,4 +409,27 @@ 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({
baseURL: 'https://BASEURL',
forgeURL: 'https://FORGEURL',
projectToken: 'ffxxx_1234567890',
settings: {
palette: {
catalogue: ['foo', 'bar', 'baz']
}
},
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.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)
})
})

0 comments on commit b205186

Please sign in to comment.