├── .github
└── workflows
│ ├── build-linux.yml
│ ├── build.yml
│ └── docker.yml
├── Cargo.lock
├── Cargo.toml
├── Cross.toml
├── Dockerfile
├── README.md
├── build.rs
├── scripts
├── build.ps1
├── build.sh
├── minify.js
├── package-lock.json
├── package.json
├── setup.ps1
└── setup.sh
├── src
├── app.rs
├── app
│ ├── config.rs
│ ├── constant.rs
│ ├── lazy.rs
│ ├── model.rs
│ └── model
│ │ └── usage_check.rs
├── chat.rs
├── chat
│ ├── adapter.rs
│ ├── aiserver.rs
│ ├── aiserver
│ │ ├── v1.rs
│ │ └── v1
│ │ │ └── lite.proto
│ ├── constant.rs
│ ├── error.rs
│ ├── model.rs
│ ├── route.rs
│ ├── route
│ │ ├── api.rs
│ │ ├── config.rs
│ │ ├── health.rs
│ │ ├── logs.rs
│ │ ├── profile.rs
│ │ └── token.rs
│ ├── service.rs
│ └── stream.rs
├── common.rs
├── common
│ ├── client.rs
│ ├── models.rs
│ ├── models
│ │ ├── config.rs
│ │ ├── error.rs
│ │ ├── health.rs
│ │ └── userinfo.rs
│ ├── utils.rs
│ └── utils
│ │ ├── checksum.rs
│ │ └── tokens.rs
└── main.rs
└── static
├── api.html
├── api.min.html
├── config.html
├── config.min.html
├── logs.html
├── logs.min.html
├── readme.html
├── readme.min.html
├── shared-styles.css
├── shared-styles.min.css
├── shared.js
├── shared.min.js
├── tokeninfo.html
└── tokeninfo.min.html
/.github/workflows/build-linux.yml:
--------------------------------------------------------------------------------
1 | name: Build Linux Binaries
2 |
3 | on:
4 | workflow_dispatch:
5 |
6 | jobs:
7 | build:
8 | name: Build ${{ matrix.target }}
9 | runs-on: ubuntu-latest
10 | strategy:
11 | matrix:
12 | target: [x86_64-unknown-linux-gnu]
13 |
14 | steps:
15 | - uses: actions/checkout@v4.2.2
16 |
17 | - name: Install Rust
18 | uses: dtolnay/rust-toolchain@stable
19 | with:
20 | targets: ${{ matrix.target }}
21 |
22 | - name: Install dependencies
23 | run: |
24 | sudo apt-get update
25 | sudo apt-get install -y protobuf-compiler pkg-config libssl-dev nodejs npm
26 |
27 | - name: Build binary
28 | run: RUSTFLAGS="-C link-arg=-s" cargo build --release --target ${{ matrix.target }}
29 |
30 | - name: Upload artifact
31 | uses: actions/upload-artifact@v4.5.0
32 | with:
33 | name: cursor-api-${{ matrix.target }}
34 | path: target/${{ matrix.target }}/release/cursor-api
35 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 |
3 | on:
4 | workflow_dispatch:
5 | push:
6 | tags:
7 | - 'v*'
8 |
9 | jobs:
10 | build:
11 | name: Build ${{ matrix.os }}
12 | runs-on: ${{ matrix.os }}
13 | strategy:
14 | matrix:
15 | os: [ubuntu-latest, windows-latest, macos-latest]
16 | include:
17 | - os: ubuntu-latest
18 | targets: x86_64-unknown-linux-gnu
19 | - os: windows-latest
20 | targets: x86_64-pc-windows-msvc
21 | - os: macos-latest
22 | targets: x86_64-apple-darwin,aarch64-apple-darwin
23 |
24 | steps:
25 | - uses: actions/checkout@v4.2.2
26 |
27 | - name: Setup Node.js
28 | uses: actions/setup-node@v4.1.0
29 | with:
30 | node-version: '20'
31 | cache: 'npm'
32 | cache-dependency-path: 'scripts/package-lock.json'
33 | run: cd scripts && npm install && cd ..
34 |
35 | - name: Install Rust
36 | uses: dtolnay/rust-toolchain@stable
37 | with:
38 | targets: ${{ matrix.targets }}
39 |
40 | - name: Install Linux dependencies (x86_64)
41 | if: runner.os == 'Linux'
42 | run: |
43 | sudo apt-get update
44 | sudo apt-get install -y \
45 | build-essential \
46 | protobuf-compiler \
47 | pkg-config \
48 | libssl-dev \
49 | openssl \
50 | musl-tools \
51 | musl-dev \
52 | libssl-dev:native \
53 | linux-libc-dev:native
54 |
55 | # 设置 OpenSSL 环境变量
56 | echo "OPENSSL_DIR=/usr" >> $GITHUB_ENV
57 | echo "OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu" >> $GITHUB_ENV
58 | echo "OPENSSL_INCLUDE_DIR=/usr/include/openssl" >> $GITHUB_ENV
59 | echo "PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig" >> $GITHUB_ENV
60 |
61 | - name: Build Linux x86_64 (Dynamic)
62 | if: runner.os == 'Linux'
63 | run: bash scripts/build.sh
64 |
65 | - name: Build Linux x86_64 (Static)
66 | if: runner.os == 'Linux'
67 | run: |
68 | # 使用 musl 目标
69 | rustup target remove x86_64-unknown-linux-gnu
70 | rustup target add x86_64-unknown-linux-musl
71 |
72 | # 设置静态编译环境变量
73 | export CC=musl-gcc
74 |
75 | bash scripts/build.sh --static
76 |
77 | - name: Install macOS dependencies
78 | if: runner.os == 'macOS'
79 | run: |
80 | brew install \
81 | protobuf \
82 | pkg-config \
83 | openssl@3
84 | echo "OPENSSL_DIR=$(brew --prefix openssl@3)" >> $GITHUB_ENV
85 | echo "PKG_CONFIG_PATH=$(brew --prefix openssl@3)/lib/pkgconfig" >> $GITHUB_ENV
86 |
87 | - name: Install Windows dependencies
88 | if: runner.os == 'Windows'
89 | run: |
90 | choco install -y protoc
91 | choco install -y openssl
92 | choco install -y nodejs-lts
93 |
94 | # 刷新环境变量
95 | $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
96 |
97 | # 设置 OpenSSL 环境变量
98 | echo "OPENSSL_DIR=C:\Program Files\OpenSSL" >> $env:GITHUB_ENV
99 | echo "PKG_CONFIG_PATH=C:\Program Files\OpenSSL\lib\pkgconfig" >> $env:GITHUB_ENV
100 |
101 | - name: Build macOS (Dynamic)
102 | if: runner.os == 'macOS' || runner.os == 'Windows'
103 | run: bash scripts/build.sh
104 |
105 | - name: Build macOS (Static)
106 | if: runner.os == 'macOS' || runner.os == 'Windows'
107 | run: bash scripts/build.sh --static
108 |
109 | # - name: Verify build artifacts
110 | # run: |
111 | # if [ ! -d "release" ] || [ -z "$(ls -A release)" ]; then
112 | # echo "Error: No build artifacts found in release directory"
113 | # exit 1
114 | # fi
115 |
116 | - name: Upload artifacts
117 | uses: actions/upload-artifact@v4.5.0
118 | with:
119 | name: binaries-${{ matrix.os }}
120 | path: release/*
121 | retention-days: 1
122 |
123 | build-freebsd:
124 | name: Build FreeBSD
125 | runs-on: ubuntu-latest
126 |
127 | steps:
128 | - uses: actions/checkout@v4.2.2
129 |
130 | - name: Build on FreeBSD
131 | uses: vmactions/freebsd-vm@v1.1.5
132 | with:
133 | usesh: true
134 | prepare: |
135 | # 设置持久化的环境变量
136 | echo 'export SSL_CERT_FILE=/etc/ssl/cert.pem' >> /root/.profile
137 | echo 'export PATH="/usr/local/bin:$PATH"' >> /root/.profile
138 |
139 | # 安装基础依赖
140 | pkg update
141 | pkg install -y \
142 | git \
143 | curl \
144 | node20 \
145 | www/npm \
146 | protobuf \
147 | ca_root_nss \
148 | bash \
149 | gmake \
150 | pkgconf \
151 | openssl \
152 | libressl-devel \
153 | libiconv \
154 | gettext-tools \
155 | gettext-runtime
156 |
157 | export SSL_CERT_FILE=/etc/ssl/cert.pem
158 |
159 | # 克隆代码(确保在正确的目录)
160 | cd /root
161 | git clone $GITHUB_SERVER_URL/$GITHUB_REPOSITORY .
162 |
163 | # 安装 rustup 和 Rust
164 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain nightly
165 |
166 | # 设置持久化的 Rust 环境变量
167 | echo '. "$HOME/.cargo/env"' >> /root/.profile
168 |
169 | # 添加所需的目标支持
170 | . /root/.profile
171 | rustup target add x86_64-unknown-freebsd
172 | rustup component add rust-src
173 |
174 | run: |
175 | # 加载环境变量
176 | . /root/.profile
177 |
178 | echo "构建动态链接版本..."
179 | /usr/local/bin/bash scripts/build.sh
180 |
181 | echo "构建静态链接版本..."
182 | /usr/local/bin/bash scripts/build.sh --static
183 |
184 | - name: Upload artifacts
185 | uses: actions/upload-artifact@v4.5.0
186 | with:
187 | name: binaries-freebsd
188 | path: release/*
189 | retention-days: 1
190 |
191 | release:
192 | name: Create Release
193 | needs: [build, build-freebsd]
194 | runs-on: ubuntu-latest
195 | permissions:
196 | contents: write
197 |
198 | steps:
199 | - uses: actions/checkout@v4.2.2
200 |
201 | - name: Download all artifacts
202 | uses: actions/download-artifact@v4.1.8
203 | with:
204 | path: artifacts
205 |
206 | - name: Prepare release assets
207 | run: |
208 | mkdir release
209 | cd artifacts
210 | for dir in binaries-*; do
211 | cp -r "$dir"/* ../release/
212 | done
213 |
214 | - name: Generate checksums
215 | run: |
216 | cd release
217 | sha256sum * > SHA256SUMS.txt
218 |
219 | - name: Create Release
220 | uses: softprops/action-gh-release@v2.2.0
221 | with:
222 | files: |
223 | release/*
224 | draft: false
225 | prerelease: false
226 | generate_release_notes: true
227 | fail_on_unmatched_files: true
--------------------------------------------------------------------------------
/.github/workflows/docker.yml:
--------------------------------------------------------------------------------
1 | name: Docker Build and Push
2 |
3 | on:
4 | workflow_dispatch:
5 | inputs:
6 | update_latest:
7 | description: '是否更新 latest 标签'
8 | required: true
9 | type: boolean
10 | default: false
11 | upload_artifacts:
12 | description: '是否上传构建产物'
13 | required: true
14 | type: boolean
15 | default: false
16 | push:
17 | tags:
18 | - 'v*'
19 |
20 | env:
21 | IMAGE_NAME: ${{ github.repository_owner }}/cursor-api
22 |
23 | jobs:
24 | build-and-push:
25 | runs-on: ubuntu-latest
26 |
27 | steps:
28 | - name: Checkout repository
29 | uses: actions/checkout@v4.2.2
30 |
31 | - name: Get version from Cargo.toml
32 | if: github.event_name == 'workflow_dispatch'
33 | id: cargo_version
34 | run: |
35 | VERSION=$(grep '^version = ' Cargo.toml | cut -d '"' -f2)
36 | echo "version=v${VERSION}" >> $GITHUB_OUTPUT
37 |
38 | - name: Log in to Docker Hub
39 | uses: docker/login-action@v3.3.0
40 | with:
41 | username: ${{ secrets.DOCKERHUB_USERNAME }}
42 | password: ${{ secrets.DOCKERHUB_TOKEN }}
43 |
44 | - name: Extract metadata for Docker
45 | id: meta
46 | uses: docker/metadata-action@v5.6.1
47 | with:
48 | images: ${{ env.IMAGE_NAME }}
49 | tags: |
50 | type=raw,value=latest,enable=${{ github.event_name == 'workflow_dispatch' && inputs.update_latest }}
51 | type=raw,value=${{ steps.cargo_version.outputs.version }},enable=${{ github.event_name == 'workflow_dispatch' }}
52 | type=ref,event=tag,enable=${{ github.event_name == 'push' }}
53 |
54 | - name: Set up Docker Buildx
55 | uses: docker/setup-buildx-action@v3.8.0
56 | with:
57 | driver-opts: |
58 | image=moby/buildkit:latest
59 | network=host
60 |
61 | - name: Build and push Docker image
62 | uses: docker/build-push-action@v6.11.0
63 | env:
64 | DOCKER_BUILD_RECORD_UPLOAD: false
65 | with:
66 | context: .
67 | push: true
68 | platforms: linux/amd64,linux/arm64
69 | tags: ${{ steps.meta.outputs.tags }}
70 | labels: ${{ steps.meta.outputs.labels }}
71 | cache-from: type=gha
72 | cache-to: type=gha,mode=max
73 | outputs: type=local,dest=./dist,enable=${{ github.event_name == 'workflow_dispatch' && inputs.upload_artifacts }}
74 |
75 | - name: Prepare artifacts
76 | if: github.event_name == 'workflow_dispatch' && inputs.upload_artifacts
77 | run: |
78 | mkdir -p artifacts/amd64 artifacts/arm64
79 | cp dist/linux_amd64/app/cursor-api artifacts/amd64/
80 | cp dist/linux_arm64/app/cursor-api artifacts/arm64/
81 |
82 | - name: Upload artifacts
83 | if: github.event_name == 'workflow_dispatch' && inputs.upload_artifacts
84 | uses: actions/upload-artifact@v4.6.0
85 | with:
86 | name: cursor-api-binaries
87 | path: artifacts/
88 | retention-days: 7
--------------------------------------------------------------------------------
/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "cursor-api"
3 | version = "0.1.3-rc.3"
4 | edition = "2021"
5 | authors = ["wisdgod
";const t={system:"系统",user:"用户",assistant:"助手"};return`角色 | 内容 |
${e.map((e=>{return`${t[e.role]||e.role} | ${(o=e.content,o.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")).replace(/\n/g," ")} |
`;var o})).join("")}
`}function showPromptModal(e){try{const t=document.getElementById("promptModal"),o=document.getElementById("promptContent");if(!t||!o)return void console.error("Modal elements not found");const n=parsePrompt(e);o.innerHTML=formatPromptToTable(n),t.style.display="block"}catch(t){console.error("显示prompt对话框失败:",t),console.error("原始prompt:",e)}}
--------------------------------------------------------------------------------
/static/tokeninfo.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Token 信息管理
9 |
10 |
11 |
12 |
41 |
42 |
43 |
44 | Token 信息管理
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
Token 配置
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | 快捷键: Ctrl + S 保存更改
73 |
74 |
75 |
76 |
77 |
78 |
79 |
125 |
126 |
127 |
--------------------------------------------------------------------------------
/static/tokeninfo.min.html:
--------------------------------------------------------------------------------
1 | Token 信息管理Token 信息管理
Token 配置
快捷键: Ctrl + S 保存更改
--------------------------------------------------------------------------------