ai-zero-token 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/README.zh-CN.md +10 -0
- package/dist/core/providers/http-client.js +1 -1
- package/dist/core/services/auth-service.js +98 -7
- package/dist/core/services/config-service.js +15 -3
- package/dist/core/services/version-service.js +18 -13
- package/dist/core/store/settings-store.js +6 -0
- package/dist/server/admin-page.js +1009 -94
- package/dist/server/app.js +66 -1
- package/package.json +1 -1
package/dist/server/app.js
CHANGED
|
@@ -4,6 +4,7 @@ import Fastify from "fastify";
|
|
|
4
4
|
import cors from "@fastify/cors";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import { createGatewayContext } from "../core/context.js";
|
|
7
|
+
import { requestText } from "../core/providers/http-client.js";
|
|
7
8
|
import { renderAdminPage } from "./admin-page.js";
|
|
8
9
|
const inputPartSchema = z.object({
|
|
9
10
|
type: z.string().optional(),
|
|
@@ -72,8 +73,18 @@ const settingsUpdateSchema = z.object({
|
|
|
72
73
|
enabled: z.boolean(),
|
|
73
74
|
url: z.string().optional(),
|
|
74
75
|
noProxy: z.string().optional()
|
|
76
|
+
}).optional(),
|
|
77
|
+
autoSwitch: z.object({
|
|
78
|
+
enabled: z.boolean()
|
|
75
79
|
}).optional()
|
|
76
80
|
});
|
|
81
|
+
const proxyTestSchema = z.object({
|
|
82
|
+
networkProxy: z.object({
|
|
83
|
+
enabled: z.boolean(),
|
|
84
|
+
url: z.string().optional(),
|
|
85
|
+
noProxy: z.string().optional()
|
|
86
|
+
})
|
|
87
|
+
});
|
|
77
88
|
const profileActionSchema = z.object({
|
|
78
89
|
profileId: z.string().min(1)
|
|
79
90
|
});
|
|
@@ -551,7 +562,8 @@ function createApp(params) {
|
|
|
551
562
|
}
|
|
552
563
|
await ctx.authService.activateProfile(parsed.data.profileId);
|
|
553
564
|
await ctx.authService.syncActiveProfileQuota("openai-codex", {
|
|
554
|
-
suppressErrors: true
|
|
565
|
+
suppressErrors: true,
|
|
566
|
+
skipAutoSwitch: true
|
|
555
567
|
});
|
|
556
568
|
return buildAdminConfig(request);
|
|
557
569
|
});
|
|
@@ -649,8 +661,61 @@ function createApp(params) {
|
|
|
649
661
|
if (parsed.data.networkProxy) {
|
|
650
662
|
await ctx.configService.setNetworkProxy(parsed.data.networkProxy);
|
|
651
663
|
}
|
|
664
|
+
if (parsed.data.autoSwitch) {
|
|
665
|
+
await ctx.configService.setAutoSwitch(parsed.data.autoSwitch);
|
|
666
|
+
}
|
|
652
667
|
return buildAdminConfig(request);
|
|
653
668
|
});
|
|
669
|
+
app.post("/_gateway/admin/settings/proxy-test", async (request, reply) => {
|
|
670
|
+
const parsed = proxyTestSchema.safeParse(request.body);
|
|
671
|
+
if (!parsed.success) {
|
|
672
|
+
reply.code(400);
|
|
673
|
+
return {
|
|
674
|
+
error: {
|
|
675
|
+
type: "validation_error",
|
|
676
|
+
message: parsed.error.issues[0]?.message ?? "\u8BF7\u6C42\u4F53\u683C\u5F0F\u9519\u8BEF"
|
|
677
|
+
}
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
const proxy = {
|
|
681
|
+
enabled: parsed.data.networkProxy.enabled,
|
|
682
|
+
url: parsed.data.networkProxy.url?.trim() ?? "",
|
|
683
|
+
noProxy: parsed.data.networkProxy.noProxy?.trim() || "localhost,127.0.0.1,::1"
|
|
684
|
+
};
|
|
685
|
+
if (proxy.enabled && !proxy.url) {
|
|
686
|
+
reply.code(400);
|
|
687
|
+
return {
|
|
688
|
+
error: {
|
|
689
|
+
type: "validation_error",
|
|
690
|
+
message: "\u542F\u7528\u4EE3\u7406\u65F6\u5FC5\u987B\u586B\u5199\u4EE3\u7406\u5730\u5740\u3002"
|
|
691
|
+
}
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
const startedAt = performance.now();
|
|
695
|
+
try {
|
|
696
|
+
const response = await requestText({
|
|
697
|
+
method: "GET",
|
|
698
|
+
url: "https://chatgpt.com/",
|
|
699
|
+
timeoutMs: 8e3,
|
|
700
|
+
proxyOverride: proxy
|
|
701
|
+
});
|
|
702
|
+
return {
|
|
703
|
+
ok: response.status >= 200 && response.status < 500,
|
|
704
|
+
status: response.status,
|
|
705
|
+
elapsedMs: Math.round(performance.now() - startedAt),
|
|
706
|
+
target: "https://chatgpt.com/",
|
|
707
|
+
transport: response.transport
|
|
708
|
+
};
|
|
709
|
+
} catch (error) {
|
|
710
|
+
reply.code(502);
|
|
711
|
+
return {
|
|
712
|
+
error: {
|
|
713
|
+
type: "proxy_test_failed",
|
|
714
|
+
message: error instanceof Error ? error.message : String(error)
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
});
|
|
654
719
|
app.get("/v1/models", async () => ({
|
|
655
720
|
object: "list",
|
|
656
721
|
data: (await ctx.modelService.listModels()).map((model) => ({
|
package/package.json
CHANGED