@asterai/cli 0.6.1 → 1.0.0-alpha.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/bin/asterai +2 -0
- package/lib/index.js +49 -0
- package/package.json +29 -83
- package/README.md +0 -166
- package/bin/dev.cmd +0 -3
- package/bin/dev.js +0 -6
- package/bin/run.cmd +0 -3
- package/bin/run.js +0 -5
- package/dist/commands/auth.d.ts +0 -10
- package/dist/commands/auth.js +0 -17
- package/dist/commands/deploy.d.ts +0 -14
- package/dist/commands/deploy.js +0 -78
- package/dist/commands/init.d.ts +0 -10
- package/dist/commands/init.js +0 -21
- package/dist/commands/pkg.d.ts +0 -27
- package/dist/commands/pkg.js +0 -98
- package/dist/commands/query.d.ts +0 -13
- package/dist/commands/query.js +0 -93
- package/dist/config.d.ts +0 -2
- package/dist/config.js +0 -21
- package/dist/const.d.ts +0 -2
- package/dist/const.js +0 -2
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/init/rust/.gitignore +0 -2
- package/init/rust/Cargo.toml +0 -25
- package/init/rust/build.sh +0 -5
- package/init/rust/deploy.sh +0 -7
- package/init/rust/plugin.wit +0 -10
- package/init/rust/src/bindings.rs +0 -685
- package/init/rust/src/lib.rs +0 -16
- package/init/typescript/.gitignore +0 -10
- package/init/typescript/package.json +0 -26
- package/init/typescript/plugin.ts +0 -13
- package/init/typescript/plugin.wit +0 -11
- package/init/typescript/tsconfig.json +0 -8
- package/oclif.manifest.json +0 -235
package/bin/asterai
ADDED
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,92 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asterai/cli",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
3
|
+
"version": "1.0.0-alpha.1",
|
|
4
|
+
"description": "CLI for asterai - the portable AI compute platform",
|
|
5
5
|
"author": "asterai <support@asterai.io>",
|
|
6
|
-
"repository":
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"asterai",
|
|
10
|
-
"cli",
|
|
11
|
-
"oclif"
|
|
12
|
-
],
|
|
13
|
-
"license": "UNLICENSED",
|
|
14
|
-
"main": "dist/index.js",
|
|
15
|
-
"type": "module",
|
|
16
|
-
"bin": {
|
|
17
|
-
"asterai": "./bin/run.js"
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/asterai-io/asterai.git"
|
|
18
9
|
},
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
10
|
+
"homepage": "https://github.com/asterai-io/asterai",
|
|
11
|
+
"license": "Apache-2.0",
|
|
12
|
+
"bin": {
|
|
13
|
+
"asterai": "bin/asterai"
|
|
22
14
|
},
|
|
15
|
+
"main": "lib/index.js",
|
|
23
16
|
"files": [
|
|
24
|
-
"/
|
|
25
|
-
"/
|
|
26
|
-
"/oclif.manifest.json",
|
|
27
|
-
"/init",
|
|
28
|
-
"/init/rust/.gitignore",
|
|
29
|
-
"/init/typescript/.gitignore",
|
|
30
|
-
"!/init/rust/target",
|
|
31
|
-
"!/init/rust/Cargo.lock",
|
|
32
|
-
"!/init/typescript/build",
|
|
33
|
-
"!/init/typescript/node_modules",
|
|
34
|
-
"!/init/typescript/generated",
|
|
35
|
-
"!/init/typescript/pnpm-lock.yaml"
|
|
17
|
+
"bin/",
|
|
18
|
+
"lib/"
|
|
36
19
|
],
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
],
|
|
44
|
-
"topicSeparator": " ",
|
|
45
|
-
"topics": {}
|
|
46
|
-
},
|
|
47
|
-
"types": "dist/index.d.ts",
|
|
48
|
-
"dependencies": {
|
|
49
|
-
"@asterai/as-proto-gen": "^1.4.1",
|
|
50
|
-
"@asterai/client": "^0.1.1",
|
|
51
|
-
"@oclif/core": "^3",
|
|
52
|
-
"@oclif/plugin-help": "^6",
|
|
53
|
-
"@oclif/plugin-plugins": "^5",
|
|
54
|
-
"assemblyscript": "^0.27.27",
|
|
55
|
-
"axios": "^1.7.2",
|
|
56
|
-
"form-data": "^4.0.0",
|
|
57
|
-
"mustache": "^4.2.0",
|
|
58
|
-
"protobufjs": "^7.4.0",
|
|
59
|
-
"protobufjs-cli": "^1.1.3",
|
|
60
|
-
"uuid": "^11.0.2"
|
|
20
|
+
"optionalDependencies": {
|
|
21
|
+
"@asterai/cli-linux-x64": "1.0.0-alpha.1",
|
|
22
|
+
"@asterai/cli-linux-arm64": "1.0.0-alpha.1",
|
|
23
|
+
"@asterai/cli-darwin-x64": "1.0.0-alpha.1",
|
|
24
|
+
"@asterai/cli-darwin-arm64": "1.0.0-alpha.1",
|
|
25
|
+
"@asterai/cli-win32-x64": "1.0.0-alpha.1"
|
|
61
26
|
},
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"@oclif/test": "^4",
|
|
65
|
-
"@types/chai": "^4",
|
|
66
|
-
"@types/mocha": "^10",
|
|
67
|
-
"@types/mustache": "^4.2.5",
|
|
68
|
-
"@types/node": "^18",
|
|
69
|
-
"chai": "^4",
|
|
70
|
-
"eslint": "^8",
|
|
71
|
-
"eslint-config-oclif": "^5",
|
|
72
|
-
"eslint-config-oclif-typescript": "^3",
|
|
73
|
-
"eslint-config-prettier": "^9",
|
|
74
|
-
"husky": "^9.0.11",
|
|
75
|
-
"mocha": "^10",
|
|
76
|
-
"oclif": "^4",
|
|
77
|
-
"prettier": "^3.2.5",
|
|
78
|
-
"pretty-quick": "^4.0.0",
|
|
79
|
-
"shx": "^0.3.3",
|
|
80
|
-
"ts-node": "^10",
|
|
81
|
-
"typescript": "^5"
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18.0.0"
|
|
82
29
|
},
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
30
|
+
"keywords": [
|
|
31
|
+
"asterai",
|
|
32
|
+
"cli",
|
|
33
|
+
"wasm",
|
|
34
|
+
"webassembly",
|
|
35
|
+
"ai",
|
|
36
|
+
"agents"
|
|
37
|
+
]
|
|
38
|
+
}
|
package/README.md
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
# @asterai/cli
|
|
2
|
-
|
|
3
|
-
CLI for building and deploying asterai plugins
|
|
4
|
-
|
|
5
|
-
[](https://oclif.io)
|
|
6
|
-
[](https://npmjs.org/package/@asterai/cli)
|
|
7
|
-
[](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.1 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.1/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.1/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]
|
|
109
|
-
|
|
110
|
-
DESCRIPTION
|
|
111
|
-
Initialise a new plugin project
|
|
112
|
-
|
|
113
|
-
EXAMPLES
|
|
114
|
-
$ asterai init project-name
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
_See code: [src/commands/init.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.6.1/src/commands/init.ts)_
|
|
118
|
-
|
|
119
|
-
## `asterai pkg [INPUT]`
|
|
120
|
-
|
|
121
|
-
bundles the WIT into a binary WASM package
|
|
122
|
-
|
|
123
|
-
```
|
|
124
|
-
USAGE
|
|
125
|
-
$ asterai pkg [INPUT] [-o <value>] [-w <value>] [-e <value>]
|
|
126
|
-
|
|
127
|
-
ARGUMENTS
|
|
128
|
-
INPUT [default: plugin.wit] path to the plugin's WIT file
|
|
129
|
-
|
|
130
|
-
FLAGS
|
|
131
|
-
-e, --endpoint=<value> [default: https://api.asterai.io]
|
|
132
|
-
-o, --output=<value> [default: package.wasm] output file name for the binary WASM package
|
|
133
|
-
-w, --wit=<value> [default: package.wit] output package converted to the WIT format
|
|
134
|
-
|
|
135
|
-
DESCRIPTION
|
|
136
|
-
bundles the WIT into a binary WASM package
|
|
137
|
-
|
|
138
|
-
EXAMPLES
|
|
139
|
-
$ asterai pkg
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
_See code: [src/commands/pkg.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.6.1/src/commands/pkg.ts)_
|
|
143
|
-
|
|
144
|
-
## `asterai query`
|
|
145
|
-
|
|
146
|
-
query an asterai app interactively
|
|
147
|
-
|
|
148
|
-
```
|
|
149
|
-
USAGE
|
|
150
|
-
$ asterai query -a <value> -k <value> [-s] [-e <value>]
|
|
151
|
-
|
|
152
|
-
FLAGS
|
|
153
|
-
-a, --app=<value> (required)
|
|
154
|
-
-e, --endpoint=<value> [default: https://api.asterai.io]
|
|
155
|
-
-k, --key=<value> (required) app query key
|
|
156
|
-
-s, --staging
|
|
157
|
-
|
|
158
|
-
DESCRIPTION
|
|
159
|
-
query an asterai app interactively
|
|
160
|
-
|
|
161
|
-
EXAMPLES
|
|
162
|
-
$ asterai query
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
_See code: [src/commands/query.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.6.1/src/commands/query.ts)_
|
|
166
|
-
<!-- commandsstop -->
|
package/bin/dev.cmd
DELETED
package/bin/dev.js
DELETED
package/bin/run.cmd
DELETED
package/bin/run.js
DELETED
package/dist/commands/auth.d.ts
DELETED
|
@@ -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
|
-
}
|
package/dist/commands/auth.js
DELETED
|
@@ -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
|
-
}
|
package/dist/commands/deploy.js
DELETED
|
@@ -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
|
-
};
|
package/dist/commands/init.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Command } from "@oclif/core";
|
|
2
|
-
export default class Codegen extends Command {
|
|
3
|
-
static args: {
|
|
4
|
-
outDir: 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
|
-
}
|
package/dist/commands/init.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Args, Command } 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 = path.join(__dirname, "../../asterai-init-plugin");
|
|
7
|
-
export default class Codegen extends Command {
|
|
8
|
-
static args = {
|
|
9
|
-
outDir: Args.string({
|
|
10
|
-
default: "plugin",
|
|
11
|
-
}),
|
|
12
|
-
};
|
|
13
|
-
static description = "Initialise a new plugin project";
|
|
14
|
-
static examples = [`<%= config.bin %> <%= command.id %> project-name`];
|
|
15
|
-
static flags = {};
|
|
16
|
-
async run() {
|
|
17
|
-
const { args } = await this.parse(Codegen);
|
|
18
|
-
const outDir = path.resolve(args.outDir);
|
|
19
|
-
fs.cpSync(SOURCE_DIR, outDir, { recursive: true });
|
|
20
|
-
}
|
|
21
|
-
}
|
package/dist/commands/pkg.d.ts
DELETED
|
@@ -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>;
|
package/dist/commands/pkg.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { Args, Command, Flags } from "@oclif/core";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import fs from "fs/promises";
|
|
4
|
-
import fsSync from "fs";
|
|
5
|
-
import { BASE_API_URL } from "../const.js";
|
|
6
|
-
import axios from "axios";
|
|
7
|
-
import FormData from "form-data";
|
|
8
|
-
import { getConfigValue } from "../config.js";
|
|
9
|
-
export default class Pkg extends Command {
|
|
10
|
-
static args = {
|
|
11
|
-
input: Args.string({
|
|
12
|
-
default: "plugin.wit",
|
|
13
|
-
description: "path to the plugin's WIT file",
|
|
14
|
-
}),
|
|
15
|
-
};
|
|
16
|
-
static flags = {
|
|
17
|
-
output: Flags.string({
|
|
18
|
-
char: "o",
|
|
19
|
-
default: "package.wasm",
|
|
20
|
-
description: "output file name for the binary WASM package",
|
|
21
|
-
}),
|
|
22
|
-
wit: Flags.string({
|
|
23
|
-
char: "w",
|
|
24
|
-
default: "package.wit",
|
|
25
|
-
description: "output package converted to the WIT format",
|
|
26
|
-
}),
|
|
27
|
-
endpoint: Flags.string({
|
|
28
|
-
char: "e",
|
|
29
|
-
default: BASE_API_URL,
|
|
30
|
-
}),
|
|
31
|
-
};
|
|
32
|
-
static description = "bundles the WIT into a binary WASM package";
|
|
33
|
-
static examples = [`<%= config.bin %> <%= command.id %>`];
|
|
34
|
-
async run() {
|
|
35
|
-
const { args, flags } = await this.parse(Pkg);
|
|
36
|
-
await pkg(args, flags);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
export const pkg = async (args, flags) => {
|
|
40
|
-
const witPath = path.resolve(args.input);
|
|
41
|
-
if (!fsSync.existsSync(witPath)) {
|
|
42
|
-
throw new Error(`WIT file not found at ${witPath}`);
|
|
43
|
-
}
|
|
44
|
-
const baseDir = path.dirname(witPath);
|
|
45
|
-
const outputFile = path.join(baseDir, flags.output);
|
|
46
|
-
const form = new FormData();
|
|
47
|
-
form.append("package.wit", await fs.readFile(witPath));
|
|
48
|
-
const response = await axios({
|
|
49
|
-
url: `${flags.endpoint}/v1/pkg`,
|
|
50
|
-
method: "post",
|
|
51
|
-
data: form,
|
|
52
|
-
headers: {
|
|
53
|
-
Authorization: getConfigValue("key"),
|
|
54
|
-
...form.getHeaders(),
|
|
55
|
-
},
|
|
56
|
-
responseType: "arraybuffer",
|
|
57
|
-
}).catch(catchAxiosError);
|
|
58
|
-
validateResponseStatus(response.status);
|
|
59
|
-
await fs.writeFile(outputFile, Buffer.from(response.data), {
|
|
60
|
-
encoding: "binary",
|
|
61
|
-
});
|
|
62
|
-
if (flags.wit) {
|
|
63
|
-
await wasm2wit(flags.endpoint, outputFile, path.join(baseDir, flags.wit));
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
outputFile,
|
|
67
|
-
witPath,
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
const wasm2wit = async (endpoint, inputFilePath, outputFilePath) => {
|
|
71
|
-
const form = new FormData();
|
|
72
|
-
form.append("package.wasm", await fs.readFile(inputFilePath));
|
|
73
|
-
const response = await axios({
|
|
74
|
-
url: `${endpoint}/v1/wasm2wit`,
|
|
75
|
-
method: "post",
|
|
76
|
-
data: form,
|
|
77
|
-
headers: {
|
|
78
|
-
Authorization: getConfigValue("key"),
|
|
79
|
-
...form.getHeaders(),
|
|
80
|
-
},
|
|
81
|
-
responseType: "text",
|
|
82
|
-
});
|
|
83
|
-
validateResponseStatus(response.status);
|
|
84
|
-
await fs.writeFile(outputFilePath, response.data, { encoding: "utf8" });
|
|
85
|
-
};
|
|
86
|
-
const validateResponseStatus = (status) => {
|
|
87
|
-
if (status < 200 || status >= 300) {
|
|
88
|
-
throw new Error("request failed");
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
const catchAxiosError = (error) => {
|
|
92
|
-
const data = error.response?.data?.toString() ?? "";
|
|
93
|
-
if (axios.isAxiosError(error) && data.length > 0) {
|
|
94
|
-
const errorMessage = data.replace(/\\n/g, "\n");
|
|
95
|
-
throw new Error(`Request failed: ${errorMessage}`);
|
|
96
|
-
}
|
|
97
|
-
throw new Error("Request failed");
|
|
98
|
-
};
|
package/dist/commands/query.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Command } from "@oclif/core";
|
|
2
|
-
export default class Query extends Command {
|
|
3
|
-
static args: {};
|
|
4
|
-
static description: string;
|
|
5
|
-
static examples: string[];
|
|
6
|
-
static flags: {
|
|
7
|
-
app: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
8
|
-
key: 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
|
-
endpoint: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
11
|
-
};
|
|
12
|
-
run(): Promise<void>;
|
|
13
|
-
}
|