mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-05 08:02:18 +00:00
fix(frontend): store exists openai key (#1870)
* fix(frontend): store exists openai key * fix: set to false if can't reach serv
This commit is contained in:
@@ -6,8 +6,7 @@
|
||||
import { sendUserToast } from '$lib/toast'
|
||||
import type Editor from '../Editor.svelte'
|
||||
import { faCheck, faClose, faMagicWandSparkles } from '@fortawesome/free-solid-svg-icons'
|
||||
import { WorkspaceService } from '$lib/gen'
|
||||
import { workspaceStore } from '$lib/stores'
|
||||
import { existsOpenaiKeyStore } from '$lib/stores'
|
||||
import type DiffEditor from '../DiffEditor.svelte'
|
||||
import { scriptLangToEditorLang } from '$lib/scripts'
|
||||
|
||||
@@ -60,7 +59,7 @@
|
||||
|
||||
async function checkIfOpenAIAvailable(lang: SupportedLanguage) {
|
||||
try {
|
||||
const exists = await WorkspaceService.existsOpenaiKey({ workspace: $workspaceStore! })
|
||||
const exists = $existsOpenaiKeyStore
|
||||
openAIAvailable = exists && SUPPORTED_LANGUAGES.has(lang)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
import Popup from '../common/popup/Popup.svelte'
|
||||
import { fade } from 'svelte/transition'
|
||||
import { Icon } from 'svelte-awesome'
|
||||
import { WorkspaceService } from '$lib/gen'
|
||||
import { workspaceStore } from '$lib/stores'
|
||||
import { existsOpenaiKeyStore } from '$lib/stores'
|
||||
import type DiffEditor from '../DiffEditor.svelte'
|
||||
import { scriptLangToEditorLang } from '$lib/scripts'
|
||||
import type { Selection } from 'monaco-editor/esm/vs/editor/editor.api'
|
||||
@@ -76,7 +75,7 @@
|
||||
|
||||
async function checkIfOpenAIAvailable(lang: SupportedLanguage) {
|
||||
try {
|
||||
const exists = await WorkspaceService.existsOpenaiKey({ workspace: $workspaceStore! })
|
||||
const exists = $existsOpenaiKeyStore
|
||||
openAIAvailable = exists && SUPPORTED_LANGUAGES.has(lang)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { OpenAI } from 'openai'
|
||||
import { OpenAPI } from '../../gen/core/OpenAPI'
|
||||
import { ResourceService, Script } from '../../gen'
|
||||
import { ResourceService, Script, WorkspaceService } from '../../gen'
|
||||
|
||||
import { workspaceStore } from '$lib/stores'
|
||||
import { existsOpenaiKeyStore, workspaceStore } from '$lib/stores'
|
||||
import { formatResourceTypes } from './utils'
|
||||
import { scriptLangToEditorLang } from '$lib/scripts'
|
||||
|
||||
@@ -77,8 +77,16 @@ export const SUPPORTED_LANGUAGES = new Set(Object.keys(PROMPTS))
|
||||
|
||||
let workspace: string | undefined = undefined
|
||||
|
||||
workspaceStore.subscribe((value) => {
|
||||
workspaceStore.subscribe(async (value) => {
|
||||
workspace = value
|
||||
if (workspace) {
|
||||
try {
|
||||
existsOpenaiKeyStore.set(await WorkspaceService.existsOpenaiKey({ workspace }))
|
||||
} catch (err) {
|
||||
existsOpenaiKeyStore.set(false)
|
||||
console.error('Could not get if openai key exists')
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
interface BaseOptions {
|
||||
|
||||
@@ -65,6 +65,7 @@ export const hubScripts = writable<
|
||||
}>
|
||||
| undefined
|
||||
>(undefined)
|
||||
export const existsOpenaiKeyStore = writable<boolean>(false)
|
||||
|
||||
export function switchWorkspace(workspace: string | undefined) {
|
||||
localStorage.removeItem('flow')
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
} from '$lib/gen'
|
||||
import {
|
||||
enterpriseLicense,
|
||||
existsOpenaiKeyStore,
|
||||
superadmin,
|
||||
userStore,
|
||||
usersWorkspaceStore,
|
||||
@@ -133,12 +134,14 @@
|
||||
workspace: $workspaceStore!,
|
||||
requestBody: { openai_key: openAIKey }
|
||||
})
|
||||
existsOpenaiKeyStore.set(true)
|
||||
sendUserToast('OpenAI key set')
|
||||
} else {
|
||||
await WorkspaceService.editOpenaiKey({
|
||||
workspace: $workspaceStore!,
|
||||
requestBody: { openai_key: undefined }
|
||||
})
|
||||
existsOpenaiKeyStore.set(false)
|
||||
sendUserToast(`OpenAI key removed`)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user