-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
838 lines (786 loc) · 25.6 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
import {
GetDatasetRequest,
GetModelRequest,
GetWorkflowRequest,
ListConceptsRequest,
ListDatasetsRequest,
ListInstalledModuleVersionsRequest,
ListModelsRequest,
ListModulesRequest,
ListWorkflowsRequest,
MultiDatasetResponse,
PostDatasetsRequest,
PostModelsRequest,
SingleModelResponse,
SingleWorkflowResponse,
SingleDatasetResponse,
PostModulesRequest,
DeleteDatasetsRequest,
DeleteModelsRequest,
DeleteWorkflowsRequest,
DeleteModulesRequest,
PostWorkflowsRequest,
} from "clarifai-nodejs-grpc/proto/clarifai/api/service_pb";
import { UserError } from "../errors";
import { ClarifaiAppUrl, ClarifaiUrlHelper } from "../urls/helper";
import { promisifyGrpcCall } from "../utils/misc";
import { AuthConfig, PaginationRequestParams } from "../utils/types";
import { Lister } from "./lister";
import {
Model,
App as GrpcApp,
Workflow,
Module,
InstalledModuleVersion,
Concept,
Dataset,
WorkflowNode,
ModelVersion,
} from "clarifai-nodejs-grpc/proto/clarifai/api/resources_pb";
import { TRAINABLE_MODEL_TYPES } from "../constants/model";
import { StatusCode } from "clarifai-nodejs-grpc/proto/clarifai/api/status/status_code_pb";
import * as fs from "fs";
import * as yaml from "js-yaml";
import { validateWorkflow } from "../workflows/validate";
import { getYamlOutputInfoProto } from "../workflows/utils";
import { Model as ModelConstructor } from "./model";
import { v4 as uuid } from "uuid";
import { fromProtobufObject } from "from-protobuf-object";
import { fromPartialProtobufObject } from "../utils/fromPartialProtobufObject";
import { flatten } from "safe-flat";
export type AppConfig =
| {
url: ClarifaiAppUrl;
authConfig: Omit<AuthConfig, "appId" | "userId"> & {
appId?: undefined;
userId?: undefined;
};
}
| {
url?: undefined;
authConfig: AuthConfig;
};
export type ListDatasetsParam =
PaginationRequestParams<ListDatasetsRequest.AsObject>;
export type ListModelsParam =
PaginationRequestParams<ListModelsRequest.AsObject>;
export type ListWorkflowsParam =
PaginationRequestParams<ListWorkflowsRequest.AsObject>;
export type ListModulesParam =
PaginationRequestParams<ListModulesRequest.AsObject>;
export type ListInstalledModuleVersionsParam =
PaginationRequestParams<ListInstalledModuleVersionsRequest.AsObject>;
export type CreateDatasetParam = Omit<Partial<Dataset.AsObject>, "id">;
export type CreateModelParam = Omit<Partial<Model.AsObject>, "id">;
/**
* App is a class that provides access to Clarifai API endpoints related to App information.
* @noInheritDoc
*/
export class App extends Lister {
private appInfo: GrpcApp;
/**
* Initializes an App object.
* @param config - The configuration object for the App.
* @param config.url - The URL of the app.
* @param config.authConfig.userId The user ID for the user to interact with.
* @param config.authConfig.appId The application ID associated with the user. Not required if the URL is provided.
* @param config.authConfig.pat A personal access token for authentication. Can also be set as an environment variable CLARIFAI_PAT.
* @param config.authConfig.token A session token for authentication. Accepts either a session token or a personal access token (pat). Can also be set as an environment variable CLARIFAI_SESSION_TOKEN.
* @param config.authConfig.base Optional. The base API URL. Defaults to "https://api.clarifai.com".
* @param config.authConfig.ui Optional. Additional UI configurations.
*
* @includeExample examples/app/index.ts
*/
constructor({ url, authConfig }: AppConfig) {
if (url && authConfig.appId) {
throw new UserError("You can only specify one of url or app_id.");
}
if (url) {
const [userId, appId] = ClarifaiUrlHelper.splitClarifaiAppUrl(url);
// @ts-expect-error - since url is parsed, we need to set appId here
if (userId) authConfig.userId = userId;
// @ts-expect-error - since url is parsed, we need to set appId here
if (appId) authConfig.appId = appId;
}
super({ authConfig: authConfig as AuthConfig });
this.appInfo = new GrpcApp();
this.appInfo.setUserId(authConfig.userId!);
this.appInfo.setId(authConfig.appId!);
}
/**
* Lists all the datasets for the app.
*
* @param pageNo - The page number to list.
* @param perPage - The number of items per page.
*
* @yields Dataset - Dataset objects for the datasets in the app.
*
* @includeExample examples/app/listDatasets.ts
*
* @remarks
* Defaults to 16 per page
*/
async *listDataSets({
params = {},
pageNo,
perPage,
}: {
params?: ListDatasetsParam;
pageNo?: number;
perPage?: number;
} = {}): AsyncGenerator<
MultiDatasetResponse.AsObject["datasetsList"],
void,
unknown
> {
const listDataSets = promisifyGrpcCall(
this.STUB.client.listDatasets,
this.STUB.client,
);
const request = fromPartialProtobufObject(ListDatasetsRequest, params);
request.setUserAppId(this.userAppId);
for await (const item of this.listPagesGenerator(
listDataSets,
request,
pageNo,
perPage,
)) {
yield item.toObject()?.datasetsList;
}
}
/**
* Lists all the available models for the user.
*
* @param params - A object of filters to apply to the list of models.
* @param onlyInApp - If True, only return models that are in the app.
* @param pageNo - The page number to list.
* @param perPage - The number of items per page.
*
* @includeExample examples/app/listModels.ts
*
* @remarks
* Defaults to 16 per page
*/
async *listModels({
params = {},
onlyInApp = true,
pageNo,
perPage,
}: {
params?: ListModelsParam;
onlyInApp?: boolean;
pageNo?: number;
perPage?: number;
} = {}): AsyncGenerator<Model.AsObject[], void, unknown> {
const listModels = promisifyGrpcCall(
this.STUB.client.listModels,
this.STUB.client,
);
const request = fromPartialProtobufObject(ListModelsRequest, params);
request.setUserAppId(this.userAppId);
for await (const item of this.listPagesGenerator(
listModels,
request,
pageNo,
perPage,
)) {
const models = [];
const modelsListResponse = item.toObject();
for (const eachModel of modelsListResponse.modelsList) {
if (!eachModel.modelVersion) {
continue;
}
if (
onlyInApp &&
eachModel.modelVersion.appId !== this.userAppId.getAppId()
) {
continue;
}
models.push(eachModel);
}
yield models;
}
}
/**
* Lists all the available workflows for the user.
*
* @param params - A object of filters to apply to the list of workflows.
* @param onlyInApp - If True, only return workflows that are in the app.
* @param pageNo - The page number to list.
* @param perPage - The number of items per page.
*
* @yields Workflow - Workflow objects for the workflows in the app.
*
* @includeExample examples/app/listWorkflows.ts
*
* @remarks
* Defaults to 16 per page
*/
async *listWorkflows({
params = {},
onlyInApp = true,
pageNo,
perPage,
}: {
params?: ListWorkflowsParam;
onlyInApp?: boolean;
pageNo?: number;
perPage?: number;
} = {}): AsyncGenerator<Workflow.AsObject[], void, unknown> {
const request = fromPartialProtobufObject(ListWorkflowsRequest, params);
const listWorkflows = promisifyGrpcCall(
this.STUB.client.listWorkflows,
this.STUB.client,
);
const listWorkflowsGenerator = this.listPagesGenerator(
listWorkflows,
request,
pageNo,
perPage,
);
for await (const workflow of listWorkflowsGenerator) {
const workflows = [];
const workflowObject = workflow.toObject();
for (const eachWorkflow of workflowObject.workflowsList) {
if (onlyInApp && eachWorkflow.appId !== this.userAppId.getAppId()) {
continue;
}
workflows.push(eachWorkflow);
}
yield workflows;
}
}
/**
* Lists all the available modules for the user.
*
* @param params - An object of filters to apply to the list of modules.
* @param onlyInApp - If true, only return modules that are in the app.
* @param pageNo - The page number to list.
* @param perPage - The number of items per page.
*
* @yields Module - Module objects for the modules in the app.
*
* @includeExample examples/app/listModules.ts
*
* @remarks
* Defaults to 16 per page
*/
async *listModules({
params = {},
onlyInApp,
pageNo,
perPage,
}: {
params?: ListModulesParam;
onlyInApp?: boolean;
pageNo?: number;
perPage?: number;
} = {}): AsyncGenerator<Module.AsObject[], void, unknown> {
const listModules = promisifyGrpcCall(
this.STUB.client.listModules,
this.STUB.client,
);
const request = fromPartialProtobufObject(ListModulesRequest, params);
request.setUserAppId(this.userAppId);
for await (const item of this.listPagesGenerator(
listModules,
request,
pageNo,
perPage,
)) {
const modules = [];
const modulesListResponse = item.toObject();
for (const eachModule of modulesListResponse.modulesList) {
if (onlyInApp && eachModule.appId !== this.userAppId.getAppId()) {
continue;
}
modules.push(eachModule);
}
yield modules;
}
}
/**
* Lists all installed module versions in the app.
*
* @param params - A dictionary of filters to apply to the list of installed module versions.
* @param pageNo - The page number to list.
* @param perPage - The number of items per page.
*
* @yields Module - Module objects for the installed module versions in the app.
*
* @includeExample examples/app/listInstalledModuleVersions.ts
*
* @remarks
* Defaults to 16 per page
*/
async *listInstalledModuleVersions({
params = {},
pageNo,
perPage,
}: {
params?: ListInstalledModuleVersionsParam;
pageNo?: number;
perPage?: number;
} = {}): AsyncGenerator<InstalledModuleVersion.AsObject[], void, unknown> {
const listInstalledModuleVersions = promisifyGrpcCall(
this.STUB.client.listInstalledModuleVersions,
this.STUB.client,
);
const request = fromPartialProtobufObject(
ListInstalledModuleVersionsRequest,
params,
);
request.setUserAppId(this.userAppId);
for await (const item of this.listPagesGenerator(
listInstalledModuleVersions,
request,
pageNo,
perPage,
)) {
const moduleVersions = [];
const modulesListResponseObject = item.toObject();
for (const eachModule of modulesListResponseObject.installedModuleVersionsList) {
// @ts-expect-error - delete needed here due to debt in the backend
delete eachModule.deployUrl;
// @ts-expect-error - delete needed here due to debt in the backend
delete eachModule.installedModuleVersionId; // TODO: remove this after the backend fix
moduleVersions.push(eachModule);
}
yield moduleVersions;
}
}
/**
* Lists all the concepts for the app.
* @param page_no - The page number to list.
* @param per_page - The number of items per page.
* @yields Concepts in the app.
*
* @includeExample examples/app/listConcepts.ts
*/
async *listConcepts({
pageNo,
perPage,
}: {
pageNo?: number;
perPage?: number;
} = {}): AsyncGenerator<Concept.AsObject[], void, unknown> {
const listConcepts = promisifyGrpcCall(
this.STUB.client.listConcepts,
this.STUB.client,
);
const request = new ListConceptsRequest();
request.setUserAppId(this.userAppId);
for await (const item of this.listPagesGenerator(
listConcepts,
request,
pageNo,
perPage,
)) {
const conceptsListResponse = item.toObject();
yield conceptsListResponse.conceptsList;
}
}
listTrainableModelTypes(): string[] {
return TRAINABLE_MODEL_TYPES;
}
/**
* Creates a dataset for the app.
*
* @param datasetId - The dataset ID for the dataset to create.
* @param params - Additional parameters to be passed to the Dataset.
*
* @returns A Dataset object for the specified dataset ID.
*
* @includeExample examples/app/createDataset.ts
*/
async createDataset({
datasetId,
params = {},
}: {
datasetId: string;
params?: CreateDatasetParam;
}): Promise<Dataset.AsObject> {
const request = new PostDatasetsRequest();
request.setUserAppId(this.userAppId);
const newDataSet = fromPartialProtobufObject(Dataset, params);
newDataSet.setId(datasetId);
request.setDatasetsList([newDataSet]);
const postDatasets = promisifyGrpcCall(
this.STUB.client.postDatasets,
this.STUB.client,
);
const response = await this.grpcRequest(postDatasets, request);
const responseObject = response.toObject();
if (responseObject.status?.code !== StatusCode.SUCCESS) {
throw new Error(responseObject.status?.description);
}
console.info("\nDataset created\n%s", responseObject.status.description);
return responseObject.datasetsList?.[0];
}
/**
* Creates a model for the app.
*
* @param modelId - The model ID for the model to create.
* @param params - Additional parameters to be passed to the Model.
*
* @returns A Model object for the specified model ID.
*
* @includeExample examples/app/createModel.ts
*/
async createModel({
modelId,
params = {},
}: {
modelId: string;
params?: CreateModelParam;
}): Promise<Model.AsObject> {
const request = new PostModelsRequest();
request.setUserAppId(this.userAppId);
const newModel = fromPartialProtobufObject(Model, {
id: modelId,
...params,
});
request.setModelsList([newModel]);
const postModels = promisifyGrpcCall(
this.STUB.client.postModels,
this.STUB.client,
);
const response = await this.grpcRequest(postModels, request);
const responseObject = response.toObject();
if (
responseObject.status?.code !== StatusCode.SUCCESS ||
!responseObject.model
) {
throw new Error(responseObject.status?.description);
}
console.info("\nModel created\n%s", responseObject.status.description);
return responseObject.model;
}
/**
* Creates a module for the app.
*
* @param moduleId - The module ID for the module to create.
* @param description - The description of the module to create.
* @returns A Module object for the specified module ID.
*
* @includeExample examples/app/createModule.ts
*/
async createModule({
moduleId,
description,
}: {
moduleId: string;
description: string;
}): Promise<Module.AsObject> {
const request = new PostModulesRequest();
request.setUserAppId(this.userAppId);
const newModule = new Module();
newModule.setId(moduleId);
newModule.setDescription(description);
request.setModulesList([newModule]);
const postModules = promisifyGrpcCall(
this.STUB.client.postModules,
this.STUB.client,
);
const response = await this.grpcRequest(postModules, request);
const responseObject = response.toObject();
if (responseObject.status?.code !== StatusCode.SUCCESS) {
throw new Error(responseObject.status?.description);
}
console.info("\nModule created\n%s", responseObject.status.description);
return responseObject.modulesList?.[0];
}
/**
* Creates a workflow for the app.
*
* @param configFilePath - The path to the yaml workflow config file.
* @param generateNewId - If true, generate a new workflow ID.
* @param display - If true, display the workflow nodes tree.
* @returns A Workflow object for the specified workflow config.
*
* @includeExample examples/app/createWorkflow.ts
*/
async createWorkflow({
configFilePath,
generateNewId = false,
display = true,
}: {
configFilePath: string;
generateNewId?: boolean;
display?: boolean;
}): Promise<Workflow.AsObject> {
if (!fs.existsSync(configFilePath)) {
throw new UserError(
`Workflow config file not found at ${configFilePath}`,
);
}
const data = yaml.load(fs.readFileSync(configFilePath, "utf8"));
const validatedData = validateWorkflow(data);
const workflow = validatedData["workflow"];
// Get all model objects from the workflow nodes.
const allModels: Model.AsObject[] = [];
for (const node of workflow.nodes) {
let modelObject: Model.AsObject | undefined;
const outputInfo = getYamlOutputInfoProto(node?.model?.outputInfo ?? {});
try {
const model = await this.model({
modelId: node.model.modelId,
modelVersionId: node.model.modelVersionId ?? "",
});
modelObject = model;
if (model) {
allModels.push(model);
}
} catch (e) {
// model doesn't exist, create a new model from yaml config
if (
(e as { message?: string })?.message?.includes(
"Model does not exist",
) &&
outputInfo
) {
const { modelId, ...otherParams } = node.model;
modelObject = await this.createModel({
modelId,
params: otherParams as CreateModelParam,
});
const model = new ModelConstructor({
modelId: modelObject.id,
authConfig: {
pat: this.pat,
appId: this.userAppId.getAppId(),
userId: this.userAppId.getUserId(),
},
});
const modelVersion = new ModelVersion().setOutputInfo(outputInfo);
const modelWithVersion = await model.createVersion(modelVersion);
if (modelWithVersion) {
allModels.push(modelWithVersion);
continue;
}
}
}
}
// Convert nodes to resources_pb2.WorkflowNodes.
const nodes: WorkflowNode.AsObject[] = [];
for (let i = 0; i < workflow["nodes"].length; i++) {
const ymlNode = workflow["nodes"][i];
const node: WorkflowNode.AsObject = {
id: ymlNode["id"],
model: allModels[i],
// TODO: setting default values, need to check for right values to set here
nodeInputsList: [],
// TODO: setting default values, need to check for right values to set here
suppressOutput: false,
};
// Add node inputs if they exist, i.e. if these nodes do not connect directly to the input.
if (ymlNode.nodeInputs) {
for (const ni of ymlNode.nodeInputs) {
node?.nodeInputsList.push({ nodeId: ni.nodeId });
}
}
nodes.push(node);
}
let workflowId = workflow["id"];
if (generateNewId) {
workflowId = uuid();
}
// Create the workflow.
const request = new PostWorkflowsRequest();
request.setUserAppId(this.userAppId);
const workflowNodesList = nodes.map((eachNode) =>
fromProtobufObject(WorkflowNode, eachNode),
);
request.setWorkflowsList([
new Workflow().setId(workflowId).setNodesList(workflowNodesList),
]);
const postWorkflows = promisifyGrpcCall(
this.STUB.client.postWorkflows,
this.STUB.client,
);
const response = await this.grpcRequest(postWorkflows, request);
const responseObject = response.toObject();
if (responseObject.status?.code !== StatusCode.SUCCESS) {
throw new Error(responseObject.status?.description);
}
console.info("\nWorkflow created\n%s", responseObject.status?.description);
// Display the workflow nodes tree.
if (display) {
console.table(flatten(responseObject.workflowsList?.[0]?.nodesList));
}
return responseObject.workflowsList?.[0];
}
/**
* Returns a Model object for the existing model ID.
*
* @param modelId - The model ID for the existing model.
* @param modelVersionId - Specific version id of the model.
* @returns A model object for the specified model ID.
*
* @includeExample examples/app/model.ts
*/
async model({
modelId,
modelVersionId,
}: {
modelId: string;
modelVersionId?: string;
}): Promise<SingleModelResponse.AsObject["model"]> {
const request = new GetModelRequest();
request.setUserAppId(this.userAppId);
request.setModelId(modelId);
if (modelVersionId) request.setVersionId(modelVersionId);
const getModel = promisifyGrpcCall(
this.STUB.client.getModel,
this.STUB.client,
);
const response = await this.grpcRequest(getModel, request);
const responseObject = response.toObject();
if (responseObject.status?.code !== StatusCode.SUCCESS) {
throw new Error(responseObject.status?.description);
}
return responseObject.model;
}
/**
* Returns a Workflow object for the existing workflow ID.
*
* @param workflowId - The workflow ID for a existing workflow.
* @returns A workflow object for the specified workflow ID.
*
* @includeExample examples/app/workflow.ts
*/
async workflow({
workflowId,
}: {
workflowId: string;
}): Promise<SingleWorkflowResponse.AsObject["workflow"]> {
const request = new GetWorkflowRequest();
request.setUserAppId(this.userAppId);
request.setWorkflowId(workflowId);
const getWorkflow = promisifyGrpcCall(
this.STUB.client.getWorkflow,
this.STUB.client,
);
const response = await this.grpcRequest(getWorkflow, request);
const responseObject = response.toObject();
if (responseObject.status?.code !== StatusCode.SUCCESS) {
throw new Error(responseObject.status?.description);
}
return responseObject.workflow;
}
/**
* Returns a Dataset object for the existing dataset ID.
*
* @param dataset_id - The dataset ID for the dataset to interact with.
* @returns A Dataset object for the existing dataset ID.
*
* @includeExample examples/app/dataset.ts
*/
async dataset({
datasetId,
}: {
datasetId: string;
}): Promise<SingleDatasetResponse.AsObject["dataset"]> {
const request = new GetDatasetRequest();
request.setUserAppId(this.userAppId);
request.setDatasetId(datasetId);
const getDataset = promisifyGrpcCall(
this.STUB.client.getDataset,
this.STUB.client,
);
const response = await this.grpcRequest(getDataset, request);
const responseObject = response.toObject();
if (responseObject.status?.code !== StatusCode.SUCCESS) {
throw new Error(responseObject.status?.description);
}
return responseObject.dataset;
}
/**
* Deletes a dataset for the user.
*
* @param datasetId - The dataset ID for the app to delete.
*
* @includeExample examples/app/deleteDataset.ts
*/
async deleteDataset({ datasetId }: { datasetId: string }): Promise<void> {
const request = new DeleteDatasetsRequest();
request.setUserAppId(this.userAppId);
request.setDatasetIdsList([datasetId]);
const deleteDatasets = promisifyGrpcCall(
this.STUB.client.deleteDatasets,
this.STUB.client,
);
const response = await this.grpcRequest(deleteDatasets, request);
const responseObject = response.toObject();
if (responseObject.status?.code !== StatusCode.SUCCESS) {
throw new Error(responseObject.status?.description);
}
console.info("\nDataset Deleted\n%s", responseObject.status?.description);
}
/**
* Deletes a model for the user.
*
* @param modelId - The model ID for the model to delete.
*
* @includeExample examples/app/deleteModel.ts
*/
async deleteModel({ modelId }: { modelId: string }): Promise<void> {
const request = new DeleteModelsRequest();
request.setUserAppId(this.userAppId);
request.setIdsList([modelId]);
const deleteModels = promisifyGrpcCall(
this.STUB.client.deleteModels,
this.STUB.client,
);
const response = await this.grpcRequest(deleteModels, request);
const responseObject = response.toObject();
if (responseObject.status?.code !== StatusCode.SUCCESS) {
throw new Error(responseObject.status?.description);
}
console.info("\nModel Deleted\n%s", responseObject.status?.description);
}
/**
* Deletes a workflow for the user.
*
* @param workflowId - The workflow ID for the workflow to delete.
*
* @includeExample examples/app/deleteWorkflow.ts
*/
async deleteWorkflow({ workflowId }: { workflowId: string }): Promise<void> {
const request = new DeleteWorkflowsRequest();
request.setUserAppId(this.userAppId);
request.setIdsList([workflowId]);
const deleteWorkflows = promisifyGrpcCall(
this.STUB.client.deleteWorkflows,
this.STUB.client,
);
const response = await this.grpcRequest(deleteWorkflows, request);
const responseObject = response.toObject();
if (responseObject.status?.code !== StatusCode.SUCCESS) {
throw new Error(responseObject.status?.description);
}
console.info("\nWorkflow Deleted\n%s", responseObject.status?.description);
}
/**
* Deletes a module for the user.
*
* @param moduleId - The module ID for the module to delete.
*
* @includeExample examples/app/deleteModule.ts
*/
async deleteModule({ moduleId }: { moduleId: string }): Promise<void> {
const request = new DeleteModulesRequest();
request.setUserAppId(this.userAppId);
request.setIdsList([moduleId]);
const deleteModules = promisifyGrpcCall(
this.STUB.client.deleteModules,
this.STUB.client,
);
const response = await this.grpcRequest(deleteModules, request);
const responseObject = response.toObject();
if (responseObject.status?.code !== StatusCode.SUCCESS) {
throw new Error(responseObject.status?.description);
}
console.info("\nModule Deleted\n%s", responseObject.status?.description);
}
}