Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Fix custom models' and key handling UI [WIP]

Tomas Valenta9c0563f137d2
diff --git a/components/Editor/Sidebar/Agent/index.tsx b/components/Editor/Sidebar/Agent/index.tsx
index b0a429db6..082b86bb5 100644
--- a/components/Editor/Sidebar/Agent/index.tsx
+++ b/components/Editor/Sidebar/Agent/index.tsx
@@ -1,17 +1,19 @@
import { useState } from 'react'
-// import hljs from 'highlight.js'
import { deployment_state, deployments } from '@prisma/client'
+import produce from 'immer'
+import { useSupabaseClient } from '@supabase/auth-helpers-react'
import Text from 'components/Text'
import { useTabs } from 'components/Tabs/useTabs'
import Tabs from 'components/Tabs'
import { Log, LogType, ToolName } from 'db/types'
-
-import LogStream from './LogStream'
-import { useSupabaseClient } from '@supabase/auth-helpers-react'
import { Database, Json } from 'db/supabase'
import { deploymentsTable } from 'db/tables'
-import produce from 'immer'
+import useModelProviderCreds from 'hooks/useModelProviderCreds'
+import { getMissingCreds } from 'state/model'
+import { useStateStore } from 'state/StoreProvider'
+
+import LogStream from './LogStream'
import RunButton from '../RunButton'
const tabsProps = {
@@ -44,12 +46,11 @@ function Agent({
const [selectedTab, setSelectedTab] = useState(0)
const client = useSupabaseClient<Database>()
const tabsCss = useTabs(tabsProps)
+ const [selector] = useStateStore()
- // useEffect(function highlightCode() {
- // if (selectedTab === 1) {
- // hljs.highlightAll()
- // }
- // }, [logs, selectedTab])
+ const [creds,] = useModelProviderCreds()
+ const model = selector.use.model()
+ const missingCreds = getMissingCreds(model.provider, creds)
async function saveAnswer({
logID,
@@ -102,12 +103,27 @@ function Agent({
setSelectedTab={setSelectedTab}
/>
)}
- <RunButton
- deploy={deploy}
- isDeployRequestRunning={isDeployRequestRunning}
- isInitializingDeploy={isInitializingDeploy}
- deployStatus={deployment?.state}
- />
+ <div className="
+ flex
+ space-x-2
+ "
+ >
+ {missingCreds.length > 0 &&
+ <Text
+ text={`Missing key "${missingCreds[0][1].label || missingCreds[0][0]}"`}
+ size={Text.size.S3}
+ className="text-red-400"
+ />
+ }
+ {<RunButton
+ disabled={missingCreds.length !== 0}
+ deploy={deploy}
+ isDeployRequestRunning={isDeployRequestRunning}
+ isInitializingDeploy={isInitializingDeploy}
+ deployStatus={deployment?.state}
+ />
+ }
+ </div>
</div>
{!deployment &&
<div
diff --git a/components/Editor/Sidebar/Model.tsx b/components/Editor/Sidebar/Model.tsx
index b8012ce23..ef02ec998 100644
--- a/components/Editor/Sidebar/Model.tsx
+++ b/components/Editor/Sidebar/Model.tsx
@@ -1,9 +1,11 @@
+import { useRouter } from 'next/router'
+
import Radio from 'components/ModelRadio'
import Text from 'components/Text'
import { useStateStore } from 'state/StoreProvider'
-import { allCredsOk, ModelProvider, models } from 'state/model'
+import { getMissingCreds, ModelProvider, models } from 'state/model'
import useModelProviderCreds from 'hooks/useModelProviderCreds'
-import { useRouter } from 'next/router'
+import Button from 'components/Button'
export interface Props { }
@@ -14,7 +16,7 @@ function Context({ }: Props) {
const model = selector.use.model()
const setModel = selector.use.setModel()
- const [creds, mergeCreds] = useModelProviderCreds()
+ const [creds,] = useModelProviderCreds()
return (
<div className="
@@ -59,28 +61,34 @@ function Context({ }: Props) {
<div className="
flex
justify-between
- space-x-2
"
>
<Text
text={provider}
className="
- font-semibold
- uppercase
- text-slate-400
- "
+ font-semibold
+ text-slate-400
+ "
size={Text.size.S2}
/>
- <Text
- text={allCredsOk(provider as ModelProvider, creds) ? 'Credentials found' : 'Credentials missing'}
+ <div
className="
- text-slate-400
- cursor-pointer
- hover:text-slate-500
+ space-x-2
+ flex
"
- size={Text.size.S3}
- onClick={() => router.push('/settings')}
- />
+ >
+ <Text
+ text={getMissingCreds(provider as ModelProvider, creds).length === 0 ? '' : 'Missing keys'}
+ className="
+ text-red-400
+ "
+ size={Text.size.S3}
+ />
+ <Button
+ text="Set keys"
+ onClick={() => router.push('/settings')}
+ />
+ </div>
</div>
<div className="
flex
diff --git a/components/Editor/Sidebar/RunButton.tsx b/components/Editor/Sidebar/RunButton.tsx
index c317f61f7..7d25b8e68 100644
--- a/components/Editor/Sidebar/RunButton.tsx
+++ b/components/Editor/Sidebar/RunButton.tsx
@@ -9,6 +9,7 @@ export interface Props {
deployStatus?: deployment_state | null
isInitializingDeploy?: boolean
isDeployRequestRunning?: boolean
+ disabled?: boolean
}
interface DeploymentRepresentation {
@@ -47,6 +48,7 @@ function getDeploymentRepresentation(deployStatus: deployment_state | null | und
function DeployButton({
deploy,
+ disabled,
deployStatus,
isDeployRequestRunning,
isInitializingDeploy,
@@ -55,7 +57,7 @@ function DeployButton({
return (
<Button
- isDisabled={isDeployRequestRunning}
+ isDisabled={isDeployRequestRunning || disabled}
text={representation.text}
onClick={deploy}
variant={Button.variant.Full}
diff --git a/components/ModelRadio.tsx b/components/ModelRadio.tsx
index d260147d0..cd1bf366e 100644
--- a/components/ModelRadio.tsx
+++ b/components/ModelRadio.tsx
@@ -24,7 +24,7 @@ function Radio<T>({ selected, items, select }: Props) {
`
${checked ? 'border-green-800' : 'bg-white border-slate-300'
}
- relative flex cursor-pointer rounded-lg px-2 py-1 border hover:border-green-800 transition-all`
+ relative flex cursor-pointer rounded px-2 py-1 border hover:border-green-800 transition-all`
}
>
{({ active, checked }) => (
diff --git a/pages/api/service/[...all].ts b/pages/api/service/[...all].ts
index 28d88259d..8ddcc3f6e 100644
--- a/pages/api/service/[...all].ts
+++ b/pages/api/service/[...all].ts
@@ -1,8 +1,10 @@
import { createProxyMiddleware } from 'http-proxy-middleware'
import type { NextApiRequest, NextApiResponse } from 'next'
+
export const config = {
api: {
+ responseLimit: false,
// Proxy middleware will handle requests itself, so Next.js should
// ignore that our handler doesn't directly return a response
externalResolver: true,
@@ -12,16 +14,17 @@ export const config = {
},
}
+const pathPrefix = '/api/service'
+
const target = process.env.API_URL!
const isSecure = target.startsWith('https://')
const proxy = createProxyMiddleware<NextApiRequest, NextApiResponse>({
target,
- pathFilter: '**',
// ws: true,
secure: !isSecure,
changeOrigin: true,
- pathRewrite: { '^/api/service': '' }, // remove prefix
+ pathRewrite: { [`^${pathPrefix}`]: '' }, // remove prefix
})
export default function handler(req: NextApiRequest, res: NextApiResponse) {
diff --git a/pages/api/supabase/[...all].ts b/pages/api/supabase/[...all].ts
index 7be18ff40..53371643e 100644
--- a/pages/api/supabase/[...all].ts
+++ b/pages/api/supabase/[...all].ts
@@ -3,6 +3,7 @@ import type { NextApiRequest, NextApiResponse } from 'next'
export const config = {
api: {
+ responseLimit: false,
// Proxy middleware will handle requests itself, so Next.js should
// ignore that our handler doesn't directly return a response
externalResolver: true,
@@ -19,7 +20,6 @@ const isSecure = target.startsWith('https://')
const proxy = createProxyMiddleware<NextApiRequest, NextApiResponse>({
target,
- pathFilter: '**',
ws: true,
secure: !isSecure,
changeOrigin: true,
diff --git a/pages/settings.tsx b/pages/settings.tsx
index e679c6aa5..3528f36dd 100644
--- a/pages/settings.tsx
+++ b/pages/settings.tsx
@@ -27,13 +27,11 @@ export const getServerSideProps: GetServerSideProps<Props> = async (ctx) => {
}
return {
- props: {
- },
+ props: {},
}
}
-interface Props {
-}
+interface Props { }
function Settings({ }: Props) {
const user = useUser()
@@ -80,7 +78,7 @@ function Settings({ }: Props) {
flex-1
flex-col
items-start
- space-y-4
+ space-y-6
"
>
<div
@@ -92,7 +90,7 @@ function Settings({ }: Props) {
>
<Text
className="text-slate-400"
- size={Text.size.S3}
+ size={Text.size.S2}
text="Email"
/>
<Text
@@ -110,7 +108,7 @@ function Settings({ }: Props) {
<Text
className="text-slate-400"
size={Text.size.S2}
- text="Credentials"
+ text="Keys"
/>
<div
className="
diff --git a/state/model.ts b/state/model.ts
index ee2918192..ae16b47c9 100644
--- a/state/model.ts
+++ b/state/model.ts
@@ -139,8 +139,10 @@ export function evaluateModelConfig(
}
}
-export function allCredsOk(provider: ModelProvider, creds: Creds) {
- return Object
+export function getMissingCreds(provider: ModelProvider, creds: Creds) {
+ const missing = Object
.entries(models[provider]?.creds || {})
- .every(([key, val]) => creds[provider]?.creds?.[key] !== undefined)
+ .filter(([key, val]) => creds[provider]?.creds?.[key] === undefined)
+
+ return missing
}