Merge master.
This commit is contained in:
commit
d23d0f59bd
|
@ -1,5 +1,7 @@
|
||||||
// BASE
|
// BASE
|
||||||
|
|
||||||
|
import { ErrorCode } from "@budibase/types"
|
||||||
|
|
||||||
export abstract class BudibaseError extends Error {
|
export abstract class BudibaseError extends Error {
|
||||||
code: string
|
code: string
|
||||||
|
|
||||||
|
@ -13,13 +15,6 @@ export abstract class BudibaseError extends Error {
|
||||||
|
|
||||||
// ERROR HANDLING
|
// ERROR HANDLING
|
||||||
|
|
||||||
export enum ErrorCode {
|
|
||||||
USAGE_LIMIT_EXCEEDED = "usage_limit_exceeded",
|
|
||||||
FEATURE_DISABLED = "feature_disabled",
|
|
||||||
INVALID_API_KEY = "invalid_api_key",
|
|
||||||
HTTP = "http",
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For the given error, build the public representation that is safe
|
* For the given error, build the public representation that is safe
|
||||||
* to be exposed over an api.
|
* to be exposed over an api.
|
||||||
|
|
|
@ -16,11 +16,12 @@ import env from "../environment"
|
||||||
import {
|
import {
|
||||||
Ctx,
|
Ctx,
|
||||||
EndpointMatcher,
|
EndpointMatcher,
|
||||||
|
ErrorCode,
|
||||||
LoginMethod,
|
LoginMethod,
|
||||||
SessionCookie,
|
SessionCookie,
|
||||||
User,
|
User,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { ErrorCode, InvalidAPIKeyError } from "../errors"
|
import { InvalidAPIKeyError } from "../errors"
|
||||||
import tracer from "dd-trace"
|
import tracer from "dd-trace"
|
||||||
import type { Middleware, Next } from "koa"
|
import type { Middleware, Next } from "koa"
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher } from "svelte"
|
||||||
import { API } from "@/api"
|
import { API } from "@/api"
|
||||||
import type { EnrichedBinding } from "@budibase/types"
|
import { ErrorCode, type EnrichedBinding } from "@budibase/types"
|
||||||
import analytics, { Events } from "@/analytics"
|
import analytics, { Events } from "@/analytics"
|
||||||
import AiInput from "../ai/AIInput.svelte"
|
import AiInput from "../ai/AIInput.svelte"
|
||||||
|
|
||||||
|
@ -43,17 +43,26 @@
|
||||||
const resp = await API.generateJs({ prompt, bindings })
|
const resp = await API.generateJs({ prompt, bindings })
|
||||||
const code = resp.code
|
const code = resp.code
|
||||||
if (code === "") {
|
if (code === "") {
|
||||||
throw new Error("We didn't understand your prompt. Please rephrase it.")
|
throw new Error(
|
||||||
|
"We didn't understand your prompt. This can happen if the prompt isn't specific, or if it's a request for something other than code. Try expressing your request in a different way."
|
||||||
|
)
|
||||||
}
|
}
|
||||||
suggestedCode = code
|
suggestedCode = code
|
||||||
dispatch("update", { code })
|
dispatch("update", { code })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
|
if (!(e instanceof Error)) {
|
||||||
|
notifications.error("Unable to generate code. Please try again later.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("code" in e && e.code === ErrorCode.USAGE_LIMIT_EXCEEDED) {
|
||||||
notifications.error(
|
notifications.error(
|
||||||
e instanceof Error
|
"Monthly usage limit reached. We're exploring options to expand this soon. Questions? Contact support@budibase.com"
|
||||||
? `Unable to generate code: ${e.message}`
|
|
||||||
: "Unable to generate code. Please try again later."
|
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
notifications.error(`Unable to generate code: ${e.message}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ import {
|
||||||
db as dbCore,
|
db as dbCore,
|
||||||
docIds,
|
docIds,
|
||||||
env as envCore,
|
env as envCore,
|
||||||
ErrorCode,
|
|
||||||
events,
|
events,
|
||||||
objectStore,
|
objectStore,
|
||||||
roles,
|
roles,
|
||||||
|
@ -70,6 +69,7 @@ import {
|
||||||
AddAppSampleDataResponse,
|
AddAppSampleDataResponse,
|
||||||
UnpublishAppResponse,
|
UnpublishAppResponse,
|
||||||
SetRevertableAppVersionResponse,
|
SetRevertableAppVersionResponse,
|
||||||
|
ErrorCode,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts"
|
import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts"
|
||||||
import sdk from "../../sdk"
|
import sdk from "../../sdk"
|
||||||
|
|
|
@ -4,3 +4,10 @@ export interface APIError {
|
||||||
error?: any
|
error?: any
|
||||||
validationErrors?: any
|
validationErrors?: any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum ErrorCode {
|
||||||
|
USAGE_LIMIT_EXCEEDED = "usage_limit_exceeded",
|
||||||
|
FEATURE_DISABLED = "feature_disabled",
|
||||||
|
INVALID_API_KEY = "invalid_api_key",
|
||||||
|
HTTP = "http",
|
||||||
|
}
|
||||||
|
|
|
@ -32,14 +32,12 @@ import {
|
||||||
OIDCConfigs,
|
OIDCConfigs,
|
||||||
OIDCLogosConfig,
|
OIDCLogosConfig,
|
||||||
PASSWORD_REPLACEMENT,
|
PASSWORD_REPLACEMENT,
|
||||||
QuotaUsageType,
|
|
||||||
SaveConfigRequest,
|
SaveConfigRequest,
|
||||||
SaveConfigResponse,
|
SaveConfigResponse,
|
||||||
SettingsBrandingConfig,
|
SettingsBrandingConfig,
|
||||||
SettingsInnerConfig,
|
SettingsInnerConfig,
|
||||||
SSOConfig,
|
SSOConfig,
|
||||||
SSOConfigType,
|
SSOConfigType,
|
||||||
StaticQuotaName,
|
|
||||||
UploadConfigFileResponse,
|
UploadConfigFileResponse,
|
||||||
UserCtx,
|
UserCtx,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
@ -53,7 +51,6 @@ const getEventFns = async (config: Config, existing?: Config) => {
|
||||||
fns.push(events.email.SMTPCreated)
|
fns.push(events.email.SMTPCreated)
|
||||||
} else if (isAIConfig(config)) {
|
} else if (isAIConfig(config)) {
|
||||||
fns.push(() => events.ai.AIConfigCreated)
|
fns.push(() => events.ai.AIConfigCreated)
|
||||||
fns.push(() => pro.quotas.addCustomAIConfig())
|
|
||||||
} else if (isGoogleConfig(config)) {
|
} else if (isGoogleConfig(config)) {
|
||||||
fns.push(() => events.auth.SSOCreated(ConfigType.GOOGLE))
|
fns.push(() => events.auth.SSOCreated(ConfigType.GOOGLE))
|
||||||
if (config.config.activated) {
|
if (config.config.activated) {
|
||||||
|
@ -92,12 +89,6 @@ const getEventFns = async (config: Config, existing?: Config) => {
|
||||||
fns.push(events.email.SMTPUpdated)
|
fns.push(events.email.SMTPUpdated)
|
||||||
} else if (isAIConfig(config)) {
|
} else if (isAIConfig(config)) {
|
||||||
fns.push(() => events.ai.AIConfigUpdated)
|
fns.push(() => events.ai.AIConfigUpdated)
|
||||||
if (
|
|
||||||
Object.keys(existing.config).length > Object.keys(config.config).length
|
|
||||||
) {
|
|
||||||
fns.push(() => pro.quotas.removeCustomAIConfig())
|
|
||||||
}
|
|
||||||
fns.push(() => pro.quotas.addCustomAIConfig())
|
|
||||||
} else if (isGoogleConfig(config)) {
|
} else if (isGoogleConfig(config)) {
|
||||||
fns.push(() => events.auth.SSOUpdated(ConfigType.GOOGLE))
|
fns.push(() => events.auth.SSOUpdated(ConfigType.GOOGLE))
|
||||||
if (!existing.config.activated && config.config.activated) {
|
if (!existing.config.activated && config.config.activated) {
|
||||||
|
@ -576,13 +567,6 @@ export async function destroy(ctx: UserCtx<void, DeleteConfigResponse>) {
|
||||||
try {
|
try {
|
||||||
await db.remove(id, rev)
|
await db.remove(id, rev)
|
||||||
await cache.destroy(cache.CacheKey.CHECKLIST)
|
await cache.destroy(cache.CacheKey.CHECKLIST)
|
||||||
if (id === configs.generateConfigID(ConfigType.AI)) {
|
|
||||||
await pro.quotas.set(
|
|
||||||
StaticQuotaName.AI_CUSTOM_CONFIGS,
|
|
||||||
QuotaUsageType.STATIC,
|
|
||||||
0
|
|
||||||
)
|
|
||||||
}
|
|
||||||
ctx.body = { message: "Config deleted successfully" }
|
ctx.body = { message: "Config deleted successfully" }
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
ctx.throw(err.status, err)
|
ctx.throw(err.status, err)
|
||||||
|
|
|
@ -16,6 +16,7 @@ import {
|
||||||
DeleteInviteUsersRequest,
|
DeleteInviteUsersRequest,
|
||||||
DeleteInviteUsersResponse,
|
DeleteInviteUsersResponse,
|
||||||
DeleteUserResponse,
|
DeleteUserResponse,
|
||||||
|
ErrorCode,
|
||||||
FetchUsersResponse,
|
FetchUsersResponse,
|
||||||
FindUserResponse,
|
FindUserResponse,
|
||||||
GetUserInvitesResponse,
|
GetUserInvitesResponse,
|
||||||
|
@ -42,7 +43,6 @@ import {
|
||||||
import {
|
import {
|
||||||
users,
|
users,
|
||||||
cache,
|
cache,
|
||||||
ErrorCode,
|
|
||||||
events,
|
events,
|
||||||
platform,
|
platform,
|
||||||
tenancy,
|
tenancy,
|
||||||
|
|
Loading…
Reference in New Issue