@red-hat-developer-hub/backstage-plugin-lightspeed 0.6.0 → 1.0.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.
- package/CHANGELOG.md +12 -0
- package/README.md +40 -58
- package/app-config.yaml +4 -0
- package/config.d.ts +1 -24
- package/dist/alpha.d.ts +111 -0
- package/dist/alpha.esm.js +3 -0
- package/dist/alpha.esm.js.map +1 -0
- package/dist/api/LightspeedApiClient.esm.js +26 -11
- package/dist/api/LightspeedApiClient.esm.js.map +1 -1
- package/dist/api/api.esm.js.map +1 -1
- package/dist/components/LightSpeedChat.esm.js +17 -1
- package/dist/components/LightSpeedChat.esm.js.map +1 -1
- package/dist/components/LightspeedChatBox.esm.js +3 -5
- package/dist/components/LightspeedChatBox.esm.js.map +1 -1
- package/dist/components/LightspeedChatBoxHeader.esm.js +14 -3
- package/dist/components/LightspeedChatBoxHeader.esm.js.map +1 -1
- package/dist/components/LightspeedPage.esm.js +17 -2
- package/dist/components/LightspeedPage.esm.js.map +1 -1
- package/dist/const.esm.js +4 -1
- package/dist/const.esm.js.map +1 -1
- package/dist/hooks/useConversationMessages.esm.js +23 -21
- package/dist/hooks/useConversationMessages.esm.js.map +1 -1
- package/dist/hooks/useCreateCoversationMessage.esm.js +2 -0
- package/dist/hooks/useCreateCoversationMessage.esm.js.map +1 -1
- package/dist/hooks/useQuestionValidation.esm.js +16 -0
- package/dist/hooks/useQuestionValidation.esm.js.map +1 -0
- package/dist/hooks/useTranslation.esm.js +1 -1
- package/dist/hooks/useTranslation.esm.js.map +1 -1
- package/dist/hooks/useWelcomePrompts.esm.js +3 -2
- package/dist/hooks/useWelcomePrompts.esm.js.map +1 -1
- package/dist/index.d.ts +1 -8
- package/dist/index.esm.js +0 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/translations/de.esm.js +1 -1
- package/dist/translations/de.esm.js.map +1 -1
- package/dist/translations/es.esm.js +1 -1
- package/dist/translations/es.esm.js.map +1 -1
- package/dist/translations/fr.esm.js +1 -1
- package/dist/translations/fr.esm.js.map +1 -1
- package/dist/translations/index.esm.js +3 -3
- package/dist/translations/index.esm.js.map +1 -1
- package/dist/translations/{translationRef.esm.js → ref.esm.js} +1 -1
- package/dist/translations/ref.esm.js.map +1 -0
- package/dist/types.esm.js.map +1 -1
- package/dist/utils/lightspeed-chatbox-utils.esm.js +18 -8
- package/dist/utils/lightspeed-chatbox-utils.esm.js.map +1 -1
- package/package.json +32 -16
- package/dist/translations/translationRef.esm.js.map +0 -1
package/dist/types.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.esm.js","sources":["../src/types.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 { SourcesCardProps } from '@patternfly/chatbot';\nimport { AlertProps } from '@patternfly/react-core';\n\nexport type Conversations = {\n [key: string]: {\n user: string;\n bot: string;\n model: string;\n loading: boolean;\n timestamp: string;\n botTimestamp: string;\n error?: AlertProps;\n };\n};\n\nexport type ReferencedDocument = {\n doc_title: string;\n doc_url: string;\n doc_description?: string;\n};\n\nexport type ReferencedDocuments = ReferencedDocument[];\nexport interface
|
|
1
|
+
{"version":3,"file":"types.esm.js","sources":["../src/types.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 { SourcesCardProps } from '@patternfly/chatbot';\nimport { AlertProps } from '@patternfly/react-core';\n\nexport type Conversations = {\n [key: string]: {\n user: string;\n bot: string;\n model: string;\n loading: boolean;\n timestamp: string;\n botTimestamp: string;\n error?: AlertProps;\n };\n};\n\nexport type ReferencedDocument = {\n doc_title: string;\n doc_url: string;\n doc_description?: string;\n};\n\nexport type ReferencedDocuments = ReferencedDocument[];\n\nexport type LCSModelType = 'embedding' | 'llm';\nexport type LCSModelApiModelType = 'embedding' | 'llm';\n\nexport interface LCSModel {\n identifier: string;\n metadata: {\n embedding_dimension: number;\n };\n api_model_type: LCSModelApiModelType;\n provider_id: string;\n type: 'model';\n provider_resource_id: string;\n model_type: LCSModelType;\n}\nexport interface LCSConversation {\n provider: string;\n model: string;\n messages: BaseMessage[];\n started_at: string;\n completed_at: string;\n referencedDocuments?: ReferencedDocuments;\n}\n\nexport interface LCSShield {\n identifier: string;\n provider_id: string;\n type: 'shield';\n params: {};\n provider_resource_id: string;\n}\nexport interface BaseMessage {\n name: string;\n type: string;\n id: number;\n content: string;\n model: string;\n timestamp: string;\n sources?: SourcesCardProps;\n referencedDocuments?: ReferencedDocuments;\n error?: AlertProps;\n}\nexport type ConversationSummary = {\n conversation_id: string;\n last_message_timestamp: number;\n topic_summary: string;\n};\n\nexport enum SupportedFileType {\n JSON = 'application/json',\n YAML = 'application/x-yaml',\n TEXT = 'text/plain',\n XML = 'text/xml',\n}\nexport interface FileContent {\n content: string;\n type: string;\n name: string;\n}\n\nexport type Attachment = {\n attachment_type: string;\n content_type: string;\n content: string;\n};\n\nexport type ConversationList = ConversationSummary[];\n\nexport type SamplePrompt =\n | {\n title: string;\n message: string;\n }\n | {\n titleKey: string;\n messageKey: string;\n };\n\nexport type SamplePrompts = SamplePrompt[];\n\nexport type CaptureFeedback = {\n conversation_id: string;\n user_question: string;\n llm_response: string;\n user_feedback: string;\n sentiment: number;\n};\n"],"names":["SupportedFileType"],"mappings":"AAsFY,IAAA,iBAAA,qBAAAA,kBAAL,KAAA;AACL,EAAAA,mBAAA,MAAO,CAAA,GAAA,kBAAA;AACP,EAAAA,mBAAA,MAAO,CAAA,GAAA,oBAAA;AACP,EAAAA,mBAAA,MAAO,CAAA,GAAA,YAAA;AACP,EAAAA,mBAAA,KAAM,CAAA,GAAA,UAAA;AAJI,EAAAA,OAAAA,kBAAAA;AAAA,CAAA,EAAA,iBAAA,IAAA,EAAA;;;;"}
|
|
@@ -71,13 +71,23 @@ const createBotMessage = (props) => createMessage({
|
|
|
71
71
|
...props,
|
|
72
72
|
role: "bot"
|
|
73
73
|
});
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
74
|
+
const getConversationsData = (conversation) => {
|
|
75
|
+
const [userMessage, botMessage] = conversation.messages || [];
|
|
76
|
+
return [
|
|
77
|
+
{
|
|
78
|
+
...userMessage,
|
|
79
|
+
timestamp: getTimestamp(
|
|
80
|
+
conversation.started_at ? new Date(conversation.started_at).getTime() : Date.now()
|
|
81
|
+
)
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
...botMessage,
|
|
85
|
+
timestamp: getTimestamp(
|
|
86
|
+
conversation.completed_at ? new Date(conversation.completed_at).getTime() : Date.now()
|
|
87
|
+
),
|
|
88
|
+
referencedDocuments: botMessage?.referencedDocuments ?? []
|
|
89
|
+
}
|
|
90
|
+
];
|
|
81
91
|
};
|
|
82
92
|
const transformDocumentsToSources = (referenced_documents) => {
|
|
83
93
|
if (!referenced_documents || referenced_documents?.length === 0) {
|
|
@@ -155,5 +165,5 @@ const getCategorizeMessages = (messages, addProps, t) => {
|
|
|
155
165
|
return filteredCategories;
|
|
156
166
|
};
|
|
157
167
|
|
|
158
|
-
export { createBotMessage, createMessage, createUserMessage, getCategorizeMessages, getDayDifference, getFootnoteProps,
|
|
168
|
+
export { createBotMessage, createMessage, createUserMessage, getCategorizeMessages, getConversationsData, getDayDifference, getFootnoteProps, getTimestamp, getTimestampVariablesString, transformDocumentsToSources };
|
|
159
169
|
//# sourceMappingURL=lightspeed-chatbox-utils.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
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, SourcesCardProps } from '@patternfly/chatbot';\nimport { PopoverProps } from '@patternfly/react-core';\n\nimport {\n BaseMessage,\n ConversationList,\n ConversationSummary,\n ReferencedDocument,\n ReferencedDocuments,\n} from '../types';\n\nexport const getFootnoteProps = (\n additionalClassName: string,\n t?: (key: string, params?: any) => string,\n) => ({\n label:\n t?.('footer.accuracy.label') ||\n 'Always check AI/LLM generated responses for accuracy prior to use.',\n popover: {\n popoverProps: {\n className: additionalClassName ?? '',\n } as PopoverProps,\n title: t?.('footer.accuracy.popover.title') || 'Verify accuracy',\n description:\n t?.('footer.accuracy.popover.description') ||\n `While Developer 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:\n t?.('footer.accuracy.popover.image.alt') ||\n 'Example image for footnote popover',\n },\n cta: {\n label: t?.('footer.accuracy.popover.cta.label') || 'Got it',\n onClick: () => {},\n },\n link: {\n label: t?.('footer.accuracy.popover.link.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 error?: {\n title: string;\n };\n sources?: SourcesCardProps;\n};\n\nexport const createMessage = ({\n role,\n name,\n avatar,\n isLoading = false,\n content,\n timestamp,\n error,\n sources,\n defaultUserName = 'Guest',\n}: MessageProps & { role: 'user' | 'bot'; defaultUserName?: string }) => ({\n role,\n name: name || defaultUserName,\n avatar,\n isLoading,\n content,\n timestamp,\n error,\n sources,\n});\n\nexport const createUserMessage = (\n props: MessageProps & { defaultUserName?: string },\n) =>\n createMessage({\n ...props,\n role: 'user',\n defaultUserName: props.defaultUserName,\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?.response_metadata?.model,\n content: message?.content || '',\n timestamp: getTimestamp(message?.response_metadata?.created_at * 1000),\n referencedDocuments: message?.additional_kwargs?.referenced_documents ?? [],\n };\n};\n\nexport const transformDocumentsToSources = (\n referenced_documents: ReferencedDocuments,\n): SourcesCardProps | undefined => {\n if (!referenced_documents || referenced_documents?.length === 0) {\n return undefined;\n }\n return {\n sources: referenced_documents.map((doc: ReferencedDocument) => ({\n body: doc.doc_description,\n title: doc.doc_title,\n link: doc?.doc_url,\n isExternal: true,\n })),\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 t?: (key: string, params?: any) => string,\n): { [k: string]: Conversation[] } => {\n const now: any = new Date();\n const today = now.toDateString();\n\n const categorizedMessages: { [k: string]: Conversation[] } = {\n [t?.('conversation.category.today') || 'Today']: [],\n [t?.('conversation.category.yesterday') || 'Yesterday']: [],\n [t?.('conversation.category.previous7Days') || 'Previous 7 Days']: [],\n [t?.('conversation.category.previous30Days') || 'Previous 30 Days']: [],\n };\n messages\n .sort((a, b) => b.last_message_timestamp - a.last_message_timestamp)\n .forEach(c => {\n const messageDate = new Date(c.last_message_timestamp * 1000);\n const messageDayString = messageDate.toDateString();\n const dayDifference = getDayDifference(\n now,\n c.last_message_timestamp * 1000,\n );\n const message: Conversation = {\n id: c.conversation_id,\n text: c.topic_summary,\n label: t?.('message.options.label') || 'Options',\n ...addProps(c),\n };\n\n if (messageDayString === today) {\n categorizedMessages[t?.('conversation.category.today') || 'Today'].push(\n message,\n );\n } else if (dayDifference === 1) {\n categorizedMessages[\n t?.('conversation.category.yesterday') || 'Yesterday'\n ].push(message);\n } else if (dayDifference <= 7) {\n categorizedMessages[\n t?.('conversation.category.previous7Days') || 'Previous 7 Days'\n ].push(message);\n } else if (dayDifference <= 30) {\n categorizedMessages[\n t?.('conversation.category.previous30Days') || 'Previous 30 Days'\n ].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":"AA0Ba,MAAA,gBAAA,GAAmB,CAC9B,mBAAA,EACA,CACI,MAAA;AAAA,EACJ,KAAA,EACE,CAAI,GAAA,uBAAuB,CAC3B,IAAA,oEAAA;AAAA,EACF,OAAS,EAAA;AAAA,IACP,YAAc,EAAA;AAAA,MACZ,WAAW,mBAAuB,IAAA;AAAA,KACpC;AAAA,IACA,KAAA,EAAO,CAAI,GAAA,+BAA+B,CAAK,IAAA,iBAAA;AAAA,IAC/C,WAAA,EACE,CAAI,GAAA,qCAAqC,CACzC,IAAA,CAAA,8NAAA,CAAA;AAAA,IACF,WAAa,EAAA;AAAA,MACX,GAAK,EAAA,iGAAA;AAAA,MACL,GAAA,EACE,CAAI,GAAA,mCAAmC,CACvC,IAAA;AAAA,KACJ;AAAA,IACA,GAAK,EAAA;AAAA,MACH,KAAA,EAAO,CAAI,GAAA,mCAAmC,CAAK,IAAA,QAAA;AAAA,MACnD,SAAS,MAAM;AAAA;AAAC,KAClB;AAAA,IACA,IAAM,EAAA;AAAA,MACJ,KAAA,EAAO,CAAI,GAAA,oCAAoC,CAAK,IAAA,YAAA;AAAA,MACpD,GAAK,EAAA;AAAA;AACP;AAEJ,CAAA;AAEa,MAAA,2BAAA,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AC7C,GACD,CAAA;AAEH,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
|
+
{"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, SourcesCardProps } from '@patternfly/chatbot';\nimport { PopoverProps } from '@patternfly/react-core';\n\nimport {\n BaseMessage,\n ConversationList,\n ConversationSummary,\n LCSConversation,\n ReferencedDocument,\n ReferencedDocuments,\n} from '../types';\n\nexport const getFootnoteProps = (\n additionalClassName: string,\n t?: (key: string, params?: any) => string,\n) => ({\n label:\n t?.('footer.accuracy.label') ||\n 'Always check AI/LLM generated responses for accuracy prior to use.',\n popover: {\n popoverProps: {\n className: additionalClassName ?? '',\n } as PopoverProps,\n title: t?.('footer.accuracy.popover.title') || 'Verify accuracy',\n description:\n t?.('footer.accuracy.popover.description') ||\n `While Developer 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:\n t?.('footer.accuracy.popover.image.alt') ||\n 'Example image for footnote popover',\n },\n cta: {\n label: t?.('footer.accuracy.popover.cta.label') || 'Got it',\n onClick: () => {},\n },\n link: {\n label: t?.('footer.accuracy.popover.link.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 error?: {\n title: string;\n };\n sources?: SourcesCardProps;\n};\n\nexport const createMessage = ({\n role,\n name,\n avatar,\n isLoading = false,\n content,\n timestamp,\n error,\n sources,\n defaultUserName = 'Guest',\n}: MessageProps & { role: 'user' | 'bot'; defaultUserName?: string }) => ({\n role,\n name: name || defaultUserName,\n avatar,\n isLoading,\n content,\n timestamp,\n error,\n sources,\n});\n\nexport const createUserMessage = (\n props: MessageProps & { defaultUserName?: string },\n) =>\n createMessage({\n ...props,\n role: 'user',\n defaultUserName: props.defaultUserName,\n });\n\nexport const createBotMessage = (props: MessageProps) =>\n createMessage({\n ...props,\n role: 'bot',\n });\n\nexport const getConversationsData = (\n conversation: LCSConversation,\n): [BaseMessage, BaseMessage] => {\n const [userMessage, botMessage] = conversation.messages || [];\n return [\n {\n ...userMessage,\n timestamp: getTimestamp(\n conversation.started_at\n ? new Date(conversation.started_at).getTime()\n : Date.now(),\n ),\n },\n {\n ...botMessage,\n timestamp: getTimestamp(\n conversation.completed_at\n ? new Date(conversation.completed_at).getTime()\n : Date.now(),\n ),\n referencedDocuments: botMessage?.referencedDocuments ?? [],\n },\n ];\n};\n\nexport const transformDocumentsToSources = (\n referenced_documents: ReferencedDocuments,\n): SourcesCardProps | undefined => {\n if (!referenced_documents || referenced_documents?.length === 0) {\n return undefined;\n }\n return {\n sources: referenced_documents.map((doc: ReferencedDocument) => ({\n body: doc.doc_description,\n title: doc.doc_title,\n link: doc?.doc_url,\n isExternal: true,\n })),\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 t?: (key: string, params?: any) => string,\n): { [k: string]: Conversation[] } => {\n const now: any = new Date();\n const today = now.toDateString();\n\n const categorizedMessages: { [k: string]: Conversation[] } = {\n [t?.('conversation.category.today') || 'Today']: [],\n [t?.('conversation.category.yesterday') || 'Yesterday']: [],\n [t?.('conversation.category.previous7Days') || 'Previous 7 Days']: [],\n [t?.('conversation.category.previous30Days') || 'Previous 30 Days']: [],\n };\n messages\n .sort((a, b) => b.last_message_timestamp - a.last_message_timestamp)\n .forEach(c => {\n const messageDate = new Date(c.last_message_timestamp * 1000);\n const messageDayString = messageDate.toDateString();\n const dayDifference = getDayDifference(\n now,\n c.last_message_timestamp * 1000,\n );\n const message: Conversation = {\n id: c.conversation_id,\n text: c.topic_summary,\n label: t?.('message.options.label') || 'Options',\n ...addProps(c),\n };\n\n if (messageDayString === today) {\n categorizedMessages[t?.('conversation.category.today') || 'Today'].push(\n message,\n );\n } else if (dayDifference === 1) {\n categorizedMessages[\n t?.('conversation.category.yesterday') || 'Yesterday'\n ].push(message);\n } else if (dayDifference <= 7) {\n categorizedMessages[\n t?.('conversation.category.previous7Days') || 'Previous 7 Days'\n ].push(message);\n } else if (dayDifference <= 30) {\n categorizedMessages[\n t?.('conversation.category.previous30Days') || 'Previous 30 Days'\n ].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":"AA2Ba,MAAA,gBAAA,GAAmB,CAC9B,mBAAA,EACA,CACI,MAAA;AAAA,EACJ,KAAA,EACE,CAAI,GAAA,uBAAuB,CAC3B,IAAA,oEAAA;AAAA,EACF,OAAS,EAAA;AAAA,IACP,YAAc,EAAA;AAAA,MACZ,WAAW,mBAAuB,IAAA;AAAA,KACpC;AAAA,IACA,KAAA,EAAO,CAAI,GAAA,+BAA+B,CAAK,IAAA,iBAAA;AAAA,IAC/C,WAAA,EACE,CAAI,GAAA,qCAAqC,CACzC,IAAA,CAAA,8NAAA,CAAA;AAAA,IACF,WAAa,EAAA;AAAA,MACX,GAAK,EAAA,iGAAA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AAE,KAAK,OAAO,CAAA;AAAA,KAChB,MAAA,IAAW,iBAAiB,CAAG,EAAA;AAC7B,MAAA,mBAAA,CACE,IAAI,qCAAqC,CAAA,IAAK,iBAChD,CAAA,CAAE,KAAK,OAAO,CAAA;AAAA,KAChB,MAAA,IAAW,iBAAiB,EAAI,EAAA;AAC9B,MAAA,mBAAA,CACE,IAAI,sCAAsC,CAAA,IAAK,kBACjD,CAAA,CAAE,KAAK,OAAO,CAAA;AAAA,KACT,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;AAEH,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;;;;"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@red-hat-developer-hub/backstage-plugin-lightspeed",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"main": "dist/index.esm.js",
|
|
5
|
-
"types": "dist/index.d.ts",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "./dist/index.esm.js",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"publishConfig": {
|
|
8
|
-
"access": "public"
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.esm.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.esm.js"
|
|
15
|
+
},
|
|
16
|
+
"./alpha": {
|
|
17
|
+
"import": "./dist/alpha.esm.js",
|
|
18
|
+
"types": "./dist/alpha.d.ts",
|
|
19
|
+
"default": "./dist/alpha.esm.js"
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"typesVersions": {
|
|
24
|
+
"*": {
|
|
25
|
+
"alpha": [
|
|
26
|
+
"dist/alpha.d.ts"
|
|
27
|
+
],
|
|
28
|
+
"package.json": [
|
|
29
|
+
"package.json"
|
|
30
|
+
]
|
|
31
|
+
}
|
|
11
32
|
},
|
|
12
33
|
"backstage": {
|
|
13
34
|
"role": "frontend-plugin",
|
|
@@ -44,11 +65,11 @@
|
|
|
44
65
|
"@material-ui/core": "^4.9.13",
|
|
45
66
|
"@material-ui/lab": "^4.0.0-alpha.61",
|
|
46
67
|
"@mui/icons-material": "^6.1.8",
|
|
47
|
-
"@patternfly/chatbot": "6.
|
|
48
|
-
"@patternfly/react-core": "6.
|
|
68
|
+
"@patternfly/chatbot": "6.4.0-prerelease.25",
|
|
69
|
+
"@patternfly/react-core": "6.4.0-prerelease.2",
|
|
70
|
+
"@patternfly/react-icons": "^6.3.1",
|
|
49
71
|
"@red-hat-developer-hub/backstage-plugin-lightspeed-common": "^0.4.0",
|
|
50
72
|
"@tanstack/react-query": "^5.59.15",
|
|
51
|
-
"openai": "^4.52.6",
|
|
52
73
|
"react-markdown": "^9.0.1",
|
|
53
74
|
"react-use": "^17.2.4"
|
|
54
75
|
},
|
|
@@ -83,6 +104,8 @@
|
|
|
83
104
|
"scalprum": {
|
|
84
105
|
"name": "red-hat-developer-hub.backstage-plugin-lightspeed",
|
|
85
106
|
"exposedModules": {
|
|
107
|
+
"Alpha": "./src/alpha.ts",
|
|
108
|
+
"PluginRoot": "./src/index.ts",
|
|
86
109
|
"LightspeedPlugin": "./src/index.ts"
|
|
87
110
|
}
|
|
88
111
|
},
|
|
@@ -104,12 +127,5 @@
|
|
|
104
127
|
"@rohitkrai03"
|
|
105
128
|
],
|
|
106
129
|
"author": "Red Hat",
|
|
107
|
-
"typesVersions": {
|
|
108
|
-
"*": {
|
|
109
|
-
"package.json": [
|
|
110
|
-
"package.json"
|
|
111
|
-
]
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
130
|
"module": "./dist/index.esm.js"
|
|
115
131
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"translationRef.esm.js","sources":["../../src/translations/translationRef.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 { createTranslationRef } from '@backstage/core-plugin-api/alpha';\n\n/**\n * Messages object containing all English translations.\n * This is our single source of truth for translations.\n * @public\n */\nexport const lightspeedMessages = {\n // Page titles and headers\n 'page.title': 'Lightspeed',\n 'page.subtitle': 'AI-powered development assistant',\n\n // Sample prompts - General Development\n 'prompts.codeReadability.title': 'Get Help On Code Readability',\n 'prompts.codeReadability.message':\n 'Can you suggest techniques I can use to make my code more readable and maintainable?',\n 'prompts.debugging.title': 'Get Help With Debugging',\n 'prompts.debugging.message':\n 'My application is throwing an error when trying to connect to the database. Can you help me identify the issue?',\n 'prompts.developmentConcept.title': 'Explain a Development Concept',\n 'prompts.developmentConcept.message':\n 'Can you explain how microservices architecture works and its advantages over a monolithic design?',\n 'prompts.codeOptimization.title': 'Suggest Code Optimizations',\n 'prompts.codeOptimization.message':\n 'Can you suggest common ways to optimize code to achieve better performance?',\n 'prompts.documentation.title': 'Documentation Summary',\n 'prompts.documentation.message':\n 'Can you summarize the documentation for implementing OAuth 2.0 authentication in a web app?',\n 'prompts.gitWorkflows.title': 'Workflows With Git',\n 'prompts.gitWorkflows.message':\n 'I want to make changes to code on another branch without losing my existing work. What is the procedure to do this using Git?',\n 'prompts.testingStrategies.title': 'Suggest Testing Strategies',\n 'prompts.testingStrategies.message':\n 'Can you recommend some common testing strategies that will make my application robust and error-free?',\n 'prompts.sortingAlgorithms.title': 'Demystify Sorting Algorithms',\n 'prompts.sortingAlgorithms.message':\n 'Can you explain the difference between a quicksort and a merge sort algorithm, and when to use each?',\n 'prompts.eventDriven.title': 'Understand Event-Driven Architecture',\n 'prompts.eventDriven.message':\n \"Can you explain what event-driven architecture is and when it's beneficial to use it in software development?\",\n\n // Sample prompts - RHDH Specific\n 'prompts.tekton.title': 'Deploy With Tekton',\n 'prompts.tekton.message':\n 'Can you help me automate the deployment of my application using Tekton pipelines?',\n 'prompts.openshift.title': 'Create An OpenShift Deployment',\n 'prompts.openshift.message':\n 'Can you guide me through creating a new deployment in OpenShift for a containerized application?',\n 'prompts.rhdh.title': 'Getting Started with Red Hat Developer Hub',\n 'prompts.rhdh.message':\n 'Can you guide me through the first steps to start using Developer Hub as a developer, like exploring the Software Catalog and adding my service?',\n\n // Conversation history\n 'conversation.history.confirm.title': 'Delete chat?',\n 'conversation.history.confirm.message':\n \"You'll no longer see this chat here. This will also delete related activity like prompts, responses, and feedback from your Lightspeed Activity.\",\n 'conversation.history.confirm.delete': 'Delete',\n\n // Permissions\n 'permission.required.title': 'Missing permissions',\n 'permission.required.description':\n 'To view lightspeed plugin, contact your administrator to give the <b>lightspeed.chat.read</b> and <b>lightspeed.chat.create</b> permissions.',\n\n // Disclaimers\n 'disclaimer.withValidation':\n \"Developer Lightspeed can answer questions on many topics using your configured models. Developer Lightspeed's responses are influenced by the Red Hat Developer Hub documentation but Developer Lightspeed does not have access to your Software Catalog, TechDocs, or Templates etc. Developer Lightspeed uses question (prompt) validation to ensure that conversations remain focused on technical topics relevant to Red Hat Developer Hub, such as Backstage, Kubernetes, and OpenShift. Do not include personal or sensitive information in your input. Interactions with Developer Lightspeed may be reviewed and used to improve products or services.\",\n 'disclaimer.withoutValidation':\n \"Developer Lightspeed can answer questions on many topics using your configured models. Developer Lightspeed's responses are influenced by the Red Hat Developer Hub documentation but Developer Lightspeed does not have access to your Software Catalog, TechDocs, or Templates etc. Do not include personal or sensitive information in your input. Interactions with Developer Lightspeed may be reviewed and used to improve products or services.\",\n\n // Footer and feedback\n 'footer.accuracy.label':\n 'Always check AI/LLM generated responses for accuracy prior to use.',\n 'footer.accuracy.popover.title': 'Verify accuracy',\n 'footer.accuracy.popover.description':\n \"While Developer 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 'footer.accuracy.popover.image.alt': 'Example image for footnote popover',\n 'footer.accuracy.popover.cta.label': 'Got it',\n 'footer.accuracy.popover.link.label': 'Learn more',\n\n // Common actions\n 'common.cancel': 'Cancel',\n\n // Menu items\n 'menu.newConversation': 'New Chat',\n\n // Chat-specific UI elements\n 'chatbox.header.title': 'Developer Lightspeed',\n 'chatbox.search.placeholder': 'Search previous chats...',\n 'chatbox.welcome.greeting': 'Hello, {{userName}}',\n 'chatbox.welcome.description': 'How can I help you today?',\n 'chatbox.message.placeholder':\n 'Send a message and optionally upload a JSON, YAML, TXT, or XML file...',\n 'chatbox.fileUpload.failed': 'File upload failed',\n 'chatbox.fileUpload.infoText':\n 'Supported file types are: .txt, .yaml, .json and .xml. The maximum file size is 25 MB.',\n\n // Accessibility and ARIA labels\n 'aria.chatbotSelector': 'Chatbot selector',\n 'aria.important': 'Important',\n\n // Modal actions\n 'modal.edit': 'Edit',\n 'modal.save': 'Save',\n 'modal.close': 'Close',\n 'modal.cancel': 'Cancel',\n\n // Conversation actions\n 'conversation.delete': 'Delete',\n 'conversation.announcement.userMessage':\n 'Message from User: {{prompt}}. Message from Bot is loading.',\n\n // User states\n 'user.guest': 'Guest',\n 'user.loading': '...',\n\n // Button tooltips and labels\n 'tooltip.attach': 'Attach',\n 'tooltip.send': 'Send',\n 'tooltip.microphone.active': 'Stop listening',\n 'tooltip.microphone.inactive': 'Use microphone',\n 'button.newChat': 'New chat',\n\n // Modal titles\n 'modal.title.preview': 'Preview attachment',\n 'modal.title.edit': 'Edit attachment',\n\n // Alt texts for icons\n 'icon.lightspeed.alt': 'lightspeed icon',\n 'icon.permissionRequired.alt': 'permission required icon',\n\n // Message utilities\n 'message.options.label': 'Options',\n\n // File attachment errors\n 'file.upload.error.alreadyExists': 'File already exists.',\n 'file.upload.error.multipleFiles': 'Uploaded more than one file.',\n 'file.upload.error.unsupportedType':\n 'Unsupported file type. Supported types are: .txt, .yaml, .json and .xml.',\n 'file.upload.error.fileTooLarge':\n 'Your file size is too large. Please ensure that your file is less than 25 MB.',\n 'file.upload.error.readFailed': 'Failed to read file: {{errorMessage}}',\n\n // Developer error messages\n 'error.context.fileAttachment':\n 'useFileAttachmentContext must be within a FileAttachmentContextProvider',\n\n // Feedback actions\n 'feedback.form.title': 'Why did you choose this rating?',\n 'feedback.form.textAreaPlaceholder': 'Provide optional additional feedback',\n 'feedback.form.submitWord': 'Submit',\n 'feedback.tooltips.goodResponse': 'Good Response',\n 'feedback.tooltips.badResponse': 'Bad Response',\n 'feedback.tooltips.copied': 'Copied',\n 'feedback.tooltips.copy': 'Copy',\n 'feedback.tooltips.listening': 'Listening',\n 'feedback.tooltips.listen': 'Listen',\n 'feedback.quickResponses.positive.helpful': 'Helpful information',\n 'feedback.quickResponses.positive.easyToUnderstand': 'Easy to understand',\n 'feedback.quickResponses.positive.resolvedIssue': 'Resolved my issue',\n 'feedback.quickResponses.negative.didntAnswer': \"Didn't answer my question\",\n 'feedback.quickResponses.negative.hardToUnderstand': 'Hard to understand',\n 'feedback.quickResponses.negative.notHelpful': 'Not Helpful',\n 'feedback.completion.title': 'Feedback submitted',\n 'feedback.completion.body':\n \"We've received your response. Thank you for sharing your feedback!\",\n\n // Conversation categorization\n 'conversation.category.today': 'Today',\n 'conversation.category.yesterday': 'Yesterday',\n 'conversation.category.previous7Days': 'Previous 7 Days',\n 'conversation.category.previous30Days': 'Previous 30 Days',\n};\n\n/**\n * Translation Reference for Developer Lightspeed\n * @public\n **/\nexport const lightspeedTranslationRef = createTranslationRef({\n id: 'plugin.lightspeed',\n messages: lightspeedMessages,\n});\n"],"names":[],"mappings":";;AAuBO,MAAM,kBAAqB,GAAA;AAAA;AAAA,EAEhC,YAAc,EAAA,YAAA;AAAA,EACd,eAAiB,EAAA,kCAAA;AAAA;AAAA,EAGjB,+BAAiC,EAAA,8BAAA;AAAA,EACjC,iCACE,EAAA,sFAAA;AAAA,EACF,yBAA2B,EAAA,yBAAA;AAAA,EAC3B,2BACE,EAAA,iHAAA;AAAA,EACF,kCAAoC,EAAA,+BAAA;AAAA,EACpC,oCACE,EAAA,mGAAA;AAAA,EACF,gCAAkC,EAAA,4BAAA;AAAA,EAClC,kCACE,EAAA,6EAAA;AAAA,EACF,6BAA+B,EAAA,uBAAA;AAAA,EAC/B,+BACE,EAAA,6FAAA;AAAA,EACF,4BAA8B,EAAA,oBAAA;AAAA,EAC9B,8BACE,EAAA,+HAAA;AAAA,EACF,iCAAmC,EAAA,4BAAA;AAAA,EACnC,mCACE,EAAA,uGAAA;AAAA,EACF,iCAAmC,EAAA,8BAAA;AAAA,EACnC,mCACE,EAAA,sGAAA;AAAA,EACF,2BAA6B,EAAA,sCAAA;AAAA,EAC7B,6BACE,EAAA,+GAAA;AAAA;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