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.
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-zero-token",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Local-first OpenAI-compatible AI CLI and gateway with Codex OAuth, multi-account management, and gpt-image-2 image generation/editing.",
5
5
  "license": "MIT",
6
6
  "type": "module",