@flowfuse/nr-assistant 0.1.2-91d5229-202407160719.0 → 0.1.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.
Files changed (3) hide show
  1. package/index.html +37 -0
  2. package/index.js +16 -4
  3. package/package.json +1 -1
package/index.html CHANGED
@@ -360,6 +360,7 @@
360
360
  toolbarMenuButtonAnchor.css('mask-repeat', 'no-repeat')
361
361
  toolbarMenuButtonAnchor.css('mask-position', 'center')
362
362
  toolbarMenuButtonAnchor.css('background-color', 'currentColor')
363
+ toolbarMenuButtonAnchor.css('height', '28px') // for backwards compatibility with <= NR3.x inline-block toolbar styling
363
364
  const deployButtonLi = $('#red-ui-header-button-deploy').closest('li')
364
365
  if (deployButtonLi.length) {
365
366
  deployButtonLi.before(toolbarMenuButton) // add the button before the deploy button
@@ -739,6 +740,42 @@
739
740
 
740
741
  function processAIErrorResponse (jqXHR, textStatus, errorThrown) {
741
742
  console.warn('error', jqXHR, textStatus, errorThrown)
743
+ if (jqXHR.status === 429) {
744
+ // get x- rate limit reset header
745
+ const reset = jqXHR.getResponseHeader('x-ratelimit-reset')
746
+ if (reset) {
747
+ const resetTime = new Date(reset * 1000)
748
+ const now = new Date()
749
+ const diff = resetTime - now
750
+ const seconds = Math.floor(diff / 1000)
751
+ const minutes = Math.floor(seconds / 60)
752
+ const remainingSeconds = seconds % 60
753
+ if (minutes > 0) {
754
+ RED.notify(`Sorry, the FlowFuse Assistant is busy. Please try again in ${minutes} minute${minutes > 1 ? 's' : ''}.`, 'warning')
755
+ } else {
756
+ RED.notify(`Sorry, the FlowFuse Assistant is busy. Please try again in ${remainingSeconds} second${remainingSeconds > 1 ? 's' : ''}.`, 'warning')
757
+ }
758
+ return
759
+ }
760
+ RED.notify('Sorry, the FlowFuse Assistant is busy. Please try again later.', 'warning')
761
+ return
762
+ }
763
+ if (jqXHR.status === 404) {
764
+ RED.notify('Sorry, the FlowFuse Assistant is not available at the moment', 'warning')
765
+ return
766
+ }
767
+ if (jqXHR.status === 401) {
768
+ RED.notify('Sorry, you are not authorised to use the FlowFuse Assistant', 'warning')
769
+ return
770
+ }
771
+ if (jqXHR.status >= 400 && jqXHR.status < 500) {
772
+ let message = 'Sorry, the FlowFuse Assistant cannot help with this request'
773
+ if (jqXHR.responseJSON?.body?.code === 'assistant_service_denied' && jqXHR.responseJSON?.body?.error) {
774
+ message = jqXHR.responseJSON.body.error
775
+ }
776
+ RED.notify(message, 'warning')
777
+ return
778
+ }
742
779
  RED.notify('Sorry, something went wrong, please try again', 'error')
743
780
  }
744
781
 
package/index.js CHANGED
@@ -63,11 +63,23 @@ module.exports = (RED) => {
63
63
  data
64
64
  })
65
65
  }).catch((error) => {
66
- const errorData = { status: 'error', message: 'Request to FlowFuse Assistant was unsuccessful', body: error.response?.body }
66
+ let body = error.response?.body
67
+ if (typeof body === 'string') {
68
+ try {
69
+ body = JSON.parse(body)
70
+ } catch (e) {
71
+ // ignore
72
+ }
73
+ }
74
+ let message = 'FlowFuse Assistant request was unsuccessful'
75
+ const errorData = { status: 'error', message, body }
67
76
  const errorCode = error.response?.statusCode || 500
68
- res.status(errorCode).json({ status: 'error', message: errorData })
69
- console.warn('nr-assistant error:', error)
70
- RED.log.warn('FlowFuse Assistant request was unsuccessful')
77
+ res.status(errorCode).json(errorData)
78
+ RED.log.trace('nr-assistant error:', error)
79
+ if (body && typeof body === 'object' && body.error) {
80
+ message = `${message}: ${body.error}`
81
+ }
82
+ RED.log.warn(message)
71
83
  })
72
84
  })
73
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowfuse/nr-assistant",
3
- "version": "0.1.2-91d5229-202407160719.0",
3
+ "version": "0.1.2",
4
4
  "description": "FlowFuse Node-RED assistant plugin",
5
5
  "main": "index.js",
6
6
  "scripts": {