@2kw/ai 5.1.0-dev.7 → 5.2.0-dev.10
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 +79 -33
- package/dist/commands/auth.d.ts +91 -1
- package/dist/commands/auth.js +344 -54
- package/dist/commands/config.d.ts +16 -0
- package/dist/commands/config.js +52 -19
- package/dist/commands/context.d.ts +25 -0
- package/dist/commands/context.js +108 -14
- package/dist/commands/convert.js +3 -2
- package/dist/commands/docs.js +10 -6
- package/dist/commands/transcribe.js +3 -1
- package/dist/lib/auth-service.d.ts +131 -0
- package/dist/lib/auth-service.js +240 -0
- package/dist/lib/auth-session.d.ts +139 -0
- package/dist/lib/auth-session.js +275 -0
- package/dist/lib/client.d.ts +57 -0
- package/dist/lib/client.js +81 -5
- package/dist/lib/config.d.ts +64 -5
- package/dist/lib/config.js +115 -15
- package/dist/lib/errors.d.ts +18 -0
- package/dist/lib/errors.js +105 -3
- package/dist/lib/redact.d.ts +35 -0
- package/dist/lib/redact.js +54 -0
- package/dist/lib/update-notifier.js +1 -1
- package/package.json +28 -4
package/README.md
CHANGED
|
@@ -1,60 +1,91 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 2kw.ai CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The command-line interface for [2kw.ai](https://2kw.ai) — the EU-hosted AI integration platform. Run [schema-driven document extraction](https://2kw.ai/extraction), route LLM calls through an [OpenAI-compatible gateway](https://2kw.ai/gateway), transcribe audio, and manage prompts, datasets, and experiments — from your terminal or inside agentic workflows.
|
|
4
|
+
|
|
5
|
+
Installs three equivalent binaries: `2kw`, `backbone`, and `bb`.
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
9
|
```bash
|
|
8
10
|
# Latest stable release
|
|
9
|
-
npm install -g @
|
|
11
|
+
npm install -g @2kw/ai
|
|
10
12
|
|
|
11
13
|
# Pre-release (dev channel)
|
|
12
|
-
npm install -g @
|
|
14
|
+
npm install -g @2kw/ai@dev
|
|
13
15
|
```
|
|
14
16
|
|
|
15
|
-
The CLI
|
|
17
|
+
The CLI notifies you when a newer version is available.
|
|
16
18
|
|
|
17
19
|
## Quick Start
|
|
18
20
|
|
|
19
21
|
```bash
|
|
20
|
-
# Authenticate
|
|
21
|
-
|
|
22
|
+
# Authenticate — opens your browser, no API key needed (7-day free trial)
|
|
23
|
+
2kw auth login
|
|
22
24
|
|
|
23
25
|
# Define a schema and run an extraction
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
2kw schemas create -n "Invoice"
|
|
27
|
+
2kw extractions create --schema <id> -m gpt-4o --text "Invoice #123, Total: €500"
|
|
28
|
+
|
|
29
|
+
# Convert and transcribe
|
|
30
|
+
2kw convert file report.docx --format md
|
|
31
|
+
2kw transcribe call.mp3 --format srt
|
|
32
|
+
|
|
33
|
+
# Chat through the gateway
|
|
34
|
+
2kw ai chat -m gpt-4o --message "Draft a summary of this quarter's extraction volume"
|
|
26
35
|
```
|
|
27
36
|
|
|
28
|
-
|
|
37
|
+
All commands work identically as `bb` for quick access — e.g. `bb schemas list`.
|
|
29
38
|
|
|
30
39
|
## Authentication
|
|
31
40
|
|
|
32
|
-
|
|
41
|
+
Sign in via the browser (recommended):
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
2kw auth login
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
This opens your browser, asks you to confirm a short code, and signs the CLI
|
|
48
|
+
in with your user account — no API key to copy. Your session lasts 7 days of
|
|
49
|
+
inactivity and renews itself while you keep using the CLI. If you belong to
|
|
50
|
+
several organizations you pick one at login, and can switch any time with
|
|
51
|
+
`2kw context set-org` — no re-login needed. `2kw auth logout` clears the local
|
|
52
|
+
credentials and signs the session out server-side (best-effort).
|
|
53
|
+
|
|
54
|
+
For CI, scripts, or air-gapped machines, store an org API key instead
|
|
55
|
+
(create one under Settings → API Keys in the web app):
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
2kw auth login --api-key sk_... # save a key directly
|
|
59
|
+
2kw auth login --manual # prompted setup (legacy flow)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Explicit API keys always take priority over a stored browser session
|
|
63
|
+
(highest priority first):
|
|
33
64
|
|
|
34
65
|
| Method | Example |
|
|
35
66
|
|--------|---------|
|
|
36
67
|
| CLI flags | `--api-key sk_... --base-url https://...` |
|
|
37
|
-
| Environment variables | `
|
|
38
|
-
| Local `.
|
|
39
|
-
| Config store |
|
|
68
|
+
| Environment variables | `AI_2KW_API_KEY`, `AI_2KW_BASE_URL` (legacy: `BACKBONE_*`) |
|
|
69
|
+
| Local `.2kw` file | JSON file in the current directory (legacy: `.backbone`) |
|
|
70
|
+
| Config store | Set via `2kw auth login` (browser session or saved key) |
|
|
40
71
|
|
|
41
72
|
```bash
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
backbone auth logout # Clear stored credentials
|
|
73
|
+
2kw auth status # Verify credentials (works for both auth types)
|
|
74
|
+
2kw auth logout # Clear credentials and send a server-side sign-out
|
|
45
75
|
```
|
|
46
76
|
|
|
77
|
+
Note: `config get apiKey --json` returns a masked value — stored secrets do
|
|
78
|
+
not round-trip through stdout. Scripts needing the raw key should use
|
|
79
|
+
`AI_2KW_API_KEY` or read the config file (path shown by `config list`).
|
|
80
|
+
|
|
47
81
|
## Contexts
|
|
48
82
|
|
|
49
|
-
|
|
83
|
+
kubectl-style contexts switch between organizations and environments:
|
|
50
84
|
|
|
51
85
|
```bash
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
backbone context create staging # Create a new context
|
|
56
|
-
backbone context rename old new # Rename a context
|
|
57
|
-
backbone context delete old # Remove a context
|
|
86
|
+
2kw context list # List all contexts
|
|
87
|
+
2kw context use acme-corp # Switch active context
|
|
88
|
+
2kw context create staging # Create a new context
|
|
58
89
|
```
|
|
59
90
|
|
|
60
91
|
## Commands
|
|
@@ -63,15 +94,20 @@ backbone context delete old # Remove a context
|
|
|
63
94
|
|---------|-------------|
|
|
64
95
|
| `auth` | Login, logout, and check auth status |
|
|
65
96
|
| `config` | Get, set, and list configuration values |
|
|
66
|
-
| `context` | Manage
|
|
97
|
+
| `context` | Manage contexts for multiple orgs/environments |
|
|
67
98
|
| `schemas` | Manage schemas, versions, labels, validation, and testing |
|
|
68
|
-
| `prompts` |
|
|
99
|
+
| `prompts` | Versioned prompt management, labels, compilation, testing |
|
|
69
100
|
| `extractions` | Create extractions (text, file, images), list, re-run, estimate tokens |
|
|
70
|
-
| `convert` | Convert
|
|
71
|
-
| `ai` | Chat completions and model listing via the
|
|
72
|
-
| `transcribe` | Transcribe audio
|
|
101
|
+
| `convert` | Convert PDF, DOCX, XLSX, images, and 20+ formats to Markdown/text/HTML/JSON |
|
|
102
|
+
| `ai` | Chat completions and model listing via the OpenAI-compatible gateway |
|
|
103
|
+
| `transcribe` | Transcribe audio (FLAC, MP3, MP4, OGG, WAV, WebM) |
|
|
104
|
+
| `datasets` | Build datasets and dataset versions for evaluation |
|
|
105
|
+
| `experiments` | Run experiments against datasets |
|
|
106
|
+
| `evaluators` | Manage evaluator templates |
|
|
107
|
+
| `scores` | Record and inspect quality scores |
|
|
108
|
+
| `tracing` | Inspect request traces and tracing settings |
|
|
73
109
|
| `providers` | Manage BYOK AI providers |
|
|
74
|
-
| `analytics` |
|
|
110
|
+
| `analytics` | Usage analytics: spend, quality, providers, errors |
|
|
75
111
|
| `billing` | Check subscription tier and usage limits |
|
|
76
112
|
| `docs` | Browse API documentation from the terminal |
|
|
77
113
|
|
|
@@ -80,11 +116,21 @@ backbone context delete old # Remove a context
|
|
|
80
116
|
| Flag | Description |
|
|
81
117
|
|------|-------------|
|
|
82
118
|
| `--api-key <key>` | Override the API key |
|
|
83
|
-
| `--base-url <url>` | Override the base URL (
|
|
84
|
-
| `--json` | Output raw JSON instead of formatted tables |
|
|
119
|
+
| `--base-url <url>` | Override the base URL (defaults to the 2kw.ai cloud API) |
|
|
120
|
+
| `--json` | Output raw JSON instead of formatted tables — built for scripting and agents |
|
|
85
121
|
| `--no-color` | Disable colored output |
|
|
86
122
|
|
|
87
|
-
|
|
123
|
+
## Why 2kw.ai
|
|
124
|
+
|
|
125
|
+
- **EU data residency** — built-in models run GDPR-compliant and EU-hosted, operated by Manfred Kunze Development GmbH (Germany)
|
|
126
|
+
- **Grounding scores** — every extracted value links back to where it came from in the source document
|
|
127
|
+
- **One platform** — gateway, extraction, transcription, and observability share one API and one bill
|
|
128
|
+
|
|
129
|
+
## Related
|
|
130
|
+
|
|
131
|
+
- [2kw.ai](https://2kw.ai) — platform overview and pricing
|
|
132
|
+
- [Documentation](https://docs.2kw.ai) — full command and API reference
|
|
133
|
+
- [`@2kw/ai-mcp-server`](https://www.npmjs.com/package/@2kw/ai-mcp-server) — the 2kw.ai MCP server for Claude Code, Cursor, and Windsurf
|
|
88
134
|
|
|
89
135
|
## License
|
|
90
136
|
|
package/dist/commands/auth.d.ts
CHANGED
|
@@ -1,3 +1,93 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
|
-
|
|
2
|
+
import { setContext, setActiveContext, type ResolvedConfig } from "../lib/config.js";
|
|
3
|
+
import { getSessionInfo, listOrganizations, pollDeviceToken, requestDeviceCode, revokeSession, setActiveOrganization } from "../lib/auth-service.js";
|
|
4
|
+
import { runDevicePolling, selectOrganization } from "../lib/auth-session.js";
|
|
5
|
+
type SessionConfig = Extract<ResolvedConfig, {
|
|
6
|
+
kind: "session";
|
|
7
|
+
}>;
|
|
8
|
+
/**
|
|
9
|
+
* Group an 8-character device user code as XXXX-XXXX.
|
|
10
|
+
*
|
|
11
|
+
* Purely presentational: the code is read off a terminal and typed into a
|
|
12
|
+
* browser, and a grouped one survives that trip with fewer mistakes. Anything
|
|
13
|
+
* that is not exactly 8 characters (a service configured for another length,
|
|
14
|
+
* or a code that already carries its own separator) is shown untouched.
|
|
15
|
+
*/
|
|
16
|
+
export declare function formatUserCode(code: string): string;
|
|
17
|
+
/** Injection points for {@link deviceFlowLogin}; all default to the real thing. */
|
|
18
|
+
export interface DeviceLoginDeps {
|
|
19
|
+
requestCode?: typeof requestDeviceCode;
|
|
20
|
+
poll?: typeof pollDeviceToken;
|
|
21
|
+
runPolling?: typeof runDevicePolling;
|
|
22
|
+
sessionInfo?: typeof getSessionInfo;
|
|
23
|
+
listOrgs?: typeof listOrganizations;
|
|
24
|
+
chooseOrg?: typeof selectOrganization;
|
|
25
|
+
setActiveOrg?: typeof setActiveOrganization;
|
|
26
|
+
/** Used to clean up a session that never got an organization. */
|
|
27
|
+
revoke?: typeof revokeSession;
|
|
28
|
+
openBrowser?: (url: string) => Promise<void>;
|
|
29
|
+
saveContext?: typeof setContext;
|
|
30
|
+
activateContext?: typeof setActiveContext;
|
|
31
|
+
}
|
|
32
|
+
export interface DeviceLoginTarget {
|
|
33
|
+
contextName: string;
|
|
34
|
+
baseUrl: string;
|
|
35
|
+
authUrl: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The browser login, end to end: ask for a device code, wait for the user to
|
|
39
|
+
* approve it, then record who they are and which organization they act as.
|
|
40
|
+
*
|
|
41
|
+
* A refused or expired approval is reported and swallowed (exit code 1, no
|
|
42
|
+
* context written) because it is the user's answer, not a fault. Everything
|
|
43
|
+
* else — an unreachable auth service, a rejected client id — propagates to
|
|
44
|
+
* `runAction`, which renders it once and machine-readably under `--json`.
|
|
45
|
+
*
|
|
46
|
+
* By design this is an interactive surface: it prints a code, opens a browser,
|
|
47
|
+
* and may ask which organization to use. Its own outcomes are therefore prose
|
|
48
|
+
* even under `--json` — a device approval that was denied is a conversation,
|
|
49
|
+
* not a payload. Faults still leave through handleError and are rendered as
|
|
50
|
+
* JSON there.
|
|
51
|
+
*/
|
|
52
|
+
export declare function deviceFlowLogin(target: DeviceLoginTarget, deps?: DeviceLoginDeps): Promise<void>;
|
|
53
|
+
/** Injection point for {@link performLogout}; defaults to the real call. */
|
|
54
|
+
export interface LogoutDeps {
|
|
55
|
+
revoke?: typeof revokeSession;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Sign out: drop the local credentials, then tell the auth service.
|
|
59
|
+
*
|
|
60
|
+
* That order is deliberate. `revokeSession` has no timeout, so an auth host
|
|
61
|
+
* that black-holes the request would hang the command with the credentials
|
|
62
|
+
* still on disk — while the user, having read "Credentials cleared", believes
|
|
63
|
+
* they are signed out. Clearing first makes the local half unconditional and
|
|
64
|
+
* leaves the network call as what it is: best-effort, and the only part that
|
|
65
|
+
* can fail. A host that refuses the connection fails fast either way.
|
|
66
|
+
*
|
|
67
|
+
* The token and URL are copied out first because the store no longer holds
|
|
68
|
+
* them by the time they are used.
|
|
69
|
+
*/
|
|
70
|
+
export declare function performLogout(deps?: LogoutDeps): Promise<void>;
|
|
71
|
+
/** How the caller wants the status rendered. */
|
|
72
|
+
export interface SessionStatusView {
|
|
73
|
+
json: boolean;
|
|
74
|
+
contextName: string;
|
|
75
|
+
multiContext: boolean;
|
|
76
|
+
}
|
|
77
|
+
/** Injection points for {@link sessionStatus}. */
|
|
78
|
+
export interface SessionStatusDeps {
|
|
79
|
+
/** The probe that decides "authenticated" — normally a bound
|
|
80
|
+
* {@link countModels}. Required: it is the whole test. */
|
|
81
|
+
countModels: () => Promise<number>;
|
|
82
|
+
/** Identity lookup; defaults to the real auth-service call. */
|
|
83
|
+
sessionInfo?: typeof getSessionInfo;
|
|
84
|
+
}
|
|
85
|
+
/** `auth status` for a browser-session context. */
|
|
86
|
+
export declare function sessionStatus(config: SessionConfig, view: SessionStatusView, deps: SessionStatusDeps): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* @param deviceDeps forwarded to {@link deviceFlowLogin} — a seam for tests
|
|
89
|
+
* that need to prove the browser flow was NOT entered.
|
|
90
|
+
*/
|
|
91
|
+
export declare function makeAuthCommand(deviceDeps?: DeviceLoginDeps): Command;
|
|
92
|
+
export {};
|
|
3
93
|
//# sourceMappingURL=auth.d.ts.map
|