@red-hat-developer-hub/backstage-plugin-lightspeed 0.2.4 → 0.3.0

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 (34) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/config.d.ts +2 -1
  3. package/dist/api/LightspeedApiClient.esm.js.map +1 -1
  4. package/dist/api/api.esm.js.map +1 -1
  5. package/dist/components/DeleteModal.esm.js.map +1 -1
  6. package/dist/components/LightSpeedChat.esm.js +39 -28
  7. package/dist/components/LightSpeedChat.esm.js.map +1 -1
  8. package/dist/components/LightspeedChatBox.esm.js +6 -2
  9. package/dist/components/LightspeedChatBox.esm.js.map +1 -1
  10. package/dist/components/LightspeedChatBoxHeader.esm.js +2 -2
  11. package/dist/components/LightspeedChatBoxHeader.esm.js.map +1 -1
  12. package/dist/components/LightspeedIcon.esm.js.map +1 -1
  13. package/dist/components/LightspeedPage.esm.js.map +1 -1
  14. package/dist/components/PermissionRequiredIcon.esm.js.map +1 -1
  15. package/dist/components/PermissionRequiredState.esm.js +1 -1
  16. package/dist/components/PermissionRequiredState.esm.js.map +1 -1
  17. package/dist/hooks/useAllModels.esm.js.map +1 -1
  18. package/dist/hooks/useBackstageUserIdentity.esm.js.map +1 -1
  19. package/dist/hooks/useConversationMessages.esm.js +3 -2
  20. package/dist/hooks/useConversationMessages.esm.js.map +1 -1
  21. package/dist/hooks/useConversations.esm.js.map +1 -1
  22. package/dist/hooks/useCreateConversation.esm.js.map +1 -1
  23. package/dist/hooks/useCreateCoversationMessage.esm.js.map +1 -1
  24. package/dist/hooks/useDeleteConversation.esm.js.map +1 -1
  25. package/dist/hooks/useLastOpenedConversation.esm.js +51 -0
  26. package/dist/hooks/useLastOpenedConversation.esm.js.map +1 -0
  27. package/dist/hooks/useLightspeedDeletePermission.esm.js.map +1 -1
  28. package/dist/hooks/useLightspeedViewPermission.esm.js.map +1 -1
  29. package/dist/plugin.esm.js +2 -2
  30. package/dist/plugin.esm.js.map +1 -1
  31. package/dist/routes.esm.js.map +1 -1
  32. package/dist/utils/lightspeed-chatbox-utils.esm.js.map +1 -1
  33. package/dist/utils/queryClient.esm.js.map +1 -1
  34. package/package.json +21 -14
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  ## @red-hat-developer-hub/backstage-plugin-lightspeed
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - e41a860: Backstage version bump to v1.34.2
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [e41a860]
12
+ - @red-hat-developer-hub/backstage-plugin-lightspeed-common@0.2.0
13
+
14
+ ## 0.2.5
15
+
16
+ ### Patch Changes
17
+
18
+ - 7b21401: Upgrade to latest PF chatbot version
19
+ - 9556c86: Persist last conversation state and reload on user revisit
20
+ - 18547a0: Updated dependency `msw` to `1.3.5`.
21
+ - d59e940: Updated dependency `prettier` to `3.4.2`.
22
+ - Updated dependencies [d59e940]
23
+ - @red-hat-developer-hub/backstage-plugin-lightspeed-common@0.1.3
24
+
3
25
  ## 0.2.4
4
26
 
5
27
  ### Patch Changes
package/config.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright 2024 The Backstage Authors
2
+ * Copyright Red Hat, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+
16
17
  export interface Config {
17
18
  /**
18
19
  * Configuration required for using lightspeed
@@ -1 +1 @@
1
- {"version":3,"file":"LightspeedApiClient.esm.js","sources":["../../src/api/LightspeedApiClient.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { ConfigApi, FetchApi } from '@backstage/core-plugin-api';\n\nimport { LightspeedAPI } from './api';\n\nexport type Options = {\n configApi: ConfigApi;\n fetchApi: FetchApi;\n};\n\nexport class LightspeedApiClient implements LightspeedAPI {\n private readonly configApi: ConfigApi;\n private readonly fetchApi: FetchApi;\n\n constructor(options: Options) {\n this.configApi = options.configApi;\n this.fetchApi = options.fetchApi;\n }\n\n async getBaseUrl() {\n return `${this.configApi.getString('backend.baseUrl')}/api/lightspeed`;\n }\n\n getServerUrl() {\n // Currently supports a single llm server\n return `${this.configApi\n .getConfigArray('lightspeed.servers')[0]\n .getOptionalString('url')}`;\n }\n\n async createMessage(\n prompt: string,\n selectedModel: string,\n conversation_id: string,\n ) {\n const baseUrl = await this.getBaseUrl();\n\n const response = await this.fetchApi.fetch(`${baseUrl}/v1/query`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n conversation_id,\n serverURL: this.getServerUrl(),\n model: selectedModel,\n query: prompt,\n historyLength: 10,\n }),\n });\n\n if (!response.body) {\n throw new Error('Readable stream is not supported or there is no body.');\n }\n\n if (!response.ok) {\n throw new Error(\n `failed to fetch data, status ${response.status}: ${response.statusText}`,\n );\n }\n return response.body.getReader();\n }\n\n private async fetcher(url: string) {\n const response = await this.fetchApi.fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n if (!response.ok) {\n throw new Error(\n `failed to fetch data, status ${response.status}: ${response.statusText}`,\n );\n }\n return response;\n }\n\n async getAllModels() {\n const baseUrl = await this.getBaseUrl();\n const result = await this.fetcher(`${baseUrl}/v1/models`);\n const response = await result.json();\n return response?.data ? response.data : [];\n }\n\n async getConversationMessages(conversation_id: string) {\n const baseUrl = await this.getBaseUrl();\n const result = await this.fetcher(\n `${baseUrl}/conversations/${encodeURIComponent(conversation_id)}`,\n );\n return await result.json();\n }\n\n async getConversations() {\n const baseUrl = await this.getBaseUrl();\n const result = await this.fetcher(`${baseUrl}/conversations`);\n return await result.json();\n }\n\n async createConversation() {\n const baseUrl = await this.getBaseUrl();\n\n const response = await this.fetchApi.fetch(`${baseUrl}/conversations`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({}),\n });\n\n if (!response.body) {\n throw new Error('Something went wrong.');\n }\n\n if (!response.ok) {\n throw new Error(\n `failed to create conversation, status ${response.status}: ${response.statusText}`,\n );\n }\n return await response.json();\n }\n\n async deleteConversation(conversation_id: string) {\n const baseUrl = await this.getBaseUrl();\n\n const response = await this.fetchApi.fetch(\n `${baseUrl}/conversations/${encodeURIComponent(conversation_id)}`,\n {\n method: 'DELETE',\n headers: {},\n },\n );\n\n if (!response.ok) {\n throw new Error(\n `failed to delete conversation, status ${response.status}: ${response.statusText}`,\n );\n }\n return { success: true };\n }\n}\n"],"names":[],"mappings":"AAwBO,MAAM,mBAA6C,CAAA;AAAA,EACvC,SAAA;AAAA,EACA,QAAA;AAAA,EAEjB,YAAY,OAAkB,EAAA;AAC5B,IAAA,IAAA,CAAK,YAAY,OAAQ,CAAA,SAAA;AACzB,IAAA,IAAA,CAAK,WAAW,OAAQ,CAAA,QAAA;AAAA;AAC1B,EAEA,MAAM,UAAa,GAAA;AACjB,IAAA,OAAO,CAAG,EAAA,IAAA,CAAK,SAAU,CAAA,SAAA,CAAU,iBAAiB,CAAC,CAAA,eAAA,CAAA;AAAA;AACvD,EAEA,YAAe,GAAA;AAEb,IAAO,OAAA,CAAA,EAAG,IAAK,CAAA,SAAA,CACZ,cAAe,CAAA,oBAAoB,EAAE,CAAC,CAAA,CACtC,iBAAkB,CAAA,KAAK,CAAC,CAAA,CAAA;AAAA;AAC7B,EAEA,MAAM,aAAA,CACJ,MACA,EAAA,aAAA,EACA,eACA,EAAA;AACA,IAAM,MAAA,OAAA,GAA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A;AAGzC,IAAI,IAAA,CAAC,SAAS,EAAI,EAAA;AAChB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAyC,sCAAA,EAAA,QAAA,CAAS,MAAM,CAAA,EAAA,EAAK,SAAS,UAAU,CAAA;AAAA,OAClF;AAAA;AAEF,IAAO,OAAA,MAAM,SAAS,IAAK,EAAA;AAAA;AAC7B,EAEA,MAAM,mBAAmB,eAAyB,EAAA;AAChD,IAAM,MAAA,OAAA,GAAU,MAAM,IAAA,CAAK,UAAW,EAAA;AAEtC,IAAM,MAAA,QAAA,GAAW,MAAM,IAAA,CAAK,QAAS,CAAA,KAAA;AAAA,MACnC,CAAG,EAAA,OAAO,CAAkB,eAAA,EAAA,kBAAA,CAAmB,eAAe,CAAC,CAAA,CAAA;AAAA,MAC/D;AAAA,QACE,MAAQ,EAAA,QAAA;AAAA,QACR,SAAS;AAAC;AACZ,KACF;AAEA,IAAI,IAAA,CAAC,SAAS,EAAI,EAAA;AAChB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAyC,sCAAA,EAAA,QAAA,CAAS,MAAM,CAAA,EAAA,EAAK,SAAS,UAAU,CAAA;AAAA,OAClF;AAAA;AAEF,IAAO,OAAA,EAAE,SAAS,IAAK,EAAA;AAAA;AAE3B;;;;"}
1
+ {"version":3,"file":"LightspeedApiClient.esm.js","sources":["../../src/api/LightspeedApiClient.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ConfigApi, FetchApi } from '@backstage/core-plugin-api';\n\nimport { LightspeedAPI } from './api';\n\nexport type Options = {\n configApi: ConfigApi;\n fetchApi: FetchApi;\n};\n\nexport class LightspeedApiClient implements LightspeedAPI {\n private readonly configApi: ConfigApi;\n private readonly fetchApi: FetchApi;\n\n constructor(options: Options) {\n this.configApi = options.configApi;\n this.fetchApi = options.fetchApi;\n }\n\n async getBaseUrl() {\n return `${this.configApi.getString('backend.baseUrl')}/api/lightspeed`;\n }\n\n getServerUrl() {\n // Currently supports a single llm server\n return `${this.configApi\n .getConfigArray('lightspeed.servers')[0]\n .getOptionalString('url')}`;\n }\n\n async createMessage(\n prompt: string,\n selectedModel: string,\n conversation_id: string,\n ) {\n const baseUrl = await this.getBaseUrl();\n\n const response = await this.fetchApi.fetch(`${baseUrl}/v1/query`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n conversation_id,\n serverURL: this.getServerUrl(),\n model: selectedModel,\n query: prompt,\n historyLength: 10,\n }),\n });\n\n if (!response.body) {\n throw new Error('Readable stream is not supported or there is no body.');\n }\n\n if (!response.ok) {\n throw new Error(\n `failed to fetch data, status ${response.status}: ${response.statusText}`,\n );\n }\n return response.body.getReader();\n }\n\n private async fetcher(url: string) {\n const response = await this.fetchApi.fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n if (!response.ok) {\n throw new Error(\n `failed to fetch data, status ${response.status}: ${response.statusText}`,\n );\n }\n return response;\n }\n\n async getAllModels() {\n const baseUrl = await this.getBaseUrl();\n const result = await this.fetcher(`${baseUrl}/v1/models`);\n const response = await result.json();\n return response?.data ? response.data : [];\n }\n\n async getConversationMessages(conversation_id: string) {\n const baseUrl = await this.getBaseUrl();\n const result = await this.fetcher(\n `${baseUrl}/conversations/${encodeURIComponent(conversation_id)}`,\n );\n return await result.json();\n }\n\n async getConversations() {\n const baseUrl = await this.getBaseUrl();\n const result = await this.fetcher(`${baseUrl}/conversations`);\n return await result.json();\n }\n\n async createConversation() {\n const baseUrl = await this.getBaseUrl();\n\n const response = await this.fetchApi.fetch(`${baseUrl}/conversations`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({}),\n });\n\n if (!response.body) {\n throw new Error('Something went wrong.');\n }\n\n if (!response.ok) {\n throw new Error(\n `failed to create conversation, status ${response.status}: ${response.statusText}`,\n );\n }\n return await response.json();\n }\n\n async deleteConversation(conversation_id: string) {\n const baseUrl = await this.getBaseUrl();\n\n const response = await this.fetchApi.fetch(\n `${baseUrl}/conversations/${encodeURIComponent(conversation_id)}`,\n {\n method: 'DELETE',\n headers: {},\n },\n );\n\n if (!response.ok) {\n throw new Error(\n `failed to delete conversation, status ${response.status}: ${response.statusText}`,\n );\n }\n return { success: true };\n }\n}\n"],"names":[],"mappings":"AAyBO,MAAM,mBAA6C,CAAA;AAAA,EACvC,SAAA;AAAA,EACA,QAAA;AAAA,EAEjB,YAAY,OAAkB,EAAA;AAC5B,IAAA,IAAA,CAAK,YAAY,OAAQ,CAAA,SAAA;AACzB,IAAA,IAAA,CAAK,WAAW,OAAQ,CAAA,QAAA;AAAA;AAC1B,EAEA,MAAM,UAAa,GAAA;AACjB,IAAA,OAAO,CAAG,EAAA,IAAA,CAAK,SAAU,CAAA,SAAA,CAAU,iBAAiB,CAAC,CAAA,eAAA,CAAA;AAAA;AACvD,EAEA,YAAe,GAAA;AAEb,IAAO,OAAA,CAAA,EAAG,IAAK,CAAA,SAAA,CACZ,cAAe,CAAA,oBAAoB,EAAE,CAAC,CAAA,CACtC,iBAAkB,CAAA,KAAK,CAAC,CAAA,CAAA;AAAA;AAC7B,EAEA,MAAM,aAAA,CACJ,MACA,EAAA,aAAA,EACA,eACA,EAAA;AACA,IAAM,MAAA,OAAA,GAAU,MAAM,IAAA,CAAK,UAAW,EAAA;AAEtC,IAAA,MAAM,WAAW,MAAM,IAAA,CAAK,SAAS,KAAM,CAAA,CAAA,EAAG,OAAO,CAAa,SAAA,CAAA,EAAA;AAAA,MAChE,MAAQ,EAAA,MAAA;AAAA,MACR,OAAS,EAAA;AAA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AA,MAAM,SAAS,IAAK,EAAA;AAAA;AAC7B,EAEA,MAAM,mBAAmB,eAAyB,EAAA;AAChD,IAAM,MAAA,OAAA,GAAU,MAAM,IAAA,CAAK,UAAW,EAAA;AAEtC,IAAM,MAAA,QAAA,GAAW,MAAM,IAAA,CAAK,QAAS,CAAA,KAAA;AAAA,MACnC,CAAG,EAAA,OAAO,CAAkB,eAAA,EAAA,kBAAA,CAAmB,eAAe,CAAC,CAAA,CAAA;AAAA,MAC/D;AAAA,QACE,MAAQ,EAAA,QAAA;AAAA,QACR,SAAS;AAAC;AACZ,KACF;AAEA,IAAI,IAAA,CAAC,SAAS,EAAI,EAAA;AAChB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAyC,sCAAA,EAAA,QAAA,CAAS,MAAM,CAAA,EAAA,EAAK,SAAS,UAAU,CAAA;AAAA,OAClF;AAAA;AAEF,IAAO,OAAA,EAAE,SAAS,IAAK,EAAA;AAAA;AAE3B;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"api.esm.js","sources":["../../src/api/api.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { createApiRef } from '@backstage/core-plugin-api';\n\nimport OpenAI from 'openai';\n\nimport { BaseMessage, ConversationList } from '../types';\n\nexport type LightspeedAPI = {\n getAllModels: () => Promise<OpenAI.Models.Model[]>;\n getConversationMessages: (conversation_id: string) => Promise<BaseMessage[]>;\n createConversation: () => Promise<{ conversation_id: string }>;\n createMessage: (\n prompt: string,\n selectedModel: string,\n conversation_id: string,\n ) => Promise<ReadableStreamDefaultReader>;\n deleteConversation: (\n conversation_id: string,\n ) => Promise<{ success: boolean }>;\n getConversations: () => Promise<ConversationList>;\n};\n\nexport const lightspeedApiRef = createApiRef<LightspeedAPI>({\n id: 'plugin.lightspeed.service',\n});\n"],"names":[],"mappings":";;AAoCO,MAAM,mBAAmB,YAA4B,CAAA;AAAA,EAC1D,EAAI,EAAA;AACN,CAAC;;;;"}
1
+ {"version":3,"file":"api.esm.js","sources":["../../src/api/api.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createApiRef } from '@backstage/core-plugin-api';\n\nimport OpenAI from 'openai';\n\nimport { BaseMessage, ConversationList } from '../types';\n\nexport type LightspeedAPI = {\n getAllModels: () => Promise<OpenAI.Models.Model[]>;\n getConversationMessages: (conversation_id: string) => Promise<BaseMessage[]>;\n createConversation: () => Promise<{ conversation_id: string }>;\n createMessage: (\n prompt: string,\n selectedModel: string,\n conversation_id: string,\n ) => Promise<ReadableStreamDefaultReader>;\n deleteConversation: (\n conversation_id: string,\n ) => Promise<{ success: boolean }>;\n getConversations: () => Promise<ConversationList>;\n};\n\nexport const lightspeedApiRef = createApiRef<LightspeedAPI>({\n id: 'plugin.lightspeed.service',\n});\n"],"names":[],"mappings":";;AAqCO,MAAM,mBAAmB,YAA4B,CAAA;AAAA,EAC1D,EAAI,EAAA;AACN,CAAC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"DeleteModal.esm.js","sources":["../../src/components/DeleteModal.tsx"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport React from 'react';\n\nimport {\n Button,\n Modal,\n ModalBody,\n ModalFooter,\n ModalHeader,\n ModalVariant,\n} from '@patternfly/react-core';\n\nexport const DeleteModal = ({\n isOpen,\n onClose,\n onConfirm,\n}: {\n isOpen: boolean;\n onClose: () => void;\n onConfirm: () => void;\n}) => (\n <Modal\n variant={ModalVariant.small}\n isOpen={isOpen}\n onClose={onClose}\n ouiaId=\"DeleteModal\"\n aria-labelledby=\"delete-modal\"\n aria-describedby=\"delete-modal-confiramtion\"\n >\n <ModalHeader title=\"Delete chat?\" />\n <ModalBody id=\"delete-modal-body-confirmation\">\n You'll no longer see this chat here. This will also delete related\n activity like prompts, responses, and feedback from your Lightspeed\n Activity.\n </ModalBody>\n <ModalFooter>\n <Button key=\"confirm\" variant=\"danger\" onClick={onConfirm}>\n Delete\n </Button>\n <Button key=\"cancel\" variant=\"link\" onClick={onClose}>\n Cancel\n </Button>\n </ModalFooter>\n </Modal>\n);\n"],"names":["React"],"mappings":";;;AA0BO,MAAM,cAAc,CAAC;AAAA,EAC1B,MAAA;AAAA,EACA,OAAA;AAAA,EACA;AACF,CAKE,qBAAAA,cAAA,CAAA,aAAA;AAAA,EAAC,KAAA;AAAA,EAAA;AAAA,IACC,SAAS,YAAa,CAAA,KAAA;AAAA,IACtB,MAAA;AAAA,IACA,OAAA;AAAA,IACA,MAAO,EAAA,aAAA;AAAA,IACP,iBAAgB,EAAA,cAAA;AAAA,IAChB,kBAAiB,EAAA;AAAA,GAAA;AAAA,kBAEjBA,cAAA,CAAA,aAAA,CAAC,WAAY,EAAA,EAAA,KAAA,EAAM,cAAe,EAAA,CAAA;AAAA,kBACjCA,cAAA,CAAA,aAAA,CAAA,SAAA,EAAA,EAAU,EAAG,EAAA,gCAAA,EAAA,EAAiC,kJAI/C,CAAA;AAAA,kBACAA,cAAA,CAAA,aAAA,CAAC,mCACEA,cAAA,CAAA,aAAA,CAAA,MAAA,EAAA,EAAO,KAAI,SAAU,EAAA,OAAA,EAAQ,UAAS,OAAS,EAAA,SAAA,EAAA,EAAW,QAE3D,CACA,kBAAAA,cAAA,CAAA,aAAA,CAAC,UAAO,GAAI,EAAA,QAAA,EAAS,SAAQ,MAAO,EAAA,OAAA,EAAS,OAAS,EAAA,EAAA,QAEtD,CACF;AACF;;;;"}
1
+ {"version":3,"file":"DeleteModal.esm.js","sources":["../../src/components/DeleteModal.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from 'react';\n\nimport {\n Button,\n Modal,\n ModalBody,\n ModalFooter,\n ModalHeader,\n ModalVariant,\n} from '@patternfly/react-core';\n\nexport const DeleteModal = ({\n isOpen,\n onClose,\n onConfirm,\n}: {\n isOpen: boolean;\n onClose: () => void;\n onConfirm: () => void;\n}) => (\n <Modal\n variant={ModalVariant.small}\n isOpen={isOpen}\n onClose={onClose}\n ouiaId=\"DeleteModal\"\n aria-labelledby=\"delete-modal\"\n aria-describedby=\"delete-modal-confiramtion\"\n >\n <ModalHeader title=\"Delete chat?\" />\n <ModalBody id=\"delete-modal-body-confirmation\">\n You'll no longer see this chat here. This will also delete related\n activity like prompts, responses, and feedback from your Lightspeed\n Activity.\n </ModalBody>\n <ModalFooter>\n <Button key=\"confirm\" variant=\"danger\" onClick={onConfirm}>\n Delete\n </Button>\n <Button key=\"cancel\" variant=\"link\" onClick={onClose}>\n Cancel\n </Button>\n </ModalFooter>\n </Modal>\n);\n"],"names":["React"],"mappings":";;;AA2BO,MAAM,cAAc,CAAC;AAAA,EAC1B,MAAA;AAAA,EACA,OAAA;AAAA,EACA;AACF,CAKE,qBAAAA,cAAA,CAAA,aAAA;AAAA,EAAC,KAAA;AAAA,EAAA;AAAA,IACC,SAAS,YAAa,CAAA,KAAA;AAAA,IACtB,MAAA;AAAA,IACA,OAAA;AAAA,IACA,MAAO,EAAA,aAAA;AAAA,IACP,iBAAgB,EAAA,cAAA;AAAA,IAChB,kBAAiB,EAAA;AAAA,GAAA;AAAA,kBAEjBA,cAAA,CAAA,aAAA,CAAC,WAAY,EAAA,EAAA,KAAA,EAAM,cAAe,EAAA,CAAA;AAAA,kBACjCA,cAAA,CAAA,aAAA,CAAA,SAAA,EAAA,EAAU,EAAG,EAAA,gCAAA,EAAA,EAAiC,kJAI/C,CAAA;AAAA,kBACAA,cAAA,CAAA,aAAA,CAAC,mCACEA,cAAA,CAAA,aAAA,CAAA,MAAA,EAAA,EAAO,KAAI,SAAU,EAAA,OAAA,EAAQ,UAAS,OAAS,EAAA,SAAA,EAAA,EAAW,QAE3D,CACA,kBAAAA,cAAA,CAAA,aAAA,CAAC,UAAO,GAAI,EAAA,QAAA,EAAS,SAAQ,MAAO,EAAA,OAAA,EAAS,OAAS,EAAA,EAAA,QAEtD,CACF;AACF;;;;"}
@@ -1,15 +1,16 @@
1
1
  import React__default from 'react';
2
2
  import { ErrorPanel } from '@backstage/core-components';
3
3
  import { makeStyles, Box } from '@material-ui/core';
4
+ import { Chatbot, ChatbotDisplayMode, ChatbotHeader, ChatbotHeaderMain, ChatbotHeaderMenu, ChatbotHeaderTitle, ChatbotContent, ChatbotFooter, MessageBar, ChatbotFootnote } from '@patternfly/chatbot';
5
+ import ChatbotConversationHistoryNav from '@patternfly/chatbot/dist/dynamic/ChatbotConversationHistoryNav';
4
6
  import { DropdownItem, Title } from '@patternfly/react-core';
5
- import { Chatbot, ChatbotDisplayMode, ChatbotHeader, ChatbotHeaderMain, ChatbotHeaderMenu, ChatbotHeaderTitle, ChatbotContent, ChatbotFooter, MessageBar, ChatbotFootnote } from '@patternfly/virtual-assistant';
6
- import ChatbotConversationHistoryNav from '@patternfly/virtual-assistant/dist/dynamic/ChatbotConversationHistoryNav';
7
7
  import { useQueryClient } from '@tanstack/react-query';
8
8
  import { useBackstageUserIdentity } from '../hooks/useBackstageUserIdentity.esm.js';
9
9
  import { useConversationMessages } from '../hooks/useConversationMessages.esm.js';
10
10
  import { useConversations } from '../hooks/useConversations.esm.js';
11
11
  import { useCreateConversation } from '../hooks/useCreateConversation.esm.js';
12
12
  import { useDeleteConversation } from '../hooks/useDeleteConversation.esm.js';
13
+ import { useLastOpenedConversation } from '../hooks/useLastOpenedConversation.esm.js';
13
14
  import { useLightspeedDeletePermission } from '../hooks/useLightspeedDeletePermission.esm.js';
14
15
  import { getCategorizeMessages, getFootnoteProps } from '../utils/lightspeed-chatbox-utils.esm.js';
15
16
  import { DeleteModal } from './DeleteModal.esm.js';
@@ -17,25 +18,16 @@ import { LightspeedChatBox } from './LightspeedChatBox.esm.js';
17
18
  import { LightspeedChatBoxHeader } from './LightspeedChatBoxHeader.esm.js';
18
19
 
19
20
  const useStyles = makeStyles((theme) => ({
20
- content: {
21
- "&.pf-chatbot__content": {
22
- padding: 0
23
- }
24
- },
25
21
  header: {
26
22
  padding: `${theme.spacing(3)}px !important`
27
23
  },
28
- drawerActions: {
29
- "&.pf-v6-c-drawer__actions": {
30
- flexDirection: "row-reverse"
31
- }
32
- },
33
24
  headerTitle: {
34
25
  justifyContent: "left !important"
35
26
  },
36
27
  footer: {
37
- "&.pf-chatbot__footer": {
38
- padding: "0 var(--pf-t--global--spacer--lg) var(--pf-t--global--spacer--lg) var(--pf-t--global--spacer--lg)"
28
+ "&>.pf-chatbot__footer-container": {
29
+ width: "95% !important",
30
+ maxWidth: "unset !important"
39
31
  }
40
32
  }
41
33
  }));
@@ -53,26 +45,38 @@ const LightspeedChat = ({
53
45
  const [announcement, setAnnouncement] = React__default.useState("");
54
46
  const [conversationId, setConversationId] = React__default.useState("");
55
47
  const [isDrawerOpen, setIsDrawerOpen] = React__default.useState(true);
56
- const [newChatCreated, setNewChatCreated] = React__default.useState(true);
48
+ const [newChatCreated, setNewChatCreated] = React__default.useState(false);
57
49
  const [isSendButtonDisabled, setIsSendButtonDisabled] = React__default.useState(false);
58
50
  const [error, setError] = React__default.useState(null);
59
51
  const [targetConversationId, setTargetConversationId] = React__default.useState("");
60
52
  const [isDeleteModalOpen, setIsDeleteModalOpen] = React__default.useState(false);
53
+ const { isReady, lastOpenedId, setLastOpenedId, clearLastOpenedId } = useLastOpenedConversation(user);
54
+ React__default.useEffect(() => {
55
+ if (isReady && lastOpenedId !== null) {
56
+ setConversationId(lastOpenedId);
57
+ }
58
+ }, [lastOpenedId, isReady]);
61
59
  const queryClient = useQueryClient();
62
60
  const { data: conversations = [] } = useConversations();
63
61
  const { mutateAsync: createConversation } = useCreateConversation();
64
62
  const { mutateAsync: deleteConversation } = useDeleteConversation();
65
63
  const { allowed: hasDeleteAccess } = useLightspeedDeletePermission();
66
64
  React__default.useEffect(() => {
67
- if (user) {
65
+ if (user && lastOpenedId === null && isReady) {
68
66
  createConversation().then(({ conversation_id }) => {
69
67
  setConversationId(conversation_id);
68
+ setNewChatCreated(true);
70
69
  }).catch((e) => {
71
70
  console.warn(e);
72
71
  setError(e);
73
72
  });
74
73
  }
75
- }, [user, setConversationId, createConversation]);
74
+ }, [user, isReady, lastOpenedId, setConversationId, createConversation]);
75
+ React__default.useEffect(() => {
76
+ if (conversationId) {
77
+ setLastOpenedId(conversationId);
78
+ }
79
+ }, [conversationId, setLastOpenedId]);
76
80
  const onComplete = (message) => {
77
81
  setIsSendButtonDisabled(false);
78
82
  setAnnouncement(`Message from Bot: ${message}`);
@@ -110,12 +114,6 @@ const LightspeedChat = ({
110
114
  })();
111
115
  }, [createConversation, setConversationId, setMessages]);
112
116
  const openDeleteModal = (conversation_id) => {
113
- document.dispatchEvent(
114
- new MouseEvent("click", {
115
- bubbles: true,
116
- cancelable: true
117
- })
118
- );
119
117
  setTargetConversationId(conversation_id);
120
118
  setIsDeleteModalOpen(true);
121
119
  };
@@ -126,13 +124,22 @@ const LightspeedChat = ({
126
124
  conversation_id: targetConversationId,
127
125
  invalidateCache: false
128
126
  });
129
- onNewChat();
127
+ if (targetConversationId === lastOpenedId) {
128
+ onNewChat();
129
+ clearLastOpenedId();
130
+ }
130
131
  setIsDeleteModalOpen(false);
131
132
  } catch (e) {
132
133
  console.warn(e);
133
134
  }
134
135
  })();
135
- }, [deleteConversation, onNewChat, targetConversationId]);
136
+ }, [
137
+ deleteConversation,
138
+ clearLastOpenedId,
139
+ lastOpenedId,
140
+ onNewChat,
141
+ targetConversationId
142
+ ]);
136
143
  const additionalMessageProps = React__default.useCallback(
137
144
  (conversationSummary) => ({
138
145
  menuItems: /* @__PURE__ */ React__default.createElement(
@@ -183,7 +190,10 @@ const LightspeedChat = ({
183
190
  },
184
191
  [setConversationId]
185
192
  );
186
- const welcomePrompts = newChatCreated ? [
193
+ const conversationFound = !!conversations.find(
194
+ (c) => c.conversation_id === conversationId
195
+ );
196
+ const welcomePrompts = newChatCreated || !conversationFound && conversationMessages.length === 0 ? [
187
197
  {
188
198
  title: "Topic 1",
189
199
  message: "Helpful prompt for Topic 1",
@@ -227,6 +237,7 @@ const LightspeedChat = ({
227
237
  )), /* @__PURE__ */ React__default.createElement(
228
238
  ChatbotConversationHistoryNav,
229
239
  {
240
+ reverseButtonOrder: true,
230
241
  displayMode: ChatbotDisplayMode.embedded,
231
242
  onDrawerToggle,
232
243
  isDrawerOpen,
@@ -234,9 +245,9 @@ const LightspeedChat = ({
234
245
  activeItemId: conversationId,
235
246
  onSelectActiveItem,
236
247
  conversations: filterConversations(filterValue),
237
- onNewChat: newChatCreated ? void 0 : onNewChat,
248
+ onNewChat: newChatCreated ? undefined : onNewChat,
238
249
  handleTextInputChange: handleFilter,
239
- drawerContent: /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(ChatbotContent, { className: classes.content }, /* @__PURE__ */ React__default.createElement(
250
+ drawerContent: /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(ChatbotContent, null, /* @__PURE__ */ React__default.createElement(
240
251
  LightspeedChatBox,
241
252
  {
242
253
  userName,
@@ -1 +1 @@
1
- {"version":3,"file":"LightSpeedChat.esm.js","sources":["../../src/components/LightSpeedChat.tsx"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport React from 'react';\n\nimport { ErrorPanel } from '@backstage/core-components';\n\nimport { Box, makeStyles } from '@material-ui/core';\nimport { DropdownItem, Title } from '@patternfly/react-core';\nimport {\n Chatbot,\n ChatbotContent,\n ChatbotDisplayMode,\n ChatbotFooter,\n ChatbotFootnote,\n ChatbotHeader,\n ChatbotHeaderMain,\n ChatbotHeaderMenu,\n ChatbotHeaderTitle,\n MessageBar,\n MessageProps,\n} from '@patternfly/virtual-assistant';\nimport ChatbotConversationHistoryNav from '@patternfly/virtual-assistant/dist/dynamic/ChatbotConversationHistoryNav';\nimport { useQueryClient } from '@tanstack/react-query';\n\nimport { useBackstageUserIdentity } from '../hooks/useBackstageUserIdentity';\nimport { useConversationMessages } from '../hooks/useConversationMessages';\nimport { useConversations } from '../hooks/useConversations';\nimport { useCreateConversation } from '../hooks/useCreateConversation';\nimport { useDeleteConversation } from '../hooks/useDeleteConversation';\nimport { useLightspeedDeletePermission } from '../hooks/useLightspeedDeletePermission';\nimport { ConversationSummary } from '../types';\nimport {\n getCategorizeMessages,\n getFootnoteProps,\n} from '../utils/lightspeed-chatbox-utils';\nimport { DeleteModal } from './DeleteModal';\nimport { LightspeedChatBox } from './LightspeedChatBox';\nimport { LightspeedChatBoxHeader } from './LightspeedChatBoxHeader';\n\nconst useStyles = makeStyles(theme => ({\n content: {\n '&.pf-chatbot__content': {\n padding: 0,\n },\n },\n header: {\n padding: `${theme.spacing(3)}px !important`,\n },\n drawerActions: {\n '&.pf-v6-c-drawer__actions': {\n flexDirection: 'row-reverse',\n },\n },\n headerTitle: {\n justifyContent: 'left !important',\n },\n footer: {\n '&.pf-chatbot__footer': {\n padding:\n '0 var(--pf-t--global--spacer--lg) var(--pf-t--global--spacer--lg) var(--pf-t--global--spacer--lg)',\n },\n },\n}));\n\ntype LightspeedChatProps = {\n selectedModel: string;\n userName?: string;\n avatar?: string;\n profileLoading: boolean;\n handleSelectedModel: (item: string) => void;\n models: { label: string; value: string }[];\n};\n\nexport const LightspeedChat = ({\n selectedModel,\n userName,\n avatar,\n profileLoading,\n handleSelectedModel,\n models,\n}: LightspeedChatProps) => {\n const classes = useStyles();\n const user = useBackstageUserIdentity();\n const [filterValue, setFilterValue] = React.useState<string>('');\n const [announcement, setAnnouncement] = React.useState<string>('');\n const [conversationId, setConversationId] = React.useState<string>('');\n const [isDrawerOpen, setIsDrawerOpen] = React.useState<boolean>(true);\n const [newChatCreated, setNewChatCreated] = React.useState<boolean>(true);\n const [isSendButtonDisabled, setIsSendButtonDisabled] =\n React.useState<boolean>(false);\n const [error, setError] = React.useState<Error | null>(null);\n const [targetConversationId, setTargetConversationId] =\n React.useState<string>('');\n const [isDeleteModalOpen, setIsDeleteModalOpen] =\n React.useState<boolean>(false);\n\n const queryClient = useQueryClient();\n\n const { data: conversations = [] } = useConversations();\n const { mutateAsync: createConversation } = useCreateConversation();\n const { mutateAsync: deleteConversation } = useDeleteConversation();\n const { allowed: hasDeleteAccess } = useLightspeedDeletePermission();\n\n React.useEffect(() => {\n if (user) {\n createConversation()\n .then(({ conversation_id }) => {\n setConversationId(conversation_id);\n })\n .catch(e => {\n // eslint-disable-next-line\n console.warn(e);\n setError(e);\n });\n }\n }, [user, setConversationId, createConversation]);\n\n const onComplete = (message: string) => {\n setIsSendButtonDisabled(false);\n setAnnouncement(`Message from Bot: ${message}`);\n queryClient.invalidateQueries({\n queryKey: ['conversations'],\n });\n };\n\n const { conversationMessages, handleInputPrompt, scrollToBottomRef } =\n useConversationMessages(\n conversationId,\n userName,\n selectedModel,\n avatar,\n onComplete,\n );\n\n const [messages, setMessages] =\n React.useState<MessageProps[]>(conversationMessages);\n\n // Auto-scrolls to the latest message\n React.useEffect(() => {\n setTimeout(() => {\n scrollToBottomRef.current?.scrollIntoView({ behavior: 'auto' });\n }, 10);\n // eslint-disable-next-line\n }, [messages, scrollToBottomRef.current]);\n\n const sendMessage = (message: string) => {\n setNewChatCreated(false);\n setAnnouncement(\n `Message from User: ${prompt}. Message from Bot is loading.`,\n );\n handleInputPrompt(message);\n setIsSendButtonDisabled(true);\n };\n\n const onNewChat = React.useCallback(() => {\n (async () => {\n setMessages([]);\n const { conversation_id } = await createConversation();\n setConversationId(conversation_id);\n setNewChatCreated(true);\n })();\n }, [createConversation, setConversationId, setMessages]);\n\n const openDeleteModal = (conversation_id: string) => {\n // TODO: Remove this temporary workaround and refactor once the dependency handling is updated in the future.\n document.dispatchEvent(\n new MouseEvent('click', {\n bubbles: true,\n cancelable: true,\n }),\n );\n setTargetConversationId(conversation_id);\n setIsDeleteModalOpen(true);\n };\n\n const handleDeleteConversation = React.useCallback(() => {\n (async () => {\n try {\n await deleteConversation({\n conversation_id: targetConversationId,\n invalidateCache: false,\n });\n onNewChat();\n setIsDeleteModalOpen(false);\n } catch (e) {\n // eslint-disable-next-line no-console\n console.warn(e);\n }\n })();\n }, [deleteConversation, onNewChat, targetConversationId]);\n\n const additionalMessageProps = React.useCallback(\n (conversationSummary: ConversationSummary) => ({\n menuItems: (\n <DropdownItem\n isDisabled={!hasDeleteAccess}\n onClick={() => openDeleteModal(conversationSummary.conversation_id)}\n >\n Delete\n </DropdownItem>\n ),\n }),\n [hasDeleteAccess],\n );\n const categorizedMessages = getCategorizeMessages(\n conversations,\n additionalMessageProps,\n );\n\n const filterConversations = React.useCallback(\n (targetValue: string) => {\n const filteredConversations = Object.entries(categorizedMessages).reduce(\n (acc, [key, items]) => {\n const filteredItems = items.filter(item =>\n item.text\n .toLocaleLowerCase('en-US')\n .includes(targetValue.toLocaleLowerCase('en-US')),\n );\n if (filteredItems.length > 0) {\n acc[key] = filteredItems;\n }\n return acc;\n },\n {} as any,\n );\n return filteredConversations;\n },\n [categorizedMessages],\n );\n\n React.useEffect(() => {\n setMessages(conversationMessages);\n }, [conversationMessages]);\n\n const onSelectActiveItem = React.useCallback(\n (\n _: React.MouseEvent | undefined,\n selectedItem: string | number | undefined,\n ) => {\n setNewChatCreated(false);\n setConversationId((c_id: string) => {\n if (c_id !== selectedItem) {\n return String(selectedItem);\n }\n return c_id;\n });\n },\n [setConversationId],\n );\n\n const welcomePrompts = newChatCreated\n ? [\n {\n title: 'Topic 1',\n message: 'Helpful prompt for Topic 1',\n onClick: () => sendMessage('Helpful prompt for Topic 1'),\n },\n {\n title: 'Topic 2',\n message: 'Helpful prompt for Topic 2',\n onClick: () => sendMessage('Helpful prompt for Topic 2'),\n },\n ]\n : [];\n\n const handleFilter = React.useCallback((value: string) => {\n setFilterValue(value);\n }, []);\n\n const onDrawerToggle = React.useCallback(() => {\n setIsDrawerOpen(isOpen => !isOpen);\n }, []);\n\n if (error) {\n return (\n <Box padding={1}>\n <ErrorPanel error={error} />\n </Box>\n );\n }\n\n return (\n <>\n {isDeleteModalOpen && (\n <DeleteModal\n isOpen={isDeleteModalOpen}\n onClose={() => setIsDeleteModalOpen(false)}\n onConfirm={handleDeleteConversation}\n />\n )}\n <Chatbot displayMode={ChatbotDisplayMode.embedded}>\n <ChatbotHeader className={classes.header}>\n <ChatbotHeaderMain>\n <ChatbotHeaderMenu\n aria-expanded={isDrawerOpen}\n onMenuToggle={() => setIsDrawerOpen(!isDrawerOpen)}\n />\n <ChatbotHeaderTitle className={classes.headerTitle}>\n <Title headingLevel=\"h1\" size=\"3xl\">\n Developer Hub Lightspeed\n </Title>\n </ChatbotHeaderTitle>\n </ChatbotHeaderMain>\n\n <LightspeedChatBoxHeader\n selectedModel={selectedModel}\n handleSelectedModel={item => handleSelectedModel(item)}\n models={models}\n />\n </ChatbotHeader>\n <ChatbotConversationHistoryNav\n displayMode={ChatbotDisplayMode.embedded}\n onDrawerToggle={onDrawerToggle}\n isDrawerOpen={isDrawerOpen}\n setIsDrawerOpen={setIsDrawerOpen}\n activeItemId={conversationId}\n onSelectActiveItem={onSelectActiveItem}\n conversations={filterConversations(filterValue)}\n onNewChat={newChatCreated ? undefined : onNewChat}\n handleTextInputChange={handleFilter}\n drawerContent={\n <>\n <ChatbotContent className={classes.content}>\n <LightspeedChatBox\n userName={userName}\n messages={messages}\n profileLoading={profileLoading}\n announcement={announcement}\n ref={scrollToBottomRef}\n welcomePrompts={welcomePrompts}\n />\n </ChatbotContent>\n <ChatbotFooter className={classes.footer}>\n <MessageBar\n onSendMessage={sendMessage}\n isSendButtonDisabled={isSendButtonDisabled}\n hasAttachButton={false}\n hasMicrophoneButton\n />\n <ChatbotFootnote {...getFootnoteProps()} />\n </ChatbotFooter>\n </>\n }\n />\n </Chatbot>\n </>\n );\n};\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;AAoDA,MAAM,SAAA,GAAY,WAAW,CAAU,KAAA,MAAA;AAAA,EACrC,OAAS,EAAA;AAAA,IACP,uBAAyB,EAAA;AAAA,MACvB,OAAS,EAAA;AAAA;AACX,GACF;AAAA,EACA,MAAQ,EAAA;AAAA,IACN,OAAS,EAAA,CAAA,EAAG,KAAM,CAAA,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,kBAAAA,cAAA,CAAA,aAAA;AAAA,IAAC,6BAAA;AAAA,IAAA;AAAA,MACC,aAAa,kBAAmB,CAAA,QAAA;AAAA,MAChC,cAAA;AAAA,MACA,YAAA;AAAA,MACA,eAAA;AAAA,MACA,YAAc,EAAA,cAAA;AAAA,MACd,kBAAA;AAAA,MACA,aAAA,EAAe,oBAAoB,WAAW,CAAA;AAAA,MAC9C,SAAA,EAAW,iBAAiB,KAAY,CAAA,GAAA,SAAA;AAAA,MACxC,qBAAuB,EAAA,YAAA;AAAA,MACvB,+BAEIA,cAAA,CAAA,aAAA,CAAAA,cAAA,CAAA,QAAA,EAAA,IAAA,kBAAAA,cAAA,CAAA,aAAA,CAAC,cAAe,EAAA,EAAA,SAAA,EAAW,QAAQ,OACjC,EAAA,kBAAAA,cAAA,CAAA,aAAA;AAAA,QAAC,iBAAA;AAAA,QAAA;AAAA,UACC,QAAA;AAAA,UACA,QAAA;AAAA,UACA,cAAA;AAAA,UACA,YAAA;AAAA,UACA,GAAK,EAAA,iBAAA;AAAA,UACL;AAAA;AAAA,OAEJ,CACA,kBAAAA,cAAA,CAAA,aAAA,CAAC,aAAc,EAAA,EAAA,SAAA,EAAW,QAAQ,MAChC,EAAA,kBAAAA,cAAA,CAAA,aAAA;AAAA,QAAC,UAAA;AAAA,QAAA;AAAA,UACC,aAAe,EAAA,WAAA;AAAA,UACf,oBAAA;AAAA,UACA,eAAiB,EAAA,KAAA;AAAA,UACjB,mBAAmB,EAAA;AAAA;AAAA,yBAEpBA,cAAA,CAAA,aAAA,CAAA,eAAA,EAAA,EAAiB,GAAG,gBAAiB,EAAA,EAAG,CAC3C,CACF;AAAA;AAAA,GAGN,CACF,CAAA;AAEJ;;;;"}
1
+ {"version":3,"file":"LightSpeedChat.esm.js","sources":["../../src/components/LightSpeedChat.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from 'react';\n\nimport { ErrorPanel } from '@backstage/core-components';\n\nimport { Box, makeStyles } from '@material-ui/core';\nimport {\n Chatbot,\n ChatbotContent,\n ChatbotDisplayMode,\n ChatbotFooter,\n ChatbotFootnote,\n ChatbotHeader,\n ChatbotHeaderMain,\n ChatbotHeaderMenu,\n ChatbotHeaderTitle,\n MessageBar,\n MessageProps,\n} from '@patternfly/chatbot';\nimport ChatbotConversationHistoryNav from '@patternfly/chatbot/dist/dynamic/ChatbotConversationHistoryNav';\nimport { DropdownItem, Title } from '@patternfly/react-core';\nimport { useQueryClient } from '@tanstack/react-query';\n\nimport { useBackstageUserIdentity } from '../hooks/useBackstageUserIdentity';\nimport { useConversationMessages } from '../hooks/useConversationMessages';\nimport { useConversations } from '../hooks/useConversations';\nimport { useCreateConversation } from '../hooks/useCreateConversation';\nimport { useDeleteConversation } from '../hooks/useDeleteConversation';\nimport { useLastOpenedConversation } from '../hooks/useLastOpenedConversation';\nimport { useLightspeedDeletePermission } from '../hooks/useLightspeedDeletePermission';\nimport { ConversationSummary } from '../types';\nimport {\n getCategorizeMessages,\n getFootnoteProps,\n} from '../utils/lightspeed-chatbox-utils';\nimport { DeleteModal } from './DeleteModal';\nimport { LightspeedChatBox } from './LightspeedChatBox';\nimport { LightspeedChatBoxHeader } from './LightspeedChatBoxHeader';\n\nconst useStyles = makeStyles(theme => ({\n header: {\n padding: `${theme.spacing(3)}px !important`,\n },\n headerTitle: {\n justifyContent: 'left !important',\n },\n footer: {\n '&>.pf-chatbot__footer-container': {\n width: '95% !important',\n maxWidth: 'unset !important',\n },\n },\n}));\n\ntype LightspeedChatProps = {\n selectedModel: string;\n userName?: string;\n avatar?: string;\n profileLoading: boolean;\n handleSelectedModel: (item: string) => void;\n models: { label: string; value: string }[];\n};\n\nexport const LightspeedChat = ({\n selectedModel,\n userName,\n avatar,\n profileLoading,\n handleSelectedModel,\n models,\n}: LightspeedChatProps) => {\n const classes = useStyles();\n const user = useBackstageUserIdentity();\n const [filterValue, setFilterValue] = React.useState<string>('');\n const [announcement, setAnnouncement] = React.useState<string>('');\n const [conversationId, setConversationId] = React.useState<string>('');\n const [isDrawerOpen, setIsDrawerOpen] = React.useState<boolean>(true);\n const [newChatCreated, setNewChatCreated] = React.useState<boolean>(false);\n const [isSendButtonDisabled, setIsSendButtonDisabled] =\n React.useState<boolean>(false);\n const [error, setError] = React.useState<Error | null>(null);\n const [targetConversationId, setTargetConversationId] =\n React.useState<string>('');\n const [isDeleteModalOpen, setIsDeleteModalOpen] =\n React.useState<boolean>(false);\n const { isReady, lastOpenedId, setLastOpenedId, clearLastOpenedId } =\n useLastOpenedConversation(user);\n\n // Sync conversationId with lastOpenedId whenever lastOpenedId changes\n React.useEffect(() => {\n if (isReady && lastOpenedId !== null) {\n setConversationId(lastOpenedId);\n }\n }, [lastOpenedId, isReady]);\n\n const queryClient = useQueryClient();\n\n const { data: conversations = [] } = useConversations();\n const { mutateAsync: createConversation } = useCreateConversation();\n const { mutateAsync: deleteConversation } = useDeleteConversation();\n const { allowed: hasDeleteAccess } = useLightspeedDeletePermission();\n\n React.useEffect(() => {\n if (user && lastOpenedId === null && isReady) {\n createConversation()\n .then(({ conversation_id }) => {\n setConversationId(conversation_id);\n setNewChatCreated(true);\n })\n .catch(e => {\n // eslint-disable-next-line\n console.warn(e);\n setError(e);\n });\n }\n }, [user, isReady, lastOpenedId, setConversationId, createConversation]);\n\n React.useEffect(() => {\n // Update last opened conversation whenever `conversationId` changes\n if (conversationId) {\n setLastOpenedId(conversationId);\n }\n }, [conversationId, setLastOpenedId]);\n\n const onComplete = (message: string) => {\n setIsSendButtonDisabled(false);\n setAnnouncement(`Message from Bot: ${message}`);\n queryClient.invalidateQueries({\n queryKey: ['conversations'],\n });\n };\n\n const { conversationMessages, handleInputPrompt, scrollToBottomRef } =\n useConversationMessages(\n conversationId,\n userName,\n selectedModel,\n avatar,\n onComplete,\n );\n\n const [messages, setMessages] =\n React.useState<MessageProps[]>(conversationMessages);\n\n // Auto-scrolls to the latest message\n React.useEffect(() => {\n setTimeout(() => {\n scrollToBottomRef.current?.scrollIntoView({ behavior: 'auto' });\n }, 10);\n // eslint-disable-next-line\n }, [messages, scrollToBottomRef.current]);\n\n const sendMessage = (message: string) => {\n setNewChatCreated(false);\n setAnnouncement(\n `Message from User: ${prompt}. Message from Bot is loading.`,\n );\n handleInputPrompt(message);\n setIsSendButtonDisabled(true);\n };\n\n const onNewChat = React.useCallback(() => {\n (async () => {\n setMessages([]);\n const { conversation_id } = await createConversation();\n setConversationId(conversation_id);\n setNewChatCreated(true);\n })();\n }, [createConversation, setConversationId, setMessages]);\n\n const openDeleteModal = (conversation_id: string) => {\n setTargetConversationId(conversation_id);\n setIsDeleteModalOpen(true);\n };\n\n const handleDeleteConversation = React.useCallback(() => {\n (async () => {\n try {\n await deleteConversation({\n conversation_id: targetConversationId,\n invalidateCache: false,\n });\n if (targetConversationId === lastOpenedId) {\n onNewChat();\n clearLastOpenedId();\n }\n setIsDeleteModalOpen(false);\n } catch (e) {\n // eslint-disable-next-line no-console\n console.warn(e);\n }\n })();\n }, [\n deleteConversation,\n clearLastOpenedId,\n lastOpenedId,\n onNewChat,\n targetConversationId,\n ]);\n\n const additionalMessageProps = React.useCallback(\n (conversationSummary: ConversationSummary) => ({\n menuItems: (\n <DropdownItem\n isDisabled={!hasDeleteAccess}\n onClick={() => openDeleteModal(conversationSummary.conversation_id)}\n >\n Delete\n </DropdownItem>\n ),\n }),\n [hasDeleteAccess],\n );\n const categorizedMessages = getCategorizeMessages(\n conversations,\n additionalMessageProps,\n );\n\n const filterConversations = React.useCallback(\n (targetValue: string) => {\n const filteredConversations = Object.entries(categorizedMessages).reduce(\n (acc, [key, items]) => {\n const filteredItems = items.filter(item =>\n item.text\n .toLocaleLowerCase('en-US')\n .includes(targetValue.toLocaleLowerCase('en-US')),\n );\n if (filteredItems.length > 0) {\n acc[key] = filteredItems;\n }\n return acc;\n },\n {} as any,\n );\n return filteredConversations;\n },\n [categorizedMessages],\n );\n\n React.useEffect(() => {\n setMessages(conversationMessages);\n }, [conversationMessages]);\n\n const onSelectActiveItem = React.useCallback(\n (\n _: React.MouseEvent | undefined,\n selectedItem: string | number | undefined,\n ) => {\n setNewChatCreated(false);\n setConversationId((c_id: string) => {\n if (c_id !== selectedItem) {\n return String(selectedItem);\n }\n return c_id;\n });\n },\n [setConversationId],\n );\n\n const conversationFound = !!conversations.find(\n c => c.conversation_id === conversationId,\n );\n\n const welcomePrompts =\n newChatCreated || (!conversationFound && conversationMessages.length === 0)\n ? [\n {\n title: 'Topic 1',\n message: 'Helpful prompt for Topic 1',\n onClick: () => sendMessage('Helpful prompt for Topic 1'),\n },\n {\n title: 'Topic 2',\n message: 'Helpful prompt for Topic 2',\n onClick: () => sendMessage('Helpful prompt for Topic 2'),\n },\n ]\n : [];\n\n const handleFilter = React.useCallback((value: string) => {\n setFilterValue(value);\n }, []);\n\n const onDrawerToggle = React.useCallback(() => {\n setIsDrawerOpen(isOpen => !isOpen);\n }, []);\n\n if (error) {\n return (\n <Box padding={1}>\n <ErrorPanel error={error} />\n </Box>\n );\n }\n\n return (\n <>\n {isDeleteModalOpen && (\n <DeleteModal\n isOpen={isDeleteModalOpen}\n onClose={() => setIsDeleteModalOpen(false)}\n onConfirm={handleDeleteConversation}\n />\n )}\n <Chatbot displayMode={ChatbotDisplayMode.embedded}>\n <ChatbotHeader className={classes.header}>\n <ChatbotHeaderMain>\n <ChatbotHeaderMenu\n aria-expanded={isDrawerOpen}\n onMenuToggle={() => setIsDrawerOpen(!isDrawerOpen)}\n />\n <ChatbotHeaderTitle className={classes.headerTitle}>\n <Title headingLevel=\"h1\" size=\"3xl\">\n Developer Hub Lightspeed\n </Title>\n </ChatbotHeaderTitle>\n </ChatbotHeaderMain>\n\n <LightspeedChatBoxHeader\n selectedModel={selectedModel}\n handleSelectedModel={item => handleSelectedModel(item)}\n models={models}\n />\n </ChatbotHeader>\n <ChatbotConversationHistoryNav\n reverseButtonOrder\n displayMode={ChatbotDisplayMode.embedded}\n onDrawerToggle={onDrawerToggle}\n isDrawerOpen={isDrawerOpen}\n setIsDrawerOpen={setIsDrawerOpen}\n activeItemId={conversationId}\n onSelectActiveItem={onSelectActiveItem}\n conversations={filterConversations(filterValue)}\n onNewChat={newChatCreated ? undefined : onNewChat}\n handleTextInputChange={handleFilter}\n drawerContent={\n <>\n <ChatbotContent>\n <LightspeedChatBox\n userName={userName}\n messages={messages}\n profileLoading={profileLoading}\n announcement={announcement}\n ref={scrollToBottomRef}\n welcomePrompts={welcomePrompts}\n />\n </ChatbotContent>\n <ChatbotFooter className={classes.footer}>\n <MessageBar\n onSendMessage={sendMessage}\n isSendButtonDisabled={isSendButtonDisabled}\n hasAttachButton={false}\n hasMicrophoneButton\n />\n <ChatbotFootnote {...getFootnoteProps()} />\n </ChatbotFooter>\n </>\n }\n />\n </Chatbot>\n </>\n );\n};\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;AAsDA,MAAM,SAAA,GAAY,WAAW,CAAU,KAAA,MAAA;AAAA,EACrC,MAAQ,EAAA;AAAA,IACN,OAAS,EAAA,CAAA,EAAG,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAC,CAAA,aAAA;AAAA,GAC9B;AAAA,EACA,WAAa,EAAA;AAAA,IACX,cAAgB,EAAA;AAAA,GAClB;AAAA,EACA,MAAQ,EAAA;AAAA,IACN,iCAAmC,EAAA;AAAA,MACjC,KAAO,EAAA,gBAAA;AAAA,MACP,QAAU,EAAA;AAAA;AACZ;AAEJ,CAAE,CAAA,CAAA;AAWK,MAAM,iBAAiB,CAAC;AAAA,EAC7B,aAAA;AAAA,EACA,QAAA;AAAA,EACA,MAAA;AAAA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AAA,yBAEpBA,cAAA,CAAA,aAAA,CAAA,eAAA,EAAA,EAAiB,GAAG,gBAAiB,EAAA,EAAG,CAC3C,CACF;AAAA;AAAA,GAGN,CACF,CAAA;AAEJ;;;;"}
@@ -1,11 +1,14 @@
1
1
  import React__default from 'react';
2
2
  import { makeStyles } from '@material-ui/core';
3
- import { MessageBox, ChatbotWelcomePrompt, Message } from '@patternfly/virtual-assistant';
3
+ import { MessageBox, ChatbotWelcomePrompt, Message } from '@patternfly/chatbot';
4
4
 
5
5
  const useStyles = makeStyles((theme) => ({
6
6
  prompt: {
7
7
  "justify-content": "flex-end"
8
8
  },
9
+ container: {
10
+ maxWidth: "unset !important"
11
+ },
9
12
  userMessageText: {
10
13
  "& div.pf-chatbot__message--user": {
11
14
  "& div.pf-chatbot__message-text": {
@@ -29,10 +32,11 @@ const LightspeedChatBox = React__default.forwardRef(
29
32
  React__default.useEffect(() => {
30
33
  setCMessages(messages);
31
34
  }, [messages]);
35
+ const messageBoxClasses = `${classes.container} ${classes.userMessageText}`;
32
36
  return /* @__PURE__ */ React__default.createElement(
33
37
  MessageBox,
34
38
  {
35
- className: welcomePrompts.length ? `${classes.userMessageText} ${classes.prompt}` : classes.userMessageText,
39
+ className: welcomePrompts.length ? `${messageBoxClasses} ${classes.prompt}` : messageBoxClasses,
36
40
  announcement,
37
41
  style: { justifyContent: "flex-end" }
38
42
  },
@@ -1 +1 @@
1
- {"version":3,"file":"LightspeedChatBox.esm.js","sources":["../../src/components/LightspeedChatBox.tsx"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport React from 'react';\n\nimport { makeStyles } from '@material-ui/core';\nimport {\n ChatbotWelcomePrompt,\n Message,\n MessageBox,\n MessageProps,\n WelcomePrompt,\n} from '@patternfly/virtual-assistant';\n\nconst useStyles = makeStyles(theme => ({\n prompt: {\n 'justify-content': 'flex-end',\n },\n userMessageText: {\n '& div.pf-chatbot__message--user': {\n '& div.pf-chatbot__message-text': {\n '& p': {\n color: theme.palette.common.white,\n },\n },\n },\n },\n}));\n\ntype LightspeedChatBoxProps = {\n userName?: string;\n messages: MessageProps[];\n profileLoading: boolean;\n announcement: string | undefined;\n welcomePrompts: WelcomePrompt[];\n};\n\nexport const LightspeedChatBox = React.forwardRef(\n (\n {\n userName,\n messages,\n announcement,\n profileLoading,\n welcomePrompts,\n }: LightspeedChatBoxProps,\n ref: React.ForwardedRef<HTMLDivElement>,\n ) => {\n const [cmessages, setCMessages] = React.useState(messages);\n const classes = useStyles();\n\n React.useEffect(() => {\n setCMessages(messages);\n }, [messages]);\n\n return (\n <MessageBox\n className={\n welcomePrompts.length\n ? `${classes.userMessageText} ${classes.prompt}`\n : classes.userMessageText\n }\n announcement={announcement}\n style={{ justifyContent: 'flex-end' }}\n >\n {welcomePrompts.length ? (\n <ChatbotWelcomePrompt\n title={`Hello, ${profileLoading ? '...' : (userName ?? 'Guest')}`}\n description=\"How can I help you today?\"\n prompts={welcomePrompts}\n />\n ) : (\n <br />\n )}\n {cmessages.map((message, index) => {\n if (index === cmessages.length - 1) {\n return (\n <React.Fragment key={`${message.role}-${index}`}>\n <Message key={`${message.role}-${index}`} {...message} />\n <div ref={ref} />\n </React.Fragment>\n );\n }\n return <Message key={`${message.role}-${index}`} {...message} />;\n })}\n </MessageBox>\n );\n },\n);\n"],"names":["React"],"mappings":";;;;AA0BA,MAAM,SAAA,GAAY,WAAW,CAAU,KAAA,MAAA;AAAA,EACrC,MAAQ,EAAA;AAAA,IACN,iBAAmB,EAAA;AAAA,GACrB;AAAA,EACA,eAAiB,EAAA;AAAA,IAC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,KAAA,KAAU,SAAU,CAAA,MAAA,GAAS,CAAG,EAAA;AAClC,UACE,uBAAAA,cAAA,CAAA,aAAA,CAACA,cAAM,CAAA,QAAA,EAAN,EAAe,GAAA,EAAK,CAAG,EAAA,OAAA,CAAQ,IAAI,CAAA,CAAA,EAAI,KAAK,CAAA,CAAA,EAAA,kBAC1CA,cAAA,CAAA,aAAA,CAAA,OAAA,EAAA,EAAQ,KAAK,CAAG,EAAA,OAAA,CAAQ,IAAI,CAAA,CAAA,EAAI,KAAK,CAAA,CAAA,EAAK,GAAG,OAAA,EAAS,CACvD,kBAAAA,cAAA,CAAA,aAAA,CAAC,KAAI,EAAA,EAAA,GAAA,EAAU,CACjB,CAAA;AAAA;AAGJ,QAAO,uBAAAA,cAAA,CAAA,aAAA,CAAC,OAAQ,EAAA,EAAA,GAAA,EAAK,CAAG,EAAA,OAAA,CAAQ,IAAI,CAAI,CAAA,EAAA,KAAK,CAAK,CAAA,EAAA,GAAG,OAAS,EAAA,CAAA;AAAA,OAC/D;AAAA,KACH;AAAA;AAGN;;;;"}
1
+ {"version":3,"file":"LightspeedChatBox.esm.js","sources":["../../src/components/LightspeedChatBox.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from 'react';\n\nimport { makeStyles } from '@material-ui/core';\nimport {\n ChatbotWelcomePrompt,\n Message,\n MessageBox,\n MessageProps,\n WelcomePrompt,\n} from '@patternfly/chatbot';\n\nconst useStyles = makeStyles(theme => ({\n prompt: {\n 'justify-content': 'flex-end',\n },\n container: {\n maxWidth: 'unset !important',\n },\n userMessageText: {\n '& div.pf-chatbot__message--user': {\n '& div.pf-chatbot__message-text': {\n '& p': {\n color: theme.palette.common.white,\n },\n },\n },\n },\n}));\n\ntype LightspeedChatBoxProps = {\n userName?: string;\n messages: MessageProps[];\n profileLoading: boolean;\n announcement: string | undefined;\n welcomePrompts: WelcomePrompt[];\n};\n\nexport const LightspeedChatBox = React.forwardRef(\n (\n {\n userName,\n messages,\n announcement,\n profileLoading,\n welcomePrompts,\n }: LightspeedChatBoxProps,\n ref: React.ForwardedRef<HTMLDivElement>,\n ) => {\n const [cmessages, setCMessages] = React.useState(messages);\n const classes = useStyles();\n\n React.useEffect(() => {\n setCMessages(messages);\n }, [messages]);\n\n const messageBoxClasses = `${classes.container} ${classes.userMessageText}`;\n return (\n <MessageBox\n className={\n welcomePrompts.length\n ? `${messageBoxClasses} ${classes.prompt}`\n : messageBoxClasses\n }\n announcement={announcement}\n style={{ justifyContent: 'flex-end' }}\n >\n {welcomePrompts.length ? (\n <ChatbotWelcomePrompt\n title={`Hello, ${profileLoading ? '...' : (userName ?? 'Guest')}`}\n description=\"How can I help you today?\"\n prompts={welcomePrompts}\n />\n ) : (\n <br />\n )}\n {cmessages.map((message, index) => {\n if (index === cmessages.length - 1) {\n return (\n <React.Fragment key={`${message.role}-${index}`}>\n <Message key={`${message.role}-${index}`} {...message} />\n <div ref={ref} />\n </React.Fragment>\n );\n }\n return <Message key={`${message.role}-${index}`} {...message} />;\n })}\n </MessageBox>\n );\n },\n);\n"],"names":["React"],"mappings":";;;;AA2BA,MAAM,SAAA,GAAY,WAAW,CAAU,KAAA,MAAA;AAAA,EACrC,MAAQ,EAAA;AAAA,IACN,iBAAmB,EAAA;AAAA,GACrB;AAAA,EACA,SAAW,EAAA;AAAA,IACT,QAAU,EAAA;AAAA,GACZ;AAAA,EACA,eAAiB,EAAA;AAAA,IACf,iCAAmC,EAAA;AAAA,MACjC,gCAAkC,EAAA;AAAA,QAChC,KAAO,EAAA;AAAA,UACL,KAAA,EAAO,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CAAA,MAAA,GAAS,CAAG,EAAA;AAClC,UACE,uBAAAA,cAAA,CAAA,aAAA,CAACA,cAAM,CAAA,QAAA,EAAN,EAAe,GAAA,EAAK,CAAG,EAAA,OAAA,CAAQ,IAAI,CAAA,CAAA,EAAI,KAAK,CAAA,CAAA,EAAA,kBAC1CA,cAAA,CAAA,aAAA,CAAA,OAAA,EAAA,EAAQ,KAAK,CAAG,EAAA,OAAA,CAAQ,IAAI,CAAA,CAAA,EAAI,KAAK,CAAA,CAAA,EAAK,GAAG,OAAA,EAAS,CACvD,kBAAAA,cAAA,CAAA,aAAA,CAAC,KAAI,EAAA,EAAA,GAAA,EAAU,CACjB,CAAA;AAAA;AAGJ,QAAO,uBAAAA,cAAA,CAAA,aAAA,CAAC,OAAQ,EAAA,EAAA,GAAA,EAAK,CAAG,EAAA,OAAA,CAAQ,IAAI,CAAI,CAAA,EAAA,KAAK,CAAK,CAAA,EAAA,GAAG,OAAS,EAAA,CAAA;AAAA,OAC/D;AAAA,KACH;AAAA;AAGN;;;;"}
@@ -1,6 +1,6 @@
1
1
  import React__default from 'react';
2
- import { Dropdown, MenuToggle, DropdownList, DropdownItem } from '@patternfly/react-core';
3
- import { ChatbotHeaderActions } from '@patternfly/virtual-assistant';
2
+ import { ChatbotHeaderActions } from '@patternfly/chatbot';
3
+ import { Dropdown, DropdownList, DropdownItem, MenuToggle } from '@patternfly/react-core';
4
4
 
5
5
  const LightspeedChatBoxHeader = ({
6
6
  selectedModel,
@@ -1 +1 @@
1
- {"version":3,"file":"LightspeedChatBoxHeader.esm.js","sources":["../../src/components/LightspeedChatBoxHeader.tsx"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport React from 'react';\n\nimport {\n Dropdown,\n DropdownItem,\n DropdownList,\n MenuToggle,\n MenuToggleElement,\n} from '@patternfly/react-core';\nimport { ChatbotHeaderActions } from '@patternfly/virtual-assistant';\n\ntype LightspeedChatBoxHeaderProps = {\n selectedModel: string;\n handleSelectedModel: (item: string) => void;\n models: { label: string; value: string }[];\n};\n\nexport const LightspeedChatBoxHeader = ({\n selectedModel,\n handleSelectedModel,\n models,\n}: LightspeedChatBoxHeaderProps) => {\n const [isOptionsMenuOpen, setIsOptionsMenuOpen] = React.useState(false);\n\n const toggle = (toggleRef: React.Ref<MenuToggleElement>) => (\n <MenuToggle\n variant=\"secondary\"\n aria-label=\"Chatbot selector\"\n ref={toggleRef}\n isExpanded={isOptionsMenuOpen}\n onClick={() => setIsOptionsMenuOpen(!isOptionsMenuOpen)}\n >\n {selectedModel}\n </MenuToggle>\n );\n\n return (\n <ChatbotHeaderActions>\n <Dropdown\n isOpen={isOptionsMenuOpen}\n onSelect={(_e, value) => {\n handleSelectedModel(value as string);\n setIsOptionsMenuOpen(false);\n }}\n onOpenChange={isOpen => setIsOptionsMenuOpen(isOpen)}\n popperProps={{ position: 'right' }}\n shouldFocusToggleOnSelect\n shouldFocusFirstItemOnOpen={false}\n toggle={toggle}\n >\n <DropdownList>\n {models.map(m => (\n <DropdownItem value={m.value} key={m.value}>\n {m.label}\n </DropdownItem>\n ))}\n </DropdownList>\n </Dropdown>\n </ChatbotHeaderActions>\n );\n};\n"],"names":["React"],"mappings":";;;;AAgCO,MAAM,0BAA0B,CAAC;AAAA,EACtC,aAAA;AAAA,EACA,mBAAA;AAAA,EACA;AACF,CAAoC,KAAA;AAClC,EAAA,MAAM,CAAC,iBAAmB,EAAA,oBAAoB,CAAI,GAAAA,cAAA,CAAM,SAAS,KAAK,CAAA;AAEtE,EAAM,MAAA,MAAA,GAAS,CAAC,SACd,qBAAAA,cAAA,CAAA,aAAA;AAAA,IAAC,UAAA;AAAA,IAAA;AAAA,MACC,OAAQ,EAAA,WAAA;AAAA,MACR,YAAW,EAAA,kBAAA;AAAA,MACX,GAAK,EAAA,SAAA;AAAA,MACL,UAAY,EAAA,iBAAA;AAAA,MACZ,OAAS,EAAA,MAAM,oBAAqB,CAAA,CAAC,iBAAiB;AAAA,KAAA;AAAA,IAErD;AAAA,GACH;AAGF,EAAA,oDACG,oBACC,EAAA,IAAA,kBAAAA,cAAA,CAAA,aAAA;AAAA,IAAC,QAAA;AAAA,IAAA;AAAA,MACC,MAAQ,EAAA,iBAAA;AAAA,MACR,QAAA,EAAU,CAAC,EAAA,EAAI,KAAU,KAAA;AACvB,QAAA,mBAAA,CAAoB,KAAe,CAAA;AACnC,QAAA,oBAAA,CAAqB,KAAK,CAAA;AAAA,OAC5B;AAAA,MACA,YAAA,EAAc,CAAU,MAAA,KAAA,oBAAA,CAAqB,MAAM,CAAA;AAAA,MACnD,WAAA,EAAa,EAAE,QAAA,EAAU,OAAQ,EAAA;AAAA,MACjC,yBAAyB,EAAA,IAAA;AAAA,MACzB,0BAA4B,EAAA,KAAA;AAAA,MAC5B;AAAA,KAAA;AAAA,iDAEC,YACE,EAAA,IAAA,EAAA,MAAA,CAAO,GAAI,CAAA,CAAA,CAAA,kDACT,YAAa,EAAA,EAAA,KAAA,EAAO,CAAE,CAAA,KAAA,EAAO,KAAK,CAAE,CAAA,KAAA,EAAA,EAClC,CAAE,CAAA,KACL,CACD,CACH;AAAA,GAEJ,CAAA;AAEJ;;;;"}
1
+ {"version":3,"file":"LightspeedChatBoxHeader.esm.js","sources":["../../src/components/LightspeedChatBoxHeader.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from 'react';\n\nimport { ChatbotHeaderActions } from '@patternfly/chatbot';\nimport {\n Dropdown,\n DropdownItem,\n DropdownList,\n MenuToggle,\n MenuToggleElement,\n} from '@patternfly/react-core';\n\ntype LightspeedChatBoxHeaderProps = {\n selectedModel: string;\n handleSelectedModel: (item: string) => void;\n models: { label: string; value: string }[];\n};\n\nexport const LightspeedChatBoxHeader = ({\n selectedModel,\n handleSelectedModel,\n models,\n}: LightspeedChatBoxHeaderProps) => {\n const [isOptionsMenuOpen, setIsOptionsMenuOpen] = React.useState(false);\n\n const toggle = (toggleRef: React.Ref<MenuToggleElement>) => (\n <MenuToggle\n variant=\"secondary\"\n aria-label=\"Chatbot selector\"\n ref={toggleRef}\n isExpanded={isOptionsMenuOpen}\n onClick={() => setIsOptionsMenuOpen(!isOptionsMenuOpen)}\n >\n {selectedModel}\n </MenuToggle>\n );\n\n return (\n <ChatbotHeaderActions>\n <Dropdown\n isOpen={isOptionsMenuOpen}\n onSelect={(_e, value) => {\n handleSelectedModel(value as string);\n setIsOptionsMenuOpen(false);\n }}\n onOpenChange={isOpen => setIsOptionsMenuOpen(isOpen)}\n popperProps={{ position: 'right' }}\n shouldFocusToggleOnSelect\n shouldFocusFirstItemOnOpen={false}\n toggle={toggle}\n >\n <DropdownList>\n {models.map(m => (\n <DropdownItem value={m.value} key={m.value}>\n {m.label}\n </DropdownItem>\n ))}\n </DropdownList>\n </Dropdown>\n </ChatbotHeaderActions>\n );\n};\n"],"names":["React"],"mappings":";;;;AAiCO,MAAM,0BAA0B,CAAC;AAAA,EACtC,aAAA;AAAA,EACA,mBAAA;AAAA,EACA;AACF,CAAoC,KAAA;AAClC,EAAA,MAAM,CAAC,iBAAmB,EAAA,oBAAoB,CAAI,GAAAA,cAAA,CAAM,SAAS,KAAK,CAAA;AAEtE,EAAM,MAAA,MAAA,GAAS,CAAC,SACd,qBAAAA,cAAA,CAAA,aAAA;AAAA,IAAC,UAAA;AAAA,IAAA;AAAA,MACC,OAAQ,EAAA,WAAA;AAAA,MACR,YAAW,EAAA,kBAAA;AAAA,MACX,GAAK,EAAA,SAAA;AAAA,MACL,UAAY,EAAA,iBAAA;AAAA,MACZ,OAAS,EAAA,MAAM,oBAAqB,CAAA,CAAC,iBAAiB;AAAA,KAAA;AAAA,IAErD;AAAA,GACH;AAGF,EAAA,oDACG,oBACC,EAAA,IAAA,kBAAAA,cAAA,CAAA,aAAA;AAAA,IAAC,QAAA;AAAA,IAAA;AAAA,MACC,MAAQ,EAAA,iBAAA;AAAA,MACR,QAAA,EAAU,CAAC,EAAA,EAAI,KAAU,KAAA;AACvB,QAAA,mBAAA,CAAoB,KAAe,CAAA;AACnC,QAAA,oBAAA,CAAqB,KAAK,CAAA;AAAA,OAC5B;AAAA,MACA,YAAA,EAAc,CAAU,MAAA,KAAA,oBAAA,CAAqB,MAAM,CAAA;AAAA,MACnD,WAAA,EAAa,EAAE,QAAA,EAAU,OAAQ,EAAA;AAAA,MACjC,yBAAyB,EAAA,IAAA;AAAA,MACzB,0BAA4B,EAAA,KAAA;AAAA,MAC5B;AAAA,KAAA;AAAA,iDAEC,YACE,EAAA,IAAA,EAAA,MAAA,CAAO,GAAI,CAAA,CAAA,CAAA,kDACT,YAAa,EAAA,EAAA,KAAA,EAAO,CAAE,CAAA,KAAA,EAAO,KAAK,CAAE,CAAA,KAAA,EAAA,EAClC,CAAE,CAAA,KACL,CACD,CACH;AAAA,GAEJ,CAAA;AAEJ;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"LightspeedIcon.esm.js","sources":["../../src/components/LightspeedIcon.tsx"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport * as React from 'react';\n\nimport logo from '../images/logo-white.svg';\n\n/**\n * @public\n * Lightspeed Icon\n */\nexport const LightspeedIcon = () => {\n return (\n <img src={logo as any} alt=\"lightspeed icon\" style={{ height: '25px' }} />\n );\n};\n"],"names":[],"mappings":";;;AAuBO,MAAM,iBAAiB,MAAM;AAClC,EACE,uBAAA,KAAA,CAAA,aAAA,CAAC,KAAI,EAAA,EAAA,GAAA,EAAK,IAAa,EAAA,GAAA,EAAI,mBAAkB,KAAO,EAAA,EAAE,MAAQ,EAAA,MAAA,EAAU,EAAA,CAAA;AAE5E;;;;"}
1
+ {"version":3,"file":"LightspeedIcon.esm.js","sources":["../../src/components/LightspeedIcon.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as React from 'react';\n\nimport logo from '../images/logo-white.svg';\n\n/**\n * @public\n * Lightspeed Icon\n */\nexport const LightspeedIcon = () => {\n return (\n <img src={logo as any} alt=\"lightspeed icon\" style={{ height: '25px' }} />\n );\n};\n"],"names":[],"mappings":";;;AAwBO,MAAM,iBAAiB,MAAM;AAClC,EACE,uBAAA,KAAA,CAAA,aAAA,CAAC,KAAI,EAAA,EAAA,GAAA,EAAK,IAAa,EAAA,GAAA,EAAI,mBAAkB,KAAO,EAAA,EAAE,MAAQ,EAAA,MAAA,EAAU,EAAA,CAAA;AAE5E;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"LightspeedPage.esm.js","sources":["../../src/components/LightspeedPage.tsx"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport React from 'react';\nimport { useAsync } from 'react-use';\n\nimport { Content, Page } from '@backstage/core-components';\nimport { identityApiRef, useApi } from '@backstage/core-plugin-api';\n\nimport { createStyles, makeStyles, useTheme } from '@material-ui/core/styles';\nimport { QueryClientProvider } from '@tanstack/react-query';\n\nimport { useAllModels } from '../hooks/useAllModels';\nimport { useLightspeedViewPermission } from '../hooks/useLightspeedViewPermission';\nimport queryClient from '../utils/queryClient';\nimport { LightspeedChat } from './LightSpeedChat';\nimport PermissionRequiredState from './PermissionRequiredState';\n\nconst useStyles = makeStyles(() =>\n createStyles({\n container: {\n padding: '0px',\n },\n }),\n);\n\nconst THEME_DARK = 'dark';\nconst THEME_DARK_CLASS = 'pf-v6-theme-dark';\n\nconst LightspeedPageInner = () => {\n const classes = useStyles();\n const {\n palette: { type },\n } = useTheme();\n\n const identityApi = useApi(identityApiRef);\n\n const { data: models } = useAllModels();\n const { allowed: hasViewAccess, loading } = useLightspeedViewPermission();\n\n const { value: profile, loading: profileLoading } = useAsync(\n async () => await identityApi.getProfileInfo(),\n );\n\n const [selectedModel, setSelectedModel] = React.useState('');\n\n const modelsItems = React.useMemo(\n () => (models ? models.map(m => ({ label: m.id, value: m.id })) : []),\n [models],\n );\n\n React.useEffect(() => {\n const htmlTagElement = document.documentElement;\n if (type === THEME_DARK) {\n htmlTagElement.classList.add(THEME_DARK_CLASS);\n } else {\n htmlTagElement.classList.remove(THEME_DARK_CLASS);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [type]);\n\n React.useEffect(() => {\n if (modelsItems.length > 0) setSelectedModel(modelsItems[0].value);\n }, [modelsItems]);\n\n if (loading) {\n return null;\n }\n\n return (\n <Page themeId=\"tool\">\n <Content className={classes.container}>\n {!hasViewAccess ? (\n <PermissionRequiredState />\n ) : (\n <LightspeedChat\n selectedModel={selectedModel}\n handleSelectedModel={item => {\n setSelectedModel(item);\n }}\n models={modelsItems}\n userName={profile?.displayName}\n avatar={profile?.picture}\n profileLoading={profileLoading}\n />\n )}\n </Content>\n </Page>\n );\n};\n\nexport const LightspeedPage = () => {\n return (\n <QueryClientProvider client={queryClient}>\n <LightspeedPageInner />\n </QueryClientProvider>\n );\n};\n"],"names":["React"],"mappings":";;;;;;;;;;;;AA8BA,MAAM,SAAY,GAAA,UAAA;AAAA,EAAW,MAC3B,YAAa,CAAA;AAAA,IACX,SAAW,EAAA;AAAA,MACT,OAAS,EAAA;AAAA;AACX,GACD;AACH,CAAA;AAEA,MAAM,UAAa,GAAA,MAAA;AACnB,MAAM,gBAAmB,GAAA,kBAAA;AAEzB,MAAM,sBAAsB,MAAM;AAChC,EAAA,MAAM,UAAU,SAAU,EAAA;AAC1B,EAAM,MAAA;AAAA,IACJ,OAAA,EAAS,EAAE,IAAK;AAAA,MACd,QAAS,EAAA;AAEb,EAAM,MAAA,WAAA,GAAc,OAAO,cAAc,CAAA;AAEzC,EAAA,MAAM,EAAE,IAAA,EAAM,MAAO,EAAA,GAAI,YAAa,EAAA;AACtC,EAAA,MAAM,EAAE,OAAA,EAAS,aAAe,EAAA,OAAA,KAAY,2BAA4B,EAAA;AAExE,EAAA,MAAM,EAAE,KAAA,EAAO,OAAS,EAAA,OAAA,EAAS,gBAAmB,GAAA,QAAA;AAAA,IAClD,YAAY,MAAM,WAAA,CAAY,cAAe;AAAA,GAC/C;AAEA,EAAA,MAAM,CAAC,aA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MAAQ,EAAA,WAAA;AAAA,MACR,UAAU,OAAS,EAAA,WAAA;AAAA,MACnB,QAAQ,OAAS,EAAA,OAAA;AAAA,MACjB;AAAA;AAAA,GAGN,CACF,CAAA;AAEJ,CAAA;AAEO,MAAM,iBAAiB,MAAM;AAClC,EAAA,oDACG,mBAAoB,EAAA,EAAA,MAAA,EAAQ,WAC3B,EAAA,kBAAAA,cAAA,CAAA,aAAA,CAAC,yBAAoB,CACvB,CAAA;AAEJ;;;;"}
1
+ {"version":3,"file":"LightspeedPage.esm.js","sources":["../../src/components/LightspeedPage.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from 'react';\nimport { useAsync } from 'react-use';\n\nimport { Content, Page } from '@backstage/core-components';\nimport { identityApiRef, useApi } from '@backstage/core-plugin-api';\n\nimport { createStyles, makeStyles, useTheme } from '@material-ui/core/styles';\nimport { QueryClientProvider } from '@tanstack/react-query';\n\nimport { useAllModels } from '../hooks/useAllModels';\nimport { useLightspeedViewPermission } from '../hooks/useLightspeedViewPermission';\nimport queryClient from '../utils/queryClient';\nimport { LightspeedChat } from './LightSpeedChat';\nimport PermissionRequiredState from './PermissionRequiredState';\n\nconst useStyles = makeStyles(() =>\n createStyles({\n container: {\n padding: '0px',\n },\n }),\n);\n\nconst THEME_DARK = 'dark';\nconst THEME_DARK_CLASS = 'pf-v6-theme-dark';\n\nconst LightspeedPageInner = () => {\n const classes = useStyles();\n const {\n palette: { type },\n } = useTheme();\n\n const identityApi = useApi(identityApiRef);\n\n const { data: models } = useAllModels();\n const { allowed: hasViewAccess, loading } = useLightspeedViewPermission();\n\n const { value: profile, loading: profileLoading } = useAsync(\n async () => await identityApi.getProfileInfo(),\n );\n\n const [selectedModel, setSelectedModel] = React.useState('');\n\n const modelsItems = React.useMemo(\n () => (models ? models.map(m => ({ label: m.id, value: m.id })) : []),\n [models],\n );\n\n React.useEffect(() => {\n const htmlTagElement = document.documentElement;\n if (type === THEME_DARK) {\n htmlTagElement.classList.add(THEME_DARK_CLASS);\n } else {\n htmlTagElement.classList.remove(THEME_DARK_CLASS);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [type]);\n\n React.useEffect(() => {\n if (modelsItems.length > 0) setSelectedModel(modelsItems[0].value);\n }, [modelsItems]);\n\n if (loading) {\n return null;\n }\n\n return (\n <Page themeId=\"tool\">\n <Content className={classes.container}>\n {!hasViewAccess ? (\n <PermissionRequiredState />\n ) : (\n <LightspeedChat\n selectedModel={selectedModel}\n handleSelectedModel={item => {\n setSelectedModel(item);\n }}\n models={modelsItems}\n userName={profile?.displayName}\n avatar={profile?.picture}\n profileLoading={profileLoading}\n />\n )}\n </Content>\n </Page>\n );\n};\n\nexport const LightspeedPage = () => {\n return (\n <QueryClientProvider client={queryClient}>\n <LightspeedPageInner />\n </QueryClientProvider>\n );\n};\n"],"names":["React"],"mappings":";;;;;;;;;;;;AA+BA,MAAM,SAAY,GAAA,UAAA;AAAA,EAAW,MAC3B,YAAa,CAAA;AAAA,IACX,SAAW,EAAA;AAAA,MACT,OAAS,EAAA;AAAA;AACX,GACD;AACH,CAAA;AAEA,MAAM,UAAa,GAAA,MAAA;AACnB,MAAM,gBAAmB,GAAA,kBAAA;AAEzB,MAAM,sBAAsB,MAAM;AAChC,EAAA,MAAM,UAAU,SAAU,EAAA;AAC1B,EAAM,MAAA;AAAA,IACJ,OAAA,EAAS,EAAE,IAAK;AAAA,MACd,QAAS,EAAA;AAEb,EAAM,MAAA,WAAA,GAAc,OAAO,cAAc,CAAA;AAEzC,EAAA,MAAM,EAAE,IAAA,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W,EAAA,OAAA,CAAQ,SACzB,EAAA,EAAA,CAAC,aACA,mBAAAA,cAAA,CAAA,aAAA,CAAC,6BAAwB,CAEzB,mBAAAA,cAAA,CAAA,aAAA;AAAA,IAAC,cAAA;AAAA,IAAA;AAAA,MACC,aAAA;AAAA,MACA,qBAAqB,CAAQ,IAAA,KAAA;AAC3B,QAAA,gBAAA,CAAiB,IAAI,CAAA;AAAA,OACvB;AAAA,MACA,MAAQ,EAAA,WAAA;AAAA,MACR,UAAU,OAAS,EAAA,WAAA;AAAA,MACnB,QAAQ,OAAS,EAAA,OAAA;AAAA,MACjB;AAAA;AAAA,GAGN,CACF,CAAA;AAEJ,CAAA;AAEO,MAAM,iBAAiB,MAAM;AAClC,EAAA,oDACG,mBAAoB,EAAA,EAAA,MAAA,EAAQ,WAC3B,EAAA,kBAAAA,cAAA,CAAA,aAAA,CAAC,yBAAoB,CACvB,CAAA;AAEJ;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"PermissionRequiredIcon.esm.js","sources":["../../src/components/PermissionRequiredIcon.tsx"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport * as React from 'react';\n\nimport permissionRequired from '../images/permission-required.svg';\n\nexport const PermissionRequiredIcon = () => {\n return <img src={permissionRequired as any} alt=\"permission required icon\" />;\n};\n"],"names":[],"mappings":";;;AAmBO,MAAM,yBAAyB,MAAM;AAC1C,EAAA,uBAAQ,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EAAI,GAAK,EAAA,kBAAA,EAA2B,KAAI,0BAA2B,EAAA,CAAA;AAC7E;;;;"}
1
+ {"version":3,"file":"PermissionRequiredIcon.esm.js","sources":["../../src/components/PermissionRequiredIcon.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as React from 'react';\n\nimport permissionRequired from '../images/permission-required.svg';\n\nexport const PermissionRequiredIcon = () => {\n return <img src={permissionRequired as any} alt=\"permission required icon\" />;\n};\n"],"names":[],"mappings":";;;AAoBO,MAAM,yBAAyB,MAAM;AAC1C,EAAA,uBAAQ,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EAAI,GAAK,EAAA,kBAAA,EAA2B,KAAI,0BAA2B,EAAA,CAAA;AAC7E;;;;"}
@@ -1,6 +1,6 @@
1
1
  import React__default from 'react';
2
2
  import { EmptyState } from '@backstage/core-components';
3
- import { Button, Typography } from '@material-ui/core';
3
+ import { Typography, Button } from '@material-ui/core';
4
4
  import { makeStyles, createStyles } from '@material-ui/core/styles';
5
5
  import OpenInNewIcon from '@mui/icons-material/OpenInNew';
6
6
  import { PermissionRequiredIcon } from './PermissionRequiredIcon.esm.js';
@@ -1 +1 @@
1
- {"version":3,"file":"PermissionRequiredState.esm.js","sources":["../../src/components/PermissionRequiredState.tsx"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport React from 'react';\n\nimport { EmptyState } from '@backstage/core-components';\n\nimport { Button, Typography } from '@material-ui/core';\nimport { createStyles, makeStyles } from '@material-ui/core/styles';\nimport OpenInNewIcon from '@mui/icons-material/OpenInNew';\n\nimport { PermissionRequiredIcon } from './PermissionRequiredIcon';\n\nconst useStyles = makeStyles(() =>\n createStyles({\n permissionError: {\n display: 'flex',\n height: '100%',\n alignItems: 'center',\n padding: '100px',\n },\n }),\n);\n\nconst PermissionRequiredState = () => {\n const classes = useStyles();\n\n return (\n <div className={classes.permissionError}>\n <EmptyState\n title=\"Missing permissions\"\n description={\n <Typography variant=\"subtitle1\">\n To view lightspeed plugin, contact your administrator to give the{' '}\n <b>lightspeed.conversations.read</b> and{' '}\n <b>lightspeed.conversations.create</b> permissions.\n </Typography>\n }\n missing={{ customImage: <PermissionRequiredIcon /> }}\n action={\n <Button\n variant=\"outlined\"\n color=\"primary\"\n target=\"_blank\"\n href=\"https://github.com/redhat-developer/rhdh-plugins/blob/main/workspaces/lightspeed/plugins/lightspeed/README.md#permission-framework-support\"\n >\n Read more &nbsp; <OpenInNewIcon />\n </Button>\n }\n />\n </div>\n );\n};\nexport default PermissionRequiredState;\n"],"names":["React"],"mappings":";;;;;;;AAyBA,MAAM,SAAY,GAAA,UAAA;AAAA,EAAW,MAC3B,YAAa,CAAA;AAAA,IACX,eAAiB,EAAA;AAAA,MACf,OAAS,EAAA,MAAA;AAAA,MACT,MAAQ,EAAA,MAAA;AAAA,MACR,UAAY,EAAA,QAAA;AAAA,MACZ,OAAS,EAAA;AAAA;AACX,GACD;AACH,CAAA;AAEA,MAAM,0BAA0B,MAAM;AACpC,EAAA,MAAM,UAAU,SAAU,EAAA;AAE1B,EAAA,uBACGA,cAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EAAI,SAAW,EAAA,OAAA,CAAQ,eACtB,EAAA,kBAAAA,cAAA,CAAA,aAAA;AAAA,IAAC,UAAA;AAAA,IAAA;AAAA,MACC,KAAM,EAAA,qBAAA;AAAA,MACN,6BACGA,cAAA,CAAA,aAAA,CAAA,UAAA,EAAA,EAAW,OAAQ,EAAA,WAAA,EAAA,EAAY,qEACoC,GAClE,kBAAAA,cAAA,CAAA,aAAA,CAAC,GAAE,EAAA,IAAA,EAAA,+BAA6B,GAAI,MAAK,EAAA,GAAA,+CACxC,GAAE,EAAA,IAAA,EAAA,iCAA+B,GAAI,eACxC,CAAA;AAAA,MAEF,OAAS,EAAA,EAAE,WAAa,kBAAAA,cAAA,CAAA,aAAA,CAAC,4BAAuB,CAAG,EAAA;AAAA,MACnD,MACE,kBAAAA,cAAA,CAAA,aAAA;AAAA,QAAC,MAAA;AAAA,QAAA;AAAA,UACC,OAAQ,EAAA,UAAA;AAAA,UACR,KAAM,EAAA,SAAA;AAAA,UACN,MAAO,EAAA,QAAA;AAAA,UACP,IAAK,EAAA;AAAA,SAAA;AAAA,QACN,iBAAA;AAAA,qDACmB,aAAc,EAAA,IAAA;AAAA;AAClC;AAAA,GAGN,CAAA;AAEJ;;;;"}
1
+ {"version":3,"file":"PermissionRequiredState.esm.js","sources":["../../src/components/PermissionRequiredState.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from 'react';\n\nimport { EmptyState } from '@backstage/core-components';\n\nimport { Button, Typography } from '@material-ui/core';\nimport { createStyles, makeStyles } from '@material-ui/core/styles';\nimport OpenInNewIcon from '@mui/icons-material/OpenInNew';\n\nimport { PermissionRequiredIcon } from './PermissionRequiredIcon';\n\nconst useStyles = makeStyles(() =>\n createStyles({\n permissionError: {\n display: 'flex',\n height: '100%',\n alignItems: 'center',\n padding: '100px',\n },\n }),\n);\n\nconst PermissionRequiredState = () => {\n const classes = useStyles();\n\n return (\n <div className={classes.permissionError}>\n <EmptyState\n title=\"Missing permissions\"\n description={\n <Typography variant=\"subtitle1\">\n To view lightspeed plugin, contact your administrator to give the{' '}\n <b>lightspeed.conversations.read</b> and{' '}\n <b>lightspeed.conversations.create</b> permissions.\n </Typography>\n }\n missing={{ customImage: <PermissionRequiredIcon /> }}\n action={\n <Button\n variant=\"outlined\"\n color=\"primary\"\n target=\"_blank\"\n href=\"https://github.com/redhat-developer/rhdh-plugins/blob/main/workspaces/lightspeed/plugins/lightspeed/README.md#permission-framework-support\"\n >\n Read more &nbsp; <OpenInNewIcon />\n </Button>\n }\n />\n </div>\n );\n};\nexport default PermissionRequiredState;\n"],"names":["React"],"mappings":";;;;;;;AA0BA,MAAM,SAAY,GAAA,UAAA;AAAA,EAAW,MAC3B,YAAa,CAAA;AAAA,IACX,eAAiB,EAAA;AAAA,MACf,OAAS,EAAA,MAAA;AAAA,MACT,MAAQ,EAAA,MAAA;AAAA,MACR,UAAY,EAAA,QAAA;AAAA,MACZ,OAAS,EAAA;AAAA;AACX,GACD;AACH,CAAA;AAEA,MAAM,0BAA0B,MAAM;AACpC,EAAA,MAAM,UAAU,SAAU,EAAA;AAE1B,EAAA,uBACGA,cAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EAAI,SAAW,EAAA,OAAA,CAAQ,eACtB,EAAA,kBAAAA,cAAA,CAAA,aAAA;AAAA,IAAC,UAAA;AAAA,IAAA;AAAA,MACC,KAAM,EAAA,qBAAA;AAAA,MACN,6BACGA,cAAA,CAAA,aAAA,CAAA,UAAA,EAAA,EAAW,OAAQ,EAAA,WAAA,EAAA,EAAY,qEACoC,GAClE,kBAAAA,cAAA,CAAA,aAAA,CAAC,GAAE,EAAA,IAAA,EAAA,+BAA6B,GAAI,MAAK,EAAA,GAAA,+CACxC,GAAE,EAAA,IAAA,EAAA,iCAA+B,GAAI,eACxC,CAAA;AAAA,MAEF,OAAS,EAAA,EAAE,WAAa,kBAAAA,cAAA,CAAA,aAAA,CAAC,4BAAuB,CAAG,EAAA;AAAA,MACnD,MACE,kBAAAA,cAAA,CAAA,aAAA;AAAA,QAAC,MAAA;AAAA,QAAA;AAAA,UACC,OAAQ,EAAA,UAAA;AAAA,UACR,KAAM,EAAA,SAAA;AAAA,UACN,MAAO,EAAA,QAAA;AAAA,UACP,IAAK,EAAA;AAAA,SAAA;AAAA,QACN,iBAAA;AAAA,qDACmB,aAAc,EAAA,IAAA;AAAA;AAClC;AAAA,GAGN,CAAA;AAEJ;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useAllModels.esm.js","sources":["../../src/hooks/useAllModels.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { useApi } from '@backstage/core-plugin-api';\n\nimport { useQuery } from '@tanstack/react-query';\n\nimport { lightspeedApiRef } from '../api/api';\n\n// Fetch all models\nexport const useAllModels = () => {\n const lightspeedApi = useApi(lightspeedApiRef);\n return useQuery({\n queryKey: ['models'],\n queryFn: async () => {\n const response = await lightspeedApi.getAllModels();\n return response;\n },\n staleTime: 1000 * 60 * 5, // 5 minutes\n });\n};\n"],"names":[],"mappings":";;;;AAsBO,MAAM,eAAe,MAAM;AAChC,EAAM,MAAA,aAAA,GAAgB,OAAO,gBAAgB,CAAA;AAC7C,EAAA,OAAO,QAAS,CAAA;AAAA,IACd,QAAA,EAAU,CAAC,QAAQ,CAAA;AAAA,IACnB,SAAS,YAAY;AACnB,MAAM,MAAA,QAAA,GAAW,MAAM,aAAA,CAAc,YAAa,EAAA;AAClD,MAAO,OAAA,QAAA;AAAA,KACT;AAAA,IACA,SAAA,EAAW,MAAO,EAAK,GAAA;AAAA;AAAA,GACxB,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"useAllModels.esm.js","sources":["../../src/hooks/useAllModels.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useApi } from '@backstage/core-plugin-api';\n\nimport { useQuery } from '@tanstack/react-query';\n\nimport { lightspeedApiRef } from '../api/api';\n\n// Fetch all models\nexport const useAllModels = () => {\n const lightspeedApi = useApi(lightspeedApiRef);\n return useQuery({\n queryKey: ['models'],\n queryFn: async () => {\n const response = await lightspeedApi.getAllModels();\n return response;\n },\n staleTime: 1000 * 60 * 5, // 5 minutes\n });\n};\n"],"names":[],"mappings":";;;;AAuBO,MAAM,eAAe,MAAM;AAChC,EAAM,MAAA,aAAA,GAAgB,OAAO,gBAAgB,CAAA;AAC7C,EAAA,OAAO,QAAS,CAAA;AAAA,IACd,QAAA,EAAU,CAAC,QAAQ,CAAA;AAAA,IACnB,SAAS,YAAY;AACnB,MAAM,MAAA,QAAA,GAAW,MAAM,aAAA,CAAc,YAAa,EAAA;AAClD,MAAO,OAAA,QAAA;AAAA,KACT;AAAA,IACA,SAAA,EAAW,MAAO,EAAK,GAAA;AAAA;AAAA,GACxB,CAAA;AACH;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useBackstageUserIdentity.esm.js","sources":["../../src/hooks/useBackstageUserIdentity.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { useAsync } from 'react-use';\n\nimport { identityApiRef, useApi } from '@backstage/core-plugin-api';\n\nexport const useBackstageUserIdentity = () => {\n const identityApi = useApi(identityApiRef);\n const { value: user } = useAsync(async () => {\n const identityRef = await identityApi.getBackstageIdentity();\n return identityRef.userEntityRef;\n });\n return user;\n};\n"],"names":[],"mappings":";;;AAmBO,MAAM,2BAA2B,MAAM;AAC5C,EAAM,MAAA,WAAA,GAAc,OAAO,cAAc,CAAA;AACzC,EAAA,MAAM,EAAE,KAAA,EAAO,IAAK,EAAA,GAAI,SAAS,YAAY;AAC3C,IAAM,MAAA,WAAA,GAAc,MAAM,WAAA,CAAY,oBAAqB,EAAA;AAC3D,IAAA,OAAO,WAAY,CAAA,aAAA;AAAA,GACpB,CAAA;AACD,EAAO,OAAA,IAAA;AACT;;;;"}
1
+ {"version":3,"file":"useBackstageUserIdentity.esm.js","sources":["../../src/hooks/useBackstageUserIdentity.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useAsync } from 'react-use';\n\nimport { identityApiRef, useApi } from '@backstage/core-plugin-api';\n\nexport const useBackstageUserIdentity = () => {\n const identityApi = useApi(identityApiRef);\n const { value: user } = useAsync(async () => {\n const identityRef = await identityApi.getBackstageIdentity();\n return identityRef.userEntityRef;\n });\n return user;\n};\n"],"names":[],"mappings":";;;AAoBO,MAAM,2BAA2B,MAAM;AAC5C,EAAM,MAAA,WAAA,GAAc,OAAO,cAAc,CAAA;AACzC,EAAA,MAAM,EAAE,KAAA,EAAO,IAAK,EAAA,GAAI,SAAS,YAAY;AAC3C,IAAM,MAAA,WAAA,GAAc,MAAM,WAAA,CAAY,oBAAqB,EAAA;AAC3D,IAAA,OAAO,WAAY,CAAA,aAAA;AAAA,GACpB,CAAA;AACD,EAAO,OAAA,IAAA;AACT;;;;"}
@@ -13,11 +13,12 @@ const useFetchConversationMessages = (currentConversation) => {
13
13
  queryFn: currentConversation ? async () => {
14
14
  const response = await lightspeedApi.getConversationMessages(currentConversation);
15
15
  return response;
16
- } : void 0,
16
+ } : undefined,
17
17
  retry: false
18
18
  });
19
19
  };
20
- const useConversationMessages = (conversationId, userName, selectedModel, avatar, onComplete) => {
20
+ const defaultAvatar = "https://img.freepik.com/premium-photo/graphic-designer-digital-avatar-generative-ai_934475-9292.jpg";
21
+ const useConversationMessages = (conversationId, userName, selectedModel, avatar = defaultAvatar, onComplete) => {
21
22
  const { mutateAsync: createMessage } = useCreateConversationMessage();
22
23
  const scrollToBottomRef = React__default.useRef(null);
23
24
  const [currentConversation, setCurrentConversation] = React__default.useState(conversationId);
@@ -1 +1 @@
1
- {"version":3,"file":"useConversationMessages.esm.js","sources":["../../src/hooks/useConversationMessages.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport React from 'react';\n\nimport { useApi } from '@backstage/core-plugin-api';\n\nimport { MessageProps } from '@patternfly/virtual-assistant';\nimport { useQuery } from '@tanstack/react-query';\n\nimport { lightspeedApiRef } from '../api/api';\nimport logo from '../images/logo.svg';\nimport {\n createBotMessage,\n createUserMessage,\n getMessageData,\n getTimestamp,\n splitJsonStrings,\n} from '../utils/lightspeed-chatbox-utils';\nimport { useCreateConversationMessage } from './useCreateCoversationMessage';\n\n// Fetch all conversation messages\nexport const useFetchConversationMessages = (currentConversation: string) => {\n const lightspeedApi = useApi(lightspeedApiRef);\n return useQuery({\n queryKey: ['conversationMessages', currentConversation],\n queryFn: currentConversation\n ? async () => {\n const response =\n await lightspeedApi.getConversationMessages(currentConversation);\n\n return response;\n }\n : undefined,\n retry: false,\n });\n};\n\ntype Conversations = { [_key: string]: MessageProps[] };\n\n/**\n * Fetches all the messages for given conversation_id\n * @param conversationId\n * @param userName\n * @param selectedModel\n * @param avatar\n *\n */\nexport const useConversationMessages = (\n conversationId: string,\n userName: string | undefined,\n selectedModel: string,\n avatar: string | undefined,\n onComplete?: (message: string) => void,\n) => {\n const { mutateAsync: createMessage } = useCreateConversationMessage();\n const scrollToBottomRef = React.useRef<HTMLDivElement>(null);\n\n const [currentConversation, setCurrentConversation] =\n React.useState(conversationId);\n const [conversations, setConversations] = React.useState<Conversations>({\n [currentConversation]: [],\n });\n const streamingConversations = React.useRef<Conversations>({\n [currentConversation]: [],\n });\n\n React.useEffect(() => {\n if (currentConversation !== conversationId) {\n setCurrentConversation(conversationId);\n setConversations({\n [conversationId]: [],\n });\n }\n }, [currentConversation, conversationId]);\n\n const { data: conversationsData = [], ...queryProps } =\n useFetchConversationMessages(currentConversation);\n\n React.useEffect(() => {\n if (!Array.isArray(conversationsData) || conversationsData.length === 0)\n return;\n\n const newConvoIndex: number[] = [];\n\n if (conversations) {\n const _conversations: { [key: string]: any[] } = {\n [currentConversation]: [],\n };\n\n let index = 0;\n for (let i = 0; i < conversationsData.length; i += 2) {\n const userMessage = conversationsData[i];\n const aiMessage = conversationsData[i + 1];\n\n const { content: humanMessage, timestamp: userTimestamp } =\n getMessageData(userMessage);\n const {\n model,\n content: botMessage,\n timestamp: botTimestamp,\n } = getMessageData(aiMessage);\n\n _conversations[currentConversation].push(\n ...[\n createUserMessage({\n avatar,\n name: userName,\n content: humanMessage,\n timestamp: userTimestamp,\n }),\n createBotMessage({\n avatar: logo,\n isLoading: false,\n name: model ?? selectedModel,\n content: botMessage,\n timestamp: botTimestamp,\n }),\n ],\n );\n\n newConvoIndex.push(index);\n index++;\n }\n\n if (streamingConversations.current[currentConversation]) {\n _conversations[currentConversation].push(\n ...streamingConversations.current[currentConversation],\n );\n }\n\n setConversations(_conversations);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n conversationsData,\n userName,\n avatar,\n currentConversation,\n selectedModel,\n streamingConversations,\n ]);\n\n const handleInputPrompt = React.useCallback(\n async (prompt: string) => {\n const conversationTuple = [\n createUserMessage({\n avatar,\n name: userName,\n content: prompt,\n timestamp: getTimestamp(Date.now()) ?? '',\n }),\n createBotMessage({\n avatar: logo,\n isLoading: true,\n name: selectedModel,\n content: '',\n timestamp: '',\n }),\n ];\n\n streamingConversations.current = {\n ...streamingConversations.current,\n [currentConversation]: conversationTuple,\n };\n\n setConversations((prevConv: Conversations) => {\n return {\n ...prevConv,\n [currentConversation]: [\n ...(prevConv?.[currentConversation] ?? []),\n ...conversationTuple,\n ],\n };\n });\n\n setTimeout(() => {\n scrollToBottomRef.current?.scrollIntoView({ behavior: 'auto' });\n }, 0);\n const finalMessages: string[] = [];\n\n try {\n const reader = await createMessage({\n prompt,\n selectedModel,\n currentConversation,\n });\n\n const decoder = new TextDecoder('utf-8');\n const keepGoing = true;\n while (keepGoing) {\n const { done, value } = await reader.read();\n if (done) break;\n\n const chunk = decoder.decode(value, { stream: true });\n\n const data = splitJsonStrings(chunk) ?? [];\n data?.forEach(line => {\n const trimmedLine = line.trim();\n // Ignore empty lines\n if (!trimmedLine) return;\n try {\n const jsonData = JSON.parse(line);\n const content = jsonData?.response?.kwargs?.content || '';\n finalMessages.push(content);\n\n // Store streaming message\n const [humanMessage, aiMessage] =\n streamingConversations.current[currentConversation];\n streamingConversations.current[currentConversation] = [\n humanMessage,\n { ...aiMessage, content: aiMessage.content + content },\n ];\n\n setConversations(prevConversations => {\n const conversation =\n prevConversations[currentConversation] ?? [];\n\n const lastMessageIndex = conversation.length - 1;\n const lastMessage =\n conversation.length === 0\n ? createBotMessage({\n content: '',\n timestamp: getTimestamp(Date.now()),\n })\n : { ...conversation[lastMessageIndex] };\n\n lastMessage.isLoading = false;\n lastMessage.content += content;\n lastMessage.name =\n jsonData?.response?.kwargs?.response_metadata?.model;\n lastMessage.timestamp = getTimestamp(\n jsonData?.response?.kwargs?.response_metadata?.created_at ||\n Date.now(),\n );\n\n const updatedConversation = [\n ...conversation.slice(0, lastMessageIndex),\n lastMessage,\n ];\n\n return {\n ...prevConversations,\n [currentConversation]: updatedConversation,\n };\n });\n } catch (error) {\n // eslint-disable-next-line no-console\n console.warn('Error parsing JSON:', error);\n if (typeof onComplete === 'function') {\n onComplete('Invalid JSON received');\n }\n }\n });\n }\n } catch (e) {\n setConversations(prevConversations => {\n const conversation = prevConversations[currentConversation] ?? [];\n\n const lastMessageIndex = conversation.length - 1;\n const lastMessage =\n conversation.length === 0\n ? createBotMessage({\n content: '',\n timestamp: getTimestamp(Date.now()),\n })\n : { ...conversation[lastMessageIndex] };\n\n lastMessage.isLoading = false;\n lastMessage.content += e;\n lastMessage.timestamp = getTimestamp(Date.now());\n\n const updatedConversation = [\n ...conversation.slice(0, lastMessageIndex),\n lastMessage,\n ];\n\n finalMessages.push(`${e}`);\n\n return {\n ...prevConversations,\n [currentConversation]: updatedConversation,\n };\n });\n }\n // reset current streaming\n streamingConversations.current[currentConversation] = [];\n if (typeof onComplete === 'function') {\n onComplete(finalMessages.join(''));\n }\n },\n\n [\n avatar,\n userName,\n onComplete,\n selectedModel,\n createMessage,\n currentConversation,\n ],\n );\n\n return {\n conversationMessages: conversations[currentConversation] ?? [],\n handleInputPrompt,\n conversations,\n scrollToBottomRef,\n ...queryProps,\n };\n};\n"],"names":["React"],"mappings":";;;;;;;;AAkCa,MAAA,4BAAA,GAA+B,CAAC,mBAAgC,KAAA;AAC3E,EAAM,MAAA,aAAA,GAAgB,OAAO,gBAAgB,CAAA;AAC7C,EAAA,OAAO,QAAS,CAAA;AAAA,IACd,QAAA,EAAU,CAAC,sBAAA,EAAwB,mBAAmB,CAAA;AAAA,IACtD,OAAA,EAAS,sBACL,YAAY;AACV,MAAA,MAAM,QACJ,GAAA,MAAM,aAAc,CAAA,uBAAA,CAAwB,mBAAmB,CAAA;AAEjE,MAAO,OAAA,QAAA;AAAA,KAET,GAAA,KAAA,CAAA;AAAA,IACJ,KAAO,EAAA;AAAA,GACR,CAAA;AACH;AAYO,MAAM,0BAA0B,CACrC,cAAA,EACA,QACA,EAAA,aAAA,EACA,QACA,UACG,KAAA;AACH,EAAA,MAAM,EAAE,WAAA,EAAa,aAAc,EAAA,GAAI,4BAA6B,EAAA;AACpE,EAAM,MAAA,iBAAA,GAAoBA,cAAM,CAAA,MAAA,CAAuB,IAAI,CAAA;AAE3D,EAAA,MAAM,CAAC,mBAAqB,EAAA,sBAAsB,CAChD,GAAAA,cAAA,CAAM,SAAS,cAAc,CAAA;AAC/B,EAAA,MAAM,CAAC,aAAA,EAAe,gBAAgB,CAAA,GAAIA,eAAM,QAAwB,CAAA;AAAA,IACtE,CAAC,mBAAmB,GAAG;AAAC,GACzB,CAAA;AACD,EAAM,MAAA,sBAAA,GAAyBA,eAAM,MAAsB,CAAA;AAAA,IACzD,CAAC,mBAAmB,GAAG;AAAC,GACzB,CAAA;AAED,EAAAA,cAAA,CAAM,UAAU,MAAM;AACpB,IAAA,IAAI,wBAA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,KACF;AAAA,IAEA;AAAA,MACE,MAAA;AAAA,MACA,QAAA;AAAA,MACA,UAAA;AAAA,MACA,aAAA;AAAA,MACA,aAAA;AAAA,MACA;AAAA;AACF,GACF;AAEA,EAAO,OAAA;AAAA,IACL,oBAAsB,EAAA,aAAA,CAAc,mBAAmB,CAAA,IAAK,EAAC;AAAA,IAC7D,iBAAA;AAAA,IACA,aAAA;AAAA,IACA,iBAAA;AAAA,IACA,GAAG;AAAA,GACL;AACF;;;;"}
1
+ {"version":3,"file":"useConversationMessages.esm.js","sources":["../../src/hooks/useConversationMessages.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from 'react';\n\nimport { useApi } from '@backstage/core-plugin-api';\n\nimport { MessageProps } from '@patternfly/chatbot';\nimport { useQuery } from '@tanstack/react-query';\n\nimport { lightspeedApiRef } from '../api/api';\nimport logo from '../images/logo.svg';\nimport {\n createBotMessage,\n createUserMessage,\n getMessageData,\n getTimestamp,\n splitJsonStrings,\n} from '../utils/lightspeed-chatbox-utils';\nimport { useCreateConversationMessage } from './useCreateCoversationMessage';\n\n// Fetch all conversation messages\nexport const useFetchConversationMessages = (currentConversation: string) => {\n const lightspeedApi = useApi(lightspeedApiRef);\n return useQuery({\n queryKey: ['conversationMessages', currentConversation],\n queryFn: currentConversation\n ? async () => {\n const response =\n await lightspeedApi.getConversationMessages(currentConversation);\n\n return response;\n }\n : undefined,\n retry: false,\n });\n};\n\ntype Conversations = { [_key: string]: MessageProps[] };\n\nconst defaultAvatar =\n 'https://img.freepik.com/premium-photo/graphic-designer-digital-avatar-generative-ai_934475-9292.jpg';\n/**\n * Fetches all the messages for given conversation_id\n * @param conversationId\n * @param userName\n * @param selectedModel\n * @param avatar\n *\n */\nexport const useConversationMessages = (\n conversationId: string,\n userName: string | undefined,\n selectedModel: string,\n avatar: string = defaultAvatar,\n onComplete?: (message: string) => void,\n) => {\n const { mutateAsync: createMessage } = useCreateConversationMessage();\n const scrollToBottomRef = React.useRef<HTMLDivElement>(null);\n\n const [currentConversation, setCurrentConversation] =\n React.useState(conversationId);\n const [conversations, setConversations] = React.useState<Conversations>({\n [currentConversation]: [],\n });\n const streamingConversations = React.useRef<Conversations>({\n [currentConversation]: [],\n });\n\n React.useEffect(() => {\n if (currentConversation !== conversationId) {\n setCurrentConversation(conversationId);\n setConversations({\n [conversationId]: [],\n });\n }\n }, [currentConversation, conversationId]);\n\n const { data: conversationsData = [], ...queryProps } =\n useFetchConversationMessages(currentConversation);\n\n React.useEffect(() => {\n if (!Array.isArray(conversationsData) || conversationsData.length === 0)\n return;\n\n const newConvoIndex: number[] = [];\n\n if (conversations) {\n const _conversations: { [key: string]: any[] } = {\n [currentConversation]: [],\n };\n\n let index = 0;\n for (let i = 0; i < conversationsData.length; i += 2) {\n const userMessage = conversationsData[i];\n const aiMessage = conversationsData[i + 1];\n\n const { content: humanMessage, timestamp: userTimestamp } =\n getMessageData(userMessage);\n const {\n model,\n content: botMessage,\n timestamp: botTimestamp,\n } = getMessageData(aiMessage);\n\n _conversations[currentConversation].push(\n ...[\n createUserMessage({\n avatar,\n name: userName,\n content: humanMessage,\n timestamp: userTimestamp,\n }),\n createBotMessage({\n avatar: logo,\n isLoading: false,\n name: model ?? selectedModel,\n content: botMessage,\n timestamp: botTimestamp,\n }),\n ],\n );\n\n newConvoIndex.push(index);\n index++;\n }\n\n if (streamingConversations.current[currentConversation]) {\n _conversations[currentConversation].push(\n ...streamingConversations.current[currentConversation],\n );\n }\n\n setConversations(_conversations);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n conversationsData,\n userName,\n avatar,\n currentConversation,\n selectedModel,\n streamingConversations,\n ]);\n\n const handleInputPrompt = React.useCallback(\n async (prompt: string) => {\n const conversationTuple = [\n createUserMessage({\n avatar,\n name: userName,\n content: prompt,\n timestamp: getTimestamp(Date.now()) ?? '',\n }),\n createBotMessage({\n avatar: logo,\n isLoading: true,\n name: selectedModel,\n content: '',\n timestamp: '',\n }),\n ];\n\n streamingConversations.current = {\n ...streamingConversations.current,\n [currentConversation]: conversationTuple,\n };\n\n setConversations((prevConv: Conversations) => {\n return {\n ...prevConv,\n [currentConversation]: [\n ...(prevConv?.[currentConversation] ?? []),\n ...conversationTuple,\n ],\n };\n });\n\n setTimeout(() => {\n scrollToBottomRef.current?.scrollIntoView({ behavior: 'auto' });\n }, 0);\n const finalMessages: string[] = [];\n\n try {\n const reader = await createMessage({\n prompt,\n selectedModel,\n currentConversation,\n });\n\n const decoder = new TextDecoder('utf-8');\n const keepGoing = true;\n while (keepGoing) {\n const { done, value } = await reader.read();\n if (done) break;\n\n const chunk = decoder.decode(value, { stream: true });\n\n const data = splitJsonStrings(chunk) ?? [];\n data?.forEach(line => {\n const trimmedLine = line.trim();\n // Ignore empty lines\n if (!trimmedLine) return;\n try {\n const jsonData = JSON.parse(line);\n const content = jsonData?.response?.kwargs?.content || '';\n finalMessages.push(content);\n\n // Store streaming message\n const [humanMessage, aiMessage] =\n streamingConversations.current[currentConversation];\n streamingConversations.current[currentConversation] = [\n humanMessage,\n { ...aiMessage, content: aiMessage.content + content },\n ];\n\n setConversations(prevConversations => {\n const conversation =\n prevConversations[currentConversation] ?? [];\n\n const lastMessageIndex = conversation.length - 1;\n const lastMessage =\n conversation.length === 0\n ? createBotMessage({\n content: '',\n timestamp: getTimestamp(Date.now()),\n })\n : { ...conversation[lastMessageIndex] };\n\n lastMessage.isLoading = false;\n lastMessage.content += content;\n lastMessage.name =\n jsonData?.response?.kwargs?.response_metadata?.model;\n lastMessage.timestamp = getTimestamp(\n jsonData?.response?.kwargs?.response_metadata?.created_at ||\n Date.now(),\n );\n\n const updatedConversation = [\n ...conversation.slice(0, lastMessageIndex),\n lastMessage,\n ];\n\n return {\n ...prevConversations,\n [currentConversation]: updatedConversation,\n };\n });\n } catch (error) {\n // eslint-disable-next-line no-console\n console.warn('Error parsing JSON:', error);\n if (typeof onComplete === 'function') {\n onComplete('Invalid JSON received');\n }\n }\n });\n }\n } catch (e) {\n setConversations(prevConversations => {\n const conversation = prevConversations[currentConversation] ?? [];\n\n const lastMessageIndex = conversation.length - 1;\n const lastMessage =\n conversation.length === 0\n ? createBotMessage({\n content: '',\n timestamp: getTimestamp(Date.now()),\n })\n : { ...conversation[lastMessageIndex] };\n\n lastMessage.isLoading = false;\n lastMessage.content += e;\n lastMessage.timestamp = getTimestamp(Date.now());\n\n const updatedConversation = [\n ...conversation.slice(0, lastMessageIndex),\n lastMessage,\n ];\n\n finalMessages.push(`${e}`);\n\n return {\n ...prevConversations,\n [currentConversation]: updatedConversation,\n };\n });\n }\n // reset current streaming\n streamingConversations.current[currentConversation] = [];\n if (typeof onComplete === 'function') {\n onComplete(finalMessages.join(''));\n }\n },\n\n [\n avatar,\n userName,\n onComplete,\n selectedModel,\n createMessage,\n currentConversation,\n ],\n );\n\n return {\n conversationMessages: conversations[currentConversation] ?? [],\n handleInputPrompt,\n conversations,\n scrollToBottomRef,\n ...queryProps,\n };\n};\n"],"names":["React"],"mappings":";;;;;;;;AAmCa,MAAA,4BAAA,GAA+B,CAAC,mBAAgC,KAAA;AAC3E,EAAM,MAAA,aAAA,GAAgB,OAAO,gBAAgB,CAAA;AAC7C,EAAA,OAAO,QAAS,CAAA;AAAA,IACd,QAAA,EAAU,CAAC,sBAAA,EAAwB,mBAAmB,CAAA;AAAA,IACtD,OAAA,EAAS,sBACL,YAAY;AACV,MAAA,MAAM,QACJ,GAAA,MAAM,aAAc,CAAA,uBAAA,CAAwB,mBAAmB,CAAA;AAEjE,MAAO,OAAA,QAAA;AAAA,KAET,GAAA,SAAA;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,gBAAgB,CAAE,EAAA;AAE1C,UAAA,WAAA,CAAY,SAAY,GAAA,KAAA;AACxB,UAAA,WAAA,CAAY,OAAW,IAAA,CAAA;AACvB,UAAA,WAAA,CAAY,SAAY,GAAA,YAAA,CAAa,IAAK,CAAA,GAAA,EAAK,CAAA;AAE/C,UAAA,MAAM,mBAAsB,GAAA;AAAA,YAC1B,GAAG,YAAA,CAAa,KAAM,CAAA,CAAA,EAAG,gBAAgB,CAAA;AAAA,YACzC;AAAA,WACF;AAEA,UAAc,aAAA,CAAA,IAAA,CAAK,CAAG,EAAA,CAAC,CAAE,CAAA,CAAA;AAEzB,UAAO,OAAA;AAAA,YACL,GAAG,iBAAA;AAAA,YACH,CAAC,mBAAmB,GAAG;AAAA,WACzB;AAAA,SACD,CAAA;AAAA;AAGH,MAAuB,sBAAA,CAAA,OAAA,CAAQ,mBAAmB,CAAA,GAAI,EAAC;AACvD,MAAI,IAAA,OAAO,eAAe,UAAY,EAAA;AACpC,QAAW,UAAA,CAAA,aAAA,CAAc,IAAK,CAAA,EAAE,CAAC,CAAA;AAAA;AACnC,KACF;AAAA,IAEA;AAAA,MACE,MAAA;AAAA,MACA,QAAA;AAAA,MACA,UAAA;AAAA,MACA,aAAA;AAAA,MACA,aAAA;AAAA,MACA;AAAA;AACF,GACF;AAEA,EAAO,OAAA;AAAA,IACL,oBAAsB,EAAA,aAAA,CAAc,mBAAmB,CAAA,IAAK,EAAC;AAAA,IAC7D,iBAAA;AAAA,IACA,aAAA;AAAA,IACA,iBAAA;AAAA,IACA,GAAG;AAAA,GACL;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useConversations.esm.js","sources":["../../src/hooks/useConversations.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { useApi } from '@backstage/core-plugin-api';\n\nimport { useQuery } from '@tanstack/react-query';\n\nimport { lightspeedApiRef } from '../api/api';\n\n// Fetch all conversations\nexport const useConversations = () => {\n const lightspeedApi = useApi(lightspeedApiRef);\n return useQuery({\n queryKey: ['conversations'],\n queryFn: async () => {\n const response = await lightspeedApi.getConversations();\n return response;\n },\n staleTime: 1000 * 60 * 5, // 5 minutes\n });\n};\n"],"names":[],"mappings":";;;;AAsBO,MAAM,mBAAmB,MAAM;AACpC,EAAM,MAAA,aAAA,GAAgB,OAAO,gBAAgB,CAAA;AAC7C,EAAA,OAAO,QAAS,CAAA;AAAA,IACd,QAAA,EAAU,CAAC,eAAe,CAAA;AAAA,IAC1B,SAAS,YAAY;AACnB,MAAM,MAAA,QAAA,GAAW,MAAM,aAAA,CAAc,gBAAiB,EAAA;AACtD,MAAO,OAAA,QAAA;AAAA,KACT;AAAA,IACA,SAAA,EAAW,MAAO,EAAK,GAAA;AAAA;AAAA,GACxB,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"useConversations.esm.js","sources":["../../src/hooks/useConversations.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useApi } from '@backstage/core-plugin-api';\n\nimport { useQuery } from '@tanstack/react-query';\n\nimport { lightspeedApiRef } from '../api/api';\n\n// Fetch all conversations\nexport const useConversations = () => {\n const lightspeedApi = useApi(lightspeedApiRef);\n return useQuery({\n queryKey: ['conversations'],\n queryFn: async () => {\n const response = await lightspeedApi.getConversations();\n return response;\n },\n staleTime: 1000 * 60 * 5, // 5 minutes\n });\n};\n"],"names":[],"mappings":";;;;AAuBO,MAAM,mBAAmB,MAAM;AACpC,EAAM,MAAA,aAAA,GAAgB,OAAO,gBAAgB,CAAA;AAC7C,EAAA,OAAO,QAAS,CAAA;AAAA,IACd,QAAA,EAAU,CAAC,eAAe,CAAA;AAAA,IAC1B,SAAS,YAAY;AACnB,MAAM,MAAA,QAAA,GAAW,MAAM,aAAA,CAAc,gBAAiB,EAAA;AACtD,MAAO,OAAA,QAAA;AAAA,KACT;AAAA,IACA,SAAA,EAAW,MAAO,EAAK,GAAA;AAAA;AAAA,GACxB,CAAA;AACH;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useCreateConversation.esm.js","sources":["../../src/hooks/useCreateConversation.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { useApi } from '@backstage/core-plugin-api';\n\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\n\nimport { lightspeedApiRef } from '../api/api';\n\nexport const useCreateConversation = () => {\n const lightspeedApi = useApi(lightspeedApiRef);\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: () => {\n return lightspeedApi.createConversation();\n },\n onSuccess: () => {\n queryClient.invalidateQueries({ queryKey: ['conversations'] });\n },\n });\n};\n"],"names":[],"mappings":";;;;AAqBO,MAAM,wBAAwB,MAAM;AACzC,EAAM,MAAA,aAAA,GAAgB,OAAO,gBAAgB,CAAA;AAC7C,EAAA,MAAM,cAAc,cAAe,EAAA;AAEnC,EAAA,OAAO,WAAY,CAAA;AAAA,IACjB,YAAY,MAAM;AAChB,MAAA,OAAO,cAAc,kBAAmB,EAAA;AAAA,KAC1C;AAAA,IACA,WAAW,MAAM;AACf,MAAA,WAAA,CAAY,kBAAkB,EAAE,QAAA,EAAU,CAAC,eAAe,GAAG,CAAA;AAAA;AAC/D,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"useCreateConversation.esm.js","sources":["../../src/hooks/useCreateConversation.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useApi } from '@backstage/core-plugin-api';\n\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\n\nimport { lightspeedApiRef } from '../api/api';\n\nexport const useCreateConversation = () => {\n const lightspeedApi = useApi(lightspeedApiRef);\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: () => {\n return lightspeedApi.createConversation();\n },\n onSuccess: () => {\n queryClient.invalidateQueries({ queryKey: ['conversations'] });\n },\n });\n};\n"],"names":[],"mappings":";;;;AAsBO,MAAM,wBAAwB,MAAM;AACzC,EAAM,MAAA,aAAA,GAAgB,OAAO,gBAAgB,CAAA;AAC7C,EAAA,MAAM,cAAc,cAAe,EAAA;AAEnC,EAAA,OAAO,WAAY,CAAA;AAAA,IACjB,YAAY,MAAM;AAChB,MAAA,OAAO,cAAc,kBAAmB,EAAA;AAAA,KAC1C;AAAA,IACA,WAAW,MAAM;AACf,MAAA,WAAA,CAAY,kBAAkB,EAAE,QAAA,EAAU,CAAC,eAAe,GAAG,CAAA;AAAA;AAC/D,GACD,CAAA;AACH;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useCreateCoversationMessage.esm.js","sources":["../../src/hooks/useCreateCoversationMessage.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { useApi } from '@backstage/core-plugin-api';\n\nimport { useMutation } from '@tanstack/react-query';\n\nimport { lightspeedApiRef } from '../api/api';\n\nexport const useCreateConversationMessage = () => {\n const lightspeedApi = useApi(lightspeedApiRef);\n\n return useMutation({\n mutationFn: async ({\n prompt,\n selectedModel,\n currentConversation,\n }: {\n prompt: string;\n selectedModel: string;\n currentConversation: string;\n }) => {\n if (!currentConversation) {\n throw new Error('Failed to generate AI response');\n }\n\n return await lightspeedApi.createMessage(\n `${prompt}`,\n selectedModel,\n currentConversation,\n );\n },\n onError: error => {\n // eslint-disable-next-line\n console.warn(error);\n },\n });\n};\n"],"names":[],"mappings":";;;;AAqBO,MAAM,+BAA+B,MAAM;AAChD,EAAM,MAAA,aAAA,GAAgB,OAAO,gBAAgB,CAAA;AAE7C,EAAA,OAAO,WAAY,CAAA;AAAA,IACjB,YAAY,OAAO;AAAA,MACjB,MAAA;AAAA,MACA,aAAA;AAAA,MACA;AAAA,KAKI,KAAA;AACJ,MAAA,IAAI,CAAC,mBAAqB,EAAA;AACxB,QAAM,MAAA,IAAI,MAAM,gCAAgC,CAAA;AAAA;AAGlD,MAAA,OAAO,MAAM,aAAc,CAAA,aAAA;AAAA,QACzB,GAAG,MAAM,CAAA,CAAA;AAAA,QACT,aAAA;AAAA,QACA;AAAA,OACF;AAAA,KACF;AAAA,IACA,SAAS,CAAS,KAAA,KAAA;AAEhB,MAAA,OAAA,CAAQ,KAAK,KAAK,CAAA;AAAA;AACpB,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"useCreateCoversationMessage.esm.js","sources":["../../src/hooks/useCreateCoversationMessage.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useApi } from '@backstage/core-plugin-api';\n\nimport { useMutation } from '@tanstack/react-query';\n\nimport { lightspeedApiRef } from '../api/api';\n\nexport const useCreateConversationMessage = () => {\n const lightspeedApi = useApi(lightspeedApiRef);\n\n return useMutation({\n mutationFn: async ({\n prompt,\n selectedModel,\n currentConversation,\n }: {\n prompt: string;\n selectedModel: string;\n currentConversation: string;\n }) => {\n if (!currentConversation) {\n throw new Error('Failed to generate AI response');\n }\n\n return await lightspeedApi.createMessage(\n `${prompt}`,\n selectedModel,\n currentConversation,\n );\n },\n onError: error => {\n // eslint-disable-next-line\n console.warn(error);\n },\n });\n};\n"],"names":[],"mappings":";;;;AAsBO,MAAM,+BAA+B,MAAM;AAChD,EAAM,MAAA,aAAA,GAAgB,OAAO,gBAAgB,CAAA;AAE7C,EAAA,OAAO,WAAY,CAAA;AAAA,IACjB,YAAY,OAAO;AAAA,MACjB,MAAA;AAAA,MACA,aAAA;AAAA,MACA;AAAA,KAKI,KAAA;AACJ,MAAA,IAAI,CAAC,mBAAqB,EAAA;AACxB,QAAM,MAAA,IAAI,MAAM,gCAAgC,CAAA;AAAA;AAGlD,MAAA,OAAO,MAAM,aAAc,CAAA,aAAA;AAAA,QACzB,GAAG,MAAM,CAAA,CAAA;AAAA,QACT,aAAA;AAAA,QACA;AAAA,OACF;AAAA,KACF;AAAA,IACA,SAAS,CAAS,KAAA,KAAA;AAEhB,MAAA,OAAA,CAAQ,KAAK,KAAK,CAAA;AAAA;AACpB,GACD,CAAA;AACH;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useDeleteConversation.esm.js","sources":["../../src/hooks/useDeleteConversation.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { useApi } from '@backstage/core-plugin-api';\n\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\n\nimport { lightspeedApiRef } from '../api/api';\nimport { ConversationList } from '../types';\n\nexport const useDeleteConversation = () => {\n const lightspeedApi = useApi(lightspeedApiRef);\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: async (props: {\n conversation_id: string;\n invalidateCache?: boolean;\n }) => {\n await lightspeedApi.deleteConversation(props.conversation_id);\n },\n onMutate: async props => {\n await queryClient.cancelQueries({ queryKey: ['conversations'] });\n\n const previousConversations: ConversationList | undefined =\n queryClient.getQueryData(['conversations']);\n\n queryClient.setQueryData(['conversations'], (old: ConversationList) =>\n old.filter(c => c.conversation_id !== props.conversation_id),\n );\n\n return { previousConversations };\n },\n onSuccess: (_, props) => {\n if (props.invalidateCache) {\n queryClient.invalidateQueries({ queryKey: ['conversations'] });\n }\n },\n onError: (_, __, context) => {\n queryClient.setQueryData(\n ['conversations'],\n context?.previousConversations,\n );\n return { success: false };\n },\n });\n};\n"],"names":[],"mappings":";;;;AAsBO,MAAM,wBAAwB,MAAM;AACzC,EAAM,MAAA,aAAA,GAAgB,OAAO,gBAAgB,CAAA;AAC7C,EAAA,MAAM,cAAc,cAAe,EAAA;AAEnC,EAAA,OAAO,WAAY,CAAA;AAAA,IACjB,UAAA,EAAY,OAAO,KAGb,KAAA;AACJ,MAAM,MAAA,aAAA,CAAc,kBAAmB,CAAA,KAAA,CAAM,eAAe,CAAA;AAAA,KAC9D;AAAA,IACA,QAAA,EAAU,OAAM,KAAS,KAAA;AACvB,MAAA,MAAM,YAAY,aAAc,CAAA,EAAE,UAAU,CAAC,eAAe,GAAG,CAAA;AAE/D,MAAA,MAAM,qBACJ,GAAA,WAAA,CAAY,YAAa,CAAA,CAAC,eAAe,CAAC,CAAA;AAE5C,MAAY,WAAA,CAAA,YAAA;AAAA,QAAa,CAAC,eAAe,CAAA;AAAA,QAAG,CAAC,QAC3C,GAAI,CAAA,MAAA,CAAO,OAAK,CAAE,CAAA,eAAA,KAAoB,MAAM,eAAe;AAAA,OAC7D;AAEA,MAAA,OAAO,EAAE,qBAAsB,EAAA;AAAA,KACjC;AAAA,IACA,SAAA,EAAW,CAAC,CAAA,EAAG,KAAU,KAAA;AACvB,MAAA,IAAI,MAAM,eAAiB,EAAA;AACzB,QAAA,WAAA,CAAY,kBAAkB,EAAE,QAAA,EAAU,CAAC,eAAe,GAAG,CAAA;AAAA;AAC/D,KACF;AAAA,IACA,OAAS,EAAA,CAAC,CAAG,EAAA,EAAA,EAAI,OAAY,KAAA;AAC3B,MAAY,WAAA,CAAA,YAAA;AAAA,QACV,CAAC,eAAe,CAAA;AAAA,QAChB,OAAS,EAAA;AAAA,OACX;AACA,MAAO,OAAA,EAAE,SAAS,KAAM,EAAA;AAAA;AAC1B,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"useDeleteConversation.esm.js","sources":["../../src/hooks/useDeleteConversation.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useApi } from '@backstage/core-plugin-api';\n\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\n\nimport { lightspeedApiRef } from '../api/api';\nimport { ConversationList } from '../types';\n\nexport const useDeleteConversation = () => {\n const lightspeedApi = useApi(lightspeedApiRef);\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: async (props: {\n conversation_id: string;\n invalidateCache?: boolean;\n }) => {\n await lightspeedApi.deleteConversation(props.conversation_id);\n },\n onMutate: async props => {\n await queryClient.cancelQueries({ queryKey: ['conversations'] });\n\n const previousConversations: ConversationList | undefined =\n queryClient.getQueryData(['conversations']);\n\n queryClient.setQueryData(['conversations'], (old: ConversationList) =>\n old.filter(c => c.conversation_id !== props.conversation_id),\n );\n\n return { previousConversations };\n },\n onSuccess: (_, props) => {\n if (props.invalidateCache) {\n queryClient.invalidateQueries({ queryKey: ['conversations'] });\n }\n },\n onError: (_, __, context) => {\n queryClient.setQueryData(\n ['conversations'],\n context?.previousConversations,\n );\n return { success: false };\n },\n });\n};\n"],"names":[],"mappings":";;;;AAuBO,MAAM,wBAAwB,MAAM;AACzC,EAAM,MAAA,aAAA,GAAgB,OAAO,gBAAgB,CAAA;AAC7C,EAAA,MAAM,cAAc,cAAe,EAAA;AAEnC,EAAA,OAAO,WAAY,CAAA;AAAA,IACjB,UAAA,EAAY,OAAO,KAGb,KAAA;AACJ,MAAM,MAAA,aAAA,CAAc,kBAAmB,CAAA,KAAA,CAAM,eAAe,CAAA;AAAA,KAC9D;AAAA,IACA,QAAA,EAAU,OAAM,KAAS,KAAA;AACvB,MAAA,MAAM,YAAY,aAAc,CAAA,EAAE,UAAU,CAAC,eAAe,GAAG,CAAA;AAE/D,MAAA,MAAM,qBACJ,GAAA,WAAA,CAAY,YAAa,CAAA,CAAC,eAAe,CAAC,CAAA;AAE5C,MAAY,WAAA,CAAA,YAAA;AAAA,QAAa,CAAC,eAAe,CAAA;AAAA,QAAG,CAAC,QAC3C,GAAI,CAAA,MAAA,CAAO,OAAK,CAAE,CAAA,eAAA,KAAoB,MAAM,eAAe;AAAA,OAC7D;AAEA,MAAA,OAAO,EAAE,qBAAsB,EAAA;AAAA,KACjC;AAAA,IACA,SAAA,EAAW,CAAC,CAAA,EAAG,KAAU,KAAA;AACvB,MAAA,IAAI,MAAM,eAAiB,EAAA;AACzB,QAAA,WAAA,CAAY,kBAAkB,EAAE,QAAA,EAAU,CAAC,eAAe,GAAG,CAAA;AAAA;AAC/D,KACF;AAAA,IACA,OAAS,EAAA,CAAC,CAAG,EAAA,EAAA,EAAI,OAAY,KAAA;AAC3B,MAAY,WAAA,CAAA,YAAA;AAAA,QACV,CAAC,eAAe,CAAA;AAAA,QAChB,OAAS,EAAA;AAAA,OACX;AACA,MAAO,OAAA,EAAE,SAAS,KAAM,EAAA;AAAA;AAC1B,GACD,CAAA;AACH;;;;"}
@@ -0,0 +1,51 @@
1
+ import { useState, useEffect, useCallback } from 'react';
2
+
3
+ const useLastOpenedConversation = (user, key = "lastOpenedConversation") => {
4
+ const [lastOpenedId, setLastOpenedId] = useState(null);
5
+ const [isReady, setIsReady] = useState(false);
6
+ useEffect(() => {
7
+ if (!user) {
8
+ setLastOpenedId(null);
9
+ setIsReady(false);
10
+ return;
11
+ }
12
+ try {
13
+ const storedData = localStorage.getItem(key);
14
+ const parsedData = storedData ? JSON.parse(storedData) : {};
15
+ setLastOpenedId(parsedData[user] || null);
16
+ } catch (error) {
17
+ console.error("Error accessing localStorage:", error);
18
+ } finally {
19
+ setIsReady(true);
20
+ }
21
+ }, [user, key]);
22
+ useEffect(() => {
23
+ if (!user || lastOpenedId === null) return;
24
+ try {
25
+ const storedData = localStorage.getItem(key);
26
+ const parsedData = storedData ? JSON.parse(storedData) : {};
27
+ if (parsedData[user] !== lastOpenedId) {
28
+ parsedData[user] = lastOpenedId;
29
+ localStorage.setItem(key, JSON.stringify(parsedData));
30
+ }
31
+ } catch (error) {
32
+ console.error("Error updating localStorage:", error);
33
+ }
34
+ }, [lastOpenedId, user, key]);
35
+ const clearLastOpenedId = useCallback(() => {
36
+ if (!user) return;
37
+ try {
38
+ const storedData = localStorage.getItem(key);
39
+ const parsedData = storedData ? JSON.parse(storedData) : {};
40
+ delete parsedData[user];
41
+ localStorage.setItem(key, JSON.stringify(parsedData));
42
+ setLastOpenedId(null);
43
+ } catch (error) {
44
+ console.error("Error clearing localStorage:", error);
45
+ }
46
+ }, [user, key]);
47
+ return { lastOpenedId, setLastOpenedId, clearLastOpenedId, isReady };
48
+ };
49
+
50
+ export { useLastOpenedConversation };
51
+ //# sourceMappingURL=useLastOpenedConversation.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLastOpenedConversation.esm.js","sources":["../../src/hooks/useLastOpenedConversation.ts"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n Dispatch,\n SetStateAction,\n useCallback,\n useEffect,\n useState,\n} from 'react';\n\ntype UseLastOpenedConversationReturn = {\n lastOpenedId: string | null;\n setLastOpenedId: Dispatch<SetStateAction<string | null>>;\n clearLastOpenedId: () => void;\n isReady: boolean;\n};\n\nexport const useLastOpenedConversation = (\n user: string | undefined,\n key = 'lastOpenedConversation',\n): UseLastOpenedConversationReturn => {\n const [lastOpenedId, setLastOpenedId] = useState<string | null>(null);\n const [isReady, setIsReady] = useState(false);\n\n useEffect(() => {\n if (!user) {\n setLastOpenedId(null);\n setIsReady(false);\n return;\n }\n\n try {\n const storedData = localStorage.getItem(key);\n const parsedData = storedData ? JSON.parse(storedData) : {};\n setLastOpenedId(parsedData[user] || null);\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('Error accessing localStorage:', error);\n } finally {\n setIsReady(true);\n }\n }, [user, key]);\n\n useEffect(() => {\n if (!user || lastOpenedId === null) return;\n // Update localStorage whenever the last opened ID changes\n try {\n const storedData = localStorage.getItem(key);\n const parsedData = storedData ? JSON.parse(storedData) : {};\n\n if (parsedData[user] !== lastOpenedId) {\n parsedData[user] = lastOpenedId;\n localStorage.setItem(key, JSON.stringify(parsedData));\n }\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('Error updating localStorage:', error);\n }\n }, [lastOpenedId, user, key]);\n\n const clearLastOpenedId = useCallback(() => {\n if (!user) return;\n\n try {\n const storedData = localStorage.getItem(key);\n const parsedData = storedData ? JSON.parse(storedData) : {};\n delete parsedData[user];\n localStorage.setItem(key, JSON.stringify(parsedData));\n setLastOpenedId(null);\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('Error clearing localStorage:', error);\n }\n }, [user, key]);\n\n return { lastOpenedId, setLastOpenedId, clearLastOpenedId, isReady };\n};\n"],"names":[],"mappings":";;AA8BO,MAAM,yBAA4B,GAAA,CACvC,IACA,EAAA,GAAA,GAAM,wBAC8B,KAAA;AACpC,EAAA,MAAM,CAAC,YAAA,EAAc,eAAe,CAAA,GAAI,SAAwB,IAAI,CAAA;AACpE,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,CAAA,GAAI,SAAS,KAAK,CAAA;AAE5C,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,CAAC,IAAM,EAAA;AACT,MAAA,eAAA,CAAgB,IAAI,CAAA;AACpB,MAAA,UAAA,CAAW,KAAK,CAA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3C,MAAA,MAAM,aAAa,UAAa,GAAA,IAAA,CAAK,KAAM,CAAA,UAAU,IAAI,EAAC;AAC1D,MAAA,OAAO,WAAW,IAAI,CAAA;AACtB,MAAA,YAAA,CAAa,OAAQ,CAAA,GAAA,EAAK,IAAK,CAAA,SAAA,CAAU,UAAU,CAAC,CAAA;AACpD,MAAA,eAAA,CAAgB,IAAI,CAAA;AAAA,aACb,KAAO,EAAA;AAEd,MAAQ,OAAA,CAAA,KAAA,CAAM,gCAAgC,KAAK,CAAA;AAAA;AACrD,GACC,EAAA,CAAC,IAAM,EAAA,GAAG,CAAC,CAAA;AAEd,EAAA,OAAO,EAAE,YAAA,EAAc,eAAiB,EAAA,iBAAA,EAAmB,OAAQ,EAAA;AACrE;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useLightspeedDeletePermission.esm.js","sources":["../../src/hooks/useLightspeedDeletePermission.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { usePermission } from '@backstage/plugin-permission-react';\n\nimport { lightspeedConversationsDeletePermission } from '@red-hat-developer-hub/backstage-plugin-lightspeed-common';\n\nexport const useLightspeedDeletePermission = () => {\n const lightspeedDeletePermissionResult = usePermission({\n permission: lightspeedConversationsDeletePermission,\n });\n\n return lightspeedDeletePermissionResult;\n};\n"],"names":[],"mappings":";;;AAmBO,MAAM,gCAAgC,MAAM;AACjD,EAAA,MAAM,mCAAmC,aAAc,CAAA;AAAA,IACrD,UAAY,EAAA;AAAA,GACb,CAAA;AAED,EAAO,OAAA,gCAAA;AACT;;;;"}
1
+ {"version":3,"file":"useLightspeedDeletePermission.esm.js","sources":["../../src/hooks/useLightspeedDeletePermission.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { usePermission } from '@backstage/plugin-permission-react';\n\nimport { lightspeedConversationsDeletePermission } from '@red-hat-developer-hub/backstage-plugin-lightspeed-common';\n\nexport const useLightspeedDeletePermission = () => {\n const lightspeedDeletePermissionResult = usePermission({\n permission: lightspeedConversationsDeletePermission,\n });\n\n return lightspeedDeletePermissionResult;\n};\n"],"names":[],"mappings":";;;AAoBO,MAAM,gCAAgC,MAAM;AACjD,EAAA,MAAM,mCAAmC,aAAc,CAAA;AAAA,IACrD,UAAY,EAAA;AAAA,GACb,CAAA;AAED,EAAO,OAAA,gCAAA;AACT;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useLightspeedViewPermission.esm.js","sources":["../../src/hooks/useLightspeedViewPermission.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { usePermission } from '@backstage/plugin-permission-react';\n\nimport {\n lightspeedConversationsCreatePermission,\n lightspeedConversationsReadPermission,\n} from '@red-hat-developer-hub/backstage-plugin-lightspeed-common';\n\nexport const useLightspeedViewPermission = () => {\n const canReadConversations = usePermission({\n permission: lightspeedConversationsReadPermission,\n });\n\n const canCreateConversations = usePermission({\n permission: lightspeedConversationsCreatePermission,\n });\n\n return {\n loading: canReadConversations.loading || canCreateConversations.loading,\n allowed: canReadConversations.allowed && canCreateConversations.allowed,\n };\n};\n"],"names":[],"mappings":";;;AAsBO,MAAM,8BAA8B,MAAM;AAC/C,EAAA,MAAM,uBAAuB,aAAc,CAAA;AAAA,IACzC,UAAY,EAAA;AAAA,GACb,CAAA;AAED,EAAA,MAAM,yBAAyB,aAAc,CAAA;AAAA,IAC3C,UAAY,EAAA;AAAA,GACb,CAAA;AAED,EAAO,OAAA;AAAA,IACL,OAAA,EAAS,oBAAqB,CAAA,OAAA,IAAW,sBAAuB,CAAA,OAAA;AAAA,IAChE,OAAA,EAAS,oBAAqB,CAAA,OAAA,IAAW,sBAAuB,CAAA;AAAA,GAClE;AACF;;;;"}
1
+ {"version":3,"file":"useLightspeedViewPermission.esm.js","sources":["../../src/hooks/useLightspeedViewPermission.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { usePermission } from '@backstage/plugin-permission-react';\n\nimport {\n lightspeedConversationsCreatePermission,\n lightspeedConversationsReadPermission,\n} from '@red-hat-developer-hub/backstage-plugin-lightspeed-common';\n\nexport const useLightspeedViewPermission = () => {\n const canReadConversations = usePermission({\n permission: lightspeedConversationsReadPermission,\n });\n\n const canCreateConversations = usePermission({\n permission: lightspeedConversationsCreatePermission,\n });\n\n return {\n loading: canReadConversations.loading || canCreateConversations.loading,\n allowed: canReadConversations.allowed && canCreateConversations.allowed,\n };\n};\n"],"names":[],"mappings":";;;AAuBO,MAAM,8BAA8B,MAAM;AAC/C,EAAA,MAAM,uBAAuB,aAAc,CAAA;AAAA,IACzC,UAAY,EAAA;AAAA,GACb,CAAA;AAED,EAAA,MAAM,yBAAyB,aAAc,CAAA;AAAA,IAC3C,UAAY,EAAA;AAAA,GACb,CAAA;AAED,EAAO,OAAA;AAAA,IACL,OAAA,EAAS,oBAAqB,CAAA,OAAA,IAAW,sBAAuB,CAAA,OAAA;AAAA,IAChE,OAAA,EAAS,oBAAqB,CAAA,OAAA,IAAW,sBAAuB,CAAA;AAAA,GAClE;AACF;;;;"}
@@ -1,6 +1,6 @@
1
1
  import '@patternfly/react-core/dist/styles/base.css';
2
- import '@patternfly/virtual-assistant/dist/css/main.css';
3
- import { createPlugin, createApiFactory, fetchApiRef, configApiRef, createRoutableExtension } from '@backstage/core-plugin-api';
2
+ import '@patternfly/chatbot/dist/css/main.css';
3
+ import { createPlugin, createApiFactory, configApiRef, fetchApiRef, createRoutableExtension } from '@backstage/core-plugin-api';
4
4
  import { lightspeedApiRef } from './api/api.esm.js';
5
5
  import { LightspeedApiClient } from './api/LightspeedApiClient.esm.js';
6
6
  import { rootRouteRef } from './routes.esm.js';
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.esm.js","sources":["../src/plugin.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport '@patternfly/react-core/dist/styles/base.css';\nimport '@patternfly/virtual-assistant/dist/css/main.css';\n\nimport {\n configApiRef,\n createApiFactory,\n createPlugin,\n createRoutableExtension,\n fetchApiRef,\n} from '@backstage/core-plugin-api';\n\nimport { lightspeedApiRef } from './api/api';\nimport { LightspeedApiClient } from './api/LightspeedApiClient';\nimport { rootRouteRef } from './routes';\n\n/**\n * Lightspeed Plugin\n * @public\n */\nexport const lightspeedPlugin = createPlugin({\n id: 'lightspeed',\n routes: {\n root: rootRouteRef,\n },\n apis: [\n createApiFactory({\n api: lightspeedApiRef,\n deps: {\n configApi: configApiRef,\n fetchApi: fetchApiRef,\n },\n factory: ({ configApi, fetchApi }) =>\n new LightspeedApiClient({ configApi, fetchApi }),\n }),\n ],\n});\n\n/**\n * Lightspeed Page\n * @public\n */\nexport const LightspeedPage = lightspeedPlugin.provide(\n createRoutableExtension({\n name: 'LightspeedPage',\n component: () =>\n import('./components/LightspeedPage').then(m => m.LightspeedPage),\n mountPoint: rootRouteRef,\n }),\n);\n"],"names":[],"mappings":";;;;;;;AAkCO,MAAM,mBAAmB,YAAa,CAAA;AAAA,EAC3C,EAAI,EAAA,YAAA;AAAA,EACJ,MAAQ,EAAA;AAAA,IACN,IAAM,EAAA;AAAA,GACR;AAAA,EACA,IAAM,EAAA;AAAA,IACJ,gBAAiB,CAAA;AAAA,MACf,GAAK,EAAA,gBAAA;AAAA,MACL,IAAM,EAAA;AAAA,QACJ,SAAW,EAAA,YAAA;AAAA,QACX,QAAU,EAAA;AAAA,OACZ;AAAA,MACA,OAAA,EAAS,CAAC,EAAE,SAAW,EAAA,QAAA,EACrB,KAAA,IAAI,mBAAoB,CAAA,EAAE,SAAW,EAAA,QAAA,EAAU;AAAA,KAClD;AAAA;AAEL,CAAC;AAMM,MAAM,iBAAiB,gBAAiB,CAAA,OAAA;AAAA,EAC7C,uBAAwB,CAAA;AAAA,IACtB,IAAM,EAAA,gBAAA;AAAA,IACN,SAAA,EAAW,MACT,OAAO,oCAA6B,EAAE,IAAK,CAAA,CAAA,CAAA,KAAK,EAAE,cAAc,CAAA;AAAA,IAClE,UAAY,EAAA;AAAA,GACb;AACH;;;;"}
1
+ {"version":3,"file":"plugin.esm.js","sources":["../src/plugin.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport '@patternfly/react-core/dist/styles/base.css';\nimport '@patternfly/chatbot/dist/css/main.css';\n\nimport {\n configApiRef,\n createApiFactory,\n createPlugin,\n createRoutableExtension,\n fetchApiRef,\n} from '@backstage/core-plugin-api';\n\nimport { lightspeedApiRef } from './api/api';\nimport { LightspeedApiClient } from './api/LightspeedApiClient';\nimport { rootRouteRef } from './routes';\n\n/**\n * Lightspeed Plugin\n * @public\n */\nexport const lightspeedPlugin = createPlugin({\n id: 'lightspeed',\n routes: {\n root: rootRouteRef,\n },\n apis: [\n createApiFactory({\n api: lightspeedApiRef,\n deps: {\n configApi: configApiRef,\n fetchApi: fetchApiRef,\n },\n factory: ({ configApi, fetchApi }) =>\n new LightspeedApiClient({ configApi, fetchApi }),\n }),\n ],\n});\n\n/**\n * Lightspeed Page\n * @public\n */\nexport const LightspeedPage = lightspeedPlugin.provide(\n createRoutableExtension({\n name: 'LightspeedPage',\n component: () =>\n import('./components/LightspeedPage').then(m => m.LightspeedPage),\n mountPoint: rootRouteRef,\n }),\n);\n"],"names":[],"mappings":";;;;;;;AAmCO,MAAM,mBAAmB,YAAa,CAAA;AAAA,EAC3C,EAAI,EAAA,YAAA;AAAA,EACJ,MAAQ,EAAA;AAAA,IACN,IAAM,EAAA;AAAA,GACR;AAAA,EACA,IAAM,EAAA;AAAA,IACJ,gBAAiB,CAAA;AAAA,MACf,GAAK,EAAA,gBAAA;AAAA,MACL,IAAM,EAAA;AAAA,QACJ,SAAW,EAAA,YAAA;AAAA,QACX,QAAU,EAAA;AAAA,OACZ;AAAA,MACA,OAAA,EAAS,CAAC,EAAE,SAAW,EAAA,QAAA,EACrB,KAAA,IAAI,mBAAoB,CAAA,EAAE,SAAW,EAAA,QAAA,EAAU;AAAA,KAClD;AAAA;AAEL,CAAC;AAMM,MAAM,iBAAiB,gBAAiB,CAAA,OAAA;AAAA,EAC7C,uBAAwB,CAAA;AAAA,IACtB,IAAM,EAAA,gBAAA;AAAA,IACN,SAAA,EAAW,MACT,OAAO,oCAA6B,EAAE,IAAK,CAAA,CAAA,CAAA,KAAK,EAAE,cAAc,CAAA;AAAA,IAClE,UAAY,EAAA;AAAA,GACb;AACH;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"routes.esm.js","sources":["../src/routes.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { createRouteRef } from '@backstage/core-plugin-api';\n\nexport const rootRouteRef = createRouteRef({\n id: 'lightspeed',\n});\n"],"names":[],"mappings":";;AAiBO,MAAM,eAAe,cAAe,CAAA;AAAA,EACzC,EAAI,EAAA;AACN,CAAC;;;;"}
1
+ {"version":3,"file":"routes.esm.js","sources":["../src/routes.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createRouteRef } from '@backstage/core-plugin-api';\n\nexport const rootRouteRef = createRouteRef({\n id: 'lightspeed',\n});\n"],"names":[],"mappings":";;AAkBO,MAAM,eAAe,cAAe,CAAA;AAAA,EACzC,EAAI,EAAA;AACN,CAAC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"lightspeed-chatbox-utils.esm.js","sources":["../../src/utils/lightspeed-chatbox-utils.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Conversation } from '@patternfly/virtual-assistant';\n\nimport { BaseMessage, ConversationList, ConversationSummary } from '../types';\n\nexport const getFootnoteProps = () => ({\n label: 'Lightspeed uses AI. Check for mistakes.',\n popover: {\n title: 'Verify accuracy',\n description: `While Lightspeed strives for accuracy, there's always a possibility of errors. It's a good practice to verify critical information from reliable sources, especially if it's crucial for decision-making or actions.`,\n bannerImage: {\n src: 'https://cdn.dribbble.com/userupload/10651749/file/original-8a07b8e39d9e8bf002358c66fce1223e.gif',\n alt: 'Example image for footnote popover',\n },\n cta: {\n label: 'Got it',\n onClick: () => {},\n },\n link: {\n label: 'Learn more',\n url: 'https://www.redhat.com/',\n },\n },\n});\n\nexport const getTimestampVariablesString = (v: number) => {\n if (v < 10) {\n return `0${v}`;\n }\n return `${v}`;\n};\n\nexport const getTimestamp = (unix_timestamp: number) => {\n if (typeof unix_timestamp !== 'number' || isNaN(unix_timestamp)) {\n // eslint-disable-next-line no-console\n console.error('Invalid Unix timestamp provided');\n return '';\n }\n\n const a = new Date(unix_timestamp);\n const month = getTimestampVariablesString(a.getMonth() + 1);\n const year = a.getFullYear();\n const date = getTimestampVariablesString(a.getDate());\n const hour = getTimestampVariablesString(a.getHours());\n const min = getTimestampVariablesString(a.getMinutes());\n const sec = getTimestampVariablesString(a.getSeconds());\n const time = `${date}/${month}/${year}, ${hour}:${min}:${sec}`;\n return time;\n};\n\nexport const splitJsonStrings = (jsonString: string): string[] => {\n const chunks = jsonString.split('}{');\n\n if (chunks.length <= 1) {\n return [jsonString];\n }\n\n return chunks.map((chunk, index, arr) => {\n if (index === 0) {\n return `${chunk}}`;\n } else if (index === arr.length - 1) {\n return `{${chunk}`;\n }\n return `{${chunk}}`;\n });\n};\n\ntype MessageProps = {\n content: string;\n timestamp: string;\n name?: string;\n avatar?: string | any;\n isLoading?: boolean;\n};\n\nexport const createMessage = ({\n role,\n name = 'Guest',\n avatar,\n isLoading = false,\n content,\n timestamp,\n}: MessageProps & { role: 'user' | 'bot' }) => ({\n role,\n name,\n avatar,\n isLoading,\n content,\n timestamp,\n});\n\nexport const createUserMessage = (props: MessageProps) =>\n createMessage({\n ...props,\n role: 'user',\n name: props.name ?? 'Guest',\n });\n\nexport const createBotMessage = (props: MessageProps) =>\n createMessage({\n ...props,\n role: 'bot',\n });\n\nexport const getMessageData = (message: BaseMessage) => {\n return {\n model: message?.kwargs?.response_metadata?.model,\n content: message?.kwargs?.content || '',\n timestamp: getTimestamp(message?.kwargs?.response_metadata?.created_at),\n };\n};\n\nexport const getDayDifference = (sourceTime: number, targetTime: number) => {\n const sourceDate = new Date(sourceTime);\n const targetDate = new Date(targetTime);\n\n sourceDate.setHours(0, 0, 0, 0);\n targetDate.setHours(0, 0, 0, 0);\n\n const timeDifference = sourceDate.getTime() - targetDate.getTime();\n\n return Math.floor(timeDifference / (1000 * 60 * 60 * 24));\n};\n\nexport const getCategorizeMessages = (\n messages: ConversationList,\n addProps: (c: ConversationSummary) => { [k: string]: any },\n): { [k: string]: Conversation[] } => {\n const now: any = new Date();\n const today = now.toDateString();\n\n const categorizedMessages: { [k: string]: Conversation[] } = {\n Today: [],\n Yesterday: [],\n 'Previous 7 Days': [],\n 'Previous 30 Days': [],\n };\n\n messages.forEach(c => {\n const messageDate = new Date(c.lastMessageTimestamp);\n const messageDayString = messageDate.toDateString();\n const dayDifference = getDayDifference(now, c.lastMessageTimestamp);\n\n const message: Conversation = {\n id: c.conversation_id,\n text: c.summary,\n label: 'Options',\n ...addProps(c),\n };\n\n if (messageDayString === today) {\n categorizedMessages.Today.push(message);\n } else if (dayDifference === 1) {\n categorizedMessages.Yesterday.push(message);\n } else if (dayDifference <= 7) {\n categorizedMessages['Previous 7 Days'].push(message);\n } else if (dayDifference <= 30) {\n categorizedMessages['Previous 30 Days'].push(message);\n } else {\n // handle month-wise grouping\n const monthYear = messageDate.toLocaleString('default', {\n month: 'long',\n year: 'numeric',\n });\n if (!categorizedMessages[monthYear]) {\n categorizedMessages[monthYear] = [];\n }\n categorizedMessages[monthYear].push(message);\n }\n });\n\n const filteredCategories = Object.keys(categorizedMessages).reduce(\n (result, category) => {\n if (categorizedMessages[category].length > 0) {\n result[category] = categorizedMessages[category];\n }\n return result;\n },\n {} as any,\n );\n\n return filteredCategories;\n};\n"],"names":[],"mappings":"AAmBO,MAAM,mBAAmB,OAAO;AAAA,EACrC,KAAO,EAAA,yCAAA;AAAA,EACP,OAAS,EAAA;AAAA,IACP,KAAO,EAAA,iBAAA;AAAA,IACP,WAAa,EAAA,CAAA,oNAAA,CAAA;AAAA,IACb,WAAa,EAAA;AAAA,MACX,GAAK,EAAA,iGAAA;AAAA,MACL,GAAK,EAAA;AAAA,KACP;AAAA,IACA,GAAK,EAAA;AAAA,MACH,KAAO,EAAA,QAAA;AAAA,MACP,SAAS,MAAM;AAAA;AAAC,KAClB;AAAA,IACA,IAAM,EAAA;AAAA,MACJ,KAAO,EAAA,YAAA;AAAA,MAC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T;;;;"}
1
+ {"version":3,"file":"lightspeed-chatbox-utils.esm.js","sources":["../../src/utils/lightspeed-chatbox-utils.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Conversation } from '@patternfly/chatbot';\n\nimport { BaseMessage, ConversationList, ConversationSummary } from '../types';\n\nexport const getFootnoteProps = () => ({\n label: 'Lightspeed uses AI. Check for mistakes.',\n popover: {\n title: 'Verify accuracy',\n description: `While Lightspeed strives for accuracy, there's always a possibility of errors. It's a good practice to verify critical information from reliable sources, especially if it's crucial for decision-making or actions.`,\n bannerImage: {\n src: 'https://cdn.dribbble.com/userupload/10651749/file/original-8a07b8e39d9e8bf002358c66fce1223e.gif',\n alt: 'Example image for footnote popover',\n },\n cta: {\n label: 'Got it',\n onClick: () => {},\n },\n link: {\n label: 'Learn more',\n url: 'https://www.redhat.com/',\n },\n },\n});\n\nexport const getTimestampVariablesString = (v: number) => {\n if (v < 10) {\n return `0${v}`;\n }\n return `${v}`;\n};\n\nexport const getTimestamp = (unix_timestamp: number) => {\n if (typeof unix_timestamp !== 'number' || isNaN(unix_timestamp)) {\n // eslint-disable-next-line no-console\n console.error('Invalid Unix timestamp provided');\n return '';\n }\n\n const a = new Date(unix_timestamp);\n const month = getTimestampVariablesString(a.getMonth() + 1);\n const year = a.getFullYear();\n const date = getTimestampVariablesString(a.getDate());\n const hour = getTimestampVariablesString(a.getHours());\n const min = getTimestampVariablesString(a.getMinutes());\n const sec = getTimestampVariablesString(a.getSeconds());\n const time = `${date}/${month}/${year}, ${hour}:${min}:${sec}`;\n return time;\n};\n\nexport const splitJsonStrings = (jsonString: string): string[] => {\n const chunks = jsonString.split('}{');\n\n if (chunks.length <= 1) {\n return [jsonString];\n }\n\n return chunks.map((chunk, index, arr) => {\n if (index === 0) {\n return `${chunk}}`;\n } else if (index === arr.length - 1) {\n return `{${chunk}`;\n }\n return `{${chunk}}`;\n });\n};\n\ntype MessageProps = {\n content: string;\n timestamp: string;\n name?: string;\n avatar?: string | any;\n isLoading?: boolean;\n};\n\nexport const createMessage = ({\n role,\n name = 'Guest',\n avatar,\n isLoading = false,\n content,\n timestamp,\n}: MessageProps & { role: 'user' | 'bot' }) => ({\n role,\n name,\n avatar,\n isLoading,\n content,\n timestamp,\n});\n\nexport const createUserMessage = (props: MessageProps) =>\n createMessage({\n ...props,\n role: 'user',\n name: props.name ?? 'Guest',\n });\n\nexport const createBotMessage = (props: MessageProps) =>\n createMessage({\n ...props,\n role: 'bot',\n });\n\nexport const getMessageData = (message: BaseMessage) => {\n return {\n model: message?.kwargs?.response_metadata?.model,\n content: message?.kwargs?.content || '',\n timestamp: getTimestamp(message?.kwargs?.response_metadata?.created_at),\n };\n};\n\nexport const getDayDifference = (sourceTime: number, targetTime: number) => {\n const sourceDate = new Date(sourceTime);\n const targetDate = new Date(targetTime);\n\n sourceDate.setHours(0, 0, 0, 0);\n targetDate.setHours(0, 0, 0, 0);\n\n const timeDifference = sourceDate.getTime() - targetDate.getTime();\n\n return Math.floor(timeDifference / (1000 * 60 * 60 * 24));\n};\n\nexport const getCategorizeMessages = (\n messages: ConversationList,\n addProps: (c: ConversationSummary) => { [k: string]: any },\n): { [k: string]: Conversation[] } => {\n const now: any = new Date();\n const today = now.toDateString();\n\n const categorizedMessages: { [k: string]: Conversation[] } = {\n Today: [],\n Yesterday: [],\n 'Previous 7 Days': [],\n 'Previous 30 Days': [],\n };\n\n messages.forEach(c => {\n const messageDate = new Date(c.lastMessageTimestamp);\n const messageDayString = messageDate.toDateString();\n const dayDifference = getDayDifference(now, c.lastMessageTimestamp);\n\n const message: Conversation = {\n id: c.conversation_id,\n text: c.summary,\n label: 'Options',\n ...addProps(c),\n };\n\n if (messageDayString === today) {\n categorizedMessages.Today.push(message);\n } else if (dayDifference === 1) {\n categorizedMessages.Yesterday.push(message);\n } else if (dayDifference <= 7) {\n categorizedMessages['Previous 7 Days'].push(message);\n } else if (dayDifference <= 30) {\n categorizedMessages['Previous 30 Days'].push(message);\n } else {\n // handle month-wise grouping\n const monthYear = messageDate.toLocaleString('default', {\n month: 'long',\n year: 'numeric',\n });\n if (!categorizedMessages[monthYear]) {\n categorizedMessages[monthYear] = [];\n }\n categorizedMessages[monthYear].push(message);\n }\n });\n\n const filteredCategories = Object.keys(categorizedMessages).reduce(\n (result, category) => {\n if (categorizedMessages[category].length > 0) {\n result[category] = categorizedMessages[category];\n }\n return result;\n },\n {} as any,\n );\n\n return filteredCategories;\n};\n"],"names":[],"mappings":"AAmBO,MAAM,mBAAmB,OAAO;AAAA,EACrC,KAAO,EAAA,yCAAA;AAAA,EACP,OAAS,EAAA;AAAA,IACP,KAAO,EAAA,iBAAA;AAAA,IACP,WAAa,EAAA,CAAA,oNAAA,CAAA;AAAA,IACb,WAAa,EAAA;AAAA,MACX,GAAK,EAAA,iGAAA;AAAA,MACL,GAAK,EAAA;AAAA,KACP;AAAA,IACA,GAAK,EAAA;AAAA,MACH,KAAO,EAAA,QAAA;AAAA,MACP,SAAS,MAAM;AAAA;AAAC,KAClB;AAAA,IACA,IAAM,EAAA;AAAA,MACJ,KAAO,EAAA,YAAA;AAAA,MACP,GAAK,EAAA;AAAA;AACP;AAEJ,CAAA;AAEa,MAAA,2BAAA,GAA8B,CAAC,CAAc,KAAA;AACxD,EAAA,IAAI,IAAI,EAAI,EAAA;AACV,IAAA,OAAO,IAAI,CAAC,CAAA,CAAA;AAAA;AAEd,EAAA,OAAO,GAAG,CAAC,CAAA,CAAA;AACb;AAEa,MAAA,YAAA,GAAe,CAAC,cAA2B,KAAA;AACtD,EAAA,IAAI,OAAO,cAAA,KAAm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C5C,MAAA,IAAW,iBAAiB,CAAG,EAAA;AAC7B,MAAoB,mBAAA,CAAA,iBAAiB,CAAE,CAAA,IAAA,CAAK,OAAO,CAAA;AAAA,KACrD,MAAA,IAAW,iBAAiB,EAAI,EAAA;AAC9B,MAAoB,mBAAA,CAAA,kBAAkB,CAAE,CAAA,IAAA,CAAK,OAAO,CAAA;AAAA,KAC/C,MAAA;AAEL,MAAM,MAAA,SAAA,GAAY,WAAY,CAAA,cAAA,CAAe,SAAW,EAAA;AAAA,QACtD,KAAO,EAAA,MAAA;AAAA,QACP,IAAM,EAAA;AAAA,OACP,CAAA;AACD,MAAI,IAAA,CAAC,mBAAoB,CAAA,SAAS,CAAG,EAAA;AACnC,QAAoB,mBAAA,CAAA,SAAS,IAAI,EAAC;AAAA;AAEpC,MAAoB,mBAAA,CAAA,SAAS,CAAE,CAAA,IAAA,CAAK,OAAO,CAAA;AAAA;AAC7C,GACD,CAAA;AAED,EAAA,MAAM,kBAAqB,GAAA,MAAA,CAAO,IAAK,CAAA,mBAAmB,CAAE,CAAA,MAAA;AAAA,IAC1D,CAAC,QAAQ,QAAa,KAAA;AACpB,MAAA,IAAI,mBAAoB,CAAA,QAAQ,CAAE,CAAA,MAAA,GAAS,CAAG,EAAA;AAC5C,QAAO,MAAA,CAAA,QAAQ,CAAI,GAAA,mBAAA,CAAoB,QAAQ,CAAA;AAAA;AAEjD,MAAO,OAAA,MAAA;AAAA,KACT;AAAA,IACA;AAAC,GACH;AAEA,EAAO,OAAA,kBAAA;AACT;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"queryClient.esm.js","sources":["../../src/utils/queryClient.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { QueryClient } from '@tanstack/react-query';\n\nconst queryClient = new QueryClient();\nexport default queryClient;\n"],"names":[],"mappings":";;AAiBM,MAAA,WAAA,GAAc,IAAI,WAAY;;;;"}
1
+ {"version":3,"file":"queryClient.esm.js","sources":["../../src/utils/queryClient.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { QueryClient } from '@tanstack/react-query';\n\nconst queryClient = new QueryClient();\nexport default queryClient;\n"],"names":[],"mappings":";;AAkBM,MAAA,WAAA,GAAc,IAAI,WAAY;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@red-hat-developer-hub/backstage-plugin-lightspeed",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "main": "dist/index.esm.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -37,16 +37,16 @@
37
37
  "prettier:fix": "prettier --ignore-unknown --write ."
38
38
  },
39
39
  "dependencies": {
40
- "@backstage/core-components": "^0.15.1",
41
- "@backstage/core-plugin-api": "^1.10.0",
42
- "@backstage/plugin-permission-react": "^0.4.28",
43
- "@backstage/theme": "^0.6.0",
40
+ "@backstage/core-components": "^0.16.2",
41
+ "@backstage/core-plugin-api": "^1.10.2",
42
+ "@backstage/plugin-permission-react": "^0.4.29",
43
+ "@backstage/theme": "^0.6.3",
44
44
  "@material-ui/core": "^4.9.13",
45
45
  "@material-ui/lab": "^4.0.0-alpha.61",
46
46
  "@mui/icons-material": "^6.1.8",
47
- "@patternfly/react-core": "6.0.0-prerelease.21",
48
- "@patternfly/virtual-assistant": "2.0.0-alpha.61",
49
- "@red-hat-developer-hub/backstage-plugin-lightspeed-common": "^0.1.2",
47
+ "@patternfly/chatbot": "2.2.0-prerelease.6",
48
+ "@patternfly/react-core": "6.1.0-prerelease.14",
49
+ "@red-hat-developer-hub/backstage-plugin-lightspeed-common": "^0.2.0",
50
50
  "@tanstack/react-query": "^5.59.15",
51
51
  "openai": "^4.52.6",
52
52
  "react-markdown": "^9.0.1",
@@ -57,10 +57,10 @@
57
57
  "react-router-dom": "^6.0.0"
58
58
  },
59
59
  "devDependencies": {
60
- "@backstage/cli": "0.28.2",
61
- "@backstage/core-app-api": "1.15.1",
62
- "@backstage/dev-utils": "1.1.2",
63
- "@backstage/test-utils": "1.7.0",
60
+ "@backstage/cli": "^0.29.4",
61
+ "@backstage/core-app-api": "^1.15.3",
62
+ "@backstage/dev-utils": "^1.1.5",
63
+ "@backstage/test-utils": "^1.7.3",
64
64
  "@emotion/is-prop-valid": "^1.3.1",
65
65
  "@ianvs/prettier-plugin-sort-imports": "^4.4.0",
66
66
  "@spotify/prettier-config": "^15.0.0",
@@ -68,8 +68,8 @@
68
68
  "@testing-library/jest-dom": "^6.0.0",
69
69
  "@testing-library/react": "^15.0.0",
70
70
  "@testing-library/user-event": "14.5.2",
71
- "msw": "1.3.3",
72
- "prettier": "3.3.3",
71
+ "msw": "1.3.5",
72
+ "prettier": "3.4.2",
73
73
  "react": "16.13.1 || ^17.0.0 || ^18.0.0",
74
74
  "react-dom": "16.13.1 || ^17.0.0 || ^18.0.0",
75
75
  "react-router-dom": "^6.0.0"
@@ -104,5 +104,12 @@
104
104
  "@rohitkrai03"
105
105
  ],
106
106
  "author": "Red Hat",
107
+ "typesVersions": {
108
+ "*": {
109
+ "index": [
110
+ "dist/index.d.ts"
111
+ ]
112
+ }
113
+ },
107
114
  "module": "./dist/index.esm.js"
108
115
  }