@cartanova/qgrid-cli 2.3.8 → 2.4.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.ko.md +131 -0
- package/README.md +60 -44
- package/bundle/web-dist/client/assets/{index-OQd6CclQ.js → index-DVdnvcvo.js} +3 -3
- package/bundle/web-dist/client/assets/{logs-8T91eoLY.js → logs-B82PGnxD.js} +1 -1
- package/bundle/web-dist/client/assets/{routes--GqHRT2A.js → routes-CvCEcpZ7.js} +1 -1
- package/bundle/web-dist/client/assets/{show-cHMucIDC.js → show-DWRh--ML.js} +1 -1
- package/bundle/web-dist/client/assets/{tokens-BXAJUeCJ.js → tokens-DOu_ZFUL.js} +1 -1
- package/bundle/web-dist/client/index.html +1 -1
- package/bundle/web-dist/server/entry-server.generated.js +1 -1
- package/dist/cli.js +86 -5
- package/package.json +7 -3
- package/postinstall.mjs +119 -0
- package/skills/qgrid/SKILL.md +54 -0
- package/skills/qgrid/agents/openai.yaml +4 -0
- package/skills/qgrid/references/ai-sdk-provider-contract.md +100 -0
- package/skills/qgrid/references/anthropic-claude-code-runtime.md +170 -0
- package/skills/qgrid/references/cli-env-and-server-boot.md +68 -0
- package/skills/qgrid/references/decision-rationale.md +179 -0
- package/skills/qgrid/references/docs-workflow.md +32 -0
- package/skills/qgrid/references/openai-codex-runtime.md +153 -0
- package/skills/qgrid/references/prompt-cache-and-usage.md +101 -0
- package/skills/qgrid/references/provider-runtime-differences.md +54 -0
- package/skills/qgrid/references/repo-map.md +37 -0
- package/skills/qgrid/references/request-log-run-lifecycle.md +76 -0
- package/skills/qgrid/references/sonamu-api-web-flow.md +47 -0
- package/skills/qgrid/references/token-auth-quota-lifecycle.md +205 -0
- package/skills/qgrid/references/tool-calling-and-multiturn.md +144 -0
- package/skills/qgrid/references/verification-and-debugging.md +193 -0
- package/bundle/dist/migrations/20260705140615_alter_request_log_steps_alter1.js +0 -14
- package/bundle/src/migrations/20260705140615_alter_request_log_steps_alter1.ts +0 -13
package/README.ko.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# @cartanova/qgrid-cli
|
|
2
|
+
|
|
3
|
+
[English](./README.md) · **한국어**
|
|
4
|
+
|
|
5
|
+
Qgrid 서버를 한 줄로 실행. OpenAI/Anthropic 구독 크레딧을 HTTP API + 대시보드로 제공하는 LLM 프록시.
|
|
6
|
+
|
|
7
|
+
## 설치
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i -g @cartanova/qgrid-cli
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
설치 시 qgrid skills가 자동 동기화됨:
|
|
14
|
+
|
|
15
|
+
- global install: `~/.codex/skills/qgrid`, `~/.claude/skills/qgrid`
|
|
16
|
+
- project install: `.agents/skills/qgrid`, `.claude/skills/qgrid`
|
|
17
|
+
|
|
18
|
+
project install에서는 symlink를 만들고, symlink가 실패하면 copy로 fallback함.
|
|
19
|
+
|
|
20
|
+
## PostgreSQL 준비
|
|
21
|
+
|
|
22
|
+
Qgrid는 OAuth 토큰과 request log를 저장하기 위해 PostgreSQL이 필요함.
|
|
23
|
+
이미 접근 가능한 PostgreSQL이 있으면 `--db` 또는 `QGRID_DB_*` 환경변수로 연결하면 됨.
|
|
24
|
+
로컬에 PostgreSQL이 없으면 Docker로 띄울 수 있음:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
docker run --name qgrid-postgres \
|
|
28
|
+
-e POSTGRES_USER=postgres \
|
|
29
|
+
-e POSTGRES_PASSWORD=postgres \
|
|
30
|
+
-e POSTGRES_DB=qgrid \
|
|
31
|
+
-p 5432:5432 \
|
|
32
|
+
-d postgres:18
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## 사용법
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# DB URL로 실행
|
|
39
|
+
qgrid --db postgres://user:password@host:port/dbname
|
|
40
|
+
|
|
41
|
+
# 포트 지정
|
|
42
|
+
qgrid --db postgres://... -p 3000
|
|
43
|
+
|
|
44
|
+
# 환경변수로 DB 설정 (플래그 생략 가능)
|
|
45
|
+
export QGRID_DB_HOST=dev.example.com
|
|
46
|
+
export QGRID_DB_PORT=5432
|
|
47
|
+
export QGRID_DB_USER=postgres
|
|
48
|
+
export QGRID_DB_PASSWORD=postgres
|
|
49
|
+
export QGRID_DB_NAME=qgrid
|
|
50
|
+
qgrid
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
서버가 뜨면 `http://localhost:44900`에서 대시보드 접속 → OAuth 로그인으로 토큰 등록.
|
|
54
|
+
`-p, --port`를 지정하면 해당 포트로 접속.
|
|
55
|
+
|
|
56
|
+
서버 포트는 기본값 `44900` 또는 `--port`로만 결정됨. `PORT` 환경변수는 CLI 서버 포트 입력으로 사용하지 않음.
|
|
57
|
+
선택한 포트가 이미 사용 중이면 기존 프로세스를 종료하거나 다른 포트로 폴백하지 않고 에러와 함께 종료.
|
|
58
|
+
|
|
59
|
+
Ctrl+C로 종료.
|
|
60
|
+
|
|
61
|
+
## 옵션
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
qgrid [options]
|
|
65
|
+
|
|
66
|
+
--db <url> PostgreSQL 연결 URL
|
|
67
|
+
-p, --port <port> 서버 포트 (기본: 44900)
|
|
68
|
+
--skip-update 자동 업데이트 확인 생략
|
|
69
|
+
-V, --version 버전 출력
|
|
70
|
+
-h, --help 도움말
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
CLI는 실행 시 npm의 최신 버전을 확인하고 patch를 포함해 설치된 버전과 다르면 자동 업데이트함.
|
|
74
|
+
업데이터는 방금 확인한 정확한 배포 버전을 설치하고 업데이트된 binary로 재시작함.
|
|
75
|
+
|
|
76
|
+
## 환경변수
|
|
77
|
+
|
|
78
|
+
`--db` 플래그가 없으면 아래 환경변수에서 DB 접속 정보를 읽음:
|
|
79
|
+
|
|
80
|
+
| 변수 | 기본값 |
|
|
81
|
+
|------|--------|
|
|
82
|
+
| `QGRID_DB_HOST` | `localhost` |
|
|
83
|
+
| `QGRID_DB_PORT` | `5432` |
|
|
84
|
+
| `QGRID_DB_USER` | `postgres` |
|
|
85
|
+
| `QGRID_DB_PASSWORD` | `postgres` |
|
|
86
|
+
| `QGRID_DB_NAME` | `qgrid` |
|
|
87
|
+
|
|
88
|
+
서버 동작 관련 환경변수:
|
|
89
|
+
|
|
90
|
+
| 변수 | 설명 | 기본값 |
|
|
91
|
+
|------|------|--------|
|
|
92
|
+
| `QGRID_WORKERS_PER_TOKEN` | OpenAI 토큰당 codex worker 수 | `3` (최대 5) |
|
|
93
|
+
| `QGRID_PUBLIC_BASE_URL` | Anthropic OAuth callback 공개 베이스 URL. 원격 접속 환경에서 설정 | 미설정 시 `http://localhost:<port>/callback` |
|
|
94
|
+
| `QGRID_OPENAI_THREAD_REUSE` | `false`로 설정 시 OpenAI thread reuse(prompt cache) 비활성화 | 활성 |
|
|
95
|
+
|
|
96
|
+
## 사전 요구사항
|
|
97
|
+
|
|
98
|
+
- Node.js >= 20
|
|
99
|
+
- PostgreSQL
|
|
100
|
+
- Docker (로컬 PostgreSQL을 컨테이너로 실행할 경우)
|
|
101
|
+
- [Codex CLI](https://github.com/openai/codex) (OpenAI 모델 사용 시)
|
|
102
|
+
- [Claude Code](https://www.anthropic.com/claude-code) (Anthropic 모델 사용 시)
|
|
103
|
+
|
|
104
|
+
## 동작 방식
|
|
105
|
+
|
|
106
|
+
CLI는 Sonamu 기반 서버를 내장 번들로 포함. 실행 시:
|
|
107
|
+
|
|
108
|
+
1. DB 연결 확인
|
|
109
|
+
2. 서버 시작 (API + 대시보드 웹 UI)
|
|
110
|
+
3. DB의 등록된 토큰 로드. 이후 토큰 등록/변경은 PostgreSQL LISTEN/NOTIFY로 실행 중인 서버에 실시간 반영
|
|
111
|
+
4. **OpenAI 토큰**: 토큰당 persistent codex app-server 프로세스 N개 spawn (기본 3, 최대 5). JSON-RPC로 통신. 요청은 idle worker에 round-robin 라우팅, 전부 busy면 큐 대기 (최대 60초). `sessionKey` 멀티턴 요청은 같은 thread로 재라우팅되어 prompt cache 적중
|
|
112
|
+
5. **Anthropic 토큰**: 요청마다 격리된 claude 프로세스를 fresh spawn (`stream-json` 입출력). 토큰은 least-used 우선으로 선택. OAuth 토큰 자동 refresh
|
|
113
|
+
6. 토큰별 quota threshold(기본 80%)를 넘은 토큰은 라우팅에서 제외 (사용률 조회 실패 시에는 fail-open으로 통과)
|
|
114
|
+
|
|
115
|
+
Qgrid 앱 자체는 Docker에 의존하지 않지만 PostgreSQL은 필요함. 로컬 PostgreSQL이 없으면 Docker로 PostgreSQL을 띄우는 구성이 가장 간단함.
|
|
116
|
+
|
|
117
|
+
## SDK 연동
|
|
118
|
+
|
|
119
|
+
서버를 띄운 뒤 [`@cartanova/qgrid-ai-sdk`](../ai-sdk/README.ko.md)로 호출:
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { generateText } from "ai";
|
|
123
|
+
import { qgrid } from "@cartanova/qgrid-ai-sdk";
|
|
124
|
+
|
|
125
|
+
const { text } = await generateText({
|
|
126
|
+
model: qgrid("openai/gpt-5.4-mini"),
|
|
127
|
+
prompt: "서울 날씨 알려줘",
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
자세한 사용법은 [`@cartanova/qgrid-ai-sdk` README](../ai-sdk/README.ko.md) 참조.
|
package/README.md
CHANGED
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
# @cartanova/qgrid-cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**English** · [한국어](./README.ko.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Run the Qgrid server in one line. An LLM proxy that exposes OpenAI/Anthropic subscription credits as an HTTP API + dashboard.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
6
8
|
|
|
7
9
|
```bash
|
|
8
10
|
npm i -g @cartanova/qgrid-cli
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
Installing also syncs the qgrid skills automatically:
|
|
14
|
+
|
|
15
|
+
- global install: `~/.codex/skills/qgrid`, `~/.claude/skills/qgrid`
|
|
16
|
+
- project install: `.agents/skills/qgrid`, `.claude/skills/qgrid`
|
|
17
|
+
|
|
18
|
+
Project installs create symlinks, falling back to copies when symlinking fails.
|
|
12
19
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
## Preparing PostgreSQL
|
|
21
|
+
|
|
22
|
+
Qgrid needs PostgreSQL to store OAuth tokens and request logs.
|
|
23
|
+
If you already have a reachable PostgreSQL, connect with `--db` or the `QGRID_DB_*` environment variables.
|
|
24
|
+
If you don't have one locally, you can spin one up with Docker:
|
|
16
25
|
|
|
17
26
|
```bash
|
|
18
27
|
docker run --name qgrid-postgres \
|
|
@@ -23,16 +32,16 @@ docker run --name qgrid-postgres \
|
|
|
23
32
|
-d postgres:18
|
|
24
33
|
```
|
|
25
34
|
|
|
26
|
-
##
|
|
35
|
+
## Usage
|
|
27
36
|
|
|
28
37
|
```bash
|
|
29
|
-
# DB URL
|
|
38
|
+
# Run with a DB URL
|
|
30
39
|
qgrid --db postgres://user:password@host:port/dbname
|
|
31
40
|
|
|
32
|
-
#
|
|
41
|
+
# Specify a port
|
|
33
42
|
qgrid --db postgres://... -p 3000
|
|
34
43
|
|
|
35
|
-
#
|
|
44
|
+
# Configure the DB with environment variables (flags can be omitted)
|
|
36
45
|
export QGRID_DB_HOST=dev.example.com
|
|
37
46
|
export QGRID_DB_PORT=5432
|
|
38
47
|
export QGRID_DB_USER=postgres
|
|
@@ -41,66 +50,73 @@ export QGRID_DB_NAME=qgrid
|
|
|
41
50
|
qgrid
|
|
42
51
|
```
|
|
43
52
|
|
|
44
|
-
|
|
45
|
-
`-p, --port
|
|
53
|
+
Once the server is up, open the dashboard at `http://localhost:44900` → register tokens through OAuth login.
|
|
54
|
+
With `-p, --port` set, connect on that port instead.
|
|
46
55
|
|
|
47
|
-
|
|
48
|
-
|
|
56
|
+
The server port is determined only by the default `44900` or `--port`. The `PORT` environment variable is not read as CLI server port input.
|
|
57
|
+
If the selected port is already in use, the CLI exits with an error instead of killing the existing process or falling back to another port.
|
|
49
58
|
|
|
50
|
-
Ctrl+C
|
|
59
|
+
Stop with Ctrl+C.
|
|
51
60
|
|
|
52
|
-
##
|
|
61
|
+
## Options
|
|
53
62
|
|
|
54
63
|
```
|
|
55
64
|
qgrid [options]
|
|
56
65
|
|
|
57
|
-
--db <url> PostgreSQL
|
|
58
|
-
-p, --port <port>
|
|
59
|
-
--skip-update
|
|
60
|
-
-V, --version
|
|
61
|
-
-h, --help
|
|
66
|
+
--db <url> PostgreSQL connection URL
|
|
67
|
+
-p, --port <port> Server port (default: 44900)
|
|
68
|
+
--skip-update Skip the automatic update check
|
|
69
|
+
-V, --version Print version
|
|
70
|
+
-h, --help Help
|
|
62
71
|
```
|
|
63
72
|
|
|
64
|
-
CLI
|
|
65
|
-
|
|
73
|
+
On startup the CLI checks the latest version on npm and self-updates whenever the installed version differs, including patch releases.
|
|
74
|
+
The updater installs the exact published version it just resolved and restarts from the updated binary.
|
|
66
75
|
|
|
67
|
-
##
|
|
76
|
+
## Environment variables
|
|
68
77
|
|
|
69
|
-
`--db`
|
|
78
|
+
Without the `--db` flag, DB connection info is read from:
|
|
70
79
|
|
|
71
|
-
|
|
|
80
|
+
| Variable | Default |
|
|
72
81
|
|------|--------|
|
|
73
82
|
| `QGRID_DB_HOST` | `localhost` |
|
|
74
83
|
| `QGRID_DB_PORT` | `5432` |
|
|
75
84
|
| `QGRID_DB_USER` | `postgres` |
|
|
76
85
|
| `QGRID_DB_PASSWORD` | `postgres` |
|
|
77
86
|
| `QGRID_DB_NAME` | `qgrid` |
|
|
78
|
-
| `QGRID_WORKERS_PER_TOKEN` | `3` (OpenAI 토큰당 codex worker 수, 최대 5) |
|
|
79
87
|
|
|
80
|
-
|
|
88
|
+
Server behavior variables:
|
|
89
|
+
|
|
90
|
+
| Variable | Description | Default |
|
|
91
|
+
|------|------|--------|
|
|
92
|
+
| `QGRID_WORKERS_PER_TOKEN` | codex workers per OpenAI token | `3` (max 5) |
|
|
93
|
+
| `QGRID_PUBLIC_BASE_URL` | Public base URL for the Anthropic OAuth callback. Set it when the server is accessed remotely | `http://localhost:<port>/callback` when unset |
|
|
94
|
+
| `QGRID_OPENAI_THREAD_REUSE` | Set to `false` to disable OpenAI thread reuse (prompt caching) | enabled |
|
|
95
|
+
|
|
96
|
+
## Prerequisites
|
|
81
97
|
|
|
82
98
|
- Node.js >= 20
|
|
83
99
|
- PostgreSQL
|
|
84
|
-
- Docker (
|
|
85
|
-
- [Codex CLI](https://github.com/openai/codex) (OpenAI
|
|
86
|
-
- [Claude Code](https://www.anthropic.com/claude-code) (Anthropic
|
|
100
|
+
- Docker (if running PostgreSQL locally as a container)
|
|
101
|
+
- [Codex CLI](https://github.com/openai/codex) (for OpenAI models)
|
|
102
|
+
- [Claude Code](https://www.anthropic.com/claude-code) (for Anthropic models)
|
|
87
103
|
|
|
88
|
-
##
|
|
104
|
+
## How it works
|
|
89
105
|
|
|
90
|
-
CLI
|
|
106
|
+
The CLI ships the Sonamu-based server as a built-in bundle. On launch:
|
|
91
107
|
|
|
92
|
-
1. DB
|
|
93
|
-
2.
|
|
94
|
-
3. DB
|
|
95
|
-
4. **OpenAI
|
|
96
|
-
5. **Anthropic
|
|
97
|
-
6.
|
|
108
|
+
1. Verify the DB connection
|
|
109
|
+
2. Start the server (API + dashboard web UI)
|
|
110
|
+
3. Load registered tokens from the DB. Later token additions/changes propagate to the running server in real time via PostgreSQL LISTEN/NOTIFY
|
|
111
|
+
4. **OpenAI tokens**: spawn N persistent codex app-server processes per token (default 3, max 5), communicating over JSON-RPC. Requests are routed round-robin across idle workers; when all are busy they queue (up to 60 seconds). Multi-turn requests carrying a `sessionKey` are routed back to the same thread for prompt-cache hits
|
|
112
|
+
5. **Anthropic tokens**: spawn a fresh, isolated claude process per request (`stream-json` in/out). Tokens are selected least-used-first. OAuth tokens are refreshed automatically
|
|
113
|
+
6. Tokens over their quota threshold (default 80%) are excluded from routing (usage-lookup failures fail open)
|
|
98
114
|
|
|
99
|
-
Qgrid
|
|
115
|
+
The Qgrid app itself does not depend on Docker, but PostgreSQL is required. If you don't run PostgreSQL locally, running it in Docker is the simplest setup.
|
|
100
116
|
|
|
101
|
-
## SDK
|
|
117
|
+
## SDK integration
|
|
102
118
|
|
|
103
|
-
|
|
119
|
+
Once the server is running, call it with [`@cartanova/qgrid-ai-sdk`](../ai-sdk/README.md):
|
|
104
120
|
|
|
105
121
|
```typescript
|
|
106
122
|
import { generateText } from "ai";
|
|
@@ -108,8 +124,8 @@ import { qgrid } from "@cartanova/qgrid-ai-sdk";
|
|
|
108
124
|
|
|
109
125
|
const { text } = await generateText({
|
|
110
126
|
model: qgrid("openai/gpt-5.4-mini"),
|
|
111
|
-
prompt: "
|
|
127
|
+
prompt: "What's the weather in Seoul?",
|
|
112
128
|
});
|
|
113
129
|
```
|
|
114
130
|
|
|
115
|
-
|
|
131
|
+
See the [`@cartanova/qgrid-ai-sdk` README](../ai-sdk/README.md) for details.
|