@asterai/cli 0.6.2 → 1.0.0-alpha.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/bin/asterai ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require('../lib/index.js');
package/lib/index.js ADDED
@@ -0,0 +1,49 @@
1
+ const { spawnSync } = require("child_process");
2
+ const { platform, arch } = process;
3
+
4
+ // Map Node.js platform/arch to the package names.
5
+ const PLATFORMS = {
6
+ "darwin-arm64": "@asterai/cli-darwin-arm64",
7
+ "darwin-x64": "@asterai/cli-darwin-x64",
8
+ "linux-arm64": "@asterai/cli-linux-arm64",
9
+ "linux-x64": "@asterai/cli-linux-x64",
10
+ "win32-x64": "@asterai/cli-win32-x64",
11
+ };
12
+
13
+ function getBinaryPath() {
14
+ const key = `${platform}-${arch}`;
15
+ const packageName = PLATFORMS[key];
16
+
17
+ if (!packageName) {
18
+ console.error(
19
+ `Unsupported platform: ${platform}-${arch}\n` +
20
+ `Supported platforms: ${Object.keys(PLATFORMS).join(", ")}`
21
+ );
22
+ process.exit(1);
23
+ }
24
+
25
+ try {
26
+ const binName = platform === "win32" ? "asterai.exe" : "asterai";
27
+ return require.resolve(`${packageName}/bin/${binName}`);
28
+ } catch (e) {
29
+ console.error(
30
+ `Could not find asterai binary for ${platform}-${arch}.\n` +
31
+ `Package ${packageName} may not be installed.\n` +
32
+ `Try reinstalling: npm install -g @asterai/cli`
33
+ );
34
+ process.exit(1);
35
+ }
36
+ }
37
+
38
+ const binaryPath = getBinaryPath();
39
+ const result = spawnSync(binaryPath, process.argv.slice(2), {
40
+ stdio: "inherit",
41
+ env: process.env,
42
+ });
43
+
44
+ if (result.error) {
45
+ console.error("Failed to run asterai:", result.error.message);
46
+ process.exit(1);
47
+ }
48
+
49
+ process.exit(result.status ?? 1);
package/package.json CHANGED
@@ -1,95 +1,38 @@
1
1
  {
2
2
  "name": "@asterai/cli",
3
- "description": "CLI for building and deploying asterai plugins",
4
- "version": "0.6.2",
3
+ "version": "1.0.0-alpha.10",
4
+ "description": "CLI for asterai - the portable AI compute platform",
5
5
  "author": "asterai <support@asterai.io>",
6
- "repository": "asterai-io/asterai-sdk",
7
- "homepage": "https://github.com/asterai-io/asterai-sdk",
8
- "keywords": [
9
- "asterai",
10
- "cli",
11
- "oclif"
12
- ],
13
- "license": "UNLICENSED",
14
- "main": "dist/index.js",
15
- "type": "module",
16
- "scripts": {
17
- "prepare": "cd .. && husky cli/.husky",
18
- "build": "shx rm -rf dist && tsc -b",
19
- "lint": "eslint . --ext .ts",
20
- "postpack": "shx rm -f oclif.manifest.json",
21
- "posttest": "pnpm run lint",
22
- "prepack": "oclif manifest && oclif readme",
23
- "test": "mocha --forbid-only \"test/**/*.test.ts\"",
24
- "version": "oclif readme && git add README.md",
25
- "format": "prettier --write .",
26
- "format-staged": "pretty-quick --staged"
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/asterai-io/asterai.git"
27
9
  },
10
+ "homepage": "https://github.com/asterai-io/asterai",
11
+ "license": "Apache-2.0",
28
12
  "bin": {
29
- "asterai": "./bin/run.js"
30
- },
31
- "bugs": "https://github.com/asterai-io/asterai-sdk/issues",
32
- "engines": {
33
- "node": ">=18.0.0"
13
+ "asterai": "bin/asterai"
34
14
  },
15
+ "main": "lib/index.js",
35
16
  "files": [
36
- "/bin",
37
- "/dist",
38
- "/oclif.manifest.json",
39
- "/init",
40
- "/init/rust/.gitignore",
41
- "/init/typescript/.gitignore",
42
- "!/init/rust/target",
43
- "!/init/rust/Cargo.lock",
44
- "!/init/typescript/build",
45
- "!/init/typescript/node_modules",
46
- "!/init/typescript/generated",
47
- "!/init/typescript/pnpm-lock.yaml"
17
+ "bin/",
18
+ "lib/"
48
19
  ],
49
- "oclif": {
50
- "bin": "asterai",
51
- "dirname": "asterai",
52
- "commands": "./dist/commands",
53
- "plugins": [
54
- "@oclif/plugin-help"
55
- ],
56
- "topicSeparator": " ",
57
- "topics": {}
20
+ "optionalDependencies": {
21
+ "@asterai/cli-linux-x64": "1.0.0-alpha.10",
22
+ "@asterai/cli-linux-arm64": "1.0.0-alpha.10",
23
+ "@asterai/cli-darwin-x64": "1.0.0-alpha.10",
24
+ "@asterai/cli-darwin-arm64": "1.0.0-alpha.10",
25
+ "@asterai/cli-win32-x64": "1.0.0-alpha.10"
58
26
  },
59
- "types": "dist/index.d.ts",
60
- "dependencies": {
61
- "@asterai/as-proto-gen": "^1.4.1",
62
- "@asterai/client": "^0.1.1",
63
- "@oclif/core": "^3",
64
- "@oclif/plugin-help": "^6",
65
- "@oclif/plugin-plugins": "^5",
66
- "assemblyscript": "^0.27.27",
67
- "axios": "^1.7.2",
68
- "form-data": "^4.0.0",
69
- "mustache": "^4.2.0",
70
- "protobufjs": "^7.4.0",
71
- "protobufjs-cli": "^1.1.3",
72
- "uuid": "^11.0.2"
27
+ "engines": {
28
+ "node": ">=18.0.0"
73
29
  },
74
- "devDependencies": {
75
- "@oclif/prettier-config": "^0.2.1",
76
- "@oclif/test": "^4",
77
- "@types/chai": "^4",
78
- "@types/mocha": "^10",
79
- "@types/mustache": "^4.2.5",
80
- "@types/node": "^18",
81
- "chai": "^4",
82
- "eslint": "^8",
83
- "eslint-config-oclif": "^5",
84
- "eslint-config-oclif-typescript": "^3",
85
- "eslint-config-prettier": "^9",
86
- "husky": "^9.0.11",
87
- "mocha": "^10",
88
- "oclif": "^4",
89
- "prettier": "^3.2.5",
90
- "pretty-quick": "^4.0.0",
91
- "shx": "^0.3.3",
92
- "ts-node": "^10",
93
- "typescript": "^5"
94
- }
30
+ "keywords": [
31
+ "asterai",
32
+ "cli",
33
+ "wasm",
34
+ "webassembly",
35
+ "ai",
36
+ "agents"
37
+ ]
95
38
  }
package/README.md DELETED
@@ -1,170 +0,0 @@
1
- # @asterai/cli
2
-
3
- CLI for building and deploying asterai plugins
4
-
5
- [![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)
6
- [![Version](https://img.shields.io/npm/v/@asterai/cli.svg)](https://npmjs.org/package/@asterai/cli)
7
- [![Downloads/week](https://img.shields.io/npm/dw/@asterai/cli.svg)](https://npmjs.org/package/@asterai/cli)
8
-
9
- <!-- toc -->
10
- * [@asterai/cli](#asteraicli)
11
- * [Usage](#usage)
12
- * [Commands](#commands)
13
- <!-- tocstop -->
14
-
15
- # Usage
16
-
17
- <!-- usage -->
18
- ```sh-session
19
- $ npm install -g @asterai/cli
20
- $ asterai COMMAND
21
- running command...
22
- $ asterai (--version)
23
- @asterai/cli/0.6.2 linux-x64 node-v20.12.2
24
- $ asterai --help [COMMAND]
25
- USAGE
26
- $ asterai COMMAND
27
- ...
28
- ```
29
- <!-- usagestop -->
30
-
31
- # Commands
32
-
33
- <!-- commands -->
34
- * [`asterai auth KEY`](#asterai-auth-key)
35
- * [`asterai deploy`](#asterai-deploy)
36
- * [`asterai help [COMMAND]`](#asterai-help-command)
37
- * [`asterai init [OUTDIR]`](#asterai-init-outdir)
38
- * [`asterai pkg [INPUT]`](#asterai-pkg-input)
39
- * [`asterai query`](#asterai-query)
40
-
41
- ## `asterai auth KEY`
42
-
43
- authenticate to asterai
44
-
45
- ```
46
- USAGE
47
- $ asterai auth KEY
48
-
49
- DESCRIPTION
50
- authenticate to asterai
51
-
52
- EXAMPLES
53
- $ asterai auth
54
- ```
55
-
56
- _See code: [src/commands/auth.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.6.2/src/commands/auth.ts)_
57
-
58
- ## `asterai deploy`
59
-
60
- uploads a plugin to asterai
61
-
62
- ```
63
- USAGE
64
- $ asterai deploy [-a <value>] [-e <value>] [-s] [--plugin <value>] [--pkg <value>]
65
-
66
- FLAGS
67
- -a, --agent=<value> agent ID to immediately activate this plugin for
68
- -e, --endpoint=<value> [default: https://api.asterai.io]
69
- -s, --staging
70
- --pkg=<value> [default: package.wasm] package WASM path
71
- --plugin=<value> [default: plugin.wasm] plugin WASM path
72
-
73
- DESCRIPTION
74
- uploads a plugin to asterai
75
-
76
- EXAMPLES
77
- $ asterai deploy --app 66a46b12-b1a7-4b72-a64a-0e4fe21902b6
78
- ```
79
-
80
- _See code: [src/commands/deploy.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.6.2/src/commands/deploy.ts)_
81
-
82
- ## `asterai help [COMMAND]`
83
-
84
- Display help for asterai.
85
-
86
- ```
87
- USAGE
88
- $ asterai help [COMMAND...] [-n]
89
-
90
- ARGUMENTS
91
- COMMAND... Command to show help for.
92
-
93
- FLAGS
94
- -n, --nested-commands Include all nested commands in the output.
95
-
96
- DESCRIPTION
97
- Display help for asterai.
98
- ```
99
-
100
- _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.0.22/src/commands/help.ts)_
101
-
102
- ## `asterai init [OUTDIR]`
103
-
104
- Initialise a new plugin project
105
-
106
- ```
107
- USAGE
108
- $ asterai init [OUTDIR] [--typescript] [--rust]
109
-
110
- FLAGS
111
- --rust init a the plugin project in rust
112
- --typescript init a the plugin project in typescript
113
-
114
- DESCRIPTION
115
- Initialise a new plugin project
116
-
117
- EXAMPLES
118
- $ asterai init project-name
119
- ```
120
-
121
- _See code: [src/commands/init.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.6.2/src/commands/init.ts)_
122
-
123
- ## `asterai pkg [INPUT]`
124
-
125
- bundles the WIT into a binary WASM package
126
-
127
- ```
128
- USAGE
129
- $ asterai pkg [INPUT] [-o <value>] [-w <value>] [-e <value>]
130
-
131
- ARGUMENTS
132
- INPUT [default: plugin.wit] path to the plugin's WIT file
133
-
134
- FLAGS
135
- -e, --endpoint=<value> [default: https://api.asterai.io]
136
- -o, --output=<value> [default: package.wasm] output file name for the binary WASM package
137
- -w, --wit=<value> [default: package.wit] output package converted to the WIT format
138
-
139
- DESCRIPTION
140
- bundles the WIT into a binary WASM package
141
-
142
- EXAMPLES
143
- $ asterai pkg
144
- ```
145
-
146
- _See code: [src/commands/pkg.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.6.2/src/commands/pkg.ts)_
147
-
148
- ## `asterai query`
149
-
150
- query an asterai app interactively
151
-
152
- ```
153
- USAGE
154
- $ asterai query -a <value> -k <value> [-s] [-e <value>]
155
-
156
- FLAGS
157
- -a, --app=<value> (required)
158
- -e, --endpoint=<value> [default: https://api.asterai.io]
159
- -k, --key=<value> (required) app query key
160
- -s, --staging
161
-
162
- DESCRIPTION
163
- query an asterai app interactively
164
-
165
- EXAMPLES
166
- $ asterai query
167
- ```
168
-
169
- _See code: [src/commands/query.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.6.2/src/commands/query.ts)_
170
- <!-- commandsstop -->
package/bin/dev.cmd DELETED
@@ -1,3 +0,0 @@
1
- @echo off
2
-
3
- node --loader ts-node/esm --no-warnings=ExperimentalWarning "%~dp0\dev" %*
package/bin/dev.js DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning
2
-
3
- // eslint-disable-next-line n/shebang
4
- import { execute } from "@oclif/core";
5
-
6
- await execute({ development: true, dir: import.meta.url });
package/bin/run.cmd DELETED
@@ -1,3 +0,0 @@
1
- @echo off
2
-
3
- node "%~dp0\run" %*
package/bin/run.js DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { execute } from "@oclif/core";
4
-
5
- await execute({ dir: import.meta.url });
@@ -1,10 +0,0 @@
1
- import { Command } from "@oclif/core";
2
- export default class Auth extends Command {
3
- static args: {
4
- key: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
5
- };
6
- static description: string;
7
- static examples: string[];
8
- static flags: {};
9
- run(): Promise<void>;
10
- }
@@ -1,17 +0,0 @@
1
- import { Args, Command } from "@oclif/core";
2
- import { getConfigValue, setConfigValue } from "../config.js";
3
- export default class Auth extends Command {
4
- static args = {
5
- key: Args.string({
6
- required: true,
7
- }),
8
- };
9
- static description = "authenticate to asterai";
10
- static examples = [`<%= config.bin %> <%= command.id %>`];
11
- static flags = {};
12
- async run() {
13
- const { args } = await this.parse(Auth);
14
- setConfigValue("key", args.key);
15
- const value = getConfigValue("key");
16
- }
17
- }
@@ -1,14 +0,0 @@
1
- import { Command } from "@oclif/core";
2
- export default class Deploy extends Command {
3
- static args: {};
4
- static description: string;
5
- static examples: string[];
6
- static flags: {
7
- agent: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
8
- endpoint: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
9
- staging: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
10
- plugin: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
- pkg: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
12
- };
13
- run(): Promise<void>;
14
- }
@@ -1,78 +0,0 @@
1
- import { Command, Flags } from "@oclif/core";
2
- import fs from "fs";
3
- import FormData from "form-data";
4
- import axios from "axios";
5
- import { getConfigValue } from "../config.js";
6
- import { BASE_API_URL, BASE_API_URL_STAGING } from "../const.js";
7
- import path from "path";
8
- // If the input file doesn't exist, try looking into this dir.
9
- const RETRY_FIND_FILE_DIR = "build/";
10
- export default class Deploy extends Command {
11
- static args = {};
12
- static description = "uploads a plugin to asterai";
13
- static examples = [
14
- `<%= config.bin %> <%= command.id %> --app 66a46b12-b1a7-4b72-a64a-0e4fe21902b6`,
15
- ];
16
- static flags = {
17
- agent: Flags.string({
18
- char: "a",
19
- description: "agent ID to immediately activate this plugin for",
20
- required: false,
21
- }),
22
- endpoint: Flags.string({
23
- char: "e",
24
- default: BASE_API_URL,
25
- }),
26
- staging: Flags.boolean({
27
- char: "s",
28
- }),
29
- plugin: Flags.string({
30
- description: "plugin WASM path",
31
- default: "plugin.wasm",
32
- }),
33
- pkg: Flags.string({
34
- description: "package WASM path",
35
- default: "package.wasm",
36
- }),
37
- };
38
- async run() {
39
- const { flags } = await this.parse(Deploy);
40
- await deploy(flags);
41
- }
42
- }
43
- const deploy = async (flags) => {
44
- const form = new FormData();
45
- if (flags.agent) {
46
- form.append("agent_id", flags.agent);
47
- }
48
- const plugin = readFile(flags.plugin);
49
- const pkg = readFile(flags.pkg);
50
- form.append("plugin.wasm", plugin);
51
- form.append("package.wasm", pkg);
52
- const baseApiUrl = flags.staging ? BASE_API_URL_STAGING : flags.endpoint;
53
- await axios({
54
- url: `${baseApiUrl}/v1/plugin`,
55
- method: "put",
56
- data: form,
57
- headers: {
58
- Authorization: getConfigValue("key"),
59
- ...form.getHeaders(),
60
- },
61
- })
62
- .then(() => console.log("done"))
63
- .catch(logRequestError);
64
- };
65
- const logRequestError = (e) => {
66
- const info = e.response?.data ?? e;
67
- console.log("request error:", info);
68
- };
69
- const readFile = (relativePath) => {
70
- if (fs.existsSync(relativePath)) {
71
- return fs.readFileSync(relativePath);
72
- }
73
- const retryPath = path.join(RETRY_FIND_FILE_DIR, relativePath);
74
- if (fs.existsSync(retryPath)) {
75
- return fs.readFileSync(retryPath);
76
- }
77
- throw new Error(`file not found: ${relativePath}`);
78
- };
@@ -1,17 +0,0 @@
1
- import { Command } from "@oclif/core";
2
- export type InitFlags = {
3
- rust?: boolean;
4
- typescript?: boolean;
5
- };
6
- export default class Codegen extends Command {
7
- static args: {
8
- outDir: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
9
- };
10
- static description: string;
11
- static examples: string[];
12
- static flags: {
13
- typescript: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
14
- rust: import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
15
- };
16
- run(): Promise<void>;
17
- }
@@ -1,53 +0,0 @@
1
- import { Args, Command, Flags } from "@oclif/core";
2
- import path from "path";
3
- import fs from "fs";
4
- import url from "url";
5
- const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
6
- const SOURCE_DIR_TYPESCRIPT = path.join(__dirname, "../../init/typescript");
7
- const SOURCE_DIR_RUST = path.join(__dirname, "../../init/rust");
8
- export default class Codegen extends Command {
9
- static args = {
10
- outDir: Args.string({
11
- default: "plugin",
12
- }),
13
- };
14
- static description = "Initialise a new plugin project";
15
- static examples = [`<%= config.bin %> <%= command.id %> project-name`];
16
- static flags = {
17
- typescript: Flags.boolean({
18
- default: undefined,
19
- description: "init a the plugin project in typescript",
20
- }),
21
- rust: Flags.boolean({
22
- default: false,
23
- description: "init a the plugin project in rust",
24
- }),
25
- };
26
- async run() {
27
- const { args, flags } = await this.parse(Codegen);
28
- assertOneLanguageFlag([flags.typescript, flags.rust]);
29
- const outDir = path.resolve(args.outDir);
30
- const sourceDir = getSourceDirByFlag(flags);
31
- fs.cpSync(sourceDir, outDir, { recursive: true });
32
- }
33
- }
34
- const assertOneLanguageFlag = (flags) => {
35
- const undefinedCount = flags.reduce((acc, curr) => (curr === undefined ? acc + 1 : acc), 0);
36
- const trueCount = flags.reduce((acc, curr) => (curr ? acc + 1 : acc), 0);
37
- if (trueCount === 0 && undefinedCount !== 1) {
38
- throw new Error("one language flag must be set");
39
- }
40
- if (trueCount > 1) {
41
- throw new Error("only one language flag can be set");
42
- }
43
- };
44
- const getSourceDirByFlag = (flags) => {
45
- if (flags.rust) {
46
- return SOURCE_DIR_RUST;
47
- }
48
- // Typescript is the default option.
49
- if (flags.typescript === true || flags.typescript === undefined) {
50
- return SOURCE_DIR_TYPESCRIPT;
51
- }
52
- throw new Error("Invalid flags configuration.");
53
- };
@@ -1,27 +0,0 @@
1
- import { Command } from "@oclif/core";
2
- export type PkgArgs = {
3
- input: string;
4
- };
5
- export type PkgFlags = {
6
- endpoint: string;
7
- output: string;
8
- wit?: string;
9
- };
10
- export type PkgOutput = {
11
- outputFile: string;
12
- witPath: string;
13
- };
14
- export default class Pkg extends Command {
15
- static args: {
16
- input: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
17
- };
18
- static flags: {
19
- output: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
20
- wit: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
21
- endpoint: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
22
- };
23
- static description: string;
24
- static examples: string[];
25
- run(): Promise<void>;
26
- }
27
- export declare const pkg: (args: PkgArgs, flags: PkgFlags) => Promise<PkgOutput>;