-
-
Notifications
You must be signed in to change notification settings - Fork 566
Add WebUI and multi account manage #196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
StarryKira
wants to merge
7
commits into
ericc-ch:master
Choose a base branch
from
StarryKira:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
完善功能
- Loading branch information
commit 486bab857af078b10ddf58e3d1e5a3c113efbef2
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## Project Overview | ||
|
|
||
| copilot-api is a reverse proxy that exposes GitHub Copilot as OpenAI and Anthropic-compatible API endpoints. Built with Bun, TypeScript, Hono, and citty (CLI framework). | ||
|
|
||
| ## Commands | ||
|
|
||
| - **Build:** `bun run build` (tsdown bundler, outputs to `dist/`) | ||
| - **Dev:** `bun run dev` (watch mode via `bun run --watch`) | ||
| - **Start:** `bun run start` (production mode) | ||
| - **Lint:** `bun run lint` (ESLint with `@echristian/eslint-config`) | ||
| - **Typecheck:** `bun run typecheck` (tsc, no emit) | ||
| - **Test all:** `bun test` | ||
| - **Test single file:** `bun test tests/<filename>.test.ts` | ||
| - **Unused code detection:** `bun run knip` | ||
|
|
||
| ## Architecture | ||
|
|
||
| ### CLI Layer (`src/main.ts`) | ||
| Entry point uses citty to define subcommands: `start`, `auth`, `check-usage`, `debug`, `console`. | ||
|
|
||
| ### Server (`src/server.ts`) | ||
| Hono app with routes mounted at both `/` and `/v1/` prefixes for compatibility: | ||
| - `POST /v1/chat/completions` — OpenAI-compatible chat completions | ||
| - `POST /v1/messages` — Anthropic-compatible messages API | ||
| - `POST /v1/messages/count_tokens` — Token counting | ||
| - `GET /v1/models` — Model listing | ||
| - `POST /v1/embeddings` — Embeddings | ||
| - `GET /usage`, `GET /token` — Monitoring endpoints | ||
|
|
||
| ### Key Directories | ||
| - `src/routes/` — Route handlers, each in its own directory with `route.ts` + `handler.ts` | ||
| - `src/services/copilot/` — GitHub Copilot API calls (completions, embeddings, models) | ||
| - `src/services/github/` — GitHub API calls (auth, tokens, usage) | ||
| - `src/lib/` — Shared utilities (state, tokens, rate limiting, error handling, proxy) | ||
| - `src/console/` — Multi-account management mode with load balancing and web UI | ||
| - `web/` — React + Vite frontend for the console mode | ||
| - `tests/` — Bun test runner, files named `*.test.ts` | ||
|
|
||
| ### Global State (`src/lib/state.ts`) | ||
| Mutable singleton `state` object holds runtime config: GitHub/Copilot tokens, account type, cached models, rate limit settings. | ||
|
|
||
| ### Anthropic Translation Layer (`src/routes/messages/`) | ||
| Converts between Anthropic message format and Copilot's OpenAI-style API. Handles both streaming (`stream-translation.ts`) and non-streaming (`non-stream-translation.ts`) responses. | ||
|
|
||
| ## Code Conventions | ||
|
|
||
| - ESM only, strict TypeScript — no `any`, no unused variables/imports | ||
| - Path alias: `~/*` maps to `src/*` (e.g., `import { state } from "~/lib/state"`) | ||
| - camelCase for variables/functions, PascalCase for types/classes | ||
| - Zod v4 for runtime validation | ||
| - Pre-commit hook runs lint-staged via simple-git-hooks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,39 @@ | ||
| # Stage 1: Build frontend | ||
| FROM node:22-alpine AS web-builder | ||
| WORKDIR /app/web | ||
|
|
||
| COPY web/package.json ./ | ||
| RUN npm install | ||
|
|
||
| COPY web/ ./ | ||
| RUN npm run build | ||
|
|
||
| # Stage 2: Build backend | ||
| FROM oven/bun:1.2.19-alpine AS builder | ||
| WORKDIR /app | ||
|
|
||
| COPY ./package.json ./bun.lock ./ | ||
| COPY package.json bun.lock ./ | ||
| RUN bun install --frozen-lockfile | ||
|
|
||
| COPY . . | ||
| RUN bun run build | ||
|
|
||
| FROM oven/bun:1.2.19-alpine AS runner | ||
| # Stage 3: Runtime | ||
| FROM oven/bun:1.2.19-alpine | ||
| WORKDIR /app | ||
|
|
||
| COPY ./package.json ./bun.lock ./ | ||
| COPY package.json bun.lock ./ | ||
| RUN bun install --frozen-lockfile --production --ignore-scripts --no-cache | ||
|
|
||
| COPY --from=builder /app/dist ./dist | ||
| COPY --from=builder /app/src ./src | ||
| COPY --from=builder /app/tsconfig.json ./ | ||
| COPY --from=web-builder /app/web/dist ./web/dist | ||
|
|
||
| EXPOSE 3000 4141 | ||
|
|
||
| EXPOSE 4141 | ||
| VOLUME /root/.local/share/copilot-api | ||
|
|
||
| HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ | ||
| CMD wget --spider -q http://localhost:4141/ || exit 1 | ||
| HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \ | ||
| CMD wget --spider -q http://localhost:3000/api/config || exit 1 | ||
|
|
||
| COPY entrypoint.sh /entrypoint.sh | ||
| RUN chmod +x /entrypoint.sh | ||
| ENTRYPOINT ["/entrypoint.sh"] | ||
| ENTRYPOINT ["bun", "run", "./src/main.ts", "console"] | ||
| CMD ["--web-port", "3000", "--proxy-port", "4141"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/accounts(and similar endpoints) return the full persisted account object via{ ...account, ... }, which includesgithubToken. This exposes GitHub access tokens to the browser unnecessarily (the UI doesn’t use them) and increases impact of any client-side compromise. Consider omittinggithubToken(and any other secrets) from API responses and adjusting the webAccounttype accordingly.