diff --git a/.github/workflows/build-darwin.yml b/.github/workflows/build-darwin.yml index 1a974f0..013ea8f 100644 --- a/.github/workflows/build-darwin.yml +++ b/.github/workflows/build-darwin.yml @@ -25,33 +25,26 @@ jobs: run: | RUSTFLAGS="-C link-arg=-s -C target-cpu=x86-64-v3" \ cargo build --release --target x86_64-apple-darwin + mv target/x86_64-apple-darwin/release/cursor-api cursor-api-x86_64-apple-darwin - name: Build arm64 binary run: | RUSTFLAGS="-C link-arg=-s -C target-cpu=apple-m1" \ cargo build --release --target aarch64-apple-darwin + mv target/aarch64-apple-darwin/release/cursor-api cursor-api-aarch64-apple-darwin - name: Create universal binary run: | lipo -create \ - target/x86_64-apple-darwin/release/cursor-api \ - target/aarch64-apple-darwin/release/cursor-api \ - -output target/cursor-api-universal + cursor-api-x86_64-apple-darwin \ + cursor-api-aarch64-apple-darwin \ + -output cursor-api-universal-apple-darwin - - name: Upload x86_64 artifact + - name: Upload artifacts uses: actions/upload-artifact@v4.6.0 with: - name: cursor-api-x86_64-apple-darwin - path: target/x86_64-apple-darwin/release/cursor-api - - - name: Upload arm64 artifact - uses: actions/upload-artifact@v4.6.0 - with: - name: cursor-api-aarch64-apple-darwin - path: target/aarch64-apple-darwin/release/cursor-api - - - name: Upload universal artifact - uses: actions/upload-artifact@v4.6.0 - with: - name: cursor-api-universal-apple-darwin - path: target/cursor-api-universal + name: cursor-api-darwin + path: | + cursor-api-x86_64-apple-darwin + cursor-api-aarch64-apple-darwin + cursor-api-universal-apple-darwin diff --git a/.gitignore b/.gitignore index e57501b..e843bf7 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ node_modules /build* /*.bin /result.txt +tools/tokenizer/ diff --git a/Cargo.lock b/Cargo.lock index bf76934..55973c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -361,7 +361,7 @@ dependencies = [ [[package]] name = "cursor-api" -version = "0.1.3-rc.4.2" +version = "0.1.3-rc.4.3" dependencies = [ "axum", "base64", diff --git a/Cargo.toml b/Cargo.toml index 0108b28..8989bd2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cursor-api" -version = "0.1.3-rc.4.2" +version = "0.1.3-rc.4.3" edition = "2021" authors = ["wisdgod "] description = "OpenAI format compatibility layer for the Cursor API" diff --git a/Dockerfile b/Dockerfile index 9ec1ae4..da4219b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,49 +1,36 @@ -# AMD64 构建阶段 -FROM --platform=linux/amd64 rust:1.84.0-slim-bookworm as builder-amd64 +ARG TARGETARCH +FROM --platform=linux/${TARGETARCH} rust:1.84.0-slim-bookworm as builder + +ARG TARGETARCH + WORKDIR /app RUN apt-get update && \ apt-get install -y --no-install-recommends \ build-essential protobuf-compiler pkg-config libssl-dev nodejs npm openssl \ && rm -rf /var/lib/apt/lists/* + COPY . . -ENV RUSTFLAGS="-C link-arg=-s -C target-cpu=x86-64-v3" -RUN cargo build --release && \ +RUN case "$TARGETARCH" in \ + amd64) TARGET_CPU="x86-64-v3" ;; \ + arm64) TARGET_CPU="neoverse-n1" ;; \ + *) echo "Unsupported architecture: $TARGETARCH" && exit 1 ;; \ + esac && \ + RUSTFLAGS="-C link-arg=-s -C target-cpu=$TARGET_CPU" cargo build --release && \ cp target/release/cursor-api /app/cursor-api -# ARM64 构建阶段 -FROM --platform=linux/arm64 rust:1.84.0-slim-bookworm as builder-arm64 -WORKDIR /app -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - build-essential protobuf-compiler pkg-config libssl-dev nodejs npm openssl \ - && rm -rf /var/lib/apt/lists/* -COPY . . -ENV RUSTFLAGS="-C link-arg=-s -C target-cpu=apple-m1" -RUN cargo build --release && \ - cp target/release/cursor-api /app/cursor-api +# 运行阶段 +FROM --platform=linux/${TARGETARCH} debian:bookworm-slim -# AMD64 运行阶段 -FROM --platform=linux/amd64 debian:bookworm-slim as run-amd64 WORKDIR /app ENV TZ=Asia/Shanghai + RUN apt-get update && \ apt-get install -y --no-install-recommends \ ca-certificates tzdata openssl \ && rm -rf /var/lib/apt/lists/* -COPY --from=builder-amd64 /app/cursor-api . -# ARM64 运行阶段 -FROM --platform=linux/arm64 debian:bookworm-slim as run-arm64 -WORKDIR /app -ENV TZ=Asia/Shanghai -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - ca-certificates tzdata openssl \ - && rm -rf /var/lib/apt/lists/* -COPY --from=builder-arm64 /app/cursor-api . +COPY --from=builder /app/cursor-api . -# 通用配置 -FROM run-${TARGETARCH} ENV PORT=3000 EXPOSE ${PORT} CMD ["./cursor-api"] \ No newline at end of file diff --git a/src/chat/service.rs b/src/chat/service.rs index e7a431a..dffc972 100644 --- a/src/chat/service.rs +++ b/src/chat/service.rs @@ -730,7 +730,7 @@ pub async fn handle_chat( index: 0, message: Some(Message { role: Role::Assistant, - content: MessageContent::Text(full_text), + content: MessageContent::Text(full_text.trim_leading_newlines()), }), delta: None, finish_reason: Some(FINISH_REASON_STOP.to_string()), diff --git a/src/common/utils.rs b/src/common/utils.rs index 94fb836..1adc30d 100644 --- a/src/common/utils.rs +++ b/src/common/utils.rs @@ -55,11 +55,13 @@ pub trait TrimNewlines { impl TrimNewlines for String { #[inline(always)] fn trim_leading_newlines(mut self) -> Self { - if self.as_bytes().get(..2) == Some(b"\n\n".as_slice()) { + let bytes = self.as_bytes(); + if bytes.len() >= 2 && bytes[0] == b'\n' && bytes[1] == b'\n' { unsafe { - let vec = self.as_mut_vec(); - vec.copy_within(2.., 0); - vec.truncate(vec.len() - 2); + let start_ptr = self.as_mut_ptr(); + let new_len = self.len() - 2; + std::ptr::copy(start_ptr.add(2), start_ptr, new_len); + self.as_mut_vec().set_len(new_len); } } self diff --git a/static/tokens.html b/static/tokens.html index 3ebb4fe..2225d9d 100644 --- a/static/tokens.html +++ b/static/tokens.html @@ -91,7 +91,8 @@ /* 操作按钮样式 */ .action-cell { - width: 100px; + width: 160px; + /* 增加宽度以容纳两个按钮 */ text-align: center !important; } @@ -99,6 +100,8 @@ padding: 2px 8px; font-size: 12px; white-space: nowrap; + margin: 0 2px; + /* 添加按钮间距 */ } /* 提示框样式 */ @@ -256,6 +259,21 @@ .model-item input[type="checkbox"] { margin-right: 8px; } + + /* 确认对话框的额外样式 */ + #confirmModal { + max-width: 400px; + } + + #confirmModal .modal-content { + margin: 20px 0; + text-align: center; + } + + #confirmModal .modal-footer button { + min-width: 80px; + margin-left: 10px; + } @@ -368,6 +386,21 @@ + + + +