You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Append writable fields to dev API new workspace endpoint (#2843)
* add writible fields to dev api new workspace endpoint
* lint
* implement validations for workspace model
* update swagger comments
* simplify validations for workspace on frontend and API
* cleanup validations
---------
Co-authored-by: Timothy Carambat <[email protected]>
"Given the following conversation, relevant context, and a follow up question, reply with an answer to the current question the user is asking. Return only your response to the question given the above information following the users instructions as needed.",
17
+
18
+
// Used for generic updates so we can validate keys in request body
19
+
// commented fields are not writable, but are available on the db object
12
20
writable: [
13
-
// Used for generic updates so we can validate keys in request body
14
21
"name",
15
-
"slug",
16
-
"vectorTag",
22
+
// "slug",
23
+
// "vectorTag",
17
24
"openAiTemp",
18
25
"openAiHistory",
19
26
"lastUpdatedAt",
@@ -23,11 +30,77 @@ const Workspace = {
23
30
"chatModel",
24
31
"topN",
25
32
"chatMode",
26
-
"pfpFilename",
33
+
// "pfpFilename",
27
34
"agentProvider",
28
35
"agentModel",
29
36
"queryRefusalResponse",
30
37
],
38
+
39
+
validations: {
40
+
name: (value)=>{
41
+
// If the name is not provided or is not a string then we will use a default name.
42
+
// as the name field is not nullable in the db schema or has a default value.
// If there is no validation for the field then we will just pass it through.
142
+
validatedFields[key]=value;
143
+
}
144
+
}
145
+
returnvalidatedFields;
146
+
},
147
+
148
+
/**
149
+
* Create a new workspace.
150
+
* @param {string} name - The name of the workspace.
151
+
* @param {number} creatorId - The ID of the user creating the workspace.
152
+
* @param {Object} additionalFields - Additional fields to apply to the workspace - will be validated.
153
+
* @returns {Promise<{workspace: Object | null, message: string | null}>} A promise that resolves to an object containing the created workspace and an error message if applicable.
if(!name)return{workspace: null,message: "name cannot be null"};
58
157
varslug=this.slugify(name,{lower: true});
59
158
slug=slug||uuidv4();
60
159
@@ -66,7 +165,11 @@ const Workspace = {
66
165
67
166
try{
68
167
constworkspace=awaitprisma.workspaces.create({
69
-
data: { name, slug },
168
+
data: {
169
+
name: this.validations.name(name),
170
+
...this.validateFields(additionalFields),
171
+
slug,
172
+
},
70
173
});
71
174
72
175
// If created with a user then we need to create the relationship as well.
@@ -80,35 +183,36 @@ const Workspace = {
80
183
}
81
184
},
82
185
186
+
/**
187
+
* Update the settings for a workspace. Applies validations to the updates provided.
188
+
* @param {number} id - The ID of the workspace to update.
189
+
* @param {Object} updates - The data to update.
190
+
* @returns {Promise<{workspace: Object | null, message: string | null}>} A promise that resolves to an object containing the updated workspace and an error message if applicable.
191
+
*/
83
192
update: asyncfunction(id=null,updates={}){
84
193
if(!id)thrownewError("No workspace id provided for update");
return{workspace: { id },message: "No valid fields to update!"};
97
198
98
199
// If the user unset the chatProvider we will need
99
200
// to then clear the chatModel as well to prevent confusion during
100
201
// LLM loading.
101
-
if(updates?.chatProvider==="default"){
102
-
updates.chatProvider=null;
103
-
updates.chatModel=null;
202
+
if(validatedUpdates?.chatProvider==="default"){
203
+
validatedUpdates.chatProvider=null;
204
+
validatedUpdates.chatModel=null;
104
205
}
105
206
106
-
returnthis._update(id,updates);
207
+
returnthis._update(id,validatedUpdates);
107
208
},
108
209
109
-
// Explicit update of settings + key validations.
110
-
// Only use this method when directly setting a key value
111
-
// that takes no user input for the keys being modified.
210
+
/**
211
+
* Direct update of workspace settings without any validation.
212
+
* @param {number} id - The ID of the workspace to update.
213
+
* @param {Object} data - The data to update.
214
+
* @returns {Promise<{workspace: Object | null, message: string | null}>} A promise that resolves to an object containing the updated workspace and an error message if applicable.
215
+
*/
112
216
_update: asyncfunction(id=null,data={}){
113
217
if(!id)thrownewError("No workspace id provided for update");
0 commit comments