@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.
@@ -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
@@ -1,2 +0,0 @@
1
- export declare const getConfigValue: <T>(key: string) => T | undefined;
2
- export declare const setConfigValue: <T>(key: string, value: T) => void;
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
@@ -1,2 +0,0 @@
1
- export declare const BASE_API_URL = "https://api.asterai.io";
2
- export declare const BASE_API_URL_STAGING = "https://staging.api.asterai.io";
package/dist/const.js DELETED
@@ -1,2 +0,0 @@
1
- export const BASE_API_URL = "https://api.asterai.io";
2
- export const BASE_API_URL_STAGING = "https://staging.api.asterai.io";
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";
@@ -1,2 +0,0 @@
1
- target/
2
- wit/
@@ -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]
@@ -1,5 +0,0 @@
1
- #!/bin/bash
2
- set -e
3
- mkdir -p wit
4
- asterai pkg -o wit/package.wasm -w wit/package.wit
5
- cargo component build --release
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
- set -e
3
- if [ -z "$1" ]; then
4
- echo "Deploying without agent ID. Optionally, pass it: $0 <agent ID>"
5
- fi
6
- bash ./build.sh
7
- asterai deploy --pkg wit/package.wasm --plugin target/wasm32-wasip1/release/plugin.wasm -a "$1"
@@ -1,10 +0,0 @@
1
- package your-username:greeter@0.1.0;
2
-
3
- interface greeter {
4
- greet: func(name: string);
5
- }
6
-
7
- world plugin {
8
- import asterai:host/api@0.1.0;
9
- export greeter;
10
- }