@budibase/frontend-core 3.12.8 → 3.12.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/api/agents.ts +36 -0
- package/src/api/app.ts +0 -2
- package/src/components/Updating.svelte +2 -2
- package/src/components/grid/cells/HeaderCell.svelte +1 -1
- package/src/utils/validation/yup/{app.js → app.ts} +22 -8
- package/src/utils/validation/yup/{index.js → index.ts} +48 -25
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/frontend-core",
|
|
3
|
-
"version": "3.12.
|
|
3
|
+
"version": "3.12.10",
|
|
4
4
|
"description": "Budibase frontend core libraries used in builder and client",
|
|
5
5
|
"author": "Budibase",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -17,5 +17,5 @@
|
|
|
17
17
|
"shortid": "2.2.15",
|
|
18
18
|
"socket.io-client": "^4.7.5"
|
|
19
19
|
},
|
|
20
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "9de98cbeb3441ce32f5cc05573fff655c7c758e9"
|
|
21
21
|
}
|
package/src/api/agents.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentChat,
|
|
3
|
+
AgentToolSource,
|
|
4
|
+
AgentToolSourceWithTools,
|
|
3
5
|
ChatAgentRequest,
|
|
4
6
|
ChatAgentResponse,
|
|
7
|
+
CreateToolSourceRequest,
|
|
5
8
|
FetchAgentHistoryResponse,
|
|
6
9
|
} from "@budibase/types"
|
|
7
10
|
import { BaseAPIClient } from "./types"
|
|
@@ -11,6 +14,13 @@ export interface AgentEndpoints {
|
|
|
11
14
|
|
|
12
15
|
removeChat: (historyId: string) => Promise<void>
|
|
13
16
|
fetchChats: () => Promise<FetchAgentHistoryResponse>
|
|
17
|
+
|
|
18
|
+
fetchToolSources: () => Promise<AgentToolSourceWithTools[]>
|
|
19
|
+
createToolSource: (
|
|
20
|
+
toolSource: CreateToolSourceRequest
|
|
21
|
+
) => Promise<{ created: true }>
|
|
22
|
+
updateToolSource: (toolSource: AgentToolSource) => Promise<AgentToolSource>
|
|
23
|
+
deleteToolSource: (toolSourceId: string) => Promise<{ deleted: true }>
|
|
14
24
|
}
|
|
15
25
|
|
|
16
26
|
export const buildAgentEndpoints = (API: BaseAPIClient): AgentEndpoints => ({
|
|
@@ -33,4 +43,30 @@ export const buildAgentEndpoints = (API: BaseAPIClient): AgentEndpoints => ({
|
|
|
33
43
|
url: "/api/agent/history",
|
|
34
44
|
})
|
|
35
45
|
},
|
|
46
|
+
|
|
47
|
+
fetchToolSources: async () => {
|
|
48
|
+
return await API.get({
|
|
49
|
+
url: "/api/agent/toolsource",
|
|
50
|
+
})
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
createToolSource: async (toolSource: CreateToolSourceRequest) => {
|
|
54
|
+
return await API.post({
|
|
55
|
+
url: "/api/agent/toolsource",
|
|
56
|
+
body: toolSource as any,
|
|
57
|
+
})
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
updateToolSource: async (toolSource: AgentToolSource) => {
|
|
61
|
+
return await API.put({
|
|
62
|
+
url: "/api/agent/toolsource",
|
|
63
|
+
body: toolSource as any,
|
|
64
|
+
})
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
deleteToolSource: async (toolSourceId: string) => {
|
|
68
|
+
return await API.delete({
|
|
69
|
+
url: `/api/agent/toolsource/${toolSourceId}`,
|
|
70
|
+
})
|
|
71
|
+
},
|
|
36
72
|
})
|
package/src/api/app.ts
CHANGED
|
@@ -139,7 +139,6 @@ export const buildAppEndpoints = (API: BaseAPIClient): AppEndpoints => ({
|
|
|
139
139
|
return await API.post({
|
|
140
140
|
url: "/api/applications",
|
|
141
141
|
body: app,
|
|
142
|
-
json: false,
|
|
143
142
|
})
|
|
144
143
|
},
|
|
145
144
|
|
|
@@ -151,7 +150,6 @@ export const buildAppEndpoints = (API: BaseAPIClient): AppEndpoints => ({
|
|
|
151
150
|
return await API.post({
|
|
152
151
|
url: `/api/applications/${appId}/duplicate`,
|
|
153
152
|
body: app,
|
|
154
|
-
json: false,
|
|
155
153
|
})
|
|
156
154
|
},
|
|
157
155
|
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
</span>
|
|
39
39
|
<span class="subtext">
|
|
40
40
|
{#if !timedOut}
|
|
41
|
-
Please wait and we
|
|
41
|
+
Please wait and we'll be back in a second!
|
|
42
42
|
<br />
|
|
43
|
-
|
|
43
|
+
Check out the
|
|
44
44
|
<a href="https://docs.budibase.com/docs/app-migrations" target="_blank"
|
|
45
45
|
>documentation</a
|
|
46
46
|
> on app migrations.
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import { string, mixed } from "yup"
|
|
2
2
|
import { APP_NAME_REGEX, APP_URL_REGEX } from "../../../constants"
|
|
3
|
+
import { App } from "@budibase/types"
|
|
4
|
+
import { ValidationStore } from "."
|
|
5
|
+
import { Helpers } from "@budibase/bbui"
|
|
3
6
|
|
|
4
|
-
export const name = (
|
|
7
|
+
export const name = (
|
|
8
|
+
validation: ValidationStore,
|
|
9
|
+
{ apps, currentApp }: { apps: App[]; currentApp?: App } = { apps: [] },
|
|
10
|
+
appOrWorkspace: "app" | "workspace"
|
|
11
|
+
) => {
|
|
5
12
|
validation.addValidator(
|
|
6
13
|
"name",
|
|
7
14
|
string()
|
|
8
15
|
.trim()
|
|
9
|
-
.required(
|
|
16
|
+
.required(`Your ${appOrWorkspace} must have a name`)
|
|
10
17
|
.matches(
|
|
11
18
|
APP_NAME_REGEX,
|
|
12
|
-
|
|
19
|
+
`${Helpers.capitalise(appOrWorkspace)} name must be letters, numbers and spaces only`
|
|
13
20
|
)
|
|
14
21
|
.test(
|
|
15
22
|
"non-existing-app-name",
|
|
16
|
-
|
|
23
|
+
`Another ${appOrWorkspace} with the same name already exists`,
|
|
17
24
|
value => {
|
|
18
25
|
if (!value) {
|
|
19
26
|
// exit early, above validator will fail
|
|
@@ -30,17 +37,21 @@ export const name = (validation, { apps, currentApp } = { apps: [] }) => {
|
|
|
30
37
|
)
|
|
31
38
|
}
|
|
32
39
|
|
|
33
|
-
export const url = (
|
|
40
|
+
export const url = (
|
|
41
|
+
validation: ValidationStore,
|
|
42
|
+
{ apps, currentApp }: { apps: App[]; currentApp?: App } = { apps: [] },
|
|
43
|
+
appOrWorkspace: "app" | "workspace"
|
|
44
|
+
) => {
|
|
34
45
|
validation.addValidator(
|
|
35
46
|
"url",
|
|
36
47
|
string()
|
|
37
48
|
.trim()
|
|
38
49
|
.nullable()
|
|
39
|
-
.required(
|
|
50
|
+
.required(`Your ${appOrWorkspace} must have a url`)
|
|
40
51
|
.matches(APP_URL_REGEX, "Please enter a valid url")
|
|
41
52
|
.test(
|
|
42
53
|
"non-existing-app-url",
|
|
43
|
-
|
|
54
|
+
`Another ${appOrWorkspace} with the same URL already exists`,
|
|
44
55
|
value => {
|
|
45
56
|
if (!value) {
|
|
46
57
|
return true
|
|
@@ -75,7 +86,10 @@ export const url = (validation, { apps, currentApp } = { apps: [] }) => {
|
|
|
75
86
|
)
|
|
76
87
|
}
|
|
77
88
|
|
|
78
|
-
export const file = (
|
|
89
|
+
export const file = (
|
|
90
|
+
validation: ValidationStore,
|
|
91
|
+
{ template }: { template?: { fromFile: boolean } | null } = {}
|
|
92
|
+
) => {
|
|
79
93
|
const templateToUse =
|
|
80
94
|
template && Object.keys(template).length === 0 ? null : template
|
|
81
95
|
validation.addValidator(
|
|
@@ -1,31 +1,49 @@
|
|
|
1
|
-
import { object, string, number } from "yup"
|
|
2
|
-
import { writable, get } from "svelte/store"
|
|
1
|
+
import { object, string, number, AnySchema } from "yup"
|
|
2
|
+
import { writable, get, type Writable } from "svelte/store"
|
|
3
3
|
import { Helpers, notifications } from "@budibase/bbui"
|
|
4
4
|
|
|
5
|
+
type ValidationState = {
|
|
6
|
+
values: Record<string, any>
|
|
7
|
+
errors: Record<string, string>
|
|
8
|
+
touched: Record<string, boolean>
|
|
9
|
+
valid: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type ValidatorMap = Record<string, AnySchema>
|
|
13
|
+
|
|
14
|
+
type AddValidatorTypeOptions = {
|
|
15
|
+
minLength?: number
|
|
16
|
+
}
|
|
17
|
+
|
|
5
18
|
export const createValidationStore = () => {
|
|
6
|
-
const DEFAULT = {
|
|
19
|
+
const DEFAULT: ValidationState = {
|
|
7
20
|
values: {},
|
|
8
21
|
errors: {},
|
|
9
22
|
touched: {},
|
|
10
23
|
valid: false,
|
|
11
24
|
}
|
|
12
25
|
|
|
13
|
-
const validator = {}
|
|
14
|
-
const validation = writable(DEFAULT)
|
|
26
|
+
const validator: ValidatorMap = {}
|
|
27
|
+
const validation: Writable<ValidationState> = writable(DEFAULT)
|
|
15
28
|
|
|
16
|
-
const addValidator = (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
29
|
+
const addValidator = (
|
|
30
|
+
propertyName: string,
|
|
31
|
+
propertyValidator: AnySchema | null
|
|
32
|
+
) => {
|
|
33
|
+
if (!propertyValidator || !propertyName) return
|
|
20
34
|
validator[propertyName] = propertyValidator
|
|
21
35
|
}
|
|
22
36
|
|
|
23
|
-
const addValidatorType = (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
37
|
+
const addValidatorType = (
|
|
38
|
+
propertyName: string,
|
|
39
|
+
type: string,
|
|
40
|
+
required?: boolean,
|
|
41
|
+
options?: AddValidatorTypeOptions
|
|
42
|
+
) => {
|
|
43
|
+
if (!type || !propertyName) return
|
|
44
|
+
|
|
45
|
+
let propertyValidator: AnySchema
|
|
27
46
|
|
|
28
|
-
let propertyValidator
|
|
29
47
|
switch (type) {
|
|
30
48
|
case "number":
|
|
31
49
|
propertyValidator = number().nullable()
|
|
@@ -45,15 +63,16 @@ export const createValidationStore = () => {
|
|
|
45
63
|
}
|
|
46
64
|
|
|
47
65
|
if (options?.minLength) {
|
|
48
|
-
propertyValidator = propertyValidator.min(options.minLength)
|
|
66
|
+
propertyValidator = (propertyValidator as any).min(options.minLength)
|
|
49
67
|
}
|
|
50
68
|
|
|
51
69
|
validator[propertyName] = propertyValidator
|
|
52
70
|
}
|
|
53
71
|
|
|
54
|
-
const observe = async (propertyName, value) => {
|
|
55
|
-
const values = get(validation)
|
|
56
|
-
let fieldIsValid
|
|
72
|
+
const observe = async (propertyName: string, value: any) => {
|
|
73
|
+
const { values } = get(validation)
|
|
74
|
+
let fieldIsValid = false
|
|
75
|
+
|
|
57
76
|
if (!Object.prototype.hasOwnProperty.call(values, propertyName)) {
|
|
58
77
|
// Initial setup
|
|
59
78
|
values[propertyName] = value
|
|
@@ -67,12 +86,12 @@ export const createValidationStore = () => {
|
|
|
67
86
|
const obj = object().shape(validator)
|
|
68
87
|
try {
|
|
69
88
|
validation.update(store => {
|
|
70
|
-
store.errors[propertyName]
|
|
89
|
+
delete store.errors[propertyName]
|
|
71
90
|
return store
|
|
72
91
|
})
|
|
73
92
|
await obj.validateAt(propertyName, { [propertyName]: value })
|
|
74
93
|
fieldIsValid = true
|
|
75
|
-
} catch (error) {
|
|
94
|
+
} catch (error: any) {
|
|
76
95
|
const [fieldError] = error.errors
|
|
77
96
|
if (fieldError) {
|
|
78
97
|
validation.update(store => {
|
|
@@ -103,21 +122,23 @@ export const createValidationStore = () => {
|
|
|
103
122
|
}
|
|
104
123
|
}
|
|
105
124
|
|
|
106
|
-
const check = async values => {
|
|
125
|
+
const check = async (values: Record<string, any>) => {
|
|
107
126
|
const obj = object().shape(validator)
|
|
108
127
|
// clear the previous errors
|
|
109
128
|
const properties = Object.keys(validator)
|
|
110
|
-
properties.forEach(property =>
|
|
129
|
+
properties.forEach(property => {
|
|
130
|
+
delete get(validation).errors[property]
|
|
131
|
+
})
|
|
111
132
|
|
|
112
133
|
let validationError = false
|
|
113
134
|
try {
|
|
114
135
|
await obj.validate(values, { abortEarly: false })
|
|
115
|
-
} catch (error) {
|
|
136
|
+
} catch (error: any) {
|
|
116
137
|
if (!error.inner) {
|
|
117
|
-
notifications.error("Unexpected validation error"
|
|
138
|
+
notifications.error("Unexpected validation error")
|
|
118
139
|
validationError = true
|
|
119
140
|
} else {
|
|
120
|
-
error.inner.forEach(err => {
|
|
141
|
+
error.inner.forEach((err: any) => {
|
|
121
142
|
validation.update(store => {
|
|
122
143
|
store.errors[err.path] = Helpers.capitalise(err.message)
|
|
123
144
|
return store
|
|
@@ -149,3 +170,5 @@ export const createValidationStore = () => {
|
|
|
149
170
|
observe,
|
|
150
171
|
}
|
|
151
172
|
}
|
|
173
|
+
|
|
174
|
+
export type ValidationStore = ReturnType<typeof createValidationStore>
|