@asterai/cli 0.3.2 → 0.5.0

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/README.md CHANGED
@@ -20,7 +20,7 @@ $ npm install -g @asterai/cli
20
20
  $ asterai COMMAND
21
21
  running command...
22
22
  $ asterai (--version)
23
- @asterai/cli/0.3.2 linux-x64 node-v20.12.2
23
+ @asterai/cli/0.5.0 linux-x64 node-v20.12.2
24
24
  $ asterai --help [COMMAND]
25
25
  USAGE
26
26
  $ asterai COMMAND
@@ -32,11 +32,11 @@ USAGE
32
32
 
33
33
  <!-- commands -->
34
34
  * [`asterai auth KEY`](#asterai-auth-key)
35
- * [`asterai build [INPUT]`](#asterai-build-input)
36
- * [`asterai codegen`](#asterai-codegen)
37
- * [`asterai deploy [INPUT]`](#asterai-deploy-input)
35
+ * [`asterai deploy`](#asterai-deploy)
38
36
  * [`asterai help [COMMAND]`](#asterai-help-command)
39
37
  * [`asterai init [OUTDIR]`](#asterai-init-outdir)
38
+ * [`asterai pkg [INPUT]`](#asterai-pkg-input)
39
+ * [`asterai query`](#asterai-query)
40
40
 
41
41
  ## `asterai auth KEY`
42
42
 
@@ -53,109 +53,114 @@ EXAMPLES
53
53
  $ asterai auth
54
54
  ```
55
55
 
56
- _See code: [src/commands/auth.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.3.2/src/commands/auth.ts)_
56
+ _See code: [src/commands/auth.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.5.0/src/commands/auth.ts)_
57
57
 
58
- ## `asterai build [INPUT]`
58
+ ## `asterai deploy`
59
59
 
60
- compiles the plugin
60
+ uploads a plugin to asterai
61
61
 
62
62
  ```
63
63
  USAGE
64
- $ asterai build [INPUT] [-m <value>]
64
+ $ asterai deploy [-a <value>] [-e <value>] [-s] [--plugin <value>] [--pkg <value>]
65
65
 
66
66
  FLAGS
67
- -m, --manifest=<value> [default: plugin.asterai.proto] manifest path
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
68
72
 
69
73
  DESCRIPTION
70
- compiles the plugin
74
+ uploads a plugin to asterai
71
75
 
72
76
  EXAMPLES
73
- $ asterai build
77
+ $ asterai deploy --app 66a46b12-b1a7-4b72-a64a-0e4fe21902b6
74
78
  ```
75
79
 
76
- _See code: [src/commands/build.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.3.2/src/commands/build.ts)_
80
+ _See code: [src/commands/deploy.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.5.0/src/commands/deploy.ts)_
77
81
 
78
- ## `asterai codegen`
82
+ ## `asterai help [COMMAND]`
79
83
 
80
- Generate code from the plugin manifest
84
+ Display help for asterai.
81
85
 
82
86
  ```
83
87
  USAGE
84
- $ asterai codegen [-m <value>] [-o <value>] [-a <value>] [-l <value>] [-s]
88
+ $ asterai help [COMMAND...] [-n]
89
+
90
+ ARGUMENTS
91
+ COMMAND... Command to show help for.
85
92
 
86
93
  FLAGS
87
- -a, --appId=<value> app id
88
- -l, --language=<value> [default: js] language of generated typings
89
- -m, --manifest=<value> [default: plugin.asterai.proto] manifest path
90
- -o, --outputDir=<value> [default: generated] output directory
91
- -s, --staging use staging endpoint
94
+ -n, --nested-commands Include all nested commands in the output.
92
95
 
93
96
  DESCRIPTION
94
- Generate code from the plugin manifest
95
-
96
- EXAMPLES
97
- $ asterai codegen
97
+ Display help for asterai.
98
98
  ```
99
99
 
100
- _See code: [src/commands/codegen.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.3.2/src/commands/codegen.ts)_
100
+ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.0.22/src/commands/help.ts)_
101
101
 
102
- ## `asterai deploy [INPUT]`
102
+ ## `asterai init [OUTDIR]`
103
103
 
104
- compiles and uploads the plugin to asterai
104
+ Initialise a new plugin project
105
105
 
106
106
  ```
107
107
  USAGE
108
- $ asterai deploy [INPUT] -a <value> [-m <value>] [-e <value>] [-s]
109
-
110
- FLAGS
111
- -a, --app=<value> (required) app ID to immediately configure this plugin with
112
- -e, --endpoint=<value> [default: https://api.asterai.io/app/plugin]
113
- -m, --manifest=<value> [default: plugin.asterai.proto] manifest path
114
- -s, --staging
108
+ $ asterai init [OUTDIR]
115
109
 
116
110
  DESCRIPTION
117
- compiles and uploads the plugin to asterai
111
+ Initialise a new plugin project
118
112
 
119
113
  EXAMPLES
120
- $ asterai deploy --app 66a46b12-b1a7-4b72-a64a-0e4fe21902b6
114
+ $ asterai init project-name
121
115
  ```
122
116
 
123
- _See code: [src/commands/deploy.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.3.2/src/commands/deploy.ts)_
117
+ _See code: [src/commands/init.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.5.0/src/commands/init.ts)_
124
118
 
125
- ## `asterai help [COMMAND]`
119
+ ## `asterai pkg [INPUT]`
126
120
 
127
- Display help for asterai.
121
+ bundles the WIT into a binary WASM package
128
122
 
129
123
  ```
130
124
  USAGE
131
- $ asterai help [COMMAND...] [-n]
125
+ $ asterai pkg [INPUT] [-o <value>] [-w <value>] [-e <value>]
132
126
 
133
127
  ARGUMENTS
134
- COMMAND... Command to show help for.
128
+ INPUT [default: plugin.wit] path to the plugin's WIT file
135
129
 
136
130
  FLAGS
137
- -n, --nested-commands Include all nested commands in the output.
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
138
134
 
139
135
  DESCRIPTION
140
- Display help for asterai.
136
+ bundles the WIT into a binary WASM package
137
+
138
+ EXAMPLES
139
+ $ asterai pkg
141
140
  ```
142
141
 
143
- _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.0.22/src/commands/help.ts)_
142
+ _See code: [src/commands/pkg.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.5.0/src/commands/pkg.ts)_
144
143
 
145
- ## `asterai init [OUTDIR]`
144
+ ## `asterai query`
146
145
 
147
- Initialise a new plugin project
146
+ query an asterai app interactively
148
147
 
149
148
  ```
150
149
  USAGE
151
- $ asterai init [OUTDIR]
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
152
157
 
153
158
  DESCRIPTION
154
- Initialise a new plugin project
159
+ query an asterai app interactively
155
160
 
156
161
  EXAMPLES
157
- $ asterai init project-name
162
+ $ asterai query
158
163
  ```
159
164
 
160
- _See code: [src/commands/init.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.3.2/src/commands/init.ts)_
165
+ _See code: [src/commands/query.ts](https://github.com/asterai-io/asterai-sdk/blob/v0.5.0/src/commands/query.ts)_
161
166
  <!-- commandsstop -->
@@ -1,23 +1,26 @@
1
1
  {
2
2
  "name": "plugin",
3
- "version": "1.0.0",
3
+ "version": "0.1.0",
4
4
  "description": "",
5
- "author": "asterai",
6
- "license": "MIT",
5
+ "author": "",
6
+ "license": "UNLICENSED",
7
+ "type": "module",
7
8
  "scripts": {
8
9
  "auth": "asterai auth",
9
- "codegen": "asterai codegen",
10
- "build": "asterai build",
10
+ "gen:pkg": "mkdirp build && asterai pkg -o build/package.wasm -w build/package.wit",
11
+ "gen:types": "jco guest-types build/package.wit -n plugin -o generated/",
12
+ "compile": "tsc",
13
+ "componentize": "jco componentize build/plugin.js -w build/package.wit -n plugin -o build/plugin.wasm",
14
+ "build": "run-s gen:pkg gen:types compile componentize",
11
15
  "deploy": "asterai deploy"
12
16
  },
13
- "type": "module",
14
17
  "devDependencies": {
15
18
  "@asterai/cli": "latest",
16
19
  "@asterai/sdk": "latest",
17
- "@asterai/as-proto": "latest",
18
- "@asterai/as-proto-gen": "latest"
19
- },
20
- "peerDependencies": {
21
- "assemblyscript": "0.27.27"
20
+ "@bytecodealliance/jco": "^1.9.1",
21
+ "@types/node": "^22.13.4",
22
+ "mkdirp": "^3.0.1",
23
+ "npm-run-all": "^4.1.5",
24
+ "typescript": "^5.7.3"
22
25
  }
23
26
  }
@@ -1,35 +1,11 @@
1
- import { BinaryOperationInput } from "./generated/BinaryOperationInput";
2
- import { CalculationOutput } from "./generated/CalculationOutput";
3
- import { PluginContext } from "./generated/PluginContext";
4
- import { ProcessQueryOutput } from "./generated/ProcessQueryOutput";
5
- import { Log } from "@asterai/sdk";
1
+ import { BinaryOperationInput } from "./generated/plugin";
2
+ import * as asterai from "asterai:host/api@0.1.0";
6
3
 
7
- export function processQuery(input: PluginContext): ProcessQueryOutput {
8
- Log.info(`math plugin received a query: ${input.query.content}`);
9
- // This doesn't return any data, but protobuf requires functions
10
- // to always have one input and one output exactly to ensure
11
- // backward compatibility.
12
- return new ProcessQueryOutput();
13
- }
14
-
15
- export function add(input: BinaryOperationInput): CalculationOutput {
4
+ export const add = (input: BinaryOperationInput): number => {
16
5
  const result = input.a + input.b;
17
- // CalculationOutput returns a system message.
18
- // The `system_message` field is sent to the LLM.
19
- return new CalculationOutput(`the result is ${result}`);
20
- }
21
-
22
- export function mul(input: BinaryOperationInput): CalculationOutput {
23
- const result = input.a * input.b;
24
- return new CalculationOutput(`the result is ${result}`);
25
- }
26
-
27
- export function div(input: BinaryOperationInput): CalculationOutput {
28
- const result = input.a / input.b;
29
- return new CalculationOutput(`the result is ${result}`);
30
- }
31
-
32
- export function pow(input: BinaryOperationInput): CalculationOutput {
33
- const result = input.a ** input.b;
34
- return new CalculationOutput(`the result is ${result}`);
35
- }
6
+ // Send the calculation result to the agent.
7
+ asterai.sendResponseToAgent(`the result is ${result}`);
8
+ // This result is not seen by the agent, but it can be consumed by
9
+ // other plugins calling this function.
10
+ return result;
11
+ };
@@ -0,0 +1,12 @@
1
+ package example:math@0.1.0;
2
+
3
+ world plugin {
4
+ import asterai:host/api@0.1.0;
5
+
6
+ export add: func(input: binary-operation-input) -> s32;
7
+
8
+ record binary-operation-input {
9
+ a: f64,
10
+ b: f64,
11
+ }
12
+ }
@@ -1,4 +1,11 @@
1
1
  {
2
- "extends": "assemblyscript/std/assembly.json",
3
- "include": ["./**/*.ts"]
2
+ "include": ["./**/*.ts"],
3
+ "compilerOptions": {
4
+ "outDir": "build",
5
+ "module": "ESNext",
6
+ "moduleResolution": "node",
7
+ "paths": {
8
+ "asterai:host/api@0.1.0": ["./generated/interfaces/asterai-host-api.d.ts"]
9
+ }
10
+ }
4
11
  }
@@ -1,16 +1,14 @@
1
1
  import { Command } from "@oclif/core";
2
2
  export default class Deploy extends Command {
3
- static args: {
4
- input: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
5
- };
3
+ static args: {};
6
4
  static description: string;
7
5
  static examples: string[];
8
6
  static flags: {
9
- app: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
- manifest: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
7
+ agent: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
8
  endpoint: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
12
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>;
13
12
  };
14
13
  run(): Promise<void>;
15
14
  }
16
- export declare const mergeProtoImports: (proto: string, protoPath: string, excludeSdk?: boolean, excludeSyntaxDefinition?: boolean, n?: number) => string;
@@ -1,59 +1,57 @@
1
- import { Args, Command, Flags } from "@oclif/core";
1
+ import { Command, Flags } from "@oclif/core";
2
2
  import fs from "fs";
3
- import path from "path";
4
3
  import FormData from "form-data";
5
4
  import axios from "axios";
6
5
  import { getConfigValue } from "../config.js";
7
- import { build } from "./build.js";
8
- const PRODUCTION_ENDPOINT = "https://api.asterai.io/app/plugin";
9
- const STAGING_ENDPOINT = "https://staging.api.asterai.io/app/plugin";
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
10
  export default class Deploy extends Command {
11
- static args = {
12
- input: Args.string({
13
- default: "plugin.ts",
14
- }),
15
- };
16
- static description = "compiles and uploads the plugin to asterai";
11
+ static args = {};
12
+ static description = "uploads a plugin to asterai";
17
13
  static examples = [
18
14
  `<%= config.bin %> <%= command.id %> --app 66a46b12-b1a7-4b72-a64a-0e4fe21902b6`,
19
15
  ];
20
16
  static flags = {
21
- app: Flags.string({
17
+ agent: Flags.string({
22
18
  char: "a",
23
- description: "app ID to immediately configure this plugin with",
24
- required: true,
25
- }),
26
- manifest: Flags.string({
27
- char: "m",
28
- description: "manifest path",
29
- default: "plugin.asterai.proto",
19
+ description: "agent ID to immediately activate this plugin for",
20
+ required: false,
30
21
  }),
31
22
  endpoint: Flags.string({
32
23
  char: "e",
33
- default: PRODUCTION_ENDPOINT,
24
+ default: BASE_API_URL,
34
25
  }),
35
26
  staging: Flags.boolean({
36
27
  char: "s",
37
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
+ }),
38
37
  };
39
38
  async run() {
40
- const { args, flags } = await this.parse(Deploy);
41
- const output = await build(args, flags);
42
- await deploy(output, flags);
39
+ const { flags } = await this.parse(Deploy);
40
+ await deploy(flags);
43
41
  }
44
42
  }
45
- const deploy = async (args, flags) => {
43
+ const deploy = async (flags) => {
46
44
  const form = new FormData();
47
- form.append("app_id", flags.app);
48
- form.append("module", fs.readFileSync(args.outputFile));
49
- const manifestString = fs.readFileSync(args.manifestPath, {
50
- encoding: "utf8",
51
- });
52
- const mergedManifestString = mergeProtoImports(manifestString, args.manifestPath);
53
- form.append("manifest", mergedManifestString);
54
- const url = flags.staging ? STAGING_ENDPOINT : flags.endpoint;
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;
55
53
  await axios({
56
- url,
54
+ url: `${baseApiUrl}/v1/plugin`,
57
55
  method: "put",
58
56
  data: form,
59
57
  headers: {
@@ -64,38 +62,17 @@ const deploy = async (args, flags) => {
64
62
  .then(() => console.log("done"))
65
63
  .catch(logRequestError);
66
64
  };
67
- export const mergeProtoImports = (proto, protoPath, excludeSdk = true, excludeSyntaxDefinition = true, n = 0) => {
68
- let mergedManifestString = "";
69
- const lines = proto.split("\n");
70
- for (let line of lines) {
71
- line = line.trim();
72
- const isSyntaxLine = line.startsWith("syntax");
73
- if (isSyntaxLine && (excludeSyntaxDefinition || n > 1)) {
74
- continue;
75
- }
76
- const isImportLine = line.startsWith("import");
77
- if (!isImportLine) {
78
- mergedManifestString = `${mergedManifestString}\n${line}`;
79
- continue;
80
- }
81
- const importLine = line.replaceAll("'", '"');
82
- const pathStart = importLine.indexOf('"') + 1;
83
- const pathEnd = importLine.lastIndexOf('"');
84
- const pathRelative = importLine.substring(pathStart, pathEnd);
85
- const isSdkImport = pathRelative.startsWith("node_modules/@asterai/sdk");
86
- if (isSdkImport && excludeSdk) {
87
- // Asterai protobuf definitions should not be uploaded
88
- // as part of the plugin manifest.
89
- continue;
90
- }
91
- const pathAbsolute = path.join(path.dirname(protoPath), pathRelative);
92
- const importProto = fs.readFileSync(pathAbsolute, { encoding: "utf8" });
93
- const importProtoMerged = mergeProtoImports(importProto, pathAbsolute, excludeSdk, excludeSyntaxDefinition, n + 1);
94
- mergedManifestString = `${mergedManifestString}\n${importProtoMerged}`;
95
- }
96
- return mergedManifestString.trim();
97
- };
98
65
  const logRequestError = (e) => {
99
66
  const info = e.response?.data ?? e;
100
67
  console.log("request error:", info);
101
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
+ };
@@ -0,0 +1,27 @@
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>;
@@ -0,0 +1,98 @@
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
+ };
@@ -0,0 +1,13 @@
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
+ }