From 0c041e63888fd71bf9d6f3ba2ee08d6c4a287714 Mon Sep 17 00:00:00 2001 From: Jordi Enric <37541088+jordienr@users.noreply.github.com> Date: Thu, 31 Oct 2024 10:27:39 +0100 Subject: [PATCH 1/4] Loki log drain update & ui fix (#30080) * fix * truncate name * improve UX for creating loki log drains * undo base64 encoding in fe * type pass in pass * Add title prop * Fix text size --------- Co-authored-by: Joshen Lim --- .../LogDrains/LogDrainDestinationSheetForm.tsx | 18 ++++++++++++++++++ .../interfaces/LogDrains/LogDrains.tsx | 13 ++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/apps/studio/components/interfaces/LogDrains/LogDrainDestinationSheetForm.tsx b/apps/studio/components/interfaces/LogDrains/LogDrainDestinationSheetForm.tsx index 51b183dc3fc..eb49a069446 100644 --- a/apps/studio/components/interfaces/LogDrains/LogDrainDestinationSheetForm.tsx +++ b/apps/studio/components/interfaces/LogDrains/LogDrainDestinationSheetForm.tsx @@ -68,6 +68,8 @@ const formUnion = z.discriminatedUnion('type', [ type: z.literal('loki'), url: z.string().min(1, { message: 'Loki URL is required' }), headers: z.record(z.string(), z.string()), + username: z.string().optional(), + password: z.string().optional(), }), ]) @@ -162,6 +164,8 @@ export function LogDrainDestinationSheetForm({ url: defaultValues?.config?.url || '', api_key: defaultValues?.config?.api_key || '', region: defaultValues?.config?.region || '', + username: defaultValues?.config?.username || '', + password: defaultValues?.config?.password || '', }, }) @@ -422,10 +426,24 @@ export function LogDrainDestinationSheetForm({ + + )} diff --git a/apps/studio/components/interfaces/LogDrains/LogDrains.tsx b/apps/studio/components/interfaces/LogDrains/LogDrains.tsx index 894832547f7..acd9d90ec13 100644 --- a/apps/studio/components/interfaces/LogDrains/LogDrains.tsx +++ b/apps/studio/components/interfaces/LogDrains/LogDrains.tsx @@ -131,8 +131,15 @@ export function LogDrains({ {logDrains?.map((drain) => ( - {drain.name} - {drain.description} + + {drain.name} + + + {drain.description} + {drain.type} @@ -180,7 +187,7 @@ export function LogDrains({ }} onCancel={() => setIsDeleteModalOpen(false)} > -
+

Are you sure you want to delete{' '} {selectedLogDrain?.name}? From d30ec48b50f4fafc643c13d2cc0764e32081b7f7 Mon Sep 17 00:00:00 2001 From: Terry Sutton Date: Thu, 31 Oct 2024 09:19:03 -0230 Subject: [PATCH 2/4] Chore/self hosted assistant disabled (#30198) * Add a message if openai_api_key not set * Fix disabled state * Some fixes * Add same check in global assistant * Remove check for api key for platform --------- Co-authored-by: Joshen Lim --- .../SQLEditor/AiAssistantPanel/index.tsx | 21 +++++++++++-- .../ui/AIAssistantPanel/AIAssistant.tsx | 22 +++++++++++-- apps/studio/data/ai/check-api-key-query.ts | 31 +++++++++++++++++++ apps/studio/data/ai/keys.ts | 3 ++ apps/studio/pages/api/ai/sql/check-api-key.ts | 24 ++++++++++++++ 5 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 apps/studio/data/ai/check-api-key-query.ts create mode 100644 apps/studio/data/ai/keys.ts create mode 100644 apps/studio/pages/api/ai/sql/check-api-key.ts diff --git a/apps/studio/components/interfaces/SQLEditor/AiAssistantPanel/index.tsx b/apps/studio/components/interfaces/SQLEditor/AiAssistantPanel/index.tsx index 9a55270116d..994de7cb037 100644 --- a/apps/studio/components/interfaces/SQLEditor/AiAssistantPanel/index.tsx +++ b/apps/studio/components/interfaces/SQLEditor/AiAssistantPanel/index.tsx @@ -4,10 +4,14 @@ import { Info } from 'lucide-react' import { useEffect, useMemo, useRef, useState } from 'react' import { toast } from 'sonner' +import { Alert, AlertDescription, AlertTitle } from '@ui/components/shadcn/ui/alert' import { Message as MessageType } from 'ai' import { useChat } from 'ai/react' import { useParams } from 'common' +import { IS_PLATFORM } from 'common/constants/environment' +import { Markdown } from 'components/interfaces/Markdown' import { SchemaComboBox } from 'components/ui/SchemaComboBox' +import { useCheckOpenAIKeyQuery } from 'data/ai/check-api-key-query' import { useEntityDefinitionsQuery } from 'data/database/entity-definitions-query' import { useOrganizationUpdateMutation } from 'data/organizations/organization-update-mutation' import { useSendEventMutation } from 'data/telemetry/send-event-mutation' @@ -73,6 +77,9 @@ export const AiAssistantPanel = ({ const shouldShowNotOptimizedAlert = selectedOrganization && !includeSchemaMetadata && showAiNotOptimizedWarningSetting + const { data: check } = useCheckOpenAIKeyQuery() + const isApiKeySet = IS_PLATFORM || !!check?.hasKey + const { data } = useEntityDefinitionsQuery( { schemas: selectedSchemas, @@ -289,11 +296,21 @@ export const AiAssistantPanel = ({

-
+
+ {!isApiKeySet && ( + + OpenAI API key not set + + + + + )} )} + {!isApiKeySet && ( + + } + /> + )}
@@ -619,7 +637,7 @@ export const AIAssistant = ({ '[&>textarea]:rounded-none [&>textarea]:border-0 [&>textarea]:!outline-none [&>textarea]:!ring-offset-0 [&>textarea]:!ring-0' )} loading={isLoading} - disabled={disablePrompts || isLoading} + disabled={!isApiKeySet || disablePrompts || isLoading} placeholder={ hasMessages ? 'Reply to the assistant...' : 'How can we help you today?' } @@ -630,7 +648,7 @@ export const AIAssistant = ({ sendMessageToAssistant(value) }} /> - {!hasMessages && ( + {!hasMessages && IS_PLATFORM && (
The Assistant is in Alpha and your prompts might be rate limited
diff --git a/apps/studio/data/ai/check-api-key-query.ts b/apps/studio/data/ai/check-api-key-query.ts new file mode 100644 index 00000000000..8e21abd1df2 --- /dev/null +++ b/apps/studio/data/ai/check-api-key-query.ts @@ -0,0 +1,31 @@ +import { useQuery, UseQueryOptions } from '@tanstack/react-query' + +import { get, isResponseOk } from 'lib/common/fetch' +import { BASE_PATH, IS_PLATFORM } from 'lib/constants' +import { resourceKeys } from './keys' + +// check to see if the OPENAI_API_KEY env var is set in self-hosted +// so we can disable the chat editor and add a warning about manually adding the key + +export async function checkOpenAIKey(signal?: AbortSignal) { + const response = await get(`${BASE_PATH}/api/ai/sql/check-api-key`, { signal }) + + if (!isResponseOk(response)) { + throw (response as any).error + } + + return response as { hasKey: boolean } +} + +export type ResourceData = Awaited> +export type ResourceError = { errorEventId: string; message: string } + +export const useCheckOpenAIKeyQuery = ({ + enabled = true, + ...options +}: UseQueryOptions = {}) => + useQuery( + resourceKeys.apiKey(), + ({ signal }) => checkOpenAIKey(signal), + { enabled: !IS_PLATFORM && enabled, ...options } + ) diff --git a/apps/studio/data/ai/keys.ts b/apps/studio/data/ai/keys.ts new file mode 100644 index 00000000000..051620ea5e1 --- /dev/null +++ b/apps/studio/data/ai/keys.ts @@ -0,0 +1,3 @@ +export const resourceKeys = { + apiKey: () => ['api-key'] as const, +} diff --git a/apps/studio/pages/api/ai/sql/check-api-key.ts b/apps/studio/pages/api/ai/sql/check-api-key.ts new file mode 100644 index 00000000000..5c95b625b26 --- /dev/null +++ b/apps/studio/pages/api/ai/sql/check-api-key.ts @@ -0,0 +1,24 @@ +import apiWrapper from 'lib/api/apiWrapper' +import { NextApiRequest, NextApiResponse } from 'next' + +export default (req: NextApiRequest, res: NextApiResponse) => apiWrapper(req, res, handler) + +async function handler(req: NextApiRequest, res: NextApiResponse) { + const { method } = req + + switch (method) { + case 'GET': + return handleGet(req, res) + default: + res.setHeader('Allow', ['POST']) + res.status(405).json({ data: null, error: { message: `Method ${method} Not Allowed` } }) + } +} + +const handleGet = async (req: NextApiRequest, res: NextApiResponse) => { + if (process.env.OPENAI_API_KEY) { + return res.status(200).json({ hasKey: true }) + } else { + return res.status(404).json({ hasKey: false }) + } +} From 93fb4b76921684e8ff692dc933605bd1a6c7d2aa Mon Sep 17 00:00:00 2001 From: Charis <26616127+charislam@users.noreply.github.com> Date: Thu, 31 Oct 2024 12:40:49 -0400 Subject: [PATCH 3/4] fix(docs): force include reference mdx docs in vercel prod bundle (#30207) --- apps/docs/next.config.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/docs/next.config.mjs b/apps/docs/next.config.mjs index 965e5c87059..9a9d8196565 100644 --- a/apps/docs/next.config.mjs +++ b/apps/docs/next.config.mjs @@ -58,6 +58,7 @@ const nextConfig = { experimental: { outputFileTracingIncludes: { '/api/crawlers': ['./features/docs/generated/**/*', './docs/ref/**/*'], + '/reference/**/*': ['./features/docs/generated/**/*', './docs/ref/**/*'], }, }, webpack: (config, options) => { From 7ea482ee29e9830e5666b9ca440b770b5cb2b8c3 Mon Sep 17 00:00:00 2001 From: Jonathan Summers-Muir Date: Fri, 1 Nov 2024 00:51:08 +0800 Subject: [PATCH 4/4] fix/ provider check on read replica (#30208) Update DeployNewReplicaPanel.tsx --- .../InfrastructureConfiguration/DeployNewReplicaPanel.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DeployNewReplicaPanel.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DeployNewReplicaPanel.tsx index 51e11bb8b8b..481ee72fe98 100644 --- a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DeployNewReplicaPanel.tsx +++ b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/DeployNewReplicaPanel.tsx @@ -242,7 +242,7 @@ const DeployNewReplicaPanel = ({
- ) : isAWSProvider ? ( + ) : !isAWSProvider ? (