@sunerpy/kiro-provider 0.2.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +217 -0
  3. package/dist/cli.js +162 -0
  4. package/package.json +49 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 sunerpy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,217 @@
1
+ # kiro-provider
2
+
3
+ > A standalone OpenAI-compatible HTTP gateway for AWS Kiro (CodeWhisperer) — point any OpenAI SDK or agent at your own Kiro accounts.
4
+
5
+ [![CI](https://github.com/sunerpy/kiro-provider/actions/workflows/ci.yml/badge.svg)](https://github.com/sunerpy/kiro-provider/actions/workflows/ci.yml)
6
+ [![codecov](https://codecov.io/gh/sunerpy/kiro-provider/branch/main/graph/badge.svg)](https://codecov.io/gh/sunerpy/kiro-provider)
7
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
8
+ [![Bun](https://img.shields.io/badge/runtime-bun-black)](https://bun.sh/)
9
+
10
+ [简体中文](docs/readme/README.zh.md) · English
11
+
12
+ ## Table of Contents
13
+
14
+ - [Features](#features)
15
+ - [Install](#install)
16
+ - [Quickstart](#quickstart)
17
+ - [Configuration](#configuration)
18
+ - [Proxy](#proxy)
19
+ - [Security](#security)
20
+ - [Using with an LLM](#using-with-an-llm)
21
+ - [Development](#development)
22
+ - [License](#license)
23
+
24
+ ## Features
25
+
26
+ - OpenAI-compatible `POST /v1/chat/completions` (streaming SSE and non-streaming JSON), `GET /v1/models`, and `GET /health`.
27
+ - Bearer API-key gate that fails closed: the server refuses to start with no configured keys, and defaults to binding `127.0.0.1`.
28
+ - Multi-account rotation with automatic token refresh and failover, backed by a local `bun:sqlite` account store with tombstone-based removal.
29
+ - `accounts import` to reuse accounts already authenticated by [OpenCode's Kiro auth](https://opencode.ai/) instead of repeating device-code login.
30
+ - A single global `proxy_url` that, when set, routes all upstream egress (model requests, token refresh, device-code login) through one HTTP(S) proxy.
31
+ - Ships as a self-contained compiled binary via `bun build --compile` — no runtime install required on the target machine.
32
+
33
+ ## Install
34
+
35
+ Pick one of three channels.
36
+
37
+ ### 1. bunx / bun (fastest, requires Bun)
38
+
39
+ kiro-provider ships an npm package built on Bun-only APIs (`bun:sqlite`, `Bun.serve`), so it runs under **Bun or `bunx`, not `npx` or plain `node`**. Install [Bun](https://bun.sh/) first, then:
40
+
41
+ ```bash
42
+ bunx @sunerpy/kiro-provider serve --help
43
+ ```
44
+
45
+ Or install it globally:
46
+
47
+ ```bash
48
+ bun add -g @sunerpy/kiro-provider
49
+ kiro-provider --help
50
+ ```
51
+
52
+ ### 2. Prebuilt binary (no dependencies)
53
+
54
+ Every release publishes standalone binaries for `linux` (x64, arm64), `darwin` (x64, arm64), and `windows` (x64). Download the one for your platform from [Releases](https://github.com/sunerpy/kiro-provider/releases/latest), `chmod +x` it, and run it directly. No Bun or Node.js needed at runtime.
55
+
56
+ One-line install (Linux/macOS):
57
+
58
+ ```bash
59
+ curl -fsSL https://raw.githubusercontent.com/sunerpy/kiro-provider/main/scripts/install.sh | sh
60
+ ```
61
+
62
+ Windows (PowerShell):
63
+
64
+ ```powershell
65
+ irm https://raw.githubusercontent.com/sunerpy/kiro-provider/main/scripts/install.ps1 | iex
66
+ ```
67
+
68
+ Both scripts pull the matching asset from `releases/latest/download/` and install it to `~/.local/bin` (override with `KIRO_PROVIDER_INSTALL_DIR`).
69
+
70
+ ### 3. From source (developers)
71
+
72
+ Requires [Bun](https://bun.sh/).
73
+
74
+ ```bash
75
+ git clone https://github.com/sunerpy/kiro-provider.git
76
+ cd kiro-provider
77
+ bun install
78
+ bun run build:binary
79
+ ./dist/kiro-provider --help
80
+ ```
81
+
82
+ Or run without compiling:
83
+
84
+ ```bash
85
+ bun install
86
+ bun run src/cli/bin.ts --help
87
+ ```
88
+
89
+ In the rest of this README, `./dist/kiro-provider` refers to any of the above; substitute `bunx @sunerpy/kiro-provider`, your installed binary path, or `bun run src/cli/bin.ts` depending on which channel you used.
90
+
91
+ ## Quickstart
92
+
93
+ 1. **Get an account into the local store.** Either sign in interactively:
94
+
95
+ ```bash
96
+ ./dist/kiro-provider login
97
+ ```
98
+
99
+ or import accounts already authenticated by OpenCode:
100
+
101
+ ```bash
102
+ ./dist/kiro-provider accounts import
103
+ ```
104
+
105
+ 2. **Create a config with your own API key.**
106
+
107
+ ```bash
108
+ mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/kiro-provider"
109
+ cp config.example.json "${XDG_CONFIG_HOME:-$HOME/.config}/kiro-provider/config.json"
110
+ # edit config.json and replace "sk-REPLACE-ME" with a private, random key
111
+ ```
112
+
113
+ 3. **Start the gateway.**
114
+
115
+ ```bash
116
+ ./dist/kiro-provider serve
117
+ ```
118
+
119
+ 4. **Call it with an OpenAI-compatible client.**
120
+
121
+ ```bash
122
+ curl -fsS http://127.0.0.1:8787/v1/models \
123
+ -H 'Authorization: Bearer sk-your-private-key'
124
+ ```
125
+
126
+ ```ts
127
+ import OpenAI from "openai";
128
+
129
+ const client = new OpenAI({
130
+ baseURL: "http://127.0.0.1:8787/v1",
131
+ apiKey: "sk-your-private-key",
132
+ });
133
+
134
+ const completion = await client.chat.completions.create({
135
+ model: "auto",
136
+ messages: [{ role: "user", content: "Explain this repository." }],
137
+ });
138
+
139
+ console.log(completion.choices[0]?.message.content);
140
+ ```
141
+
142
+ Or with the [Vercel AI SDK](https://sdk.vercel.ai/) via `@ai-sdk/openai-compatible`:
143
+
144
+ ```ts
145
+ import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
146
+ import { generateText } from "ai";
147
+
148
+ const kiro = createOpenAICompatible({
149
+ name: "kiro-provider",
150
+ baseURL: "http://127.0.0.1:8787/v1",
151
+ apiKey: "sk-your-private-key",
152
+ });
153
+
154
+ const { text } = await generateText({
155
+ model: kiro("auto"),
156
+ prompt: "Explain this repository.",
157
+ });
158
+ ```
159
+
160
+ ## Configuration
161
+
162
+ Config is loaded from `~/.config/kiro-provider/config.json` (or `$XDG_CONFIG_HOME/kiro-provider/config.json`), overridable by `KIRO_PROVIDER_*` environment variables and, for `serve`, by CLI flags. Precedence is **CLI flag > environment variable > config file > schema default**.
163
+
164
+ | Field | Default | Env var |
165
+ | --- | --- | --- |
166
+ | `host` | `127.0.0.1` | `KIRO_PROVIDER_HOST` |
167
+ | `port` | `8787` | `KIRO_PROVIDER_PORT` |
168
+ | `api_keys` | required, non-empty | `KIRO_PROVIDER_API_KEYS` |
169
+ | `proxy_url` | `null` | `KIRO_PROVIDER_PROXY_URL` |
170
+ | `default_region` | `us-east-1` | `KIRO_PROVIDER_DEFAULT_REGION` |
171
+ | `account_selection_strategy` | `lowest-usage` | `KIRO_PROVIDER_ACCOUNT_SELECTION_STRATEGY` |
172
+ | `log_level` | `info` | `KIRO_PROVIDER_LOG_LEVEL` |
173
+
174
+ The full field reference, including retry/timeout tuning and the test-only `test_upstream_endpoint`, lives in [`docs/CONFIGURATION.md`](docs/CONFIGURATION.md).
175
+
176
+ ## Proxy
177
+
178
+ Some networks reach one model family directly while another needs a proxy (for example, GPT direct, Claude via an approved egress). Set `proxy_url` (config file, `KIRO_PROVIDER_PROXY_URL`, or `serve --proxy`) to route **all** upstream traffic — model calls, token refresh, and device-code login — through a single HTTP(S) proxy. Leave it `null` for direct connections. See [`docs/CONFIGURATION.md`](docs/CONFIGURATION.md#proxy) for precedence details and examples.
179
+
180
+ ## Security
181
+
182
+ - **Fail-closed authentication.** The server will not start without at least one non-empty `api_keys` entry, and every route requires `Authorization: Bearer <key>`.
183
+ - **Local bind by default.** `host` defaults to `127.0.0.1`; only bind `0.0.0.0` behind a firewall or authenticated reverse proxy.
184
+ - **Locked-down account store.** `accounts.db` (and its WAL/SHM files) are created with mode `0600`.
185
+ - **No secrets in logs.** Proxy URLs and account tokens are never printed; don't commit a real config file, account database, or gateway key.
186
+
187
+ > **Responsible use.** kiro-provider reuses AWS Kiro accounts you already control and consumes your own account quota. Supply your own accounts — this project is not a way to share or resell someone else's Kiro access, and it should not be used to circumvent per-account usage limits.
188
+
189
+ ## Using with an LLM
190
+
191
+ Point any OpenAI-compatible client (`openai`, `@ai-sdk/openai-compatible`, LangChain, etc.) at `http://<host>:<port>/v1` with one of your configured `api_keys`.
192
+
193
+ <details>
194
+ <summary>Agent command reference</summary>
195
+
196
+ - `kiro-provider serve [--config <path>] [--host <host>] [--port <port>] [--proxy <url>]` — start the gateway.
197
+ - `kiro-provider login [--config <path>] [--start-url <url>] [--region <region>]` — device-code login (AWS Builder ID, or IAM Identity Center with `--start-url`).
198
+ - `kiro-provider accounts list` — list stored accounts and their health.
199
+ - `kiro-provider accounts import [--from <path>] [--config <path>]` — import accounts from an OpenCode `kiro.db` (default source: `~/.config/opencode/kiro.db`).
200
+ - `kiro-provider accounts remove <id|email>` — remove one account (writes a tombstone).
201
+
202
+ Contract: human-readable status lines go to stdout, errors to stderr, non-zero exit on failure. `GET /v1/models` and `GET /health` return structured JSON.
203
+
204
+ </details>
205
+
206
+ ## Development
207
+
208
+ ```bash
209
+ bun install
210
+ bun run typecheck
211
+ bun test
212
+ bash scripts/security-check.sh # security regression suite (Linux, needs openssl/curl/ss)
213
+ ```
214
+
215
+ ## License
216
+
217
+ [MIT](LICENSE)