@kivacore/cli-browser 0.0.0-stage → 0.13.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/README.md CHANGED
@@ -1,3 +1,94 @@
1
- # Temporary Holding Version
1
+ # @kivacore/cli-browser
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The API commands of the [`kiva` CLI](https://www.npmjs.com/package/@kivacore/cli), packaged to run in a web page. Use it to
4
+ build a terminal-style console or a CLI simulator on top of the Kiva API: the commands, flags and output are the ones of the
5
+ real CLI, because they are built from the same source.
6
+
7
+ One ES module, no dependencies, no Node APIs.
8
+
9
+ ```ts
10
+ import { createKivaCli } from "@kivacore/cli-browser";
11
+
12
+ const cli = createKivaCli({ accessToken });
13
+
14
+ const apps = await cli.run("apps list");
15
+ console.log(apps.stdout);
16
+
17
+ const who = await cli.run("auth who --json");
18
+ console.log(JSON.parse(who.stdout).data.email);
19
+ ```
20
+
21
+ ## Signing in
22
+
23
+ There is no `auth login`. The page signs the user in and hands the tokens to the CLI:
24
+
25
+ ```ts
26
+ const cli = createKivaCli({
27
+ accessToken,
28
+ refreshToken, // optional: lets the CLI renew an expired access token
29
+ clientId, // the OAuth2 client the tokens were issued to; needed with refreshToken
30
+ apiBaseUrl: "https://api.kiva.app", // the default
31
+ onTokensChange: ({ accessToken, refreshToken, expiresAt }) => saveTokens({ accessToken, refreshToken }),
32
+ });
33
+ ```
34
+
35
+ The first command that needs a session asks the API who the token belongs to (`GET /users/me`), so results carry the same
36
+ `context` (email and tenant) as the real CLI. When the user signs in again or switches tenant, pass the new tokens with
37
+ `cli.setTokens({ accessToken, refreshToken, clientId })`.
38
+
39
+ Without a refresh token, commands fail once the access token expires, until `setTokens` is called.
40
+
41
+ The API must allow cross-origin requests from the page's origin.
42
+
43
+ ## Running commands
44
+
45
+ `run` takes a command line or an argument list. A leading `kiva` is optional, and quoting follows shell rules, so JSON
46
+ arguments can be written as in a terminal:
47
+
48
+ ```ts
49
+ await cli.run(`ds create crm contacts --data '{"name":"Ada"}'`);
50
+ await cli.run(["ds", "create", "crm", "contacts", "--data", JSON.stringify({ name: "Ada" })]);
51
+ ```
52
+
53
+ It resolves to `{ argv, exitCode, stdout, stderr }` and does not reject when a command fails: check `exitCode`. As in the
54
+ real CLI, a failing command prints its error to `stdout`; `stderr` holds what the browser build itself refuses.
55
+
56
+ Options for a single command:
57
+
58
+ | Option | Purpose |
59
+ | ---------------------- | ----------------------------------------------------------------------------- |
60
+ | `stdin` | Text piped to the command, like `echo '{…}' \| kiva ds create crm contacts`. |
61
+ | `env` | Extra environment variables for this command. |
62
+ | `tty` | `false` formats output for a program, as when the real CLI's output is piped. |
63
+ | `onStdout`, `onStderr` | Receive output while the command runs. |
64
+
65
+ Every global flag of the CLI works: `--json`, `--format <toon|json|yaml|md|jsonl>`, `--filter-output`, `--help`, `--schema`,
66
+ `--llms`, and the rest listed by `kiva --help`.
67
+
68
+ Commands run one at a time; calls made while another command is running wait their turn.
69
+
70
+ ## Files
71
+
72
+ Options that read a file (`--from-file`, uploads) read from an in-memory filesystem that belongs to the CLI instance:
73
+
74
+ ```ts
75
+ const cli = createKivaCli({ accessToken, files: { "contacts.csv": csvText } });
76
+ cli.files.write("logo.png", pngBytes);
77
+
78
+ await cli.run("ds create crm contacts --from-file contacts.csv");
79
+ ```
80
+
81
+ `cli.files` has `write`, `read`, `readBytes`, `remove` and `list`. Relative paths resolve against `/`. Files the commands
82
+ write, such as the OpenAPI spec `discover` downloads, appear there too. Nothing is persisted: a new instance starts empty.
83
+
84
+ ## What is included
85
+
86
+ `auth` (`who`, `tenant`, `accounts list`, `tenants list`, `sso-session`), `apps`, `ds`, `dsql`, `discover`, `studio`,
87
+ `automation`, `agent`, `acl`, `account`, `messaging`, `connect` and `curl`.
88
+
89
+ Left out, because they need a terminal, local files, git or an interactive sign-in: the agents (`work`, `code`, `server`,
90
+ `tui`), `env`, `browser`, `knowledge`, `project-plan`, `release`, `agent-skills`, `update`, `auth login` and the other
91
+ session-changing `auth` commands, `apps clone`, and `apps create --local-development`. Running one returns exit code `1`
92
+ with an explanation.
93
+
94
+ The package version is the version of the `kiva` CLI it was built from; `cli.version` returns it.
package/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import type { IKivaBrowserCli, IKivaBrowserCliOptions } from "./types.js";
2
+ export type * from "./types.js";
3
+ /**
4
+ * Creates a Kiva CLI that runs in a web page. It carries the API commands of the `kiva` CLI
5
+ * (`apps`, `ds`, `dsql`, `studio`, `auth who`, …) and runs them with the tokens given here.
6
+ *
7
+ * ```ts
8
+ * const cli = createKivaCli({ accessToken });
9
+ * const { stdout, exitCode } = await cli.run("apps list");
10
+ * ```
11
+ */
12
+ export declare function createKivaCli(options: IKivaBrowserCliOptions): IKivaBrowserCli;