@choiceopen/automation-plugin-cli 0.0.1

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/README.md ADDED
@@ -0,0 +1,274 @@
1
+ automation-plugin-cli
2
+ =================
3
+
4
+ A command-line utility for building and publishing Choiceform Automation Plugin.
5
+
6
+
7
+ [![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)
8
+ [![Version](https://img.shields.io/npm/v/automation-plugin-cli.svg)](https://npmjs.org/package/automation-plugin-cli)
9
+ [![Downloads/week](https://img.shields.io/npm/dw/automation-plugin-cli.svg)](https://npmjs.org/package/automation-plugin-cli)
10
+
11
+
12
+ <!-- toc -->
13
+ * [Usage](#usage)
14
+ * [Commands](#commands)
15
+ <!-- tocstop -->
16
+ # Usage
17
+ <!-- usage -->
18
+ ```sh-session
19
+ $ npm install -g @choiceopen/automation-plugin-cli
20
+ $ automation COMMAND
21
+ running command...
22
+ $ automation (--version)
23
+ @choiceopen/automation-plugin-cli/0.0.1 darwin-arm64 node-v24.12.0
24
+ $ automation --help [COMMAND]
25
+ USAGE
26
+ $ automation COMMAND
27
+ ...
28
+ ```
29
+ <!-- usagestop -->
30
+ # Commands
31
+ <!-- commands -->
32
+ * [`automation auth login`](#automation-auth-login)
33
+ * [`automation autocomplete [SHELL]`](#automation-autocomplete-shell)
34
+ * [`automation help [COMMAND]`](#automation-help-command)
35
+ * [`automation plugin checksum [FILE]`](#automation-plugin-checksum-file)
36
+ * [`automation plugin init`](#automation-plugin-init)
37
+ * [`automation plugin pack [FILE]`](#automation-plugin-pack-file)
38
+ * [`automation plugin permission [FILE]`](#automation-plugin-permission-file)
39
+ * [`automation plugin run [FILE]`](#automation-plugin-run-file)
40
+ * [`automation version`](#automation-version)
41
+
42
+ ## `automation auth login`
43
+
44
+ Uses device authorization flow to login with your Choiceform account by following these steps:
45
+
46
+ ```
47
+ USAGE
48
+ $ automation auth login
49
+
50
+ DESCRIPTION
51
+ Uses device authorization flow to login with your Choiceform account by following these steps:
52
+
53
+ 1. Request a validation code automatically
54
+ 2. Show the validation code and a verification URL to the user
55
+ 3. Open the verification URL in the user's browser and paste the verification code
56
+ 4. Submit the validation code to complete the device authorization flow
57
+
58
+ EXAMPLES
59
+ Login by using device authorization flow
60
+
61
+ $ automation auth login
62
+ ```
63
+
64
+ _See code: [src/commands/auth/login.ts](https://github.com/choice-open/automation-plugin-cli/blob/v0.0.1/src/commands/auth/login.ts)_
65
+
66
+ ## `automation autocomplete [SHELL]`
67
+
68
+ Display autocomplete installation instructions.
69
+
70
+ ```
71
+ USAGE
72
+ $ automation autocomplete [SHELL] [-r]
73
+
74
+ ARGUMENTS
75
+ [SHELL] (zsh|bash|powershell) Shell type
76
+
77
+ FLAGS
78
+ -r, --refresh-cache Refresh cache (ignores displaying instructions)
79
+
80
+ DESCRIPTION
81
+ Display autocomplete installation instructions.
82
+
83
+ EXAMPLES
84
+ $ automation autocomplete
85
+
86
+ $ automation autocomplete bash
87
+
88
+ $ automation autocomplete zsh
89
+
90
+ $ automation autocomplete powershell
91
+
92
+ $ automation autocomplete --refresh-cache
93
+ ```
94
+
95
+ _See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v3.2.39/src/commands/autocomplete/index.ts)_
96
+
97
+ ## `automation help [COMMAND]`
98
+
99
+ Display help for automation.
100
+
101
+ ```
102
+ USAGE
103
+ $ automation help [COMMAND...] [-n]
104
+
105
+ ARGUMENTS
106
+ [COMMAND...] Command to show help for.
107
+
108
+ FLAGS
109
+ -n, --nested-commands Include all nested commands in the output.
110
+
111
+ DESCRIPTION
112
+ Display help for automation.
113
+ ```
114
+
115
+ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.2.36/src/commands/help.ts)_
116
+
117
+ ## `automation plugin checksum [FILE]`
118
+
119
+ describe the command here
120
+
121
+ ```
122
+ USAGE
123
+ $ automation plugin checksum [FILE] [-f] [-n <value>]
124
+
125
+ ARGUMENTS
126
+ [FILE] file to read
127
+
128
+ FLAGS
129
+ -f, --force
130
+ -n, --name=<value> name to print
131
+
132
+ DESCRIPTION
133
+ describe the command here
134
+
135
+ EXAMPLES
136
+ $ automation plugin checksum
137
+ ```
138
+
139
+ _See code: [src/commands/plugin/checksum.ts](https://github.com/choice-open/automation-plugin-cli/blob/v0.0.1/src/commands/plugin/checksum.ts)_
140
+
141
+ ## `automation plugin init`
142
+
143
+ Initialize a new plugin with step-by-step interactive instructions.
144
+
145
+ ```
146
+ USAGE
147
+ $ automation plugin init [-i] [-n my-awesome-plugin] [-d Descriptive
148
+ text...] [-a John Doe] [-e john.doe@example.com] [-u <value>] [--locales en_US|zh_Hans|ja_JP...] [-l
149
+ elixir|python|typescript] [-t extension|llm|tool|trigger] [-p endpoints:register|model:call_llm|model:call_embedding
150
+ |model:call_moderation|model:call_rerank|model:call_stt|model:call_tts|storage:kv|tools:invoke...]
151
+
152
+ FLAGS
153
+ -a, --author=John Doe Author name
154
+ -d, --description=Descriptive text... Short description
155
+ -e, --email=john.doe@example.com Author email address
156
+ -i, --[no-]interactive Use interactive mode (by default)
157
+ -l, --language=<option> Programming language to use for plugin development
158
+ <options: elixir|python|typescript>
159
+ -n, --name=my-awesome-plugin Plugin name
160
+ -p, --permissions=<option>... Permissions required by the plugin
161
+ <options:
162
+ endpoints:register|model:call_llm|model:call_embedding|model:call_moderation|mo
163
+ del:call_rerank|model:call_stt|model:call_tts|storage:kv|tools:invoke>
164
+ -t, --type=<option> Plugin type
165
+ <options: extension|llm|tool|trigger>
166
+ -u, --url=<value> Repository URL
167
+ --locales=<option>... Provide READMEs in which languages
168
+ <options: en_US|zh_Hans|ja_JP>
169
+
170
+ DESCRIPTION
171
+ Initialize a new plugin with step-by-step interactive instructions.
172
+
173
+ Providing required flags skips interactive flow and completes initialization in one go.
174
+
175
+ EXAMPLES
176
+ Start with interactive initialization:
177
+
178
+ $ automation plugin init
179
+ ```
180
+
181
+ _See code: [src/commands/plugin/init.ts](https://github.com/choice-open/automation-plugin-cli/blob/v0.0.1/src/commands/plugin/init.ts)_
182
+
183
+ ## `automation plugin pack [FILE]`
184
+
185
+ describe the command here
186
+
187
+ ```
188
+ USAGE
189
+ $ automation plugin pack [FILE] [-f] [-n <value>]
190
+
191
+ ARGUMENTS
192
+ [FILE] file to read
193
+
194
+ FLAGS
195
+ -f, --force
196
+ -n, --name=<value> name to print
197
+
198
+ DESCRIPTION
199
+ describe the command here
200
+
201
+ EXAMPLES
202
+ $ automation plugin pack
203
+ ```
204
+
205
+ _See code: [src/commands/plugin/pack.ts](https://github.com/choice-open/automation-plugin-cli/blob/v0.0.1/src/commands/plugin/pack.ts)_
206
+
207
+ ## `automation plugin permission [FILE]`
208
+
209
+ describe the command here
210
+
211
+ ```
212
+ USAGE
213
+ $ automation plugin permission [FILE] [-f] [-n <value>]
214
+
215
+ ARGUMENTS
216
+ [FILE] file to read
217
+
218
+ FLAGS
219
+ -f, --force
220
+ -n, --name=<value> name to print
221
+
222
+ DESCRIPTION
223
+ describe the command here
224
+
225
+ EXAMPLES
226
+ $ automation plugin permission
227
+ ```
228
+
229
+ _See code: [src/commands/plugin/permission.ts](https://github.com/choice-open/automation-plugin-cli/blob/v0.0.1/src/commands/plugin/permission.ts)_
230
+
231
+ ## `automation plugin run [FILE]`
232
+
233
+ describe the command here
234
+
235
+ ```
236
+ USAGE
237
+ $ automation plugin run [FILE] [-f] [-n <value>]
238
+
239
+ ARGUMENTS
240
+ [FILE] file to read
241
+
242
+ FLAGS
243
+ -f, --force
244
+ -n, --name=<value> name to print
245
+
246
+ DESCRIPTION
247
+ describe the command here
248
+
249
+ EXAMPLES
250
+ $ automation plugin run
251
+ ```
252
+
253
+ _See code: [src/commands/plugin/run.ts](https://github.com/choice-open/automation-plugin-cli/blob/v0.0.1/src/commands/plugin/run.ts)_
254
+
255
+ ## `automation version`
256
+
257
+ ```
258
+ USAGE
259
+ $ automation version [--json] [--verbose]
260
+
261
+ FLAGS
262
+ --verbose Show additional information about the CLI.
263
+
264
+ GLOBAL FLAGS
265
+ --json Format output as json.
266
+
267
+ FLAG DESCRIPTIONS
268
+ --verbose Show additional information about the CLI.
269
+
270
+ Additionally shows the architecture, node version, operating system, and versions of plugins that the CLI is using.
271
+ ```
272
+
273
+ _See code: [@oclif/plugin-version](https://github.com/oclif/plugin-version/blob/v2.2.36/src/commands/version.ts)_
274
+ <!-- commandsstop -->
package/bin/dev.cmd ADDED
@@ -0,0 +1,3 @@
1
+ @echo off
2
+
3
+ node --loader ts-node/esm --no-warnings=ExperimentalWarning "%~dp0\dev" %*
package/bin/dev.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env -S node --loader ts-node/esm --disable-warning=DeprecationWarning --disable-warning=ExperimentalWarning --trace-deprecation
2
+
3
+ import { execute } from "@oclif/core"
4
+
5
+ await execute({ development: true, dir: import.meta.url })
package/bin/run.cmd ADDED
@@ -0,0 +1,3 @@
1
+ @echo off
2
+
3
+ node "%~dp0\run" %*
package/bin/run.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { execute } from "@oclif/core"
4
+
5
+ await execute({ dir: import.meta.url })
@@ -0,0 +1,11 @@
1
+ import { Command } from "@oclif/core";
2
+ export default class Auth extends Command {
3
+ static description: string;
4
+ static enableJsonFlag: boolean;
5
+ static examples: {
6
+ command: string;
7
+ description: string;
8
+ }[];
9
+ static hidden: boolean;
10
+ run(): Promise<void>;
11
+ }
@@ -0,0 +1,15 @@
1
+ import { Command } from "@oclif/core";
2
+ export default class Auth extends Command {
3
+ static description = "Manages your plugin via subcommands";
4
+ static enableJsonFlag = true;
5
+ static examples = [
6
+ {
7
+ command: "<%= config.bin %> help <%= command.id %> [COMMAND]",
8
+ description: "Check help for each individual sub-command",
9
+ },
10
+ ];
11
+ static hidden = true;
12
+ async run() {
13
+ await this.config.runCommand("help", ["auth"]);
14
+ }
15
+ }
@@ -0,0 +1,15 @@
1
+ import { Command } from "@oclif/core";
2
+ export default class AuthLogin extends Command {
3
+ static description: string;
4
+ static examples: {
5
+ command: string;
6
+ description: string;
7
+ }[];
8
+ static flags: {};
9
+ private pollingInterval;
10
+ private client_id;
11
+ private grant_type;
12
+ run(): Promise<void>;
13
+ private requestDeviceCode;
14
+ private pollForToken;
15
+ }
@@ -0,0 +1,115 @@
1
+ import confirm from "@inquirer/confirm";
2
+ import { Command } from "@oclif/core";
3
+ import { colorize } from "@oclif/core/ux";
4
+ import { assert } from "es-toolkit";
5
+ import open from "open";
6
+ import { dedent } from "ts-dedent";
7
+ import yoctoSpinner from "yocto-spinner";
8
+ import * as configStore from "../../utils/config.js";
9
+ export default class AuthLogin extends Command {
10
+ static description = dedent `
11
+ Uses device authorization flow to login with your Choiceform account by following these steps:
12
+
13
+ 1. Request a validation code automatically
14
+ 2. Show the validation code and a verification URL to the user
15
+ 3. Open the verification URL in the user's browser and paste the verification code
16
+ 4. Submit the validation code to complete the device authorization flow
17
+ `;
18
+ static examples = [
19
+ {
20
+ command: "<%= config.bin %> <%= command.id %>",
21
+ description: "Login by using device authorization flow",
22
+ },
23
+ ];
24
+ static flags = {};
25
+ pollingInterval = 5;
26
+ client_id = "automation_plugin_cli";
27
+ grant_type = "urn:ietf:params:oauth:grant-type:device_code";
28
+ async run() {
29
+ await this.parse(AuthLogin);
30
+ const config = await configStore.load();
31
+ assert(config.auth?.endpoint, "Auth endpoint is required");
32
+ const payload = await this.requestDeviceCode(config.auth.endpoint);
33
+ this.log(colorize("yellowBright", "Starting device authorization flow...\n"));
34
+ this.log(colorize("bold", colorize("gray", "Verification URL : ")), payload.verification_uri);
35
+ this.log(colorize("bold", colorize("gray", "Verification Code: ")), `${payload.user_code}\n`);
36
+ const autoOpen = await confirm({
37
+ message: dedent `
38
+ Do you want to open the verification URL in your browser automatically?
39
+ If not, you can manually open the URL and paste the code.
40
+ `,
41
+ });
42
+ if (autoOpen) {
43
+ await open(payload.verification_uri_complete);
44
+ }
45
+ const spinner = yoctoSpinner({ text: "Polling for token..." }).start();
46
+ const result = (await this.pollForToken(payload.device_code, spinner));
47
+ await configStore.update({ auth: { access_token: result.access_token } });
48
+ const session = await fetch(`${config.auth.endpoint}/v1/auth/get-session`, {
49
+ headers: {
50
+ "Content-Type": "application/json",
51
+ "User-Agent": "Choiceform (Automation Plugin CLI)",
52
+ Authorization: `Bearer ${result.access_token}`,
53
+ },
54
+ }).then((response) => response.json());
55
+ this.log(colorize("greenBright", dedent `
56
+ Welcome back, ${session.user.name} <${session.user.email}>!
57
+ To create a new plugin, you can use the following command:
58
+ \`${colorize("bold", colorize("yellowBright", "automation plugin init"))}\`
59
+ `));
60
+ }
61
+ async requestDeviceCode(endpoint) {
62
+ const response = await fetch(`${endpoint}/v1/auth/device/code`, {
63
+ method: "POST",
64
+ headers: {
65
+ "Content-Type": "application/json",
66
+ "User-Agent": "Choiceform (Automation Plugin CLI)",
67
+ },
68
+ body: JSON.stringify({ client_id: this.client_id }),
69
+ });
70
+ return (await response.json());
71
+ }
72
+ async pollForToken(device_code, spinner) {
73
+ return new Promise((resolve) => {
74
+ const poll = async () => {
75
+ const response = await fetch("http://localhost:5001/v1/auth/device/token", {
76
+ method: "POST",
77
+ headers: {
78
+ "Content-Type": "application/json",
79
+ "User-Agent": "Choiceform (Automation Plugin CLI)",
80
+ },
81
+ body: JSON.stringify({
82
+ grant_type: this.grant_type,
83
+ client_id: this.client_id,
84
+ device_code,
85
+ }),
86
+ });
87
+ const payload = (await response.json());
88
+ if (payload.error) {
89
+ switch (payload.error) {
90
+ case "authorization_pending":
91
+ setTimeout(poll, this.pollingInterval * 1000);
92
+ break;
93
+ case "slow_down":
94
+ this.pollingInterval += 5;
95
+ break;
96
+ case "access_denied":
97
+ spinner.error("Access was denied by the user");
98
+ return process.exit(0);
99
+ case "expired_token":
100
+ spinner.error("The device code has expired. Please try again.");
101
+ return process.exit(0);
102
+ default:
103
+ spinner.error(`Error: ${payload.error_description}`);
104
+ return process.exit(1);
105
+ }
106
+ }
107
+ else {
108
+ spinner.success("Token acquired successfully\n");
109
+ resolve(payload);
110
+ }
111
+ };
112
+ setTimeout(poll, this.pollingInterval * 1000);
113
+ });
114
+ }
115
+ }
@@ -0,0 +1,13 @@
1
+ import { Command } from "@oclif/core";
2
+ export default class PluginChecksum extends Command {
3
+ static args: {
4
+ file: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
5
+ };
6
+ static description: string;
7
+ static examples: string[];
8
+ static flags: {
9
+ force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
+ name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ };
12
+ run(): Promise<void>;
13
+ }
@@ -0,0 +1,22 @@
1
+ import { Args, Command, Flags } from "@oclif/core";
2
+ export default class PluginChecksum extends Command {
3
+ static args = {
4
+ file: Args.string({ description: "file to read" }),
5
+ };
6
+ static description = "describe the command here";
7
+ static examples = ["<%= config.bin %> <%= command.id %>"];
8
+ static flags = {
9
+ // flag with no value (-f, --force)
10
+ force: Flags.boolean({ char: "f" }),
11
+ // flag with a value (-n, --name=VALUE)
12
+ name: Flags.string({ char: "n", description: "name to print" }),
13
+ };
14
+ async run() {
15
+ const { args, flags } = await this.parse(PluginChecksum);
16
+ const name = flags.name ?? "world";
17
+ this.log(`hello ${name} from /Users/nightire/Code/github.com/choice-open/automation-plugin-cli/src/commands/plugin/checksum.ts`);
18
+ if (args.file && flags.force) {
19
+ this.log(`you input --force and --file: ${args.file}`);
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,11 @@
1
+ import { Command } from "@oclif/core";
2
+ export default class Plugin extends Command {
3
+ static description: string;
4
+ static enableJsonFlag: boolean;
5
+ static examples: {
6
+ command: string;
7
+ description: string;
8
+ }[];
9
+ static hidden: boolean;
10
+ run(): Promise<void>;
11
+ }
@@ -0,0 +1,15 @@
1
+ import { Command } from "@oclif/core";
2
+ export default class Plugin extends Command {
3
+ static description = "Manages your plugin via subcommands";
4
+ static enableJsonFlag = true;
5
+ static examples = [
6
+ {
7
+ command: "<%= config.bin %> help <%= command.id %> [COMMAND]",
8
+ description: "Check help for each individual sub-command",
9
+ },
10
+ ];
11
+ static hidden = true;
12
+ async run() {
13
+ await this.config.runCommand("help", ["plugin"]);
14
+ }
15
+ }
@@ -0,0 +1,33 @@
1
+ import { Command } from "@oclif/core";
2
+ export default class PluginInit extends Command {
3
+ static description: string;
4
+ static examples: {
5
+ command: string;
6
+ description: string;
7
+ }[];
8
+ static flags: {
9
+ interactive: import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
+ name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ description: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
12
+ author: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
13
+ email: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
14
+ url: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
15
+ locales: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
+ language: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
17
+ type: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
+ permissions: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
19
+ };
20
+ run(): Promise<void>;
21
+ private nameIsValid;
22
+ private reconcileInteractiveFlag;
23
+ private runInteractiveMode;
24
+ private collectName;
25
+ private collectDescription;
26
+ private collectAuthor;
27
+ private collectEmail;
28
+ private collectURL;
29
+ private collectLocales;
30
+ private collectLanguage;
31
+ private collectType;
32
+ private collectPermissions;
33
+ }