mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-03 19:30:51 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6563490a6 | ||
|
|
18c1ba6c3c | ||
|
|
c2627cac3e | ||
|
|
df472119e7 |
35
.github/workflows/release.yml
vendored
35
.github/workflows/release.yml
vendored
@@ -15,6 +15,9 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
fetch-tags: true
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
@@ -36,27 +39,25 @@ jobs:
|
|||||||
mv index.html management.html
|
mv index.html management.html
|
||||||
ls -lh management.html
|
ls -lh management.html
|
||||||
|
|
||||||
|
- name: Generate release notes
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
current_tag="${GITHUB_REF_NAME}"
|
||||||
|
previous_tag="$(git tag --list 'v*' --sort=-v:refname | grep -v "^${current_tag}$" | head -n 1 || true)"
|
||||||
|
if [ -n "${previous_tag}" ]; then
|
||||||
|
range="${previous_tag}..${current_tag}"
|
||||||
|
else
|
||||||
|
range="${current_tag}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
: > release-notes.md
|
||||||
|
git log --pretty=format:"- %h %s" "${range}" >> release-notes.md
|
||||||
|
|
||||||
- name: Create Release
|
- name: Create Release
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
with:
|
with:
|
||||||
files: dist/management.html
|
files: dist/management.html
|
||||||
body: |
|
body_path: release-notes.md
|
||||||
## CLI Proxy API Management Center - ${{ github.ref_name }}
|
|
||||||
|
|
||||||
### Download and Usage
|
|
||||||
1. Download the `management.html` file
|
|
||||||
2. Open it directly in your browser
|
|
||||||
3. All assets (CSS, JavaScript, images) are bundled into this single file
|
|
||||||
|
|
||||||
### Features
|
|
||||||
- Single file, no external dependencies required
|
|
||||||
- Complete management interface for CLI Proxy API
|
|
||||||
- Support for local and remote connections
|
|
||||||
- Multi-language support (Chinese/English)
|
|
||||||
- Dark/Light theme support
|
|
||||||
|
|
||||||
---
|
|
||||||
🤖 Generated with GitHub Actions
|
|
||||||
draft: false
|
draft: false
|
||||||
prerelease: false
|
prerelease: false
|
||||||
env:
|
env:
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -17,6 +17,7 @@ dist-ssr
|
|||||||
*.local
|
*.local
|
||||||
|
|
||||||
# Editor directories and files
|
# Editor directories and files
|
||||||
|
settings.local.json
|
||||||
.vscode/*
|
.vscode/*
|
||||||
!.vscode/extensions.json
|
!.vscode/extensions.json
|
||||||
.idea
|
.idea
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
export function LoadingSpinner({ size = 20 }: { size?: number }) {
|
export function LoadingSpinner({
|
||||||
|
size = 20,
|
||||||
|
className = ''
|
||||||
|
}: {
|
||||||
|
size?: number;
|
||||||
|
className?: string;
|
||||||
|
}) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="loading-spinner"
|
className={`loading-spinner${className ? ` ${className}` : ''}`}
|
||||||
style={{ width: size, height: size, borderWidth: size / 7 }}
|
style={{ width: size, height: size, borderWidth: size / 7 }}
|
||||||
role="status"
|
role="status"
|
||||||
aria-live="polite"
|
aria-live="polite"
|
||||||
|
|||||||
@@ -200,8 +200,6 @@
|
|||||||
"ampcode_upstream_api_key_current": "Current Amp official key: {{key}}",
|
"ampcode_upstream_api_key_current": "Current Amp official key: {{key}}",
|
||||||
"ampcode_clear_upstream_api_key": "Clear official key",
|
"ampcode_clear_upstream_api_key": "Clear official key",
|
||||||
"ampcode_clear_upstream_api_key_confirm": "Are you sure you want to clear the Ampcode upstream API key (Amp official)?",
|
"ampcode_clear_upstream_api_key_confirm": "Are you sure you want to clear the Ampcode upstream API key (Amp official)?",
|
||||||
"ampcode_restrict_management_label": "Restrict Amp management routes to localhost",
|
|
||||||
"ampcode_restrict_management_hint": "When enabled, Amp management routes (/api/auth, /api/user, /api/threads, etc.) only accept 127.0.0.1/::1 (recommended).",
|
|
||||||
"ampcode_force_model_mappings_label": "Force model mappings",
|
"ampcode_force_model_mappings_label": "Force model mappings",
|
||||||
"ampcode_force_model_mappings_hint": "When enabled, mappings override local API-key availability checks.",
|
"ampcode_force_model_mappings_hint": "When enabled, mappings override local API-key availability checks.",
|
||||||
"ampcode_model_mappings_label": "Model mappings (from → to)",
|
"ampcode_model_mappings_label": "Model mappings (from → to)",
|
||||||
|
|||||||
@@ -200,8 +200,6 @@
|
|||||||
"ampcode_upstream_api_key_current": "当前Amp官方密钥: {{key}}",
|
"ampcode_upstream_api_key_current": "当前Amp官方密钥: {{key}}",
|
||||||
"ampcode_clear_upstream_api_key": "清除官方密钥",
|
"ampcode_clear_upstream_api_key": "清除官方密钥",
|
||||||
"ampcode_clear_upstream_api_key_confirm": "确定要清除 Ampcode 的 upstream API key(Amp官方)吗?",
|
"ampcode_clear_upstream_api_key_confirm": "确定要清除 Ampcode 的 upstream API key(Amp官方)吗?",
|
||||||
"ampcode_restrict_management_label": "仅允许本机访问 Amp 管理路由",
|
|
||||||
"ampcode_restrict_management_hint": "开启后,/api/auth、/api/user、/api/threads 等 Amp 管理路由仅允许 127.0.0.1/::1 访问(推荐)。",
|
|
||||||
"ampcode_force_model_mappings_label": "强制应用模型映射",
|
"ampcode_force_model_mappings_label": "强制应用模型映射",
|
||||||
"ampcode_force_model_mappings_hint": "开启后,模型映射将覆盖本地 API Key 可用性判断。",
|
"ampcode_force_model_mappings_hint": "开启后,模型映射将覆盖本地 API Key 可用性判断。",
|
||||||
"ampcode_model_mappings_label": "模型映射 (from → to)",
|
"ampcode_model_mappings_label": "模型映射 (from → to)",
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ interface OpenAIFormState {
|
|||||||
interface AmpcodeFormState {
|
interface AmpcodeFormState {
|
||||||
upstreamUrl: string;
|
upstreamUrl: string;
|
||||||
upstreamApiKey: string;
|
upstreamApiKey: string;
|
||||||
restrictManagementToLocalhost: boolean;
|
|
||||||
forceModelMappings: boolean;
|
forceModelMappings: boolean;
|
||||||
mappingEntries: ModelEntry[];
|
mappingEntries: ModelEntry[];
|
||||||
}
|
}
|
||||||
@@ -174,7 +173,6 @@ const entriesToAmpcodeMappings = (entries: ModelEntry[]): AmpcodeModelMapping[]
|
|||||||
const buildAmpcodeFormState = (ampcode?: AmpcodeConfig | null): AmpcodeFormState => ({
|
const buildAmpcodeFormState = (ampcode?: AmpcodeConfig | null): AmpcodeFormState => ({
|
||||||
upstreamUrl: ampcode?.upstreamUrl ?? '',
|
upstreamUrl: ampcode?.upstreamUrl ?? '',
|
||||||
upstreamApiKey: '',
|
upstreamApiKey: '',
|
||||||
restrictManagementToLocalhost: ampcode?.restrictManagementToLocalhost ?? true,
|
|
||||||
forceModelMappings: ampcode?.forceModelMappings ?? false,
|
forceModelMappings: ampcode?.forceModelMappings ?? false,
|
||||||
mappingEntries: ampcodeMappingsToEntries(ampcode?.modelMappings),
|
mappingEntries: ampcodeMappingsToEntries(ampcode?.modelMappings),
|
||||||
});
|
});
|
||||||
@@ -701,9 +699,6 @@ export function AiProvidersPage() {
|
|||||||
await ampcodeApi.clearUpstreamUrl();
|
await ampcodeApi.clearUpstreamUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
await ampcodeApi.updateRestrictManagementToLocalhost(
|
|
||||||
ampcodeForm.restrictManagementToLocalhost
|
|
||||||
);
|
|
||||||
await ampcodeApi.updateForceModelMappings(ampcodeForm.forceModelMappings);
|
await ampcodeApi.updateForceModelMappings(ampcodeForm.forceModelMappings);
|
||||||
|
|
||||||
if (ampcodeLoaded || ampcodeMappingsDirty) {
|
if (ampcodeLoaded || ampcodeMappingsDirty) {
|
||||||
@@ -720,12 +715,18 @@ export function AiProvidersPage() {
|
|||||||
|
|
||||||
const previous = config?.ampcode ?? {};
|
const previous = config?.ampcode ?? {};
|
||||||
const next: AmpcodeConfig = {
|
const next: AmpcodeConfig = {
|
||||||
...previous,
|
|
||||||
upstreamUrl: upstreamUrl || undefined,
|
upstreamUrl: upstreamUrl || undefined,
|
||||||
restrictManagementToLocalhost: ampcodeForm.restrictManagementToLocalhost,
|
|
||||||
forceModelMappings: ampcodeForm.forceModelMappings,
|
forceModelMappings: ampcodeForm.forceModelMappings,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (previous.upstreamApiKey) {
|
||||||
|
next.upstreamApiKey = previous.upstreamApiKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(previous.modelMappings)) {
|
||||||
|
next.modelMappings = previous.modelMappings;
|
||||||
|
}
|
||||||
|
|
||||||
if (overrideKey) {
|
if (overrideKey) {
|
||||||
next.upstreamApiKey = overrideKey;
|
next.upstreamApiKey = overrideKey;
|
||||||
}
|
}
|
||||||
@@ -1505,16 +1506,6 @@ export function AiProvidersPage() {
|
|||||||
: t('common.not_set')}
|
: t('common.not_set')}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.fieldRow}>
|
|
||||||
<span className={styles.fieldLabel}>
|
|
||||||
{t('ai_providers.ampcode_restrict_management_label')}:
|
|
||||||
</span>
|
|
||||||
<span className={styles.fieldValue}>
|
|
||||||
{(config?.ampcode?.restrictManagementToLocalhost ?? true)
|
|
||||||
? t('common.yes')
|
|
||||||
: t('common.no')}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div className={styles.fieldRow}>
|
<div className={styles.fieldRow}>
|
||||||
<span className={styles.fieldLabel}>
|
<span className={styles.fieldLabel}>
|
||||||
{t('ai_providers.ampcode_force_model_mappings_label')}:
|
{t('ai_providers.ampcode_force_model_mappings_label')}:
|
||||||
@@ -1739,18 +1730,6 @@ export function AiProvidersPage() {
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="form-group">
|
|
||||||
<ToggleSwitch
|
|
||||||
label={t('ai_providers.ampcode_restrict_management_label')}
|
|
||||||
checked={ampcodeForm.restrictManagementToLocalhost}
|
|
||||||
onChange={(value) =>
|
|
||||||
setAmpcodeForm((prev) => ({ ...prev, restrictManagementToLocalhost: value }))
|
|
||||||
}
|
|
||||||
disabled={ampcodeModalLoading || ampcodeSaving}
|
|
||||||
/>
|
|
||||||
<div className="hint">{t('ai_providers.ampcode_restrict_management_hint')}</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="form-group">
|
<div className="form-group">
|
||||||
<ToggleSwitch
|
<ToggleSwitch
|
||||||
label={t('ai_providers.ampcode_force_model_mappings_label')}
|
label={t('ai_providers.ampcode_force_model_mappings_label')}
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ export function OAuthPage() {
|
|||||||
{t('auth_login.oauth_callback_button')}
|
{t('auth_login.oauth_callback_button')}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
{state.callbackStatus === 'success' && (
|
{state.callbackStatus === 'success' && state.status === 'waiting' && (
|
||||||
<div className="status-badge success" style={{ marginTop: 8 }}>
|
<div className="status-badge success" style={{ marginTop: 8 }}>
|
||||||
{t('auth_login.oauth_callback_status_success')}
|
{t('auth_login.oauth_callback_status_success')}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -66,11 +66,12 @@
|
|||||||
border: 1px solid var(--border-color);
|
border: 1px solid var(--border-color);
|
||||||
background: var(--bg-primary);
|
background: var(--bg-primary);
|
||||||
box-shadow: var(--shadow-lg);
|
box-shadow: var(--shadow-lg);
|
||||||
|
}
|
||||||
|
|
||||||
:global(.loading-spinner) {
|
.loadingOverlaySpinner {
|
||||||
border-color: rgba(59, 130, 246, 0.25);
|
border-color: rgba(59, 130, 246, 0.25);
|
||||||
border-top-color: var(--primary-color);
|
border-top-color: var(--primary-color);
|
||||||
}
|
box-shadow: 0 0 10px rgba(59, 130, 246, 0.25);
|
||||||
}
|
}
|
||||||
|
|
||||||
.loadingOverlayText {
|
.loadingOverlayText {
|
||||||
|
|||||||
@@ -520,7 +520,7 @@ export function UsagePage() {
|
|||||||
{loading && !usage && (
|
{loading && !usage && (
|
||||||
<div className={styles.loadingOverlay} aria-busy="true">
|
<div className={styles.loadingOverlay} aria-busy="true">
|
||||||
<div className={styles.loadingOverlayContent}>
|
<div className={styles.loadingOverlayContent}>
|
||||||
<LoadingSpinner size={28} />
|
<LoadingSpinner size={28} className={styles.loadingOverlaySpinner} />
|
||||||
<span className={styles.loadingOverlayText}>{t('common.loading')}</span>
|
<span className={styles.loadingOverlayText}>{t('common.loading')}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -18,9 +18,6 @@ export const ampcodeApi = {
|
|||||||
updateUpstreamApiKey: (apiKey: string) => apiClient.put('/ampcode/upstream-api-key', { value: apiKey }),
|
updateUpstreamApiKey: (apiKey: string) => apiClient.put('/ampcode/upstream-api-key', { value: apiKey }),
|
||||||
clearUpstreamApiKey: () => apiClient.delete('/ampcode/upstream-api-key'),
|
clearUpstreamApiKey: () => apiClient.delete('/ampcode/upstream-api-key'),
|
||||||
|
|
||||||
updateRestrictManagementToLocalhost: (enabled: boolean) =>
|
|
||||||
apiClient.put('/ampcode/restrict-management-to-localhost', { value: enabled }),
|
|
||||||
|
|
||||||
async getModelMappings(): Promise<AmpcodeModelMapping[]> {
|
async getModelMappings(): Promise<AmpcodeModelMapping[]> {
|
||||||
const data = await apiClient.get('/ampcode/model-mappings');
|
const data = await apiClient.get('/ampcode/model-mappings');
|
||||||
const list = data?.['model-mappings'] ?? data?.modelMappings ?? data?.items ?? data;
|
const list = data?.['model-mappings'] ?? data?.modelMappings ?? data?.items ?? data;
|
||||||
|
|||||||
@@ -82,6 +82,10 @@ class ApiClient {
|
|||||||
(config) => {
|
(config) => {
|
||||||
// 设置 baseURL
|
// 设置 baseURL
|
||||||
config.baseURL = this.apiBase;
|
config.baseURL = this.apiBase;
|
||||||
|
if (config.url) {
|
||||||
|
// Normalize deprecated Gemini endpoint to the current path.
|
||||||
|
config.url = config.url.replace(/\/generative-language-api-key\b/g, '/gemini-api-key');
|
||||||
|
}
|
||||||
|
|
||||||
// 添加认证头
|
// 添加认证头
|
||||||
if (this.managementKey) {
|
if (this.managementKey) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { apiClient } from './client';
|
import { apiClient } from './client';
|
||||||
|
import { LOGS_TIMEOUT_MS } from '@/utils/constants';
|
||||||
|
|
||||||
export interface LogsQuery {
|
export interface LogsQuery {
|
||||||
after?: number;
|
after?: number;
|
||||||
@@ -25,14 +26,17 @@ export interface ErrorLogsResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const logsApi = {
|
export const logsApi = {
|
||||||
fetchLogs: (params: LogsQuery = {}): Promise<LogsResponse> => apiClient.get('/logs', { params }),
|
fetchLogs: (params: LogsQuery = {}): Promise<LogsResponse> =>
|
||||||
|
apiClient.get('/logs', { params, timeout: LOGS_TIMEOUT_MS }),
|
||||||
|
|
||||||
clearLogs: () => apiClient.delete('/logs'),
|
clearLogs: () => apiClient.delete('/logs'),
|
||||||
|
|
||||||
fetchErrorLogs: (): Promise<ErrorLogsResponse> => apiClient.get('/request-error-logs'),
|
fetchErrorLogs: (): Promise<ErrorLogsResponse> =>
|
||||||
|
apiClient.get('/request-error-logs', { timeout: LOGS_TIMEOUT_MS }),
|
||||||
|
|
||||||
downloadErrorLog: (filename: string) =>
|
downloadErrorLog: (filename: string) =>
|
||||||
apiClient.getRaw(`/request-error-logs/${encodeURIComponent(filename)}`, {
|
apiClient.getRaw(`/request-error-logs/${encodeURIComponent(filename)}`, {
|
||||||
responseType: 'blob',
|
responseType: 'blob',
|
||||||
|
timeout: LOGS_TIMEOUT_MS
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -205,15 +205,6 @@ const normalizeAmpcodeConfig = (payload: any): AmpcodeConfig | undefined => {
|
|||||||
const upstreamApiKey = source['upstream-api-key'] ?? source.upstreamApiKey ?? source['upstream_api_key'];
|
const upstreamApiKey = source['upstream-api-key'] ?? source.upstreamApiKey ?? source['upstream_api_key'];
|
||||||
if (upstreamApiKey) config.upstreamApiKey = String(upstreamApiKey);
|
if (upstreamApiKey) config.upstreamApiKey = String(upstreamApiKey);
|
||||||
|
|
||||||
const restrictManagementToLocalhost = normalizeBoolean(
|
|
||||||
source['restrict-management-to-localhost'] ??
|
|
||||||
source.restrictManagementToLocalhost ??
|
|
||||||
source['restrict_management_to_localhost']
|
|
||||||
);
|
|
||||||
if (restrictManagementToLocalhost !== undefined) {
|
|
||||||
config.restrictManagementToLocalhost = restrictManagementToLocalhost;
|
|
||||||
}
|
|
||||||
|
|
||||||
const forceModelMappings = normalizeBoolean(
|
const forceModelMappings = normalizeBoolean(
|
||||||
source['force-model-mappings'] ?? source.forceModelMappings ?? source['force_model_mappings']
|
source['force-model-mappings'] ?? source.forceModelMappings ?? source['force_model_mappings']
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ export interface AmpcodeModelMapping {
|
|||||||
export interface AmpcodeConfig {
|
export interface AmpcodeConfig {
|
||||||
upstreamUrl?: string;
|
upstreamUrl?: string;
|
||||||
upstreamApiKey?: string;
|
upstreamApiKey?: string;
|
||||||
restrictManagementToLocalhost?: boolean;
|
|
||||||
modelMappings?: AmpcodeModelMapping[];
|
modelMappings?: AmpcodeModelMapping[];
|
||||||
forceModelMappings?: boolean;
|
forceModelMappings?: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export const LOG_REFRESH_DELAY_MS = 500;
|
|||||||
// 日志相关
|
// 日志相关
|
||||||
export const MAX_LOG_LINES = 2000;
|
export const MAX_LOG_LINES = 2000;
|
||||||
export const LOG_FETCH_LIMIT = 2500;
|
export const LOG_FETCH_LIMIT = 2500;
|
||||||
|
export const LOGS_TIMEOUT_MS = 60 * 1000;
|
||||||
|
|
||||||
// 认证文件分页
|
// 认证文件分页
|
||||||
export const DEFAULT_AUTH_FILES_PAGE_SIZE = 20;
|
export const DEFAULT_AUTH_FILES_PAGE_SIZE = 20;
|
||||||
|
|||||||
Reference in New Issue
Block a user