@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/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/.gitignore
DELETED
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