From 86f0ffc7d19e82ed5c12dab6d477a0bdba911622 Mon Sep 17 00:00:00 2001 From: hiento09 <136591877+hiento09@users.noreply.github.com> Date: Tue, 5 Sep 2023 16:29:07 +0700 Subject: [PATCH] Chore/disable submodule (#56) * Chore disable git submodule for web-client and app-backend * Chore add newest source code of app-backend and web-client --------- Co-authored-by: Hien To --- .gitmodules | 6 - app-backend | 1 - app-backend/.gitignore | 4 + app-backend/README.md | 59 + app-backend/docker-compose.yml | 52 + app-backend/hasura/config.yaml | 7 + app-backend/hasura/metadata/actions.graphql | 20 + app-backend/hasura/metadata/actions.yaml | 32 + app-backend/hasura/metadata/allow_list.yaml | 1 + app-backend/hasura/metadata/api_limits.yaml | 1 + .../hasura/metadata/backend_configs.yaml | 11 + .../hasura/metadata/cron_triggers.yaml | 1 + .../hasura/metadata/databases/databases.yaml | 9 + .../tables/public_collection_products.yaml | 43 + .../jandb/tables/public_collections.yaml | 36 + .../jandb/tables/public_conversations.yaml | 68 + .../jandb/tables/public_message_medias.yaml | 68 + .../jandb/tables/public_messages.yaml | 97 + .../jandb/tables/public_product_prompts.yaml | 43 + .../jandb/tables/public_products.yaml | 65 + .../jandb/tables/public_prompts.yaml | 36 + .../databases/jandb/tables/tables.yaml | 8 + .../graphql_schema_introspection.yaml | 1 + .../hasura/metadata/inherited_roles.yaml | 1 + .../hasura/metadata/metrics_config.yaml | 1 + app-backend/hasura/metadata/network.yaml | 1 + .../hasura/metadata/opentelemetry.yaml | 1 + .../hasura/metadata/query_collections.yaml | 1 + .../hasura/metadata/remote_schemas.yaml | 1 + .../hasura/metadata/rest_endpoints.yaml | 1 + app-backend/hasura/metadata/version.yaml | 1 + .../down.sql | 1 + .../up.sql | 18 + .../down.sql | 1 + .../up.sql | 18 + .../down.sql | 1 + .../up.sql | 18 + .../down.sql | 1 + .../up.sql | 18 + .../down.sql | 1 + .../up.sql | 18 + .../down.sql | 1 + .../up.sql | 18 + .../down.sql | 1 + .../up.sql | 18 + .../down.sql | 1 + .../up.sql | 18 + .../down.sql | 1 + .../up.sql | 5 + .../down.sql | 1 + .../up.sql | 5 + .../down.sql | 1 + .../up.sql | 2 + .../down.sql | 1 + .../up.sql | 2 + .../jandb/1692710119690_productsSeed.sql | 4 + .../jandb/1692710265351_collectionsSeed.sql | 4 + .../1692710371524_collectionProductsSeed.sql | 11 + .../seeds/jandb/1692711599434_promptsSeed.sql | 16 + .../1692711671035_productPromptsSeed.sql | 21 + app-backend/sample.env | 23 + app-backend/sample.env_postgresql | 1 + app-backend/worker/Dockerfile | 16 + app-backend/worker/worker.ts | 197 + app-backend/worker/wrangler.toml | 11 + web-client | 1 - web-client/.eslintrc.json | 6 + web-client/.gitignore | 45 + web-client/Dockerfile | 48 + web-client/README.md | 102 + .../app/_components/ActionButton/index.tsx | 41 + .../app/_components/AdvancedPrompt/index.tsx | 69 + .../AdvancedPromptGenerationParams/index.tsx | 18 + .../AdvancedPromptImageUpload/index.tsx | 31 + .../AdvancedPromptResolution/index.tsx | 29 + .../_components/AdvancedPromptText/index.tsx | 41 + .../_components/AdvancedTextArea/index.tsx | 27 + web-client/app/_components/AiSearch/index.tsx | 20 + .../app/_components/AiTypeCard/index.tsx | 20 + web-client/app/_components/ApiPane/index.tsx | 79 + web-client/app/_components/ApiStep/index.tsx | 15 + .../app/_components/ButtonSlider/index.tsx | 45 + .../app/_components/ChangeTheme/index.tsx | 25 + web-client/app/_components/ChatBody/index.tsx | 186 + .../app/_components/ChatContainer/index.tsx | 91 + .../_components/CompactHistoryItem/index.tsx | 39 + .../app/_components/CompactLogo/index.tsx | 16 + .../app/_components/CompactSideBar/index.tsx | 33 + .../ConfirmDeleteConversationModal/index.tsx | 99 + .../_components/ConfirmSignOutModal/index.tsx | 90 + .../_components/ConversationalCard/index.tsx | 47 + .../_components/ConversationalList/index.tsx | 25 + .../app/_components/DescriptionPane/index.tsx | 33 + .../_components/DiscordContainer/index.tsx | 31 + .../app/_components/Draggable/index.tsx | 37 + .../app/_components/DropdownList/index.tsx | 64 + web-client/app/_components/Footer/index.tsx | 29 + .../_components/GenerateImageCard/index.tsx | 31 + .../_components/GenerateImageList/index.tsx | 27 + .../GenerativeSampleContainer/index.tsx | 52 + web-client/app/_components/Header/index.tsx | 61 + .../app/_components/HistoryEmpty/index.tsx | 27 + .../app/_components/HistoryItem/index.tsx | 87 + .../app/_components/HistoryItemDate/index.tsx | 12 + .../app/_components/HistoryList/index.tsx | 58 + .../app/_components/InputToolbar/index.tsx | 146 + web-client/app/_components/JanImage/index.tsx | 33 + .../app/_components/JanWelcomeTitle/index.tsx | 20 + .../app/_components/LoadingIndicator.tsx | 13 + .../_components/MenuAdvancedPrompt/index.tsx | 23 + .../app/_components/MenuHeader/index.tsx | 56 + .../app/_components/MobileDownload/index.tsx | 69 + .../_components/MobileInstallPane/index.tsx | 44 + .../app/_components/MobileMenuPane/index.tsx | 52 + .../app/_components/MobileShowcase/index.tsx | 91 + .../app/_components/ModelDetailCost/index.tsx | 21 + .../_components/ModelDetailSideBar/index.tsx | 36 + .../app/_components/ModelInfo/index.tsx | 42 + .../app/_components/ModelInfoItem/index.tsx | 15 + .../app/_components/ModelMenu/index.tsx | 44 + .../_components/NewChatBlankState/index.tsx | 56 + web-client/app/_components/OverviewPane.tsx | 94 + .../_components/SampleLlmContainer/index.tsx | 46 + .../app/_components/SearchBar/index.tsx | 24 + .../app/_components/SendButton/index.tsx | 29 + .../_components/SessionProviderWrapper.tsx | 11 + .../app/_components/ShortcutItem/index.tsx | 32 + .../app/_components/ShortcutList/index.tsx | 42 + .../app/_components/ShowMoreButton/index.tsx | 23 + .../app/_components/SidebarLeft/index.tsx | 109 + .../_components/SimpleControlNetMessage.tsx | 66 + .../_components/SimpleImageMessage/index.tsx | 105 + .../_components/SimpleTextMessage/index.tsx | 56 + web-client/app/_components/Slide/index.tsx | 47 + web-client/app/_components/Slider/index.tsx | 54 + .../_components/StreamTextMessage/index.tsx | 107 + .../app/_components/TabModelDetail/index.tsx | 35 + web-client/app/_components/TextCode/index.tsx | 31 + .../app/_components/TitleBlankState/index.tsx | 11 + .../app/_components/TogglableHeader/index.tsx | 34 + .../app/_components/UploadFileImage/index.tsx | 102 + .../_components/UserProfileDropDown/index.tsx | 38 + .../app/_components/UserToolbar/index.tsx | 23 + web-client/app/_helpers/ApolloWrapper.tsx | 74 + web-client/app/_helpers/MobxWrapper.tsx | 13 + web-client/app/_helpers/ThemeWrapper.tsx | 16 + web-client/app/_helpers/withAnalytics.tsx | 16 + web-client/app/_helpers/withSetPropAction.ts | 30 + .../app/_hooks/useCreateConversation.ts | 80 + web-client/app/_hooks/useGetCurrentUser.ts | 47 + web-client/app/_hooks/useGetModelApiInfo.ts | 75 + .../app/_hooks/useGetUserConversations.ts | 62 + web-client/app/_hooks/useSignIn.ts | 9 + web-client/app/_hooks/useSignOut.ts | 13 + web-client/app/_models/ChatMessage.ts | 35 + web-client/app/_models/Conversation.ts | 78 + web-client/app/_models/History.ts | 604 ++ web-client/app/_models/Input.ts | 19 + web-client/app/_models/Output.ts | 14 + web-client/app/_models/Product.ts | 22 + web-client/app/_models/ProductV2.ts | 81 + web-client/app/_models/RootStore.ts | 36 + web-client/app/_models/Shortcut.ts | 7 + web-client/app/_models/User.ts | 15 + web-client/app/_services/controlnet.ts | 42 + web-client/app/_utils/const.ts | 1 + web-client/app/_utils/datetime.ts | 15 + web-client/app/_utils/message.ts | 43 + web-client/app/_utils/tokenAccessor.ts | 19 + .../app/api/auth/[...nextauth]/route.ts | 73 + web-client/app/api/auth/logout/route.ts | 23 + web-client/app/download/page.tsx | 19 + web-client/app/favicon.ico | Bin 0 -> 15406 bytes web-client/app/globals.css | 374 ++ web-client/app/layout.tsx | 42 + web-client/app/page.tsx | 34 + web-client/app/privacy/page.tsx | 74 + web-client/app/support/page.tsx | 41 + web-client/codegen.ts | 27 + web-client/dev.Dockerfile | 27 + web-client/docker-compose.yml | 19 + web-client/env-example | 14 + .../graphql/fragments/collection.graphql | 4 + .../graphql/fragments/conversation.graphql | 12 + web-client/graphql/fragments/media.graphql | 7 + web-client/graphql/fragments/message.graphql | 16 + web-client/graphql/fragments/product.graphql | 16 + web-client/graphql/fragments/prompt.graphql | 5 + .../mutations/createConversation.graphql | 5 + .../graphql/mutations/createMessage.graphql | 9 + .../mutations/deleteConversation.graphql | 5 + .../graphql/mutations/imageGeneration.graphql | 23 + .../mutations/updateConversation.graphql | 5 + .../graphql/mutations/updateMessage.graphql | 5 + .../graphql/queries/getCollections.graphql | 15 + .../queries/getConversationMessages.graphql | 14 + .../graphql/queries/getConversations.graphql | 11 + .../getProductByCollectionSlug.graphql | 15 + .../graphql/queries/getProductPrompts.graphql | 5 + .../graphql/queries/getProducts.graphql | 15 + .../graphql/queries/getProductsIn.graphql | 5 + .../subscriptions/subscribeMessage.graphql | 6 + web-client/next.config.js | 16 + web-client/package-lock.json | 4369 +++++++++++++ web-client/package.json | 54 + web-client/postcss.config.js | 6 + web-client/public/icons/Jan.svg | 5 + web-client/public/icons/app_icon.svg | 14 + web-client/public/icons/apple.svg | 10 + web-client/public/icons/arrow-circle-down.svg | 3 + web-client/public/icons/arrow-gray.svg | 3 + web-client/public/icons/brain.svg | 5 + web-client/public/icons/chat.svg | 4 + .../public/icons/chats-circle-light.svg | 11 + web-client/public/icons/chevron-left.svg | 3 + web-client/public/icons/chevron-right.svg | 3 + web-client/public/icons/close_modal_btn.png | Bin 0 -> 358 bytes web-client/public/icons/code.svg | 5 + web-client/public/icons/copy.svg | 4 + web-client/public/icons/discord-icon.svg | 4 + web-client/public/icons/discord.svg | 10 + web-client/public/icons/download.svg | 3 + web-client/public/icons/edit_text.svg | 7 + web-client/public/icons/google_play_logo.svg | 1 + web-client/public/icons/googleplay.svg | 3 + web-client/public/icons/ic_api.svg | 4 + web-client/public/icons/ic_arrowback.svg | 3 + web-client/public/icons/ic_arrowright.svg | 3 + web-client/public/icons/ic_billing.svg | 4 + .../public/icons/ic_conversation_ai.svg | 62 + web-client/public/icons/ic_dashboard.svg | 4 + web-client/public/icons/ic_enhance.svg | 5 + web-client/public/icons/ic_generative_art.svg | 62 + web-client/public/icons/ic_image.svg | 3 + web-client/public/icons/ic_member.svg | 4 + web-client/public/icons/ic_on_device_ai.svg | 59 + web-client/public/icons/ic_plus.svg | 3 + web-client/public/icons/ic_prompt_library.svg | 124 + web-client/public/icons/ic_random.svg | 3 + web-client/public/icons/ic_setting.svg | 10 + web-client/public/icons/ic_sidebar.svg | 19 + web-client/public/icons/ic_sidebar_fill.svg | 19 + web-client/public/icons/ico_Discord.svg | 4 + web-client/public/icons/ico_logo.svg | 9 + .../public/icons/ico_mobile-android.svg | 3 + web-client/public/icons/ico_settingblack.svg | 3 + web-client/public/icons/janai_logo.svg | 1 + web-client/public/icons/loading.svg | 35 + web-client/public/icons/magnifyingglass.svg | 3 + web-client/public/icons/messicon.svg | 3 + web-client/public/icons/play.svg | 3 + web-client/public/icons/refresh.svg | 3 + web-client/public/icons/search.svg | 3 + .../public/icons/share_with_friend_btn.svg | 12 + web-client/public/icons/social_icon_apple.svg | 3 + .../public/icons/social_icon_google.svg | 13 + web-client/public/icons/telegram-icon.svg | 10 + web-client/public/icons/trash_bin.svg | 3 + .../public/icons/unicorn_angle-down.svg | 3 + web-client/public/icons/unicorn_angle-up.svg | 3 + .../public/icons/unicorn_arrow-random.svg | 3 + web-client/public/icons/unicorn_arrow.svg | 3 + web-client/public/icons/unicorn_chat.svg | 3 + .../public/icons/unicorn_clipboard-alt.svg | 3 + .../icons/unicorn_exclamation-circle.svg | 3 + web-client/public/icons/unicorn_exit.svg | 3 + web-client/public/icons/unicorn_image-v.svg | 5 + web-client/public/icons/unicorn_image-v2.svg | 3 + .../public/icons/unicorn_info-circle-fill.svg | 4 + .../public/icons/unicorn_info-circle.svg | 3 + .../public/icons/unicorn_layers-alt.svg | 3 + web-client/public/icons/unicorn_plus.svg | 3 + web-client/public/icons/unicorn_trash.svg | 3 + web-client/public/icons/upload_photo.svg | 9 + web-client/public/icons/whatsapp-icon.svg | 16 + web-client/public/images/mobile.jpg | Bin 0 -> 347270 bytes web-client/public/images/preview.jpg | Bin 0 -> 167088 bytes web-client/public/next.svg | 1 + web-client/public/vercel.svg | 1 + web-client/tailwind.config.js | 19 + web-client/tsconfig.json | 29 + web-client/yarn.lock | 5436 +++++++++++++++++ 282 files changed, 17895 insertions(+), 8 deletions(-) delete mode 160000 app-backend create mode 100644 app-backend/.gitignore create mode 100644 app-backend/README.md create mode 100644 app-backend/docker-compose.yml create mode 100644 app-backend/hasura/config.yaml create mode 100644 app-backend/hasura/metadata/actions.graphql create mode 100644 app-backend/hasura/metadata/actions.yaml create mode 100644 app-backend/hasura/metadata/allow_list.yaml create mode 100644 app-backend/hasura/metadata/api_limits.yaml create mode 100644 app-backend/hasura/metadata/backend_configs.yaml create mode 100644 app-backend/hasura/metadata/cron_triggers.yaml create mode 100644 app-backend/hasura/metadata/databases/databases.yaml create mode 100644 app-backend/hasura/metadata/databases/jandb/tables/public_collection_products.yaml create mode 100644 app-backend/hasura/metadata/databases/jandb/tables/public_collections.yaml create mode 100644 app-backend/hasura/metadata/databases/jandb/tables/public_conversations.yaml create mode 100644 app-backend/hasura/metadata/databases/jandb/tables/public_message_medias.yaml create mode 100644 app-backend/hasura/metadata/databases/jandb/tables/public_messages.yaml create mode 100644 app-backend/hasura/metadata/databases/jandb/tables/public_product_prompts.yaml create mode 100644 app-backend/hasura/metadata/databases/jandb/tables/public_products.yaml create mode 100644 app-backend/hasura/metadata/databases/jandb/tables/public_prompts.yaml create mode 100644 app-backend/hasura/metadata/databases/jandb/tables/tables.yaml create mode 100644 app-backend/hasura/metadata/graphql_schema_introspection.yaml create mode 100644 app-backend/hasura/metadata/inherited_roles.yaml create mode 100644 app-backend/hasura/metadata/metrics_config.yaml create mode 100644 app-backend/hasura/metadata/network.yaml create mode 100644 app-backend/hasura/metadata/opentelemetry.yaml create mode 100644 app-backend/hasura/metadata/query_collections.yaml create mode 100644 app-backend/hasura/metadata/remote_schemas.yaml create mode 100644 app-backend/hasura/metadata/rest_endpoints.yaml create mode 100644 app-backend/hasura/metadata/version.yaml create mode 100644 app-backend/hasura/migrations/jandb/1692603657609_create_table_public_collections/down.sql create mode 100644 app-backend/hasura/migrations/jandb/1692603657609_create_table_public_collections/up.sql create mode 100644 app-backend/hasura/migrations/jandb/1692603899157_create_table_public_products/down.sql create mode 100644 app-backend/hasura/migrations/jandb/1692603899157_create_table_public_products/up.sql create mode 100644 app-backend/hasura/migrations/jandb/1692603954223_create_table_public_prompts/down.sql create mode 100644 app-backend/hasura/migrations/jandb/1692603954223_create_table_public_prompts/up.sql create mode 100644 app-backend/hasura/migrations/jandb/1692604164229_create_table_public_conversations/down.sql create mode 100644 app-backend/hasura/migrations/jandb/1692604164229_create_table_public_conversations/up.sql create mode 100644 app-backend/hasura/migrations/jandb/1692604250751_create_table_public_messages/down.sql create mode 100644 app-backend/hasura/migrations/jandb/1692604250751_create_table_public_messages/up.sql create mode 100644 app-backend/hasura/migrations/jandb/1692604354631_create_table_public_message_medias/down.sql create mode 100644 app-backend/hasura/migrations/jandb/1692604354631_create_table_public_message_medias/up.sql create mode 100644 app-backend/hasura/migrations/jandb/1692604743434_create_table_public_collection_products/down.sql create mode 100644 app-backend/hasura/migrations/jandb/1692604743434_create_table_public_collection_products/up.sql create mode 100644 app-backend/hasura/migrations/jandb/1692604794719_create_table_public_product_prompts/down.sql create mode 100644 app-backend/hasura/migrations/jandb/1692604794719_create_table_public_product_prompts/up.sql create mode 100644 app-backend/hasura/migrations/jandb/1692605865437_set_fk_public_collection_products_collection_id/down.sql create mode 100644 app-backend/hasura/migrations/jandb/1692605865437_set_fk_public_collection_products_collection_id/up.sql create mode 100644 app-backend/hasura/migrations/jandb/1692605887650_set_fk_public_collection_products_product_id/down.sql create mode 100644 app-backend/hasura/migrations/jandb/1692605887650_set_fk_public_collection_products_product_id/up.sql create mode 100644 app-backend/hasura/migrations/jandb/1692885821205_alter_table_public_messages_add_column_status/down.sql create mode 100644 app-backend/hasura/migrations/jandb/1692885821205_alter_table_public_messages_add_column_status/up.sql create mode 100644 app-backend/hasura/migrations/jandb/1692891470212_alter_table_public_messages_add_column_prompt_cache/down.sql create mode 100644 app-backend/hasura/migrations/jandb/1692891470212_alter_table_public_messages_add_column_prompt_cache/up.sql create mode 100644 app-backend/hasura/seeds/jandb/1692710119690_productsSeed.sql create mode 100644 app-backend/hasura/seeds/jandb/1692710265351_collectionsSeed.sql create mode 100644 app-backend/hasura/seeds/jandb/1692710371524_collectionProductsSeed.sql create mode 100644 app-backend/hasura/seeds/jandb/1692711599434_promptsSeed.sql create mode 100644 app-backend/hasura/seeds/jandb/1692711671035_productPromptsSeed.sql create mode 100644 app-backend/sample.env create mode 100644 app-backend/sample.env_postgresql create mode 100644 app-backend/worker/Dockerfile create mode 100644 app-backend/worker/worker.ts create mode 100644 app-backend/worker/wrangler.toml delete mode 160000 web-client create mode 100644 web-client/.eslintrc.json create mode 100644 web-client/.gitignore create mode 100644 web-client/Dockerfile create mode 100644 web-client/README.md create mode 100644 web-client/app/_components/ActionButton/index.tsx create mode 100644 web-client/app/_components/AdvancedPrompt/index.tsx create mode 100644 web-client/app/_components/AdvancedPromptGenerationParams/index.tsx create mode 100644 web-client/app/_components/AdvancedPromptImageUpload/index.tsx create mode 100644 web-client/app/_components/AdvancedPromptResolution/index.tsx create mode 100644 web-client/app/_components/AdvancedPromptText/index.tsx create mode 100644 web-client/app/_components/AdvancedTextArea/index.tsx create mode 100644 web-client/app/_components/AiSearch/index.tsx create mode 100644 web-client/app/_components/AiTypeCard/index.tsx create mode 100644 web-client/app/_components/ApiPane/index.tsx create mode 100644 web-client/app/_components/ApiStep/index.tsx create mode 100644 web-client/app/_components/ButtonSlider/index.tsx create mode 100644 web-client/app/_components/ChangeTheme/index.tsx create mode 100644 web-client/app/_components/ChatBody/index.tsx create mode 100644 web-client/app/_components/ChatContainer/index.tsx create mode 100644 web-client/app/_components/CompactHistoryItem/index.tsx create mode 100644 web-client/app/_components/CompactLogo/index.tsx create mode 100644 web-client/app/_components/CompactSideBar/index.tsx create mode 100644 web-client/app/_components/ConfirmDeleteConversationModal/index.tsx create mode 100644 web-client/app/_components/ConfirmSignOutModal/index.tsx create mode 100644 web-client/app/_components/ConversationalCard/index.tsx create mode 100644 web-client/app/_components/ConversationalList/index.tsx create mode 100644 web-client/app/_components/DescriptionPane/index.tsx create mode 100644 web-client/app/_components/DiscordContainer/index.tsx create mode 100644 web-client/app/_components/Draggable/index.tsx create mode 100644 web-client/app/_components/DropdownList/index.tsx create mode 100644 web-client/app/_components/Footer/index.tsx create mode 100644 web-client/app/_components/GenerateImageCard/index.tsx create mode 100644 web-client/app/_components/GenerateImageList/index.tsx create mode 100644 web-client/app/_components/GenerativeSampleContainer/index.tsx create mode 100644 web-client/app/_components/Header/index.tsx create mode 100644 web-client/app/_components/HistoryEmpty/index.tsx create mode 100644 web-client/app/_components/HistoryItem/index.tsx create mode 100644 web-client/app/_components/HistoryItemDate/index.tsx create mode 100644 web-client/app/_components/HistoryList/index.tsx create mode 100644 web-client/app/_components/InputToolbar/index.tsx create mode 100644 web-client/app/_components/JanImage/index.tsx create mode 100644 web-client/app/_components/JanWelcomeTitle/index.tsx create mode 100644 web-client/app/_components/LoadingIndicator.tsx create mode 100644 web-client/app/_components/MenuAdvancedPrompt/index.tsx create mode 100644 web-client/app/_components/MenuHeader/index.tsx create mode 100644 web-client/app/_components/MobileDownload/index.tsx create mode 100644 web-client/app/_components/MobileInstallPane/index.tsx create mode 100644 web-client/app/_components/MobileMenuPane/index.tsx create mode 100644 web-client/app/_components/MobileShowcase/index.tsx create mode 100644 web-client/app/_components/ModelDetailCost/index.tsx create mode 100644 web-client/app/_components/ModelDetailSideBar/index.tsx create mode 100644 web-client/app/_components/ModelInfo/index.tsx create mode 100644 web-client/app/_components/ModelInfoItem/index.tsx create mode 100644 web-client/app/_components/ModelMenu/index.tsx create mode 100644 web-client/app/_components/NewChatBlankState/index.tsx create mode 100644 web-client/app/_components/OverviewPane.tsx create mode 100644 web-client/app/_components/SampleLlmContainer/index.tsx create mode 100644 web-client/app/_components/SearchBar/index.tsx create mode 100644 web-client/app/_components/SendButton/index.tsx create mode 100644 web-client/app/_components/SessionProviderWrapper.tsx create mode 100644 web-client/app/_components/ShortcutItem/index.tsx create mode 100644 web-client/app/_components/ShortcutList/index.tsx create mode 100644 web-client/app/_components/ShowMoreButton/index.tsx create mode 100644 web-client/app/_components/SidebarLeft/index.tsx create mode 100644 web-client/app/_components/SimpleControlNetMessage.tsx create mode 100644 web-client/app/_components/SimpleImageMessage/index.tsx create mode 100644 web-client/app/_components/SimpleTextMessage/index.tsx create mode 100644 web-client/app/_components/Slide/index.tsx create mode 100644 web-client/app/_components/Slider/index.tsx create mode 100644 web-client/app/_components/StreamTextMessage/index.tsx create mode 100644 web-client/app/_components/TabModelDetail/index.tsx create mode 100644 web-client/app/_components/TextCode/index.tsx create mode 100644 web-client/app/_components/TitleBlankState/index.tsx create mode 100644 web-client/app/_components/TogglableHeader/index.tsx create mode 100644 web-client/app/_components/UploadFileImage/index.tsx create mode 100644 web-client/app/_components/UserProfileDropDown/index.tsx create mode 100644 web-client/app/_components/UserToolbar/index.tsx create mode 100644 web-client/app/_helpers/ApolloWrapper.tsx create mode 100644 web-client/app/_helpers/MobxWrapper.tsx create mode 100644 web-client/app/_helpers/ThemeWrapper.tsx create mode 100644 web-client/app/_helpers/withAnalytics.tsx create mode 100644 web-client/app/_helpers/withSetPropAction.ts create mode 100644 web-client/app/_hooks/useCreateConversation.ts create mode 100644 web-client/app/_hooks/useGetCurrentUser.ts create mode 100644 web-client/app/_hooks/useGetModelApiInfo.ts create mode 100644 web-client/app/_hooks/useGetUserConversations.ts create mode 100644 web-client/app/_hooks/useSignIn.ts create mode 100644 web-client/app/_hooks/useSignOut.ts create mode 100644 web-client/app/_models/ChatMessage.ts create mode 100644 web-client/app/_models/Conversation.ts create mode 100644 web-client/app/_models/History.ts create mode 100644 web-client/app/_models/Input.ts create mode 100644 web-client/app/_models/Output.ts create mode 100644 web-client/app/_models/Product.ts create mode 100644 web-client/app/_models/ProductV2.ts create mode 100644 web-client/app/_models/RootStore.ts create mode 100644 web-client/app/_models/Shortcut.ts create mode 100644 web-client/app/_models/User.ts create mode 100644 web-client/app/_services/controlnet.ts create mode 100644 web-client/app/_utils/const.ts create mode 100644 web-client/app/_utils/datetime.ts create mode 100644 web-client/app/_utils/message.ts create mode 100644 web-client/app/_utils/tokenAccessor.ts create mode 100644 web-client/app/api/auth/[...nextauth]/route.ts create mode 100644 web-client/app/api/auth/logout/route.ts create mode 100644 web-client/app/download/page.tsx create mode 100644 web-client/app/favicon.ico create mode 100644 web-client/app/globals.css create mode 100644 web-client/app/layout.tsx create mode 100644 web-client/app/page.tsx create mode 100644 web-client/app/privacy/page.tsx create mode 100644 web-client/app/support/page.tsx create mode 100644 web-client/codegen.ts create mode 100644 web-client/dev.Dockerfile create mode 100644 web-client/docker-compose.yml create mode 100644 web-client/env-example create mode 100644 web-client/graphql/fragments/collection.graphql create mode 100644 web-client/graphql/fragments/conversation.graphql create mode 100644 web-client/graphql/fragments/media.graphql create mode 100644 web-client/graphql/fragments/message.graphql create mode 100644 web-client/graphql/fragments/product.graphql create mode 100644 web-client/graphql/fragments/prompt.graphql create mode 100644 web-client/graphql/mutations/createConversation.graphql create mode 100644 web-client/graphql/mutations/createMessage.graphql create mode 100644 web-client/graphql/mutations/deleteConversation.graphql create mode 100644 web-client/graphql/mutations/imageGeneration.graphql create mode 100644 web-client/graphql/mutations/updateConversation.graphql create mode 100644 web-client/graphql/mutations/updateMessage.graphql create mode 100644 web-client/graphql/queries/getCollections.graphql create mode 100644 web-client/graphql/queries/getConversationMessages.graphql create mode 100644 web-client/graphql/queries/getConversations.graphql create mode 100644 web-client/graphql/queries/getProductByCollectionSlug.graphql create mode 100644 web-client/graphql/queries/getProductPrompts.graphql create mode 100644 web-client/graphql/queries/getProducts.graphql create mode 100644 web-client/graphql/queries/getProductsIn.graphql create mode 100644 web-client/graphql/subscriptions/subscribeMessage.graphql create mode 100644 web-client/next.config.js create mode 100644 web-client/package-lock.json create mode 100644 web-client/package.json create mode 100644 web-client/postcss.config.js create mode 100644 web-client/public/icons/Jan.svg create mode 100644 web-client/public/icons/app_icon.svg create mode 100644 web-client/public/icons/apple.svg create mode 100644 web-client/public/icons/arrow-circle-down.svg create mode 100644 web-client/public/icons/arrow-gray.svg create mode 100644 web-client/public/icons/brain.svg create mode 100644 web-client/public/icons/chat.svg create mode 100644 web-client/public/icons/chats-circle-light.svg create mode 100644 web-client/public/icons/chevron-left.svg create mode 100644 web-client/public/icons/chevron-right.svg create mode 100644 web-client/public/icons/close_modal_btn.png create mode 100644 web-client/public/icons/code.svg create mode 100644 web-client/public/icons/copy.svg create mode 100644 web-client/public/icons/discord-icon.svg create mode 100644 web-client/public/icons/discord.svg create mode 100644 web-client/public/icons/download.svg create mode 100644 web-client/public/icons/edit_text.svg create mode 100644 web-client/public/icons/google_play_logo.svg create mode 100644 web-client/public/icons/googleplay.svg create mode 100644 web-client/public/icons/ic_api.svg create mode 100644 web-client/public/icons/ic_arrowback.svg create mode 100644 web-client/public/icons/ic_arrowright.svg create mode 100644 web-client/public/icons/ic_billing.svg create mode 100644 web-client/public/icons/ic_conversation_ai.svg create mode 100644 web-client/public/icons/ic_dashboard.svg create mode 100644 web-client/public/icons/ic_enhance.svg create mode 100644 web-client/public/icons/ic_generative_art.svg create mode 100644 web-client/public/icons/ic_image.svg create mode 100644 web-client/public/icons/ic_member.svg create mode 100644 web-client/public/icons/ic_on_device_ai.svg create mode 100644 web-client/public/icons/ic_plus.svg create mode 100644 web-client/public/icons/ic_prompt_library.svg create mode 100644 web-client/public/icons/ic_random.svg create mode 100644 web-client/public/icons/ic_setting.svg create mode 100644 web-client/public/icons/ic_sidebar.svg create mode 100644 web-client/public/icons/ic_sidebar_fill.svg create mode 100644 web-client/public/icons/ico_Discord.svg create mode 100644 web-client/public/icons/ico_logo.svg create mode 100644 web-client/public/icons/ico_mobile-android.svg create mode 100644 web-client/public/icons/ico_settingblack.svg create mode 100644 web-client/public/icons/janai_logo.svg create mode 100644 web-client/public/icons/loading.svg create mode 100644 web-client/public/icons/magnifyingglass.svg create mode 100644 web-client/public/icons/messicon.svg create mode 100644 web-client/public/icons/play.svg create mode 100644 web-client/public/icons/refresh.svg create mode 100644 web-client/public/icons/search.svg create mode 100644 web-client/public/icons/share_with_friend_btn.svg create mode 100644 web-client/public/icons/social_icon_apple.svg create mode 100644 web-client/public/icons/social_icon_google.svg create mode 100644 web-client/public/icons/telegram-icon.svg create mode 100644 web-client/public/icons/trash_bin.svg create mode 100644 web-client/public/icons/unicorn_angle-down.svg create mode 100644 web-client/public/icons/unicorn_angle-up.svg create mode 100644 web-client/public/icons/unicorn_arrow-random.svg create mode 100644 web-client/public/icons/unicorn_arrow.svg create mode 100644 web-client/public/icons/unicorn_chat.svg create mode 100644 web-client/public/icons/unicorn_clipboard-alt.svg create mode 100644 web-client/public/icons/unicorn_exclamation-circle.svg create mode 100644 web-client/public/icons/unicorn_exit.svg create mode 100644 web-client/public/icons/unicorn_image-v.svg create mode 100644 web-client/public/icons/unicorn_image-v2.svg create mode 100644 web-client/public/icons/unicorn_info-circle-fill.svg create mode 100644 web-client/public/icons/unicorn_info-circle.svg create mode 100644 web-client/public/icons/unicorn_layers-alt.svg create mode 100644 web-client/public/icons/unicorn_plus.svg create mode 100644 web-client/public/icons/unicorn_trash.svg create mode 100644 web-client/public/icons/upload_photo.svg create mode 100644 web-client/public/icons/whatsapp-icon.svg create mode 100644 web-client/public/images/mobile.jpg create mode 100644 web-client/public/images/preview.jpg create mode 100644 web-client/public/next.svg create mode 100644 web-client/public/vercel.svg create mode 100644 web-client/tailwind.config.js create mode 100644 web-client/tsconfig.json create mode 100644 web-client/yarn.lock diff --git a/.gitmodules b/.gitmodules index 225119ae4..fb1c6e128 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,3 @@ -[submodule "web-client"] - path = web-client - url = ../jan-web.git -[submodule "app-backend"] - path = app-backend - url = ../app-backend.git [submodule "jan-inference/sd/sd_cpp"] path = jan-inference/sd/sd_cpp url = https://github.com/leejet/stable-diffusion.cpp diff --git a/app-backend b/app-backend deleted file mode 160000 index 4c44efe71..000000000 --- a/app-backend +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4c44efe7187b15cd2b65f3c8f6a089982941dbd7 diff --git a/app-backend/.gitignore b/app-backend/.gitignore new file mode 100644 index 000000000..4caef3e61 --- /dev/null +++ b/app-backend/.gitignore @@ -0,0 +1,4 @@ +.DS_Store +.env +.env_postgresql +worker/node_modules/.mf diff --git a/app-backend/README.md b/app-backend/README.md new file mode 100644 index 000000000..0c693253b --- /dev/null +++ b/app-backend/README.md @@ -0,0 +1,59 @@ +## Jan Backend + +A Hasura Data API Platform designed to provide APIs for client interaction with the Language Model (LLM) through chat or the generation of art using Stable Diffusion. It is encapsulated within a Docker container for easy local deployment + +## Quickstart +1. Run docker up + +```bash +docker compose up +``` + +2. Install [HasuraCLI](https://hasura.io/docs/latest/hasura-cli/overview/) + +3. Open Hasura Console + +```bash +cd hasura && hasura console +``` + +4. Apply Migration + +```bash +hasura migrate apply +``` + +5. Apply Metadata + +```bash +hasura metadata apply +``` + +6. Apply seeds + +```bash +hasura seed apply +``` + +## Hasura One Click Deploy +Use this URL to deploy this app to Hasura Cloud + +[![Hasura Deploy](https://hasura.io/deploy-button.svg)](https://cloud.hasura.io/deploy?github_repo=https://github.com/janhq/app-backend/&hasura_dir=/hasura) + +[One-click deploy docs](https://hasura.io/docs/latest/getting-started/getting-started-cloud/) + +## Modify schema & model +[Hasura Tutorials](https://hasura.io/docs/latest/resources/tutorials/index/) + +## Events & Workers + +Serverless function (Cloudflare worker) to stream llm message & update + +Readmore about Hasura Events here: +> https://hasura.io/docs/latest/event-triggers/serverless/ + +## Deploy Worker +```bash +npx wrangler deploy +``` +[Cloudflare Worker Guide](https://developers.cloudflare.com/workers/get-started/guide/) \ No newline at end of file diff --git a/app-backend/docker-compose.yml b/app-backend/docker-compose.yml new file mode 100644 index 000000000..5f60468e0 --- /dev/null +++ b/app-backend/docker-compose.yml @@ -0,0 +1,52 @@ +version: "3.6" +services: + postgres: + image: postgres:13 + restart: always + volumes: + - db_data:/var/lib/postgresql/data + env_file: + - .env_postgresql + graphql-engine: + image: hasura/graphql-engine:v2.31.0.cli-migrations-v3 + ports: + - "8080:8080" + restart: always + env_file: + - .env + volumes: + - ./hasura/migrations:/migrations + - ./hasura/metadata:/metadata + depends_on: + data-connector-agent: + condition: service_healthy + + data-connector-agent: + image: hasura/graphql-data-connector:v2.31.0 + restart: always + ports: + - 8081:8081 + environment: + QUARKUS_LOG_LEVEL: ERROR # FATAL, ERROR, WARN, INFO, DEBUG, TRACE + ## https://quarkus.io/guides/opentelemetry#configuration-reference + QUARKUS_OPENTELEMETRY_ENABLED: "false" + ## QUARKUS_OPENTELEMETRY_TRACER_EXPORTER_OTLP_ENDPOINT: http://jaeger:4317 + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8081/api/v1/athena/health"] + interval: 5s + timeout: 10s + retries: 5 + start_period: 5s + worker: + build: + context: ./worker + dockerfile: ./Dockerfile + restart: always + environment: + - "NODE_ENV=development" + volumes: + - ./worker:/worker + ports: + - "8787:8787" +volumes: + db_data: diff --git a/app-backend/hasura/config.yaml b/app-backend/hasura/config.yaml new file mode 100644 index 000000000..d13faa054 --- /dev/null +++ b/app-backend/hasura/config.yaml @@ -0,0 +1,7 @@ +version: 3 +endpoint: http://localhost:8080 +admin_secret: myadminsecretkey +metadata_directory: metadata +actions: + kind: synchronous + handler_webhook_baseurl: http://localhost:3000 diff --git a/app-backend/hasura/metadata/actions.graphql b/app-backend/hasura/metadata/actions.graphql new file mode 100644 index 000000000..4b8328f43 --- /dev/null +++ b/app-backend/hasura/metadata/actions.graphql @@ -0,0 +1,20 @@ +type Mutation { + imageGeneration( + input: ImageGenerationInput! + ): ImageGenerationOutput +} + +input ImageGenerationInput { + prompt: String! + neg_prompt: String! + model: String! + seed: Int! + steps: Int! + width: Int! + height: Int! +} + +type ImageGenerationOutput { + url: String! +} + diff --git a/app-backend/hasura/metadata/actions.yaml b/app-backend/hasura/metadata/actions.yaml new file mode 100644 index 000000000..c05edd96a --- /dev/null +++ b/app-backend/hasura/metadata/actions.yaml @@ -0,0 +1,32 @@ +actions: + - name: imageGeneration + definition: + kind: synchronous + handler: '{{HASURA_ACTION_STABLE_DIFFUSION_URL}}' + request_transform: + body: + action: transform + template: |- + { + "prompt": {{$body.input.input.prompt}}, + "neg_prompt": {{$body.input.input.neg_prompt}}, + "unet_model": {{$body.input.input.model}}, + "seed": {{$body.input.input.seed}}, + "steps": {{$body.input.input.steps}}, + "width": {{$body.input.input.width}}, + "height": {{$body.input.input.height}} + } + method: POST + query_params: {} + template_engine: Kriti + url: '{{$base_url}}/inferences/txt2img' + version: 2 + permissions: + - role: user +custom_types: + enums: [] + input_objects: + - name: ImageGenerationInput + objects: + - name: ImageGenerationOutput + scalars: [] diff --git a/app-backend/hasura/metadata/allow_list.yaml b/app-backend/hasura/metadata/allow_list.yaml new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/app-backend/hasura/metadata/allow_list.yaml @@ -0,0 +1 @@ +[] diff --git a/app-backend/hasura/metadata/api_limits.yaml b/app-backend/hasura/metadata/api_limits.yaml new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/app-backend/hasura/metadata/api_limits.yaml @@ -0,0 +1 @@ +{} diff --git a/app-backend/hasura/metadata/backend_configs.yaml b/app-backend/hasura/metadata/backend_configs.yaml new file mode 100644 index 000000000..1266c8d5c --- /dev/null +++ b/app-backend/hasura/metadata/backend_configs.yaml @@ -0,0 +1,11 @@ +dataconnector: + athena: + uri: http://data-connector-agent:8081/api/v1/athena + mariadb: + uri: http://data-connector-agent:8081/api/v1/mariadb + mysql8: + uri: http://data-connector-agent:8081/api/v1/mysql + oracle: + uri: http://data-connector-agent:8081/api/v1/oracle + snowflake: + uri: http://data-connector-agent:8081/api/v1/snowflake diff --git a/app-backend/hasura/metadata/cron_triggers.yaml b/app-backend/hasura/metadata/cron_triggers.yaml new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/app-backend/hasura/metadata/cron_triggers.yaml @@ -0,0 +1 @@ +[] diff --git a/app-backend/hasura/metadata/databases/databases.yaml b/app-backend/hasura/metadata/databases/databases.yaml new file mode 100644 index 000000000..b420475e7 --- /dev/null +++ b/app-backend/hasura/metadata/databases/databases.yaml @@ -0,0 +1,9 @@ +- name: jandb + kind: postgres + configuration: + connection_info: + database_url: + from_env: PG_DATABASE_URL + isolation_level: read-committed + use_prepared_statements: false + tables: "!include jandb/tables/tables.yaml" diff --git a/app-backend/hasura/metadata/databases/jandb/tables/public_collection_products.yaml b/app-backend/hasura/metadata/databases/jandb/tables/public_collection_products.yaml new file mode 100644 index 000000000..955361aed --- /dev/null +++ b/app-backend/hasura/metadata/databases/jandb/tables/public_collection_products.yaml @@ -0,0 +1,43 @@ +table: + name: collection_products + schema: public +array_relationships: + - name: collections + using: + manual_configuration: + column_mapping: + collection_id: id + insertion_order: null + remote_table: + name: collections + schema: public + - name: products + using: + manual_configuration: + column_mapping: + product_id: id + insertion_order: null + remote_table: + name: products + schema: public +select_permissions: + - role: public + permission: + columns: + - created_at + - updated_at + - collection_id + - id + - product_id + filter: {} + comment: "" + - role: user + permission: + columns: + - created_at + - updated_at + - collection_id + - id + - product_id + filter: {} + comment: "" diff --git a/app-backend/hasura/metadata/databases/jandb/tables/public_collections.yaml b/app-backend/hasura/metadata/databases/jandb/tables/public_collections.yaml new file mode 100644 index 000000000..c84847f1c --- /dev/null +++ b/app-backend/hasura/metadata/databases/jandb/tables/public_collections.yaml @@ -0,0 +1,36 @@ +table: + name: collections + schema: public +array_relationships: + - name: collection_products + using: + manual_configuration: + column_mapping: + id: collection_id + insertion_order: null + remote_table: + name: collection_products + schema: public +select_permissions: + - role: public + permission: + columns: + - slug + - description + - name + - created_at + - updated_at + - id + filter: {} + comment: "" + - role: user + permission: + columns: + - slug + - description + - name + - created_at + - updated_at + - id + filter: {} + comment: "" diff --git a/app-backend/hasura/metadata/databases/jandb/tables/public_conversations.yaml b/app-backend/hasura/metadata/databases/jandb/tables/public_conversations.yaml new file mode 100644 index 000000000..41637a39b --- /dev/null +++ b/app-backend/hasura/metadata/databases/jandb/tables/public_conversations.yaml @@ -0,0 +1,68 @@ +table: + name: conversations + schema: public +object_relationships: + - name: conversation_product + using: + manual_configuration: + column_mapping: + product_id: id + insertion_order: null + remote_table: + name: products + schema: public +array_relationships: + - name: conversation_messages + using: + manual_configuration: + column_mapping: + id: conversation_id + insertion_order: null + remote_table: + name: messages + schema: public +insert_permissions: + - role: user + permission: + check: + user_id: + _eq: X-Hasura-User-Id + columns: + - last_image_url + - last_text_message + - product_id + - user_id + comment: "" +select_permissions: + - role: user + permission: + columns: + - last_image_url + - last_text_message + - user_id + - created_at + - updated_at + - id + - product_id + filter: + user_id: + _eq: X-Hasura-User-Id + comment: "" +update_permissions: + - role: user + permission: + columns: + - last_image_url + - last_text_message + filter: + user_id: + _eq: X-Hasura-User-Id + check: null + comment: "" +delete_permissions: + - role: user + permission: + filter: + user_id: + _eq: X-Hasura-User-Id + comment: "" diff --git a/app-backend/hasura/metadata/databases/jandb/tables/public_message_medias.yaml b/app-backend/hasura/metadata/databases/jandb/tables/public_message_medias.yaml new file mode 100644 index 000000000..1f223b01a --- /dev/null +++ b/app-backend/hasura/metadata/databases/jandb/tables/public_message_medias.yaml @@ -0,0 +1,68 @@ +table: + name: message_medias + schema: public +object_relationships: + - name: media_message + using: + manual_configuration: + column_mapping: + message_id: id + insertion_order: null + remote_table: + name: messages + schema: public +insert_permissions: + - role: user + permission: + check: + media_message: + message_conversation: + user_id: + _eq: X-Hasura-User-Id + columns: + - media_url + - message_id + - mime_type + comment: "" +select_permissions: + - role: user + permission: + columns: + - mime_type + - media_url + - created_at + - updated_at + - id + - message_id + filter: + media_message: + message_conversation: + user_id: + _eq: X-Hasura-User-Id + comment: "" +update_permissions: + - role: user + permission: + columns: + - mime_type + - media_url + - created_at + - updated_at + - id + - message_id + filter: + media_message: + message_conversation: + user_id: + _eq: X-Hasura-User-Id + check: null + comment: "" +delete_permissions: + - role: user + permission: + filter: + media_message: + message_conversation: + user_id: + _eq: X-Hasura-User-Id + comment: "" diff --git a/app-backend/hasura/metadata/databases/jandb/tables/public_messages.yaml b/app-backend/hasura/metadata/databases/jandb/tables/public_messages.yaml new file mode 100644 index 000000000..a3a1ea662 --- /dev/null +++ b/app-backend/hasura/metadata/databases/jandb/tables/public_messages.yaml @@ -0,0 +1,97 @@ +table: + name: messages + schema: public +object_relationships: + - name: message_conversation + using: + manual_configuration: + column_mapping: + conversation_id: id + insertion_order: null + remote_table: + name: conversations + schema: public +array_relationships: + - name: message_medias + using: + manual_configuration: + column_mapping: + id: message_id + insertion_order: null + remote_table: + name: message_medias + schema: public +insert_permissions: + - role: user + permission: + check: + message_conversation: + user_id: + _eq: X-Hasura-User-Id + columns: + - content + - conversation_id + - message_sender_type + - message_type + - prompt_cache + - sender + - sender_avatar_url + - sender_name + - status + comment: "" +select_permissions: + - role: user + permission: + columns: + - content + - conversation_id + - created_at + - id + - message_sender_type + - message_type + - sender + - sender_avatar_url + - sender_name + - status + - updated_at + filter: + message_conversation: + user_id: + _eq: X-Hasura-User-Id + comment: "" +update_permissions: + - role: user + permission: + columns: + - content + - message_sender_type + - message_type + - sender + - sender_avatar_url + - sender_name + - status + filter: + message_conversation: + user_id: + _eq: X-Hasura-User-Id + check: null + comment: "" +delete_permissions: + - role: user + permission: + filter: + message_conversation: + user_id: + _eq: X-Hasura-User-Id + comment: "" +event_triggers: + - name: new_llm_message + definition: + enable_manual: false + insert: + columns: '*' + retry_conf: + interval_sec: 10 + num_retries: 0 + timeout_sec: 60 + webhook: '{{HASURA_EVENTS_HOOK_URL}}' diff --git a/app-backend/hasura/metadata/databases/jandb/tables/public_product_prompts.yaml b/app-backend/hasura/metadata/databases/jandb/tables/public_product_prompts.yaml new file mode 100644 index 000000000..8a0f9e90b --- /dev/null +++ b/app-backend/hasura/metadata/databases/jandb/tables/public_product_prompts.yaml @@ -0,0 +1,43 @@ +table: + name: product_prompts + schema: public +array_relationships: + - name: products + using: + manual_configuration: + column_mapping: + product_id: id + insertion_order: null + remote_table: + name: products + schema: public + - name: prompts + using: + manual_configuration: + column_mapping: + prompt_id: id + insertion_order: null + remote_table: + name: prompts + schema: public +select_permissions: + - role: public + permission: + columns: + - created_at + - updated_at + - id + - product_id + - prompt_id + filter: {} + comment: "" + - role: user + permission: + columns: + - created_at + - updated_at + - id + - product_id + - prompt_id + filter: {} + comment: "" diff --git a/app-backend/hasura/metadata/databases/jandb/tables/public_products.yaml b/app-backend/hasura/metadata/databases/jandb/tables/public_products.yaml new file mode 100644 index 000000000..f38873115 --- /dev/null +++ b/app-backend/hasura/metadata/databases/jandb/tables/public_products.yaml @@ -0,0 +1,65 @@ +table: + name: products + schema: public +array_relationships: + - name: product_collections + using: + manual_configuration: + column_mapping: + id: product_id + insertion_order: null + remote_table: + name: collection_products + schema: public + - name: product_prompts + using: + manual_configuration: + column_mapping: + id: product_id + insertion_order: null + remote_table: + name: product_prompts + schema: public +select_permissions: + - role: public + permission: + columns: + - nsfw + - slug + - inputs + - outputs + - author + - description + - greeting + - image_url + - long_description + - name + - source_url + - technical_description + - version + - created_at + - updated_at + - id + filter: {} + comment: "" + - role: user + permission: + columns: + - nsfw + - slug + - inputs + - outputs + - author + - description + - greeting + - image_url + - long_description + - name + - source_url + - technical_description + - version + - created_at + - updated_at + - id + filter: {} + comment: "" diff --git a/app-backend/hasura/metadata/databases/jandb/tables/public_prompts.yaml b/app-backend/hasura/metadata/databases/jandb/tables/public_prompts.yaml new file mode 100644 index 000000000..81cb8aadb --- /dev/null +++ b/app-backend/hasura/metadata/databases/jandb/tables/public_prompts.yaml @@ -0,0 +1,36 @@ +table: + name: prompts + schema: public +array_relationships: + - name: prompt_products + using: + manual_configuration: + column_mapping: + id: prompt_id + insertion_order: null + remote_table: + name: product_prompts + schema: public +select_permissions: + - role: public + permission: + columns: + - slug + - content + - image_url + - created_at + - updated_at + - id + filter: {} + comment: "" + - role: user + permission: + columns: + - slug + - content + - image_url + - created_at + - updated_at + - id + filter: {} + comment: "" diff --git a/app-backend/hasura/metadata/databases/jandb/tables/tables.yaml b/app-backend/hasura/metadata/databases/jandb/tables/tables.yaml new file mode 100644 index 000000000..f541617f9 --- /dev/null +++ b/app-backend/hasura/metadata/databases/jandb/tables/tables.yaml @@ -0,0 +1,8 @@ +- "!include public_collection_products.yaml" +- "!include public_collections.yaml" +- "!include public_conversations.yaml" +- "!include public_message_medias.yaml" +- "!include public_messages.yaml" +- "!include public_product_prompts.yaml" +- "!include public_products.yaml" +- "!include public_prompts.yaml" diff --git a/app-backend/hasura/metadata/graphql_schema_introspection.yaml b/app-backend/hasura/metadata/graphql_schema_introspection.yaml new file mode 100644 index 000000000..61a4dcac2 --- /dev/null +++ b/app-backend/hasura/metadata/graphql_schema_introspection.yaml @@ -0,0 +1 @@ +disabled_for_roles: [] diff --git a/app-backend/hasura/metadata/inherited_roles.yaml b/app-backend/hasura/metadata/inherited_roles.yaml new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/app-backend/hasura/metadata/inherited_roles.yaml @@ -0,0 +1 @@ +[] diff --git a/app-backend/hasura/metadata/metrics_config.yaml b/app-backend/hasura/metadata/metrics_config.yaml new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/app-backend/hasura/metadata/metrics_config.yaml @@ -0,0 +1 @@ +{} diff --git a/app-backend/hasura/metadata/network.yaml b/app-backend/hasura/metadata/network.yaml new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/app-backend/hasura/metadata/network.yaml @@ -0,0 +1 @@ +{} diff --git a/app-backend/hasura/metadata/opentelemetry.yaml b/app-backend/hasura/metadata/opentelemetry.yaml new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/app-backend/hasura/metadata/opentelemetry.yaml @@ -0,0 +1 @@ +{} diff --git a/app-backend/hasura/metadata/query_collections.yaml b/app-backend/hasura/metadata/query_collections.yaml new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/app-backend/hasura/metadata/query_collections.yaml @@ -0,0 +1 @@ +[] diff --git a/app-backend/hasura/metadata/remote_schemas.yaml b/app-backend/hasura/metadata/remote_schemas.yaml new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/app-backend/hasura/metadata/remote_schemas.yaml @@ -0,0 +1 @@ +[] diff --git a/app-backend/hasura/metadata/rest_endpoints.yaml b/app-backend/hasura/metadata/rest_endpoints.yaml new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/app-backend/hasura/metadata/rest_endpoints.yaml @@ -0,0 +1 @@ +[] diff --git a/app-backend/hasura/metadata/version.yaml b/app-backend/hasura/metadata/version.yaml new file mode 100644 index 000000000..0a70affa4 --- /dev/null +++ b/app-backend/hasura/metadata/version.yaml @@ -0,0 +1 @@ +version: 3 diff --git a/app-backend/hasura/migrations/jandb/1692603657609_create_table_public_collections/down.sql b/app-backend/hasura/migrations/jandb/1692603657609_create_table_public_collections/down.sql new file mode 100644 index 000000000..df0f0d344 --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692603657609_create_table_public_collections/down.sql @@ -0,0 +1 @@ +DROP TABLE "public"."collections"; diff --git a/app-backend/hasura/migrations/jandb/1692603657609_create_table_public_collections/up.sql b/app-backend/hasura/migrations/jandb/1692603657609_create_table_public_collections/up.sql new file mode 100644 index 000000000..fec2cb55d --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692603657609_create_table_public_collections/up.sql @@ -0,0 +1,18 @@ +CREATE TABLE "public"."collections" ("id" uuid NOT NULL DEFAULT gen_random_uuid(), "slug" varchar NOT NULL, "name" text NOT NULL, "description" text NOT NULL, "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), PRIMARY KEY ("id") , UNIQUE ("slug")); +CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"() +RETURNS TRIGGER AS $$ +DECLARE + _new record; +BEGIN + _new := NEW; + _new."updated_at" = NOW(); + RETURN _new; +END; +$$ LANGUAGE plpgsql; +CREATE TRIGGER "set_public_collections_updated_at" +BEFORE UPDATE ON "public"."collections" +FOR EACH ROW +EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"(); +COMMENT ON TRIGGER "set_public_collections_updated_at" ON "public"."collections" +IS 'trigger to set value of column "updated_at" to current timestamp on row update'; +CREATE EXTENSION IF NOT EXISTS pgcrypto; diff --git a/app-backend/hasura/migrations/jandb/1692603899157_create_table_public_products/down.sql b/app-backend/hasura/migrations/jandb/1692603899157_create_table_public_products/down.sql new file mode 100644 index 000000000..3b41d9305 --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692603899157_create_table_public_products/down.sql @@ -0,0 +1 @@ +DROP TABLE "public"."products"; diff --git a/app-backend/hasura/migrations/jandb/1692603899157_create_table_public_products/up.sql b/app-backend/hasura/migrations/jandb/1692603899157_create_table_public_products/up.sql new file mode 100644 index 000000000..038926bb7 --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692603899157_create_table_public_products/up.sql @@ -0,0 +1,18 @@ +CREATE TABLE "public"."products" ("id" uuid NOT NULL DEFAULT gen_random_uuid(), "slug" varchar NOT NULL, "name" text NOT NULL, "description" text, "image_url" text, "long_description" text, "technical_description" text, "author" text, "version" text, "source_url" text, "nsfw" boolean NOT NULL DEFAULT true, "greeting" text, "inputs" jsonb, "outputs" jsonb, "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), PRIMARY KEY ("id") , UNIQUE ("slug")); +CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"() +RETURNS TRIGGER AS $$ +DECLARE + _new record; +BEGIN + _new := NEW; + _new."updated_at" = NOW(); + RETURN _new; +END; +$$ LANGUAGE plpgsql; +CREATE TRIGGER "set_public_products_updated_at" +BEFORE UPDATE ON "public"."products" +FOR EACH ROW +EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"(); +COMMENT ON TRIGGER "set_public_products_updated_at" ON "public"."products" +IS 'trigger to set value of column "updated_at" to current timestamp on row update'; +CREATE EXTENSION IF NOT EXISTS pgcrypto; diff --git a/app-backend/hasura/migrations/jandb/1692603954223_create_table_public_prompts/down.sql b/app-backend/hasura/migrations/jandb/1692603954223_create_table_public_prompts/down.sql new file mode 100644 index 000000000..74f77626e --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692603954223_create_table_public_prompts/down.sql @@ -0,0 +1 @@ +DROP TABLE "public"."prompts"; diff --git a/app-backend/hasura/migrations/jandb/1692603954223_create_table_public_prompts/up.sql b/app-backend/hasura/migrations/jandb/1692603954223_create_table_public_prompts/up.sql new file mode 100644 index 000000000..7f444c43b --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692603954223_create_table_public_prompts/up.sql @@ -0,0 +1,18 @@ +CREATE TABLE "public"."prompts" ("id" uuid NOT NULL DEFAULT gen_random_uuid(), "slug" varchar NOT NULL, "content" text, "image_url" text, "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), PRIMARY KEY ("id") , UNIQUE ("slug")); +CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"() +RETURNS TRIGGER AS $$ +DECLARE + _new record; +BEGIN + _new := NEW; + _new."updated_at" = NOW(); + RETURN _new; +END; +$$ LANGUAGE plpgsql; +CREATE TRIGGER "set_public_prompts_updated_at" +BEFORE UPDATE ON "public"."prompts" +FOR EACH ROW +EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"(); +COMMENT ON TRIGGER "set_public_prompts_updated_at" ON "public"."prompts" +IS 'trigger to set value of column "updated_at" to current timestamp on row update'; +CREATE EXTENSION IF NOT EXISTS pgcrypto; diff --git a/app-backend/hasura/migrations/jandb/1692604164229_create_table_public_conversations/down.sql b/app-backend/hasura/migrations/jandb/1692604164229_create_table_public_conversations/down.sql new file mode 100644 index 000000000..53839d4c2 --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692604164229_create_table_public_conversations/down.sql @@ -0,0 +1 @@ +DROP TABLE "public"."conversations"; diff --git a/app-backend/hasura/migrations/jandb/1692604164229_create_table_public_conversations/up.sql b/app-backend/hasura/migrations/jandb/1692604164229_create_table_public_conversations/up.sql new file mode 100644 index 000000000..5df679bf7 --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692604164229_create_table_public_conversations/up.sql @@ -0,0 +1,18 @@ +CREATE TABLE "public"."conversations" ("id" uuid NOT NULL DEFAULT gen_random_uuid(), "product_id" uuid NOT NULL, "user_id" Text NOT NULL, "last_image_url" text, "last_text_message" text, "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), PRIMARY KEY ("id") ); +CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"() +RETURNS TRIGGER AS $$ +DECLARE + _new record; +BEGIN + _new := NEW; + _new."updated_at" = NOW(); + RETURN _new; +END; +$$ LANGUAGE plpgsql; +CREATE TRIGGER "set_public_conversations_updated_at" +BEFORE UPDATE ON "public"."conversations" +FOR EACH ROW +EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"(); +COMMENT ON TRIGGER "set_public_conversations_updated_at" ON "public"."conversations" +IS 'trigger to set value of column "updated_at" to current timestamp on row update'; +CREATE EXTENSION IF NOT EXISTS pgcrypto; diff --git a/app-backend/hasura/migrations/jandb/1692604250751_create_table_public_messages/down.sql b/app-backend/hasura/migrations/jandb/1692604250751_create_table_public_messages/down.sql new file mode 100644 index 000000000..eae375db7 --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692604250751_create_table_public_messages/down.sql @@ -0,0 +1 @@ +DROP TABLE "public"."messages"; diff --git a/app-backend/hasura/migrations/jandb/1692604250751_create_table_public_messages/up.sql b/app-backend/hasura/migrations/jandb/1692604250751_create_table_public_messages/up.sql new file mode 100644 index 000000000..e9645e75d --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692604250751_create_table_public_messages/up.sql @@ -0,0 +1,18 @@ +CREATE TABLE "public"."messages" ("id" uuid NOT NULL DEFAULT gen_random_uuid(), "conversation_id" uuid NOT NULL, "message_type" varchar, "message_sender_type" varchar, "sender" text NOT NULL, "sender_name" text, "sender_avatar_url" text, "content" text, "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), PRIMARY KEY ("id") ); +CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"() +RETURNS TRIGGER AS $$ +DECLARE + _new record; +BEGIN + _new := NEW; + _new."updated_at" = NOW(); + RETURN _new; +END; +$$ LANGUAGE plpgsql; +CREATE TRIGGER "set_public_messages_updated_at" +BEFORE UPDATE ON "public"."messages" +FOR EACH ROW +EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"(); +COMMENT ON TRIGGER "set_public_messages_updated_at" ON "public"."messages" +IS 'trigger to set value of column "updated_at" to current timestamp on row update'; +CREATE EXTENSION IF NOT EXISTS pgcrypto; diff --git a/app-backend/hasura/migrations/jandb/1692604354631_create_table_public_message_medias/down.sql b/app-backend/hasura/migrations/jandb/1692604354631_create_table_public_message_medias/down.sql new file mode 100644 index 000000000..dfec07a82 --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692604354631_create_table_public_message_medias/down.sql @@ -0,0 +1 @@ +DROP TABLE "public"."message_medias"; diff --git a/app-backend/hasura/migrations/jandb/1692604354631_create_table_public_message_medias/up.sql b/app-backend/hasura/migrations/jandb/1692604354631_create_table_public_message_medias/up.sql new file mode 100644 index 000000000..8b82699b9 --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692604354631_create_table_public_message_medias/up.sql @@ -0,0 +1,18 @@ +CREATE TABLE "public"."message_medias" ("id" uuid NOT NULL DEFAULT gen_random_uuid(), "message_id" uuid NOT NULL, "media_url" text, "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), "mime_type" varchar, PRIMARY KEY ("id") ); +CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"() +RETURNS TRIGGER AS $$ +DECLARE + _new record; +BEGIN + _new := NEW; + _new."updated_at" = NOW(); + RETURN _new; +END; +$$ LANGUAGE plpgsql; +CREATE TRIGGER "set_public_message_medias_updated_at" +BEFORE UPDATE ON "public"."message_medias" +FOR EACH ROW +EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"(); +COMMENT ON TRIGGER "set_public_message_medias_updated_at" ON "public"."message_medias" +IS 'trigger to set value of column "updated_at" to current timestamp on row update'; +CREATE EXTENSION IF NOT EXISTS pgcrypto; diff --git a/app-backend/hasura/migrations/jandb/1692604743434_create_table_public_collection_products/down.sql b/app-backend/hasura/migrations/jandb/1692604743434_create_table_public_collection_products/down.sql new file mode 100644 index 000000000..f2b37e379 --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692604743434_create_table_public_collection_products/down.sql @@ -0,0 +1 @@ +DROP TABLE "public"."collection_products"; diff --git a/app-backend/hasura/migrations/jandb/1692604743434_create_table_public_collection_products/up.sql b/app-backend/hasura/migrations/jandb/1692604743434_create_table_public_collection_products/up.sql new file mode 100644 index 000000000..16ebe6b43 --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692604743434_create_table_public_collection_products/up.sql @@ -0,0 +1,18 @@ +CREATE TABLE "public"."collection_products" ("id" uuid NOT NULL DEFAULT gen_random_uuid(), "collection_id" uuid NOT NULL, "product_id" uuid NOT NULL, "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), PRIMARY KEY ("id") , UNIQUE ("collection_id", "product_id")); +CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"() +RETURNS TRIGGER AS $$ +DECLARE + _new record; +BEGIN + _new := NEW; + _new."updated_at" = NOW(); + RETURN _new; +END; +$$ LANGUAGE plpgsql; +CREATE TRIGGER "set_public_collection_products_updated_at" +BEFORE UPDATE ON "public"."collection_products" +FOR EACH ROW +EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"(); +COMMENT ON TRIGGER "set_public_collection_products_updated_at" ON "public"."collection_products" +IS 'trigger to set value of column "updated_at" to current timestamp on row update'; +CREATE EXTENSION IF NOT EXISTS pgcrypto; diff --git a/app-backend/hasura/migrations/jandb/1692604794719_create_table_public_product_prompts/down.sql b/app-backend/hasura/migrations/jandb/1692604794719_create_table_public_product_prompts/down.sql new file mode 100644 index 000000000..34881bd4d --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692604794719_create_table_public_product_prompts/down.sql @@ -0,0 +1 @@ +DROP TABLE "public"."product_prompts"; diff --git a/app-backend/hasura/migrations/jandb/1692604794719_create_table_public_product_prompts/up.sql b/app-backend/hasura/migrations/jandb/1692604794719_create_table_public_product_prompts/up.sql new file mode 100644 index 000000000..b8bc3a57d --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692604794719_create_table_public_product_prompts/up.sql @@ -0,0 +1,18 @@ +CREATE TABLE "public"."product_prompts" ("id" uuid NOT NULL DEFAULT gen_random_uuid(), "product_id" uuid NOT NULL, "prompt_id" uuid NOT NULL, "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), PRIMARY KEY ("id") , UNIQUE ("product_id", "prompt_id")); +CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"() +RETURNS TRIGGER AS $$ +DECLARE + _new record; +BEGIN + _new := NEW; + _new."updated_at" = NOW(); + RETURN _new; +END; +$$ LANGUAGE plpgsql; +CREATE TRIGGER "set_public_product_prompts_updated_at" +BEFORE UPDATE ON "public"."product_prompts" +FOR EACH ROW +EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"(); +COMMENT ON TRIGGER "set_public_product_prompts_updated_at" ON "public"."product_prompts" +IS 'trigger to set value of column "updated_at" to current timestamp on row update'; +CREATE EXTENSION IF NOT EXISTS pgcrypto; diff --git a/app-backend/hasura/migrations/jandb/1692605865437_set_fk_public_collection_products_collection_id/down.sql b/app-backend/hasura/migrations/jandb/1692605865437_set_fk_public_collection_products_collection_id/down.sql new file mode 100644 index 000000000..49b450db6 --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692605865437_set_fk_public_collection_products_collection_id/down.sql @@ -0,0 +1 @@ +alter table "public"."collection_products" drop constraint "collection_products_collection_id_fkey"; diff --git a/app-backend/hasura/migrations/jandb/1692605865437_set_fk_public_collection_products_collection_id/up.sql b/app-backend/hasura/migrations/jandb/1692605865437_set_fk_public_collection_products_collection_id/up.sql new file mode 100644 index 000000000..29ee8b76b --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692605865437_set_fk_public_collection_products_collection_id/up.sql @@ -0,0 +1,5 @@ +alter table "public"."collection_products" + add constraint "collection_products_collection_id_fkey" + foreign key ("collection_id") + references "public"."collections" + ("id") on update cascade on delete cascade; diff --git a/app-backend/hasura/migrations/jandb/1692605887650_set_fk_public_collection_products_product_id/down.sql b/app-backend/hasura/migrations/jandb/1692605887650_set_fk_public_collection_products_product_id/down.sql new file mode 100644 index 000000000..1ca809d97 --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692605887650_set_fk_public_collection_products_product_id/down.sql @@ -0,0 +1 @@ +alter table "public"."collection_products" drop constraint "collection_products_product_id_fkey"; diff --git a/app-backend/hasura/migrations/jandb/1692605887650_set_fk_public_collection_products_product_id/up.sql b/app-backend/hasura/migrations/jandb/1692605887650_set_fk_public_collection_products_product_id/up.sql new file mode 100644 index 000000000..ef8457ce6 --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692605887650_set_fk_public_collection_products_product_id/up.sql @@ -0,0 +1,5 @@ +alter table "public"."collection_products" + add constraint "collection_products_product_id_fkey" + foreign key ("product_id") + references "public"."products" + ("id") on update cascade on delete cascade; diff --git a/app-backend/hasura/migrations/jandb/1692885821205_alter_table_public_messages_add_column_status/down.sql b/app-backend/hasura/migrations/jandb/1692885821205_alter_table_public_messages_add_column_status/down.sql new file mode 100644 index 000000000..7d02924bb --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692885821205_alter_table_public_messages_add_column_status/down.sql @@ -0,0 +1 @@ +alter table "public"."messages" drop column "status"; diff --git a/app-backend/hasura/migrations/jandb/1692885821205_alter_table_public_messages_add_column_status/up.sql b/app-backend/hasura/migrations/jandb/1692885821205_alter_table_public_messages_add_column_status/up.sql new file mode 100644 index 000000000..428bf5b74 --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692885821205_alter_table_public_messages_add_column_status/up.sql @@ -0,0 +1,2 @@ +alter table "public"."messages" add column "status" varchar + null default 'ready'; diff --git a/app-backend/hasura/migrations/jandb/1692891470212_alter_table_public_messages_add_column_prompt_cache/down.sql b/app-backend/hasura/migrations/jandb/1692891470212_alter_table_public_messages_add_column_prompt_cache/down.sql new file mode 100644 index 000000000..29b407049 --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692891470212_alter_table_public_messages_add_column_prompt_cache/down.sql @@ -0,0 +1 @@ +alter table "public"."messages" drop column "prompt_cache"; \ No newline at end of file diff --git a/app-backend/hasura/migrations/jandb/1692891470212_alter_table_public_messages_add_column_prompt_cache/up.sql b/app-backend/hasura/migrations/jandb/1692891470212_alter_table_public_messages_add_column_prompt_cache/up.sql new file mode 100644 index 000000000..ea23f42ed --- /dev/null +++ b/app-backend/hasura/migrations/jandb/1692891470212_alter_table_public_messages_add_column_prompt_cache/up.sql @@ -0,0 +1,2 @@ +alter table "public"."messages" add column "prompt_cache" jsonb + null; diff --git a/app-backend/hasura/seeds/jandb/1692710119690_productsSeed.sql b/app-backend/hasura/seeds/jandb/1692710119690_productsSeed.sql new file mode 100644 index 000000000..0058c1838 --- /dev/null +++ b/app-backend/hasura/seeds/jandb/1692710119690_productsSeed.sql @@ -0,0 +1,4 @@ +SET check_function_bodies = false; +INSERT INTO public.products ("slug", "name", "nsfw", "image_url", "description", "long_description", "technical_description", "author", "version", "source_url", "inputs", "outputs", "greeting") VALUES +('llama2', 'Llama-2-7B-Chat', 't', 'https://static-assets.jan.ai/llama2.jpg','Llama 2 is Meta`s open source large language model (LLM)', 'Llama 2 is a collection of pretrained and fine-tuned generative text models ranging in scale from 7 billion to 70 billion parameters. This is the repository for the 7B pretrained model. Links to other models can be found in the index at the bottom.', 'Meta developed and publicly released the Llama 2 family of large language models (LLMs), a collection of pretrained and fine-tuned generative text models ranging in scale from 7 billion to 70 billion parameters. Our fine-tuned LLMs, called Llama-2-Chat, are optimized for dialogue use cases. Llama-2-Chat models outperform open-source chat models on most benchmarks we tested, and in our human evaluations for helpfulness and safety, are on par with some popular closed-source models like ChatGPT and PaLM.', 'Meta', 'Llama2-7B-GGML', 'https://huggingface.co/TheBloke/airoboros-13B-gpt4-1.4-GGML', '{"body": [{"name": "messages", "type": "array", "items": [{"type": "object", "properties": [{"name": "role", "type": "string", "example": "system", "description": "Defines the role of the message."}, {"name": "content", "type": "string", "example": "Hello, world!", "description": "Contains the content of the message."}]}], "description": "An array of messages, each containing a role and content. The latest message is always at the end of the array."}, {"name": "stream", "type": "boolean", "example": true, "description": "Indicates whether the client wants to keep the connection open for streaming."}, {"name": "max_tokens", "type": "integer", "example": 500, "description": "Defines the maximum number of tokens that the client wants to receive."}], "slug": "llm", "headers": {"accept": "text/event-stream", "content-type": "application/json"}}', '{"slug": "llm", "type": "object", "properties": [{"name": "id", "type": "string", "example": "chatcmpl-4c4e5eb5-bf53-4dbc-9136-1cf69fc5fd7c", "description": "The unique identifier of the chat completion chunk."}, {"name": "model", "type": "string", "example": "gpt-3.5-turbo", "description": "The name of the GPT model used to generate the completion."}, {"name": "created", "type": "integer", "example": 1692169988, "description": "The Unix timestamp representing the time when the completion was generated."}, {"name": "object", "type": "string", "example": "chat.completion.chunk", "description": "A string indicating the type of the chat completion chunk."}, {"name": "choices", "type": "array", "items": [{"type": "object", "properties": [{"name": "index", "type": "integer", "example": 0, "description": "The index of the choice made by the GPT model."}, {"name": "delta", "type": "object", "properties": [{"name": "content", "type": "string", "example": "What", "description": "The content generated by the GPT model."}], "description": "A JSON object containing the content generated by the GPT model."}, {"name": "finish_reason", "type": "string", "example": null, "description": "A string indicating why the GPT model stopped generating content."}]}], "description": "An array containing the choices made by the GPT model to generate the completion."}], "description": "A JSON object representing a chat completion chunk."}', '👋I’m a versatile AI trained on a wide range of topics, here to answer your questions about the universe. What are you curious about today?'), +('stablediffusion', 'Stable-Diffusion-v1.5', 't', 'https://static-assets.jan.ai/stablediffusion.jpg', 'Stable Diffusion is a latent text-to-image diffusion model capable of generating photo-realistic images given any text input.', 'The Stable-Diffusion-v1-5 checkpoint was initialized with the weights of the Stable-Diffusion-v1-2 checkpoint and subsequently fine-tuned on 595k steps at resolution 512x512 on "laion-aesthetics v2 5+" and 10% dropping of the text-conditioning to improve classifier-free guidance sampling.', 'This is a model that can be used to generate and modify images based on text prompts. It is a Latent Diffusion Model that uses a fixed, pretrained text encoder (CLIP ViT-L/14) as suggested in the Imagen paper.', 'runwayml', '4.0.0', 'https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors', '{"body": [{"name": "prompt", "type": "string", "description": "Input prompt"}, {"name": "negative_prompt", "type": "string", "description": "Specify things to not see in the output"}, {"name": "width", "type": "integer", "description": "Width of output image. Maximum size is 1024x768 or 768x1024 because of memory limits"}, {"name": "height", "type": "integer", "description": "Height of output image. Maximum size is 1024x768 or 768x1024 because of memory limits"}, {"name": "num_outputs", "type": "integer", "description": "Number of images to output. (minimum: 1; maximum: 4)"}, {"name": "num_inference_steps", "type": "integer", "description": "Number of denoising steps (minimum: 1; maximum: 500)"}, {"name": "guidance_scale", "type": "integer", "description": "Scale for classifier-free guidance (minimum: 1; maximum: 20)"}], "slug": "sd", "headers": {"accept": "application/json", "content-type": "multipart/form-data"}}', '{"slug": "sd", "type": "object", "properties": [{"name": "url", "type": "string", "description": "The unique identifier of the chat completion chunk."}], "description": "URL result image."}', 'Hello there 👋') diff --git a/app-backend/hasura/seeds/jandb/1692710265351_collectionsSeed.sql b/app-backend/hasura/seeds/jandb/1692710265351_collectionsSeed.sql new file mode 100644 index 000000000..6ab40e8b3 --- /dev/null +++ b/app-backend/hasura/seeds/jandb/1692710265351_collectionsSeed.sql @@ -0,0 +1,4 @@ +SET check_function_bodies = false; +INSERT INTO public.collections ("slug", "name", "description") VALUES +('conversational', 'Conversational', 'Chatbot alternatives to ChatGPT. Converse with these models and get answers.'), +('text-to-image', 'Text to image', 'Converse with these models to generate images.'); diff --git a/app-backend/hasura/seeds/jandb/1692710371524_collectionProductsSeed.sql b/app-backend/hasura/seeds/jandb/1692710371524_collectionProductsSeed.sql new file mode 100644 index 000000000..31d3ca83c --- /dev/null +++ b/app-backend/hasura/seeds/jandb/1692710371524_collectionProductsSeed.sql @@ -0,0 +1,11 @@ +SET check_function_bodies = false; + +INSERT INTO public.collection_products (collection_id, product_id) +SELECT (SELECT id FROM public.collections WHERE slug = 'conversational') AS collection_id, id AS product_id +FROM public.products +WHERE slug IN ('llama2'); + +INSERT INTO public.collection_products (collection_id, product_id) +SELECT (SELECT id FROM public.collections WHERE slug = 'text-to-image') AS collection_id, id AS product_id +FROM public.products +WHERE slug IN ('stablediffusion'); \ No newline at end of file diff --git a/app-backend/hasura/seeds/jandb/1692711599434_promptsSeed.sql b/app-backend/hasura/seeds/jandb/1692711599434_promptsSeed.sql new file mode 100644 index 000000000..17a85ea0d --- /dev/null +++ b/app-backend/hasura/seeds/jandb/1692711599434_promptsSeed.sql @@ -0,0 +1,16 @@ +SET check_function_bodies = false; +INSERT INTO public.prompts ("slug", "content", "image_url") VALUES +('conversational-ai-future', 'What are possible developments for AI technology in the next decade?', ''), +('conversational-managing-stress', 'What are some tips for managing stress?', ''), +('conversational-postapoc-robot', 'Let''s role play. You are a robot in a post-apocalyptic world.', ''), +('conversational-python-pytorch', 'What is the difference between Python and Pytorch?', ''), +('conversational-quadratic-equation', 'Can you explain how to solve a quadratic equation?', ''), +('conversational-roman-history', 'What is the history of the Roman Empire?', ''), +('openjourney-1girl-gothic-lolita', '(masterpiece, top quality, best, official art, beautiful and aesthetic:1. 2), 1girl, (pop art:1. 4), (zentangle, flower effects:1. 2), (art nouveau:1. 1), (Gothic Lolita:1. 3)', 'https://static-assets.jan.ai/openjourney-2.jpeg'), +('openjourney-female-robot-rust', 'old, female robot, metal, rust, wisible wires, destroyed, sad, dark, dirty, looking at viewer, portrait, photography, detailed skin, realistic, photo-realistic, 8k, highly detailed, full length frame, High detail RAW color art, piercing, diffused soft lighting, shallow depth of field, sharp focus, hyperrealism, cinematic lighting', 'https://static-assets.jan.ai/openjourney-3.jpeg'), +('openjourney-ginger-cat', 'full body fluffy ginger cat with blue eyes by studio ghibli, makoto shinkai, by artgerm, by wlop, by greg rutkowski, volumetric lighting, octane render, 4 k resolution, trending on artstation, masterpiece', 'https://static-assets.jan.ai/openjourney-0.jpg'), +('openjourney-human-face-paint', 'FluidArt, human face covered in paint, photoshoot pose, portrait, dramatic, tri-color, long sleeved frilly victorian dress made of thick dripping paint, rich thick cords of paint, medusa paint hair, appendages and legs transform into thick dripping paint, wide-zoom shot, hair metamorphosis into thick paint', 'https://static-assets.jan.ai/openjourney-4.jpeg'), +('openjourney-pocahontas', 'mdjrny-v4 style portrait photograph of Madison Beer as Pocahontas, young beautiful native american woman, perfect symmetrical face, feather jewelry, traditional handmade dress, armed female hunter warrior, (((wild west))) environment, Utah landscape, ultra realistic, concept art, elegant, ((intricate)), ((highly detailed)), depth of field, ((professionally color graded)), 8k, art by artgerm and greg rutkowski and alphonse mucha', 'https://static-assets.jan.ai/openjourney-1.jpeg'), +('text2image-gray-dog-eyes', 'realistic portrait of an gray dog, bright eyes, radiant and ethereal intricately detailed photography, cinematic lighting, 50mm lens with bokeh', 'https://static-assets.jan.ai/openjourney-7.jpeg'), +('text2image-ogre-exoskeleton', 'mdjrny-v4 style OGRE is wearing a powered exoskeleton , long horn, , cute face, tsutomu nihei style, Claude Monet, banksy art, 8K, Highly Detailed, Dramatic Lighting, high quality, ray of god, explosion, lens flare, beautiful detailed sky, cinematic lighting, overexposure, quality, colorful, hdr, concept design, photorealistic, hyper real, Alphonse Mucha, Pixar, cyberpunk 2077, masterpiece, the best quality, super fine illustrations, beatiful detailed cyberpunk city, extremely detailed eyes and face, beatiful detailed hair, wavy hair,beatiful detailed steet,mecha clothes, robot girl, bodysuit, very delicate light, fine lighting, very fine 8KCG wallpapers, plateau, sunrise, overexposure, randomly distributed clouds, cliff, rotating star sky, lake in mountain stream, luminous particles , Unreal Engine5, 8K', 'https://static-assets.jan.ai/openjourney-6.jpeg'), +('text2image-pablo-picasso', 'a young caucasian man holding his chin.pablo picasso style, acrylic painting, trending on pixiv fanbox, palette knife and brush. strokes,', 'https://static-assets.jan.ai/openjourney-5.jpeg'); diff --git a/app-backend/hasura/seeds/jandb/1692711671035_productPromptsSeed.sql b/app-backend/hasura/seeds/jandb/1692711671035_productPromptsSeed.sql new file mode 100644 index 000000000..a78a116e2 --- /dev/null +++ b/app-backend/hasura/seeds/jandb/1692711671035_productPromptsSeed.sql @@ -0,0 +1,21 @@ +SET check_function_bodies = false; + +INSERT INTO public.product_prompts (product_id, prompt_id) +SELECT p.id AS product_id, r.id AS prompt_id +FROM public.products p +JOIN public.prompts r +ON (p.id + IN (SELECT x.id FROM public.products x INNER JOIN public.collection_products y ON x.id = y.product_id + INNER JOIN public.collections z ON y.collection_id = z.id + WHERE z.slug = 'text-to-image')) +WHERE r.image_url IS NOT NULL AND r.image_url != ''; + +INSERT INTO public.product_prompts (product_id, prompt_id) +SELECT p.id AS product_id, r.id AS prompt_id +FROM public.products p +JOIN public.prompts r +ON (p.id + IN (SELECT x.id FROM public.products x INNER JOIN public.collection_products y ON x.id = y.product_id + INNER JOIN public.collections z ON y.collection_id = z.id + WHERE z.slug = 'conversational')) +WHERE r.image_url IS NULL OR r.image_url = ''; \ No newline at end of file diff --git a/app-backend/sample.env b/app-backend/sample.env new file mode 100644 index 000000000..9a7b438f1 --- /dev/null +++ b/app-backend/sample.env @@ -0,0 +1,23 @@ +## postgres database to store Hasura metadata +HASURA_GRAPHQL_METADATA_DATABASE_URL=postgres://postgres:postgrespassword@postgres:5432/postgres +## this env var can be used to add the above postgres database to Hasura as a data source. this can be removed/updated based on your needs +PG_DATABASE_URL=postgres://postgres:postgrespassword@postgres:5432/postgres +## enable the console served by server +HASURA_GRAPHQL_ENABLE_CONSOLE="true" # set to "false" to disable console +## enable debugging mode. It is recommended to disable this in production +HASURA_GRAPHQL_DEV_MODE="true" +HASURA_GRAPHQL_ENABLED_LOG_TYPES=startup, http-log, webhook-log, websocket-log, query-log +## uncomment next line to run console offline (i.e load console assets from server instead of CDN) +# HASURA_GRAPHQL_CONSOLE_ASSETS_DIR: /srv/console-assets +## uncomment next line to set an admin secret +HASURA_GRAPHQL_ADMIN_SECRET=myadminsecretkey +HASURA_GRAPHQL_UNAUTHORIZED_ROLE="public" +HASURA_GRAPHQL_METADATA_DEFAULTS='{"backend_configs":{"dataconnector":{"athena":{"uri":"http://data-connector-agent:8081/api/v1/athena"},"mariadb":{"uri":"http://data-connector-agent:8081/api/v1/mariadb"},"mysql8":{"uri":"http://data-connector-agent:8081/api/v1/mysql"},"oracle":{"uri":"http://data-connector-agent:8081/api/v1/oracle"},"snowflake":{"uri":"http://data-connector-agent:8081/api/v1/snowflake"}}}}' +HASURA_GRAPHQL_JWT_SECRET={"type": "RS256", "key": "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----"} + +# Environment variable for auto migrate +HASURA_GRAPHQL_MIGRATIONS_DIR=/migrations +HASURA_GRAPHQL_METADATA_DIR=/metadata +HASURA_GRAPHQL_ENABLE_CONSOLE='true' +HASURA_ACTION_STABLE_DIFFUSION_URL=http://sd:8000 +HASURA_EVENTS_HOOK_URL="http://worker:8787" \ No newline at end of file diff --git a/app-backend/sample.env_postgresql b/app-backend/sample.env_postgresql new file mode 100644 index 000000000..39aa93db5 --- /dev/null +++ b/app-backend/sample.env_postgresql @@ -0,0 +1 @@ +POSTGRES_PASSWORD=postgrespassword \ No newline at end of file diff --git a/app-backend/worker/Dockerfile b/app-backend/worker/Dockerfile new file mode 100644 index 000000000..2575b54f4 --- /dev/null +++ b/app-backend/worker/Dockerfile @@ -0,0 +1,16 @@ +# Dockerfile + +# alpine does not work with wrangler +FROM node + +RUN mkdir -p /worker + +WORKDIR /worker + +RUN npm install -g wrangler + +COPY . /worker + +EXPOSE 8787 + +CMD ["wrangler", "dev"] \ No newline at end of file diff --git a/app-backend/worker/worker.ts b/app-backend/worker/worker.ts new file mode 100644 index 000000000..1c4812b26 --- /dev/null +++ b/app-backend/worker/worker.ts @@ -0,0 +1,197 @@ +export interface Env { + HASURA_ADMIN_API_KEY: string; + LLM_INFERENCE_ENDPOINT: string; + INFERENCE_API_KEY: string; + HASURA_GRAPHQL_ENGINE_ENDPOINT: string; +} + +export default { + async fetch(request: Request, env: Env) { + return handleRequest(env, request); + }, +}; + +async function handleRequest(env: Env, request: Request) { + const apiurl = env.LLM_INFERENCE_ENDPOINT; + const requestBody = await request.json(); + + let lastCallTime = 0; + let timeoutId: any; + let done = true; + + function throttle(fn: () => void, delay: number) { + return async function () { + const now = new Date().getTime(); + const timeSinceLastCall = now - lastCallTime; + + if (timeSinceLastCall >= delay && done) { + lastCallTime = now; + done = false; + await fn(); + done = true; + } else { + clearTimeout(timeoutId); + timeoutId = setTimeout(async () => { + lastCallTime = now; + done = false; + await fn(); + done = true; + }, delay - timeSinceLastCall); + } + }; + } + + const messageBody = { + id: requestBody.event.data.new.id, + content: requestBody.event.data.new.content, + messages: requestBody.event.data.new.prompt_cache, + status: requestBody.event.data.new.status, + }; + + if (messageBody.status !== "pending") { + return new Response(JSON.stringify({ status: "success" }), { + status: 200, + statusText: "success", + }); + } + + const llmRequestBody = { + messages: messageBody.messages, + stream: true, + model: "gpt-3.5-turbo", + max_tokens: 500, + }; + + const init = { + body: JSON.stringify(llmRequestBody), + headers: { + "Content-Type": "application/json", + Accept: "text/event-stream", + Authorization: "Access-Control-Allow-Origin: *", + "api-key": env.INFERENCE_API_KEY, + }, + method: "POST", + }; + return fetch(apiurl, init) + .then((res) => res.body?.getReader()) + .then(async (reader) => { + if (!reader) { + console.error("Error: fail to read data from response"); + return; + } + let answer = ""; + let cachedChunk = ""; + while (true) { + const { done, value } = await reader.read(); + if (done) { + break; + } + + const textDecoder = new TextDecoder("utf-8"); + const chunk = textDecoder.decode(value); + cachedChunk += chunk; + const matched = cachedChunk.match(/data: {(.*)}/g); + if (!matched) { + continue; + } + + let deltaText = ""; + for (const line of cachedChunk.split("\n")) { + const trimmedLine = line.trim(); + if (!trimmedLine || trimmedLine === "data: [DONE]") { + continue; + } + + const json = trimmedLine.replace("data: ", ""); + try { + const obj = JSON.parse(json); + const content = obj.choices[0].delta.content; + if (content) deltaText = deltaText.concat(content); + } catch (e) { + console.log(e); + } + } + cachedChunk = ""; + + answer = answer + deltaText; + + const variables = { + id: messageBody.id, + data: { + content: answer, + }, + }; + + throttle(async () => { + await fetch(env.HASURA_GRAPHQL_ENGINE_ENDPOINT + "/v1/graphql", { + method: "POST", + body: JSON.stringify({ query: updateMessageQuery, variables }), + headers: { + "Content-Type": "application/json", + "x-hasura-admin-secret": env.HASURA_ADMIN_API_KEY, + }, + }) + .catch((error) => { + console.error(error); + }) + .finally(() => console.log("++-- request sent")); + }, 300)(); + } + + const variables = { + id: messageBody.id, + data: { + status: "ready", + prompt_cache: null, + }, + }; + + await fetch(env.HASURA_GRAPHQL_ENGINE_ENDPOINT + "/v1/graphql", { + method: "POST", + body: JSON.stringify({ query: updateMessageQuery, variables }), + headers: { + "Content-Type": "application/json", + "x-hasura-admin-secret": env.HASURA_ADMIN_API_KEY, + }, + }).catch((error) => { + console.error(error); + }); + + const convUpdateVars = { + id: requestBody.event.data.new.conversation_id, + content: answer + } + await fetch(env.HASURA_GRAPHQL_ENGINE_ENDPOINT + "/v1/graphql", { + method: "POST", + body: JSON.stringify({ query: updateConversationquery, variables: convUpdateVars }), + headers: { + "Content-Type": "application/json", + "x-hasura-admin-secret": env.HASURA_ADMIN_API_KEY, + }, + }).catch((error) => { + console.error(error); + }); + + return new Response(JSON.stringify({ status: "success" }), { + status: 200, + statusText: "success", + }); + }); +} + +const updateMessageQuery = ` +mutation chatCompletions($id: uuid = "", $data: messages_set_input) { + update_messages_by_pk(pk_columns: {id: $id}, _set: $data) { + id + content + } +} +`; + +const updateConversationquery = ` +mutation updateConversation($id: uuid = "", $content: String = "") { + update_conversations_by_pk(pk_columns: {id: $id}, _set: {last_text_message: $content}) { + id + } +} +` diff --git a/app-backend/worker/wrangler.toml b/app-backend/worker/wrangler.toml new file mode 100644 index 000000000..06260728c --- /dev/null +++ b/app-backend/worker/wrangler.toml @@ -0,0 +1,11 @@ +name = "cloudlfare_worker" +main = "worker.ts" +compatibility_date = "2023-06-08" +workers_dev = true + +[vars] +HASURA_GRAPHQL_ENGINE_ENDPOINT = "http://graphql-engine:8080" +HASURA_ADMIN_API_KEY = "myadminsecretkey" +LLM_INFERENCE_ENDPOINT="http://llm:8000/v1/chat/completions" +INFERENCE_API_KEY="" +PROJECT_ID = "" diff --git a/web-client b/web-client deleted file mode 160000 index ace5d4cd5..000000000 --- a/web-client +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ace5d4cd50311799e4dfa34b37e31c8f4e0a53d9 diff --git a/web-client/.eslintrc.json b/web-client/.eslintrc.json new file mode 100644 index 000000000..f0f3abee4 --- /dev/null +++ b/web-client/.eslintrc.json @@ -0,0 +1,6 @@ +{ + "extends": "next/core-web-vitals", + "rules": { + "@next/next/no-img-element": "off" + } +} diff --git a/web-client/.gitignore b/web-client/.gitignore new file mode 100644 index 000000000..f3079381e --- /dev/null +++ b/web-client/.gitignore @@ -0,0 +1,45 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# apollo graphql +/graphql/generated + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# next.js +/.next/ +/out/ + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# local env files +.env*.local + +# vercel +.vercel + +# typescript +*.tsbuildinfo +next-env.d.ts +.env + +# Firebase config file +app/_services/firebase/firebase_configs.json +# Sentry Auth Token +.sentryclirc + diff --git a/web-client/Dockerfile b/web-client/Dockerfile new file mode 100644 index 000000000..eede493fd --- /dev/null +++ b/web-client/Dockerfile @@ -0,0 +1,48 @@ +FROM node:20-alpine AS base + +# 1. Install dependencies only when needed +FROM base AS deps +# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. +RUN apk add --no-cache libc6-compat + +WORKDIR /app + +# Install dependencies based on the preferred package manager +COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ +RUN npm install && npm i -g @nestjs/cli typescript ts-node + +# 2. Rebuild the source code only when needed +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . +# This will do the trick, use the corresponding env file for each environment. + +RUN npm run build + +# 3. Production image, copy all the files and run next +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV=production + +RUN \ + addgroup -g 1001 -S nodejs; \ + adduser -S nextjs -u 1001 + +COPY --from=builder /app/public ./public + +# Automatically leverage output traces to reduce image size +# https://nextjs.org/docs/advanced-features/output-file-tracing +COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next +COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/package.json ./package.json + + +USER nextjs + +EXPOSE 3000 + +ENV PORT 3000 + +CMD ["npm", "start"] \ No newline at end of file diff --git a/web-client/README.md b/web-client/README.md new file mode 100644 index 000000000..eb4700bca --- /dev/null +++ b/web-client/README.md @@ -0,0 +1,102 @@ +# Jan Web + +Jan Web is a Next.js application designed to provide users with the ability to interact with the Language Model (LLM) through chat or generate art using Stable Diffusion. This application runs as a single-page application (SPA) and is encapsulated within a Docker container for easy local deployment. + +## Features + +- Chat with the Language Model: Engage in interactive conversations with the Language Model. Ask questions, seek information, or simply have a chat. + +- Generate Art with Stable Diffusion: Utilize the power of Stable Diffusion to generate unique and captivating pieces of art. Experiment with various parameters to achieve desired results. + +## Installation and Usage + +### Use as complete suite +For using our complete solution, check [this](https://github.com/janhq/jan) + +### For interactive development + +1. **Clone the Repository:** + + ``` + git clone https://github.com/your-username/jan-web.git + cd jan-web + ``` + +2. **Install dependencies:** + + ``` + yarn + ``` + +3. **Run development:** + + ``` + yarn dev + ``` + +4. **Access Jan Web:** + + Open your web browser and navigate to `http://localhost:3000` to access the Jan Web application. + +## Configuration + +You can customize the endpoint of the Jan Web application through environment file. These options can be found in the `.env` file located in the project's root directory. + +```env +// .env + +KEYCLOAK_CLIENT_ID=hasura +KEYCLOAK_CLIENT_SECRET=********** +AUTH_ISSUER=http://localhost:8088/realms/hasura +NEXTAUTH_URL=http://localhost:3000 +NEXTAUTH_SECRET=my-secret +END_SESSION_URL=http://localhost:8088/realms/hasura/protocol/openid-connect/logout +REFRESH_TOKEN_URL=http://localhost:8088/realms/hasura/protocol/openid-connect/token +HASURA_ADMIN_TOKEN=myadminsecretkey +NEXT_PUBLIC_GRAPHQL_ENGINE_URL=localhost:8080 +``` + +Replace above configuration with your actual infrastructure. + +## Dependencies + +|Library| Category | Version | Description | +|--|--|--|--| +| [next](https://nextjs.org/) | Framework | 13.4.10 | +| [typescript](https://www.typescriptlang.org/) | Language | 5.1.6 | +| [tailwindcss](https://tailwindcss.com/) | UI | 3.3.3 | +| [Tailwind UI](https://tailwindui.com/) | UI | | +| [react-hook-form](https://www.react-hook-form.com/) | UI | ^7.45.4 | +| [@headlessui/react](https://headlessui.com/) | UI | ^1.7.15 | +| [@heroicons/react](https://heroicons.com/) | UI | ^2.0.18 | +| [@tailwindcss/typography](https://tailwindcss.com/docs/typography-plugin) | UI | ^0.5.9 | +| [embla-carousel](https://www.embla-carousel.com/) | UI | ^8.0.0-rc11 | +| [@apollo/client](https://www.apollographql.com/docs/react/) | State management | ^3.8.1 | +| [mobx](https://mobx.js.org/README.html) | State management | ^6.10.0 | +| [mobx-react-lite](https://www.npmjs.com/package/mobx-react-lite) | State management | ^4.0.3 | +| [mobx-state-tree](https://mobx-state-tree.js.org/) | State management | ^5.1.8 | + + +## Deploy to Netlify +Clone this repository on own GitHub account and deploy to Netlify: + +[![Netlify Deploy button](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/janhq/jan-web) + +## Deploy to Vercel + +Deploy Jan Web on Vercel in one click: + +[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/janhq/jan-web) + + +## Contributing + +Contributions are welcome! If you find a bug or have suggestions for improvements, feel free to open an issue or submit a pull request on the [GitHub repository](https://github.com/janhq/jan-web/tree/6337306c54e735a4a5c2132dcd1377f21fd76a33). + +## License + +This project is licensed under the Fair-code License - see the [License](https://faircode.io/#licenses) for more details. + +--- + +Feel free to reach out [Discord](https://jan.ai/discord) if you have any questions or need further assistance. Happy coding with Jan Web and exploring the capabilities of the Language Model and Stable Diffusion! 🚀🎨🤖 \ No newline at end of file diff --git a/web-client/app/_components/ActionButton/index.tsx b/web-client/app/_components/ActionButton/index.tsx new file mode 100644 index 000000000..a23bb51e2 --- /dev/null +++ b/web-client/app/_components/ActionButton/index.tsx @@ -0,0 +1,41 @@ +import classNames from "classnames"; +import Image from "next/image"; + +type Props = { + title: string; + icon: string; + isLoading?: boolean; + onClick: () => void; +}; + +const ActionButton: React.FC = (props) => { + return ( + <> + {!props.isLoading && ( + + )} + {props.isLoading && ( +
+ loading +
+ )} + + ); +}; + +export default ActionButton; diff --git a/web-client/app/_components/AdvancedPrompt/index.tsx b/web-client/app/_components/AdvancedPrompt/index.tsx new file mode 100644 index 000000000..19270ef3f --- /dev/null +++ b/web-client/app/_components/AdvancedPrompt/index.tsx @@ -0,0 +1,69 @@ +"use client"; +import { useCallback } from "react"; +import Image from "next/image"; +import { useStore } from "@/_models/RootStore"; +import { observer } from "mobx-react-lite"; +import { MenuAdvancedPrompt } from "../MenuAdvancedPrompt"; +import { useForm } from "react-hook-form"; +import { useMutation } from "@apollo/client"; +import { CreateMessageDocument, CreateMessageMutation } from "@/graphql"; + +export const AdvancedPrompt: React.FC = observer(() => { + const { register, handleSubmit } = useForm(); + const { historyStore } = useStore(); + + const onAdvancedPrompt = useCallback(() => { + historyStore.toggleAdvancedPrompt(); + }, []); + + const [createMessageMutation] = useMutation( + CreateMessageDocument + ); + const onSubmit = (data: any) => { + historyStore.sendControlNetPrompt( + createMessageMutation, + data.prompt, + data.negativePrompt, + data.fileInput[0] + ); + }; + + return ( +
+ +
+ +
+
+ + +
+
+ ); +}); diff --git a/web-client/app/_components/AdvancedPromptGenerationParams/index.tsx b/web-client/app/_components/AdvancedPromptGenerationParams/index.tsx new file mode 100644 index 000000000..1636361db --- /dev/null +++ b/web-client/app/_components/AdvancedPromptGenerationParams/index.tsx @@ -0,0 +1,18 @@ +import React, { useState } from "react"; +import TogglableHeader from "../TogglableHeader"; + +const AdvancedPromptGenerationParams = () => { + const [expand, setExpand] = useState(true); + return ( + <> + setExpand(!expand)} + /> + + ); +}; + +export default AdvancedPromptGenerationParams; diff --git a/web-client/app/_components/AdvancedPromptImageUpload/index.tsx b/web-client/app/_components/AdvancedPromptImageUpload/index.tsx new file mode 100644 index 000000000..26e780fba --- /dev/null +++ b/web-client/app/_components/AdvancedPromptImageUpload/index.tsx @@ -0,0 +1,31 @@ +import React, { useState } from "react"; +import { DropdownsList } from "../DropdownList"; +import TogglableHeader from "../TogglableHeader"; +import { UploadFileImage } from "../UploadFileImage"; +import { FieldValues, UseFormRegister } from "react-hook-form"; + +type Props = { + register: UseFormRegister; +}; + +const AdvancedPromptImageUpload: React.FC = ({ register }) => { + const [expand, setExpand] = useState(true); + const data = ["test1", "test2", "test3", "test4"]; + + return ( + <> + setExpand(!expand)} + /> +
+ + +
+ + ); +}; + +export default AdvancedPromptImageUpload; diff --git a/web-client/app/_components/AdvancedPromptResolution/index.tsx b/web-client/app/_components/AdvancedPromptResolution/index.tsx new file mode 100644 index 000000000..6bfe9218d --- /dev/null +++ b/web-client/app/_components/AdvancedPromptResolution/index.tsx @@ -0,0 +1,29 @@ +import React, { useState } from "react"; +import { DropdownsList } from "../DropdownList"; +import TogglableHeader from "../TogglableHeader"; + +const AdvancedPromptResolution = () => { + const [expand, setExpand] = useState(true); + const data = ["512", "524", "536"]; + const ratioData = ["1:1", "2:2", "3:3"]; + + return ( + <> + setExpand(!expand)} + /> +
+
+ + +
+ +
+ + ); +}; + +export default AdvancedPromptResolution; diff --git a/web-client/app/_components/AdvancedPromptText/index.tsx b/web-client/app/_components/AdvancedPromptText/index.tsx new file mode 100644 index 000000000..b5ec36477 --- /dev/null +++ b/web-client/app/_components/AdvancedPromptText/index.tsx @@ -0,0 +1,41 @@ +import React, { useState } from "react"; +import TogglableHeader from "../TogglableHeader"; +import { AdvancedTextArea } from "../AdvancedTextArea"; +import { FieldValues, UseFormRegister } from "react-hook-form"; + +type Props = { + register: UseFormRegister; +}; + +const AdvancedPromptText: React.FC = ({ register }) => { + const [expand, setExpand] = useState(true); + + return ( + <> + setExpand(!expand)} + /> +
+ + +
+ + ); +}; + +export default AdvancedPromptText; diff --git a/web-client/app/_components/AdvancedTextArea/index.tsx b/web-client/app/_components/AdvancedTextArea/index.tsx new file mode 100644 index 000000000..980efedac --- /dev/null +++ b/web-client/app/_components/AdvancedTextArea/index.tsx @@ -0,0 +1,27 @@ +import { FieldValues, UseFormRegister } from "react-hook-form"; + +type Props = { + formId?: string; + height: number; + title: string; + placeholder: string; + register: UseFormRegister; +}; + +export const AdvancedTextArea: React.FC = ({ + formId = "", + height, + placeholder, + title, + register, +}) => ( +
+ +