diff --git a/AgentQnA/ui/svelte/.eslintrc.cjs b/AgentQnA/ui/svelte/.eslintrc.cjs index b5e265e255..cfe2be4d4d 100644 --- a/AgentQnA/ui/svelte/.eslintrc.cjs +++ b/AgentQnA/ui/svelte/.eslintrc.cjs @@ -1,11 +1,7 @@ module.exports = { root: true, parser: "@typescript-eslint/parser", - extends: [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "prettier", - ], + extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"], plugins: ["svelte3", "@typescript-eslint", "neverthrow"], ignorePatterns: ["*.cjs"], overrides: [{ files: ["*.svelte"], processor: "svelte3/svelte3" }], diff --git a/AgentQnA/ui/svelte/postcss.config.cjs b/AgentQnA/ui/svelte/postcss.config.cjs index fe10e55a83..e68d4de268 100644 --- a/AgentQnA/ui/svelte/postcss.config.cjs +++ b/AgentQnA/ui/svelte/postcss.config.cjs @@ -1,13 +1,13 @@ -const tailwindcss = require('tailwindcss'); -const autoprefixer = require('autoprefixer'); +const tailwindcss = require("tailwindcss"); +const autoprefixer = require("autoprefixer"); const config = { plugins: [ //Some plugins, like tailwindcss/nesting, need to run before Tailwind, tailwindcss(), //But others, like autoprefixer, need to run after, - autoprefixer - ] + autoprefixer, + ], }; module.exports = config; diff --git a/AgentQnA/ui/svelte/src/app.d.ts b/AgentQnA/ui/svelte/src/app.d.ts index 3ba6db3e1b..76f5cae98c 100644 --- a/AgentQnA/ui/svelte/src/app.d.ts +++ b/AgentQnA/ui/svelte/src/app.d.ts @@ -1,3 +1,6 @@ +// Copyright (C) 2025 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + // See: https://kit.svelte.dev/docs/types#app // import { Result} from "neverthrow"; @@ -21,44 +24,27 @@ interface User { type AuthResponse = Result; interface AuthAdapter { - login(props: { - email: string; - password: string; - }): Promise; - signup(props: { - email: string; - password: string; - password_confirm: string; - }): Promise; - validate_session(props: { - token: string; - }): Promise; - logout(props: { - token: string; - email: string; - }): Promise>; - forgotPassword(props: { - email: string; - password: string; - }): Promise>; + login(props: { email: string; password: string }): Promise; + signup(props: { email: string; password: string; password_confirm: string }): Promise; + validate_session(props: { token: string }): Promise; + logout(props: { token: string; email: string }): Promise>; + forgotPassword(props: { email: string; password: string }): Promise>; } interface ChatAdapter { - modelList(props: { - }): Promise>; - txt2img(props: { - }): Promise>; + modelList(props: {}): Promise>; + txt2img(props: {}): Promise>; } interface ChatMessage { - role: string, - content: string + role: string; + content: string; } interface ChatMessageType { - model: string, - knowledge: string, - temperature: string, - max_new_tokens: string, - topk: string, -} \ No newline at end of file + model: string; + knowledge: string; + temperature: string; + max_new_tokens: string; + topk: string; +} diff --git a/AgentQnA/ui/svelte/src/app.html b/AgentQnA/ui/svelte/src/app.html index e112596fc3..97807d0c92 100644 --- a/AgentQnA/ui/svelte/src/app.html +++ b/AgentQnA/ui/svelte/src/app.html @@ -1,4 +1,9 @@ - + + + diff --git a/AgentQnA/ui/svelte/src/lib/assets/Agent/createSub.svelte b/AgentQnA/ui/svelte/src/lib/assets/Agent/createSub.svelte index 537c50514e..b31044d0fc 100644 --- a/AgentQnA/ui/svelte/src/lib/assets/Agent/createSub.svelte +++ b/AgentQnA/ui/svelte/src/lib/assets/Agent/createSub.svelte @@ -1,3 +1,8 @@ + + + \ No newline at end of file + diff --git a/AgentQnA/ui/svelte/src/lib/assets/Agent/eye.svelte b/AgentQnA/ui/svelte/src/lib/assets/Agent/eye.svelte index 1885f6dc35..06f9a821e4 100644 --- a/AgentQnA/ui/svelte/src/lib/assets/Agent/eye.svelte +++ b/AgentQnA/ui/svelte/src/lib/assets/Agent/eye.svelte @@ -1,3 +1,8 @@ + + - \ No newline at end of file + diff --git a/AgentQnA/ui/svelte/src/lib/assets/Agent/newAI.svelte b/AgentQnA/ui/svelte/src/lib/assets/Agent/newAI.svelte index 240613046a..6fc1179daf 100644 --- a/AgentQnA/ui/svelte/src/lib/assets/Agent/newAI.svelte +++ b/AgentQnA/ui/svelte/src/lib/assets/Agent/newAI.svelte @@ -1,3 +1,8 @@ + + + \ No newline at end of file + diff --git a/AgentQnA/ui/svelte/src/lib/assets/Agent/search.svelte b/AgentQnA/ui/svelte/src/lib/assets/Agent/search.svelte index 4f29744eec..79c22c7b2f 100644 --- a/AgentQnA/ui/svelte/src/lib/assets/Agent/search.svelte +++ b/AgentQnA/ui/svelte/src/lib/assets/Agent/search.svelte @@ -1,3 +1,8 @@ + + \ No newline at end of file + > diff --git a/AgentQnA/ui/svelte/src/lib/assets/Agent/searchDelete.svelte b/AgentQnA/ui/svelte/src/lib/assets/Agent/searchDelete.svelte index f6a8a7cef7..e6907c21df 100644 --- a/AgentQnA/ui/svelte/src/lib/assets/Agent/searchDelete.svelte +++ b/AgentQnA/ui/svelte/src/lib/assets/Agent/searchDelete.svelte @@ -1,3 +1,8 @@ + + \ No newline at end of file + > diff --git a/AgentQnA/ui/svelte/src/lib/assets/Agent/searchResult.svelte b/AgentQnA/ui/svelte/src/lib/assets/Agent/searchResult.svelte index 7f81f0ea63..378f3cdf50 100644 --- a/AgentQnA/ui/svelte/src/lib/assets/Agent/searchResult.svelte +++ b/AgentQnA/ui/svelte/src/lib/assets/Agent/searchResult.svelte @@ -1,3 +1,8 @@ + + + + + + + \ No newline at end of file + diff --git a/AgentQnA/ui/svelte/src/lib/assets/Agent/toolIcon.svelte b/AgentQnA/ui/svelte/src/lib/assets/Agent/toolIcon.svelte index ea800c991a..342f5df387 100644 --- a/AgentQnA/ui/svelte/src/lib/assets/Agent/toolIcon.svelte +++ b/AgentQnA/ui/svelte/src/lib/assets/Agent/toolIcon.svelte @@ -1,3 +1,8 @@ + + + - diff --git a/AgentQnA/ui/svelte/src/lib/assets/icons/ActiveLikeButtonIcon.svelte b/AgentQnA/ui/svelte/src/lib/assets/icons/ActiveLikeButtonIcon.svelte index 445be635ab..b410c73386 100644 --- a/AgentQnA/ui/svelte/src/lib/assets/icons/ActiveLikeButtonIcon.svelte +++ b/AgentQnA/ui/svelte/src/lib/assets/icons/ActiveLikeButtonIcon.svelte @@ -1,3 +1,8 @@ + + + + + + \ No newline at end of file +> diff --git a/AgentQnA/ui/svelte/src/lib/assets/icons/Question.svelte b/AgentQnA/ui/svelte/src/lib/assets/icons/Question.svelte index 4dfe981145..c4f296e2c2 100644 --- a/AgentQnA/ui/svelte/src/lib/assets/icons/Question.svelte +++ b/AgentQnA/ui/svelte/src/lib/assets/icons/Question.svelte @@ -1 +1,6 @@ - \ No newline at end of file + + + diff --git a/AgentQnA/ui/svelte/src/lib/assets/icons/addKnowledge.svelte b/AgentQnA/ui/svelte/src/lib/assets/icons/addKnowledge.svelte index 62f558894f..001de15b19 100644 --- a/AgentQnA/ui/svelte/src/lib/assets/icons/addKnowledge.svelte +++ b/AgentQnA/ui/svelte/src/lib/assets/icons/addKnowledge.svelte @@ -1,3 +1,8 @@ + + + +
diff --git a/AgentQnA/ui/svelte/src/lib/components/chat/chat.svelte b/AgentQnA/ui/svelte/src/lib/components/chat/chat.svelte index cfc0e2084f..9acae878ee 100644 --- a/AgentQnA/ui/svelte/src/lib/components/chat/chat.svelte +++ b/AgentQnA/ui/svelte/src/lib/components/chat/chat.svelte @@ -1,3 +1,8 @@ + + diff --git a/AgentQnA/ui/svelte/src/lib/components/shared/shared-utils.ts b/AgentQnA/ui/svelte/src/lib/components/shared/shared-utils.ts index 1317d53f28..0a4b7443de 100644 --- a/AgentQnA/ui/svelte/src/lib/components/shared/shared-utils.ts +++ b/AgentQnA/ui/svelte/src/lib/components/shared/shared-utils.ts @@ -1,190 +1,167 @@ -import { chatList$, chats$ } from './shared.store'; +// Copyright (C) 2025 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + +import { chatList$, chats$ } from "./shared.store"; import { nanoid } from "nanoid"; import { - LOCAL_STORAGE_KEY, - type Chat, - type ChatListItem, - type ModelOptionType, - type SelectedType, - type Message, + LOCAL_STORAGE_KEY, + type Chat, + type ChatListItem, + type ModelOptionType, + type SelectedType, + type Message, } from "./shared.type"; -export function defineType( - optionType: string, - selected: SelectedType, - MODEL_OPTION: ModelOptionType, -) { - let type: any = {}; - let modeltype: any = {}; - - if (optionType == "Model") { - type = { - model: selected['Model'], - temperature: MODEL_OPTION.options.find( - (option) => option.label === "Temperature" - )?.value, - max_new_tokens: MODEL_OPTION.options.find( - (option) => option.label === "Max Tokens" - )?.value, - topk: MODEL_OPTION.options.find( - (option) => option.label === "Top K" - )?.value, - } - } else if (optionType == "knowledge base") { - const knowledge_map: { [key: string]: string } = { "Wikipedia": "WIKI", "INC Document": "INC", "ASK_GM": "ASK_GM", "Young_Pat": "Young_Pat", "Customized": "Customized" } - type = { - model: "knowledge", - knowledge: knowledge_map[selected["knowledge base"]], - }; - if (selected["advance option"]) { - type.advanceOption = selected["advance option"] - } - } - - return type; +export function defineType(optionType: string, selected: SelectedType, MODEL_OPTION: ModelOptionType) { + let type: any = {}; + let modeltype: any = {}; + + if (optionType == "Model") { + type = { + model: selected["Model"], + temperature: MODEL_OPTION.options.find((option) => option.label === "Temperature")?.value, + max_new_tokens: MODEL_OPTION.options.find((option) => option.label === "Max Tokens")?.value, + topk: MODEL_OPTION.options.find((option) => option.label === "Top K")?.value, + }; + } else if (optionType == "knowledge base") { + const knowledge_map: { [key: string]: string } = { + Wikipedia: "WIKI", + "INC Document": "INC", + ASK_GM: "ASK_GM", + Young_Pat: "Young_Pat", + Customized: "Customized", + }; + type = { + model: "knowledge", + knowledge: knowledge_map[selected["knowledge base"]], + }; + if (selected["advance option"]) { + type.advanceOption = selected["advance option"]; + } + } + + return type; } let chat: Record; let chatlist: ChatListItem[]; export const createNewChatListItem = (chatId: string, title: string): ChatListItem => { - return { - chatId, - title: title - }; + return { + chatId, + title: title, + }; }; -export const createNewChat = ( - chatId: string, - messages: Message[], - agentName: string, - agentDescripe: string, -): Chat => { - return { - chatId, - messages, - agentName, - agentDescripe, - }; +export const createNewChat = (chatId: string, messages: Message[], agentName: string, agentDescripe: string): Chat => { + return { + chatId, + messages, + agentName, + agentDescripe, + }; }; /** * Insert new chat (For the root route) */ -export const insertNewChat = ( - msgs: Message[], - title: string, - agentName: string, - agentDescripe: string, -) => { - const newChatId = nanoid(8); - - chatList$.update((chatList) => { - chatList.unshift(createNewChatListItem(newChatId, title)); - return chatList; - }); - chats$.update((chats) => { - chats[newChatId] = createNewChat(newChatId, msgs, agentName, agentDescripe); - return chats; - }); - - try { - const unsubscribe_chatlist = chatList$.subscribe((value: ChatListItem[]) => { - chatlist = value; - }); - const unsubscribe_chats = chats$.subscribe((value: Record) => { - chat = value; - }); - localStorage.setItem( - LOCAL_STORAGE_KEY.CHAT_LIST, - JSON.stringify(chatlist) - ); - localStorage.setItem(newChatId, JSON.stringify(chat[newChatId])); - - unsubscribe_chatlist(); - unsubscribe_chats(); - } catch (e: any) { } - - return newChatId; +export const insertNewChat = (msgs: Message[], title: string, agentName: string, agentDescripe: string) => { + const newChatId = nanoid(8); + + chatList$.update((chatList) => { + chatList.unshift(createNewChatListItem(newChatId, title)); + return chatList; + }); + chats$.update((chats) => { + chats[newChatId] = createNewChat(newChatId, msgs, agentName, agentDescripe); + return chats; + }); + + try { + const unsubscribe_chatlist = chatList$.subscribe((value: ChatListItem[]) => { + chatlist = value; + }); + const unsubscribe_chats = chats$.subscribe((value: Record) => { + chat = value; + }); + localStorage.setItem(LOCAL_STORAGE_KEY.CHAT_LIST, JSON.stringify(chatlist)); + localStorage.setItem(newChatId, JSON.stringify(chat[newChatId])); + + unsubscribe_chatlist(); + unsubscribe_chats(); + } catch (e: any) {} + + return newChatId; }; /** * Update chat */ -export const updateChat = ( - id: string, - msgs: Message[], - title: string, - agentName: string, - agentDescripe: string, -) => { - chats$.update((chats) => { - chats[id].messages = msgs; - chats[id].agentName = agentName; - chats[id].agentDescripe = agentDescripe; - - return chats; - }); - - chatList$.update((chatList) => { - chatList = chatList.map((chat) => { - if (chat.chatId === id) { - chat.title = title; - } - return chat; - }); - return chatList; - }); - // Problem - try { - const unsubscribe_chatlist = chatList$.subscribe((value: ChatListItem[]) => { - chatlist = value; - }); - const unsubscribe_chats = chats$.subscribe((value: Record) => { - chat = value; - }); - localStorage.setItem( - LOCAL_STORAGE_KEY.CHAT_LIST, - JSON.stringify(chatlist) - ); - localStorage.setItem(id, JSON.stringify(chat[id])); - unsubscribe_chatlist(); - unsubscribe_chats(); - } catch (e: any) { - console.log('update chat error', e); - } +export const updateChat = (id: string, msgs: Message[], title: string, agentName: string, agentDescripe: string) => { + chats$.update((chats) => { + chats[id].messages = msgs; + chats[id].agentName = agentName; + chats[id].agentDescripe = agentDescripe; + + return chats; + }); + + chatList$.update((chatList) => { + chatList = chatList.map((chat) => { + if (chat.chatId === id) { + chat.title = title; + } + return chat; + }); + return chatList; + }); + // Problem + try { + const unsubscribe_chatlist = chatList$.subscribe((value: ChatListItem[]) => { + chatlist = value; + }); + const unsubscribe_chats = chats$.subscribe((value: Record) => { + chat = value; + }); + localStorage.setItem(LOCAL_STORAGE_KEY.CHAT_LIST, JSON.stringify(chatlist)); + localStorage.setItem(id, JSON.stringify(chat[id])); + unsubscribe_chatlist(); + unsubscribe_chats(); + } catch (e: any) { + console.log("update chat error", e); + } }; export const upsertChat = ( - chatId: string, - msgs: Message[], - title: string, - agentName: string, - agentDescripe: string, + chatId: string, + msgs: Message[], + title: string, + agentName: string, + agentDescripe: string, ) => { - if (!chatId) { - chatId = insertNewChat(msgs, title, agentName, agentDescripe); - } else { - updateChat(chatId, msgs, title, agentName, agentDescripe); - } + if (!chatId) { + chatId = insertNewChat(msgs, title, agentName, agentDescripe); + } else { + updateChat(chatId, msgs, title, agentName, agentDescripe); + } - return chatId; + return chatId; }; export function scrollToBottom(scrollToDiv: HTMLElement) { - if (scrollToDiv) { - setTimeout( - () => - scrollToDiv.scroll({ - behavior: "auto", - top: scrollToDiv.scrollHeight, - }), - 100 - ); - } + if (scrollToDiv) { + setTimeout( + () => + scrollToDiv.scroll({ + behavior: "auto", + top: scrollToDiv.scrollHeight, + }), + 100, + ); + } } -export const truncateString = (str = '', cutLength = 18) => { - const truncated = str?.substring?.(0, cutLength); +export const truncateString = (str = "", cutLength = 18) => { + const truncated = str?.substring?.(0, cutLength); - return truncated?.length < str?.length ? `${truncated}...` : truncated; -}; \ No newline at end of file + return truncated?.length < str?.length ? `${truncated}...` : truncated; +}; diff --git a/AgentQnA/ui/svelte/src/lib/components/shared/shared.store.ts b/AgentQnA/ui/svelte/src/lib/components/shared/shared.store.ts index 6d2a473234..a072fdec3a 100644 --- a/AgentQnA/ui/svelte/src/lib/components/shared/shared.store.ts +++ b/AgentQnA/ui/svelte/src/lib/components/shared/shared.store.ts @@ -1,9 +1,9 @@ -import { derived, writable } from 'svelte/store'; +// Copyright (C) 2025 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 -import type { - Chat, - ChatListItem, -} from './shared.type'; +import { derived, writable } from "svelte/store"; + +import type { Chat, ChatListItem } from "./shared.type"; /** * Banners @@ -11,7 +11,7 @@ import type { export const banners$ = writable([] as any); export const hasBanners$ = derived(banners$, (banners) => { - return banners.length > 0; + return banners.length > 0; }); /** @@ -27,9 +27,8 @@ export const parentPath = writable("" as string); export const parentIdx = writable(-1 as number); export const hintStart = writable(false as boolean); -export const hintEnd = writable({status: false, hintContent: ''}); +export const hintEnd = writable({ status: false, hintContent: "" }); export const netError = writable(false as boolean); - export const needRecreate = writable(false as boolean); export const displayHintRecreate = writable(false as boolean); diff --git a/AgentQnA/ui/svelte/src/lib/components/shared/shared.type.ts b/AgentQnA/ui/svelte/src/lib/components/shared/shared.type.ts index 6e186304a2..4b18abe014 100644 --- a/AgentQnA/ui/svelte/src/lib/components/shared/shared.type.ts +++ b/AgentQnA/ui/svelte/src/lib/components/shared/shared.type.ts @@ -1,75 +1,83 @@ +// Copyright (C) 2025 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + export interface ModelOptionType { - names: string[]; - options: { - label: string; - value: number; - minRange: number; - maxRange: number; - step: number; - type: string; - }[]; + names: string[]; + options: { + label: string; + value: number; + minRange: number; + maxRange: number; + step: number; + type: string; + }[]; } -export interface SelectedType { [key:string]:string, Model: string, "knowledge base": string, 'advance option': string } +export interface SelectedType { + [key: string]: string; + Model: string; + "knowledge base": string; + "advance option": string; +} export enum LOCAL_STORAGE_KEY { - OPEN_AI_API_KEY = 'openAiApiKey', - CHAT_LIST = 'bChatList', - GPT_MODEL = 'bGptModel' + OPEN_AI_API_KEY = "openAiApiKey", + CHAT_LIST = "bChatList", + GPT_MODEL = "bGptModel", } export enum MESSAGE_ROLE { - SYSTEM = 'system', - ASSISTANT = 'assistant', - USER = 'user', - HUMAN = 'Human' + SYSTEM = "system", + ASSISTANT = "assistant", + USER = "user", + HUMAN = "Human", } export enum BANNER_TYPE { - ERROR = 'error', - INFO = 'info', - WARNING = 'warning', - SUCCESS = 'success' + ERROR = "error", + INFO = "info", + WARNING = "warning", + SUCCESS = "success", } export enum ERROR { - LOCAL_STORAGE_SET_ITEM = 'LOCAL_STORAGE_SET_ITEM', - OPENAI_CHAT_COMPLETION = 'OPENAI_CHAT_COMPLETION', - REGISTRATION = 'REGISTRATION', - LOGIN = 'LOGIN', - PASSWORD_RESET = 'PASSWORD_RESET', - USER_DATA_FETCH = 'USER_DATA_FETCH', - PASSWORD_CHANGE = 'PASSWORD_CHANGE', - CHECKOUT_SESSION_CREATE = 'CHECKOUT_SESSION_CREATE', - DATA_SYNC_SAVE = 'CHAT_SYNC_SAVE', - DATA_SYNC_SAVE_LIMIT = 'CHAT_SYNC_SAVE_LIMIT', - DATA_SYNC_IMPORT = 'CHAT_SYNC_IMPORT', - DATA_SYNC_DELETE_SAVED_CHAT = 'CHAT_SYNC_DELETE_SAVED_CHAT' + LOCAL_STORAGE_SET_ITEM = "LOCAL_STORAGE_SET_ITEM", + OPENAI_CHAT_COMPLETION = "OPENAI_CHAT_COMPLETION", + REGISTRATION = "REGISTRATION", + LOGIN = "LOGIN", + PASSWORD_RESET = "PASSWORD_RESET", + USER_DATA_FETCH = "USER_DATA_FETCH", + PASSWORD_CHANGE = "PASSWORD_CHANGE", + CHECKOUT_SESSION_CREATE = "CHECKOUT_SESSION_CREATE", + DATA_SYNC_SAVE = "CHAT_SYNC_SAVE", + DATA_SYNC_SAVE_LIMIT = "CHAT_SYNC_SAVE_LIMIT", + DATA_SYNC_IMPORT = "CHAT_SYNC_IMPORT", + DATA_SYNC_DELETE_SAVED_CHAT = "CHAT_SYNC_DELETE_SAVED_CHAT", } export type Message = { - tool: string; - content: []; - goal: string; - source: [] + tool: string; + content: []; + goal: string; + source: []; }; export type ChatListItem = { - chatId: string; - title: string; + chatId: string; + title: string; }; export type Chat = { - chatId: string; - messages: Message[]; - agentName: string, - agentDescripe: string, + chatId: string; + messages: Message[]; + agentName: string; + agentDescripe: string; }; // In-memory only export type Banner = { - bannerId: string; - bannerType: BANNER_TYPE; - title: string; - description: string; + bannerId: string; + bannerType: BANNER_TYPE; + title: string; + description: string; }; diff --git a/AgentQnA/ui/svelte/src/lib/components/shared/store.ts b/AgentQnA/ui/svelte/src/lib/components/shared/store.ts index e3fa8f81b8..f496f131ba 100644 --- a/AgentQnA/ui/svelte/src/lib/components/shared/store.ts +++ b/AgentQnA/ui/svelte/src/lib/components/shared/store.ts @@ -1,4 +1,7 @@ -import { writable } from 'svelte/store'; +// Copyright (C) 2025 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + +import { writable } from "svelte/store"; let open = writable(false); diff --git a/AgentQnA/ui/svelte/src/lib/components/timeline.svelte b/AgentQnA/ui/svelte/src/lib/components/timeline.svelte index d2d2133d5e..14baff43b0 100644 --- a/AgentQnA/ui/svelte/src/lib/components/timeline.svelte +++ b/AgentQnA/ui/svelte/src/lib/components/timeline.svelte @@ -1,10 +1,15 @@ + +