@asterai/cli 0.6.2 → 1.0.0-alpha.2
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 +27 -84
- package/README.md +0 -170
- 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 -17
- package/dist/commands/init.js +0 -53
- 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/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/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 -248
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
|
-
}
|
package/dist/commands/query.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { Flags, Command } from "@oclif/core";
|
|
2
|
-
import readline from "node:readline";
|
|
3
|
-
import { AsteraiClient } from "@asterai/client";
|
|
4
|
-
import { v4 as uuidv4 } from "uuid";
|
|
5
|
-
const ANSI_COLORS = {
|
|
6
|
-
reset: "\x1b[0m",
|
|
7
|
-
bold: "\u001b[1m",
|
|
8
|
-
};
|
|
9
|
-
const USER_PREFIX = `${ANSI_COLORS.bold}user: ${ANSI_COLORS.reset}`;
|
|
10
|
-
const ASSISTANT_PREFIX = `${ANSI_COLORS.bold}assistant: ${ANSI_COLORS.reset}`;
|
|
11
|
-
const PRODUCTION_BASE_URL = "https://api.asterai.io";
|
|
12
|
-
const STAGING_BASE_URL = "https://staging.api.asterai.io";
|
|
13
|
-
export default class Query extends Command {
|
|
14
|
-
static args = {};
|
|
15
|
-
static description = "query an asterai app interactively";
|
|
16
|
-
static examples = [`<%= config.bin %> <%= command.id %>`];
|
|
17
|
-
static flags = {
|
|
18
|
-
app: Flags.string({
|
|
19
|
-
char: "a",
|
|
20
|
-
required: true,
|
|
21
|
-
}),
|
|
22
|
-
key: Flags.string({
|
|
23
|
-
char: "k",
|
|
24
|
-
required: true,
|
|
25
|
-
description: "app query key",
|
|
26
|
-
}),
|
|
27
|
-
staging: Flags.boolean({
|
|
28
|
-
char: "s",
|
|
29
|
-
}),
|
|
30
|
-
endpoint: Flags.string({
|
|
31
|
-
char: "e",
|
|
32
|
-
default: PRODUCTION_BASE_URL,
|
|
33
|
-
}),
|
|
34
|
-
};
|
|
35
|
-
async run() {
|
|
36
|
-
console.clear();
|
|
37
|
-
const { flags } = await this.parse(Query);
|
|
38
|
-
let output = "";
|
|
39
|
-
const addToOutput = (v) => {
|
|
40
|
-
output += v;
|
|
41
|
-
};
|
|
42
|
-
const apiBaseUrl = flags.staging ? STAGING_BASE_URL : flags.endpoint;
|
|
43
|
-
const client = new AsteraiClient({
|
|
44
|
-
appId: flags.app,
|
|
45
|
-
queryKey: flags.key,
|
|
46
|
-
apiBaseUrl,
|
|
47
|
-
});
|
|
48
|
-
const conversationId = uuidv4();
|
|
49
|
-
// Configure STDIN for when raw mode is enabled.
|
|
50
|
-
process.stdin.setEncoding("utf8");
|
|
51
|
-
process.stdin.on("data", key => {
|
|
52
|
-
if (key.toString() === "\u0003") {
|
|
53
|
-
process.stdout.write("\n");
|
|
54
|
-
process.exit();
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
const getUserInput = async () => {
|
|
58
|
-
addToOutput(USER_PREFIX);
|
|
59
|
-
const rl = readline.createInterface({
|
|
60
|
-
input: process.stdin,
|
|
61
|
-
output: process.stdout,
|
|
62
|
-
});
|
|
63
|
-
const input = await new Promise(resolve => rl.question(USER_PREFIX, i => resolve(i)));
|
|
64
|
-
rl.close();
|
|
65
|
-
// Enable raw mode to prevent STDIN from echoing in STDOUT.
|
|
66
|
-
process.stdin.setRawMode(true);
|
|
67
|
-
addToOutput(`${input}\r\n${ASSISTANT_PREFIX}`);
|
|
68
|
-
console.clear();
|
|
69
|
-
process.stdout.write(output);
|
|
70
|
-
const query = {
|
|
71
|
-
query: input,
|
|
72
|
-
conversationId,
|
|
73
|
-
};
|
|
74
|
-
const response = await client.query(query);
|
|
75
|
-
response.onToken(token => {
|
|
76
|
-
addToOutput(token);
|
|
77
|
-
process.stdout.write(token);
|
|
78
|
-
});
|
|
79
|
-
return new Promise(resolve => {
|
|
80
|
-
response.onEnd(() => {
|
|
81
|
-
addToOutput("\n");
|
|
82
|
-
process.stdout.write("\n");
|
|
83
|
-
// Disable raw mode to prepare for next user input.
|
|
84
|
-
process.stdin.setRawMode(false);
|
|
85
|
-
resolve(undefined);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
};
|
|
89
|
-
while (true) {
|
|
90
|
-
await getUserInput();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
package/dist/config.d.ts
DELETED
package/dist/config.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import os from "os";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
const CONFIG_PATH = path.join(os.homedir(), "/.asterai-cli.json");
|
|
5
|
-
const getConfig = () => {
|
|
6
|
-
let config;
|
|
7
|
-
try {
|
|
8
|
-
config = JSON.parse(fs.readFileSync(CONFIG_PATH).toString());
|
|
9
|
-
}
|
|
10
|
-
catch {
|
|
11
|
-
config = {};
|
|
12
|
-
}
|
|
13
|
-
return config;
|
|
14
|
-
};
|
|
15
|
-
export const getConfigValue = (key) => getConfig()[key];
|
|
16
|
-
export const setConfigValue = (key, value) => {
|
|
17
|
-
const config = getConfig();
|
|
18
|
-
config[key] = value;
|
|
19
|
-
const serialized = JSON.stringify(config);
|
|
20
|
-
fs.writeFileSync(CONFIG_PATH, serialized);
|
|
21
|
-
};
|
package/dist/const.d.ts
DELETED
package/dist/const.js
DELETED
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { run } from "@oclif/core";
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { run } from "@oclif/core";
|
package/init/rust/Cargo.toml
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
name = "plugin"
|
|
3
|
-
# Note that this version does not matter for the plugin,
|
|
4
|
-
# only the one in plugin.wit is used.
|
|
5
|
-
version = "0.0.0"
|
|
6
|
-
edition = "2021"
|
|
7
|
-
publish = false
|
|
8
|
-
|
|
9
|
-
[dependencies]
|
|
10
|
-
wit-bindgen-rt = { version = "0.39.0", features = ["bitflags"] }
|
|
11
|
-
|
|
12
|
-
[lib]
|
|
13
|
-
crate-type = ["cdylib"]
|
|
14
|
-
|
|
15
|
-
[profile.release]
|
|
16
|
-
codegen-units = 1
|
|
17
|
-
opt-level = "s"
|
|
18
|
-
debug = false
|
|
19
|
-
strip = true
|
|
20
|
-
lto = true
|
|
21
|
-
|
|
22
|
-
[package.metadata.component]
|
|
23
|
-
package = "your-username:plugin"
|
|
24
|
-
|
|
25
|
-
[package.metadata.component.dependencies]
|
package/init/rust/build.sh
DELETED
package/init/rust/deploy.sh
DELETED