@uniai-test-1/cli 0.1.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/install.md ADDED
@@ -0,0 +1,167 @@
1
+ # UniAI CLI — install guide (for AI agents)
2
+
3
+ **This document is written for an AI agent.** Follow the steps below to install and verify the
4
+ **UniAI CLI** (npm package `@uniai/cli`, command `uniai`) on the user's machine. The user normally
5
+ installs it globally via **npm** and does **not** need this repository's source. Do not invent
6
+ version numbers or paths; defer to the user's actual environment.
7
+
8
+ The CLI is built for agents: every command accepts `--json` and returns a structured envelope, so
9
+ read the JSON fields (`ok`, `text`, `url`, `error`) instead of scraping prose.
10
+
11
+ ---
12
+
13
+ ## 1. Pre-install checks
14
+
15
+ **Principle:** run the checks first; if **Node / npm / network** does not meet the requirements
16
+ below, the agent should **fix the environment itself in the user's terminal** (e.g. upgrade Node,
17
+ configure an npm registry/proxy) and then continue. Only escalate to the user when you lack
18
+ permission or the environment cannot be automated.
19
+
20
+ 1. **Node.js** — requires **>= 20.0.0**. Verify with `node -v`. If missing or too old, install or
21
+ upgrade Node.
22
+ 2. **npm** (**the only** supported package manager) — verify with `npm -v`. If broken, repair npm.
23
+ Do **not** use `pnpm` / `yarn` to install `@uniai/cli`; even if they are present they are only
24
+ for other projects.
25
+ 3. **Network** — must be able to reach the npm registry (default `registry.npmjs.org`). If
26
+ unreachable, configure a mirror or proxy, then retry.
27
+
28
+ ---
29
+
30
+ ## 2. Install the CLI (and, optionally, skills)
31
+
32
+ **Only the commands below are allowed** (do not use `pnpm add -g`, `yarn global add`, etc.). Run
33
+ them in order; proceed to the next step only after the previous one passes.
34
+
35
+ ### 2.1 Install the CLI
36
+
37
+ ```bash
38
+ npm install -g @uniai/cli
39
+ ```
40
+
41
+ **Verify** (check the exit code and output):
42
+
43
+ ```bash
44
+ uniai --version
45
+ which uniai # on Windows: where uniai
46
+ ```
47
+
48
+ If `command not found`: the global bin directory is not on `PATH`. Check `npm config get prefix`;
49
+ its `bin` directory must be on `PATH`.
50
+
51
+ ### 2.2 Install the UniAI agent skill (recommended)
52
+
53
+ Register the UniAI skill so agents (Claude Code, Cursor, codex, ...) discover the `uniai` command and
54
+ use it on their own. It installs into the shared `~/.agents/skills` and is symlink-bridged into each
55
+ agent's native skills directory.
56
+
57
+ Pull the latest **published** skill from the remote source. The content there is maintained
58
+ out-of-band, so re-running this command picks up updates without reinstalling the CLI:
59
+
60
+ ```bash
61
+ uniai skills add Clion-a/uniai-skills --ref release -g
62
+ uniai skills list -g
63
+ ```
64
+
65
+ `--ref release` pins to the published tag (not in-progress drafts). The command **auto-falls back** to
66
+ the copy bundled in this npm package when the remote is unreachable (offline / rate-limited / no git);
67
+ you can also force the bundled copy explicitly:
68
+
69
+ ```bash
70
+ uniai skills add --self -g
71
+ ```
72
+
73
+ ---
74
+
75
+ ## 3. Authentication (required before any API call)
76
+
77
+ UniAI authenticates with a **Personal Access Token (PAT)** that starts with `uap_`. Get one from
78
+ the UniAI web console: **log in → Personal Center → Security tab → Personal Access Tokens → Generate**
79
+ (<https://www.uniai.ai>).
80
+
81
+ Always probe the current state first, then act, then confirm with a masked value.
82
+
83
+ ### Recommended: persist the token once
84
+
85
+ 1. Point the user to create/copy a PAT at **<https://www.uniai.ai> → Personal Center → Security tab →
86
+ Personal Access Tokens → Generate**.
87
+ 2. Offer **two ways to log in** and let the user choose:
88
+ - **(A) you do it** — the user pastes the token into the chat and you run the command yourself via
89
+ your shell/terminal tool (do **not** echo the token back in your prose replies);
90
+ - **(B) they do it** — the user runs the command in their own terminal, so the token never passes
91
+ through the chat (prefer this if they are security-conscious).
92
+
93
+ ```bash
94
+ uniai auth login --token <USER_PROVIDED_PAT>
95
+ ```
96
+
97
+ 3. Confirm:
98
+
99
+ ```bash
100
+ uniai auth status # prints a masked token only, never the full value
101
+ ```
102
+
103
+ ### Other ways
104
+
105
+ - **Environment variable** (no file written): set `UNIAI_TOKEN=uap_...` in the shell.
106
+ - **Per-command flag** (this run only, not persisted): append `--token uap_...` to any command,
107
+ e.g. `uniai chat "hello" --token uap_...`.
108
+ - **Custom / on-prem endpoint**: pass `--api-base <url>`, set `UNIAI_API_BASE`, or
109
+ `uniai config set --key apiBase --value <url>`. The default is `https://www.uniai.ai/api/v1`.
110
+
111
+ Credential precedence: `--token` > `UNIAI_TOKEN` env > `~/.uniai/config.json`.
112
+
113
+ ### Agent security boundaries
114
+
115
+ - **Never** write a real PAT into repositories, logs, skills, or the public part of a chat
116
+ transcript. When reporting status, use only the **masked** field; never echo the full token.
117
+ - In CI / non-interactive environments, inject the token via a secret manager or env var; never
118
+ hardcode it in a script. Read errors from the `--json` envelope rather than printing raw output.
119
+
120
+ ---
121
+
122
+ ## 4. Minimal functional verification
123
+
124
+ After authentication, run a real round-trip and read the structured fields:
125
+
126
+ ```bash
127
+ uniai auth status
128
+ uniai chat "ping" --json
129
+ ```
130
+
131
+ A successful chat prints `{"ok":true,"text":"..."}`. On failure it prints
132
+ `{"ok":false,"error":"..."}` — diagnose from the `error` field (network, invalid token, out of
133
+ credits, etc.) and consult the table below.
134
+
135
+ ---
136
+
137
+ ## 5. Troubleshooting (agent checklist)
138
+
139
+ | Symptom | Likely cause | Suggested action |
140
+ | --- | --- | --- |
141
+ | `uniai: command not found` | global bin not on `PATH` | check `npm config get prefix`, add its `bin` to `PATH` |
142
+ | install error mentioning `engines` | Node too old | upgrade Node to **>= 20** |
143
+ | `{"ok":false,"error":"...401..."}` / auth failed | not logged in or invalid/expired PAT | regenerate the PAT in the console, then `uniai auth login --token <PAT>` |
144
+ | `{"ok":false,"error":"...402..."}` / out of credits | insufficient credits | ask the user to top up in the console, then retry |
145
+ | cannot reach the API / network error | network, proxy, or wrong endpoint | check connectivity; for on-prem pass `--api-base <url>` |
146
+ | only `pnpm` available, no `npm` | agent tried to install with pnpm | install/repair **npm** first, then `npm install -g @uniai/cli` (do not use pnpm) |
147
+
148
+ ---
149
+
150
+ ## What you can do once installed
151
+
152
+ Tell the user, briefly, what the CLI enables — calling UniAI platform features straight from the
153
+ terminal, all with `--json` for scripting:
154
+
155
+ ```bash
156
+ uniai chat "explain async/await in one paragraph"
157
+ uniai image generate "a watercolor fox" --download fox.png
158
+ uniai video generate "a drone shot over mountains" --aspect-ratio 16:9 --download clip.mp4
159
+ uniai speech synthesize "hello world" --download hello.mp3
160
+ uniai speech recognize ./note.m4a --language auto
161
+ uniai ocr ./receipt.jpg
162
+ uniai usage # check your credit balance before spending (alias: quota)
163
+ uniai code "binary search in rust" --language rust
164
+ uniai search "latest on WebGPU" --limit 5
165
+ ```
166
+
167
+ Run `uniai <command> --help` for the full options of any single command.
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@uniai-test-1/cli",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "description": "UniAI CLI — install UniAI's MCP tool server into an external Codex CLI (init / uninstall / status), call UniAI platform features directly from the terminal (chat / image / video / speech / code / search), or install Agent Skills into ~/.agents/skills (skills add / list / remove).",
6
+ "type": "module",
7
+ "keywords": [
8
+ "cli",
9
+ "mcp",
10
+ "codex",
11
+ "ai-agent",
12
+ "agent-skills",
13
+ "image-generation",
14
+ "video-generation",
15
+ "text-to-speech",
16
+ "speech-to-text",
17
+ "web-search",
18
+ "uniai",
19
+ "llm"
20
+ ],
21
+ "author": "UniAI (https://www.uniai.ai)",
22
+ "bin": {
23
+ "uniai": "./dist/cli.mjs"
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "install.md",
28
+ "skill"
29
+ ],
30
+ "scripts": {
31
+ "typecheck": "tsc --noEmit --pretty",
32
+ "build": "tsc --noEmit && node esbuild.config.mjs && node scripts/copy-bundle.mjs",
33
+ "prepack": "npm run build",
34
+ "test": "node --import tsx --test test/*.test.ts",
35
+ "prepublishOnly": "npm run build && npm test && node scripts/prepublish-guard.mjs"
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "^20.14.9",
39
+ "esbuild": "^0.25.0",
40
+ "tsx": "^4.16.2",
41
+ "typescript": "^5.4.5"
42
+ },
43
+ "engines": {
44
+ "node": ">=20.0.0"
45
+ },
46
+ "license": "Apache-2.0",
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "https://www.uniai.ai"
53
+ },
54
+ "homepage": "https://www.uniai.ai",
55
+ "bugs": {
56
+ "url": "https://www.uniai.ai"
57
+ }
58
+ }
package/skill/SKILL.md ADDED
@@ -0,0 +1,85 @@
1
+ ---
2
+ name: uniai-cli
3
+ description: Call UniAI platform AI features from the terminal with the `uniai` CLI — text chat, image generation & editing, video generation, text-to-speech (TTS) and speech recognition (STT), OCR, web search, code generation, and credit-balance checks. Use whenever the user wants to create an image or video, synthesize or transcribe speech, read text out of an image, search the web for current information, generate code, chat with a model, or check their UniAI credits — and the `uniai` command is available on PATH.
4
+ ---
5
+
6
+ # UniAI CLI
7
+
8
+ The `uniai` command calls UniAI platform AI features directly from the terminal. Every command
9
+ accepts `--json` and returns a structured envelope, so prefer `--json` and read the fields
10
+ (`ok`, `text`, `url`, `credits`, `error`) instead of scraping prose.
11
+
12
+ ## When to use this skill
13
+
14
+ Reach for `uniai` when the user wants any of: an image, a video, speech audio (TTS), a transcript
15
+ of audio (STT), text read out of an image (OCR), a web search for up-to-date information, generated
16
+ code, a quick model chat, or their credit balance — and `uniai` is installed.
17
+
18
+ ## Prerequisites
19
+
20
+ - `uniai --version` must succeed. If it is missing, install with `npm i -g @uniai/cli` (npm only;
21
+ do not use pnpm/yarn for this), or have the user read the package's `install.md`.
22
+ - Auth: needs a UniAI Personal Access Token (PAT, starts with `uap_`). Probe with `uniai auth status`
23
+ (prints a masked token). If it is not configured, first tell the user to create a PAT at
24
+ <https://www.uniai.ai> → Personal Center → Security tab → Personal Access Tokens → Generate, then
25
+ offer **two ways to log in** and let them choose:
26
+ - **(A) you do it** — they paste the token into the chat and you run `uniai auth login --token
27
+ <pasted_pat>` yourself via your shell/terminal tool.
28
+ - **(B) they do it** — they run `uniai auth login --token <pat>` themselves in their own terminal,
29
+ so the token never passes through the chat (prefer this if they are security-conscious).
30
+ After either path, verify with `uniai auth status`. Security: never echo the token back in your
31
+ prose replies — report only the masked value.
32
+ - Before a paid generation (image/video/speech), you may check budget first with
33
+ `uniai usage --json` and read `credits.total`.
34
+
35
+ ## Commands
36
+
37
+ ```bash
38
+ uniai chat "<message>" --json
39
+ uniai image generate "<prompt>" [--model <id>] [--aspect-ratio 1:1|16:9|9:16|4:3|3:4|21:9|3:1] [--count <n>] [--quality low|medium|high] [--reference <path|url>[,...]] [--download out.png] --json
40
+ uniai image models --json # list available image models + their supported params
41
+ uniai image edit --image <url> [--output-format png|jpg|webp] [--download out.png] --json
42
+ uniai video generate "<prompt>" [--model <id>] [--aspect-ratio 16:9|9:16|1:1] [--duration <2-15>] [--first-frame <img>] [--reference <img,..>] [--source-video <vid>] [--download out.mp4] --json
43
+ uniai video models --json # list available video models + their modes/durations/resolutions
44
+ uniai speech synthesize "<text>" [--voice <id>] [--format mp3|wav] [--download out.mp3] --json
45
+ uniai speech recognize <audio: path|url> [--language auto|zh|en|ja|ko] --json
46
+ uniai ocr <image: path|url> --json
47
+ uniai search "<query>" [--limit 1-20] --json
48
+ uniai code "<description>" --language <python|typescript|...> --json
49
+ uniai usage --json # credit balance (alias: uniai quota)
50
+ ```
51
+
52
+ For media commands, pass `--download <file>` to save the result locally; report the saved path to
53
+ the user. Run `uniai <command> --help` for the full options of any single command.
54
+
55
+ **Image-to-image (from an uploaded/existing photo):** when the user wants a new image based on a photo
56
+ they gave you — e.g. "full-body shot of this person", "change the clothing", "same character, new
57
+ pose", "make a variation of this" — use `uniai image generate "<prompt>" --reference <path>` and pass
58
+ the photo's **local file path** (the tool uploads it for you; up to 5, comma-separated). Do NOT use
59
+ `uniai image edit` for that — `edit` only sharpens/feathers edges or processes the background of a URL,
60
+ it cannot follow a prompt or change content.
61
+
62
+ **Choosing model / parameters:** the CLI does not pop confirmation dialogs — it passes only the flags
63
+ you give and uses the platform-recommended model + parameters for everything else. So if the user cares
64
+ about the model, aspect ratio, count, or quality, ask them (or run `uniai image models` to show the
65
+ options), then pass the matching flags (`--model`, `--aspect-ratio`, `--count`, `--quality`). If they
66
+ don't care, just generate; sensible defaults are used. (No need to re-implement a selection flow — the
67
+ recommendation/confirmation logic lives in the shared core.)
68
+
69
+ **Video from an image / clip (animate, edit, extend):** for `uniai video generate`, the mode is
70
+ auto-derived from the media you attach — `--first-frame <img>` animates a photo (image-to-video),
71
+ `--first-frame` + `--last-frame` interpolates first→last, `--reference <img,..>` does reference-to-video,
72
+ `--source-video <vid>` edits/restyles a clip, `--continuation-video <vid>` extends one; none = text-to-video.
73
+ Pass the user's uploaded file's **local path** (it is uploaded for you). A prompt is always required
74
+ (describe the motion/scene). Run `uniai video models` to see which models support which modes. The same
75
+ `--model` / `--aspect-ratio` / parameter logic as image applies.
76
+
77
+ ## Output contract
78
+
79
+ - success: `{"ok":true,"text":"...","url":"<media url, when applicable>"}`
80
+ - failure: `{"ok":false,"error":"..."}`
81
+ - exit codes: `0` success · `1` runtime / auth / network error · `2` invalid usage
82
+
83
+ On `out of credits`, tell the user to top up in the UniAI web console. On an auth failure, have them
84
+ re-run `uniai auth login --token uap_...`. On a forbidden/scope error for `usage`, the PAT needs the
85
+ `read:credits` scope.