-
Notifications
You must be signed in to change notification settings - Fork 308
/
aibuildermodel-list.ts
73 lines (60 loc) · 1.9 KB
/
aibuildermodel-list.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
import { Logger } from '../../../../cli/Logger';
import GlobalOptions from '../../../../GlobalOptions';
import { odata } from '../../../../utils/odata';
import { powerPlatform } from '../../../../utils/powerPlatform';
import PowerPlatformCommand from '../../../base/PowerPlatformCommand';
import commands from '../../commands';
interface CommandArgs {
options: Options;
}
interface Options extends GlobalOptions {
environment: string;
asAdmin?: boolean;
}
class PpAiBuilderModelListCommand extends PowerPlatformCommand {
public get name(): string {
return commands.AIBUILDERMODEL_LIST;
}
public get description(): string {
return 'List available AI builder models in the specified Power Platform environment.';
}
public defaultProperties(): string[] | undefined {
return ['msdyn_name', 'msdyn_aimodelid', 'createdon', 'modifiedon'];
}
constructor() {
super();
this.#initTelemetry();
this.#initOptions();
}
#initTelemetry(): void {
this.telemetry.push((args: CommandArgs) => {
Object.assign(this.telemetryProperties, {
asAdmin: !!args.options.asAdmin
});
});
}
#initOptions(): void {
this.options.unshift(
{
option: '-e, --environment <environment>'
},
{
option: '--asAdmin'
}
);
}
public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
if (this.verbose) {
logger.logToStderr(`Retrieving available AI Builder models`);
}
try {
const dynamicsApiUrl = await powerPlatform.getDynamicsInstanceApiUrl(args.options.environment, args.options.asAdmin);
const aimodels = await odata.getAllItems<any>(`${dynamicsApiUrl}/api/data/v9.0/msdyn_aimodels?$filter=iscustomizable/Value eq true`);
logger.log(aimodels);
}
catch (err: any) {
this.handleRejectedODataJsonPromise(err);
}
}
}
module.exports = new PpAiBuilderModelListCommand();