Files
cursor2api/Dockerfile
huangzhenting c4b81f33d1 fix: improve token budget accuracy and add TokenDiff logging
- converter: replace rough overhead formula (tools*70+350) with actual
  estimateTokens on built few-shot messages + Cursor hidden overhead
  (1300 base + perTool by schema_mode); remove 16000 output reservation
- cursor-client: sendCursorRequestFull now returns {text, usage?} to
  capture real Cursor inputTokens/outputTokens from messageMetadata
- handler: add estimateCursorReqTokens() and [TokenDiff] log to compare
  tiktoken estimate vs actual Cursor usage; fix non-stream retry paths
  to update usage from retry result; skip auto-continue when response < 200 chars
- openai-handler: update 4 call sites for new sendCursorRequestFull return type
- config: raise default maxHistoryTokens from 130000 to 150000
- docs/config: remove incorrect 'tiktoken underestimates 10~20%' claim;
  update overhead description and reference range to 130000~170000
2026-03-22 02:35:04 +08:00

57 lines
1.5 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ==== Stage 1: 构建阶段 (Builder) ====
FROM node:22-alpine AS builder
# 设置工作目录
WORKDIR /app
# 仅拷贝包配置并安装所有依赖项(利用 Docker 缓存层)
COPY package.json package-lock.json ./
RUN npm ci
# 拷贝项目源代码并执行 TypeScript 编译
COPY tsconfig.json ./
COPY src ./src
RUN npm run build
# ==== Stage 2: 生产运行阶段 (Runner) ====
FROM node:22-alpine AS runner
WORKDIR /app
# 设置为生产环境
ENV NODE_ENV=production
# 增大 Node.js 堆内存上限,防止日志文件过大时加载 OOMtesseract.js / js-tiktoken 初始化也有一定内存需求)
ENV NODE_OPTIONS="--max-old-space-size=4096"
# 出于安全考虑,避免使用 root 用户运行服务
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 cursor
# 拷贝包配置并仅安装生产环境依赖(极大减小镜像体积)
COPY package.json package-lock.json ./
RUN npm ci --omit=dev \
&& npm cache clean --force
# 从 builder 阶段拷贝编译后的产物
COPY --from=builder --chown=cursor:nodejs /app/dist ./dist
# 拷贝前端静态资源(日志查看器 Web UI
COPY --chown=cursor:nodejs public ./public
# 创建日志目录并授权
RUN mkdir -p /app/logs && chown cursor:nodejs /app/logs
# 注意config.yaml 不打包进镜像,通过 docker-compose volumes 挂载
# 如果未挂载,服务会使用内置默认值 + 环境变量
# 切换到非 root 用户
USER cursor
# 声明对外暴露的端口和持久化卷
EXPOSE 3010
VOLUME ["/app/logs"]
# 启动服务
CMD ["npm", "start"]