@@ -7,22 +7,22 @@ import { EXAMPLE_CONFIG_YAML } from "./config/template.js";
77import { AuthManager } from "./auth/manager.js" ;
88import { startServer , type ProxyServer } from "./server/server.js" ;
99import { startControlListener , LogBuffer , type ControlState } from "./android/control.js" ;
10- import { ResponseStore } from "./responses/store.js" ;
1110import { loadCredential , saveCredential , clearCredential , getStorePath } from "./auth/store.js" ;
1211import { ZaiOAuthClient , BigmodelOAuthClient } from "./auth/oauth.js" ;
1312import { KeyResolver } from "./auth/resolver.js" ;
1413import type { Credential } from "./auth/types.js" ;
1514import type { ProviderId } from "./provider/types.js" ;
1615import type { ProxyConfig } from "./config/types.js" ;
17- import { parse , stringify } from "yaml" ;
18- import { spawn } from "node:child_process" ;
16+ import { updateConfigYaml } from "./config/edit.js" ;
17+ import { openBrowser } from "./runtime/open-browser.js" ;
18+ import { buildServerOptions } from "./server/server-options.js" ;
1919import { readFileSync , existsSync , writeFileSync } from "node:fs" ;
2020import { join } from "node:path" ;
2121import { homedir } from "node:os" ;
2222import { randomUUID } from "node:crypto" ;
2323import { ensureNodeFetchNoTimeouts } from "./runtime/node-fetch-compat.js" ;
2424
25- const VERSION = "2.6.0" ;
25+ export const VERSION = "2.6.0" ;
2626
2727if ( require . main === module ) main ( ) ;
2828
@@ -74,6 +74,16 @@ function runCli(): void {
7474 process . stderr . write ( `zcode-proxy: android entry failed: ${ ( err as Error ) . stack ?? String ( err ) } \n` ) ;
7575 process . exit ( 1 ) ;
7676 } ) ;
77+ } else if ( cmd === "tui" ) {
78+ // Dynamic import: the TUI module imports helpers back from this file, so a
79+ // static edge would create a load-time cycle (same pattern as claimCommand).
80+ const tuiArgs = parseServeArgs ( args . slice ( 1 ) ) ;
81+ import ( "./tui/app.js" )
82+ . then ( ( m ) => m . runTui ( tuiArgs ) )
83+ . catch ( ( err : unknown ) => {
84+ process . stderr . write ( `zcode-proxy: tui failed: ${ ( err as Error ) . stack ?? String ( err ) } \n` ) ;
85+ process . exit ( 1 ) ;
86+ } ) ;
7787 } else if ( cmd === "serve" || cmd . endsWith ( ".yaml" ) || cmd . endsWith ( ".yml" ) ) {
7888 const serveArgs = cmd === "serve"
7989 ? parseServeArgs ( args . slice ( 1 ) )
@@ -97,6 +107,7 @@ Usage:
97107 zcode-proxy serve [config.yaml] Start the proxy server (default)
98108 zcode-proxy serve debug [config.yaml]
99109 Start with verbose per-request diagnostics
110+ zcode-proxy tui [config.yaml] Interactive terminal UI (login / start-stop / live logs)
100111 zcode-proxy android Android entry: proxy + localhost control listener
101112 zcode-proxy auth login <provider> Login via OAuth (provider: zai | bigmodel)
102113 zcode-proxy auth login <provider> --import
@@ -110,6 +121,7 @@ Usage:
110121Examples:
111122 zcode-proxy Start server with default config.yaml
112123 zcode-proxy serve debug Start with extra debug logging
124+ zcode-proxy tui Terminal UI: login, start/stop, live logs
113125 zcode-proxy auth login bigmodel OAuth login for Bigmodel
114126 zcode-proxy auth login bigmodel --import
115127 Import existing key from ZCode config
@@ -170,15 +182,6 @@ async function serve(configPath: string | undefined, debug: boolean): Promise<vo
170182 } ) ;
171183}
172184
173- /** Build `startServer` options, wiring the Responses store and MCP pool when their config gates are on. */
174- function buildServerOptions ( config : ProxyConfig , auth : AuthManager , debug : boolean ) : { config : ProxyConfig ; auth : AuthManager ; debug : boolean ; responseStore ?: ResponseStore } {
175- const opts : { config : ProxyConfig ; auth : AuthManager ; debug : boolean ; responseStore ?: ResponseStore } = { config, auth, debug } ;
176- if ( config . responses . enabled ) {
177- opts . responseStore = new ResponseStore ( { maxEntries : config . responses . storeMaxEntries , ttlMs : config . responses . storeTtlMs } ) ;
178- }
179- return opts ;
180- }
181-
182185/**
183186 * Desktop-Linux identity defaults for the Android entry (anti-pattern #34).
184187 * Without these, the Node process on Android reports its true host values:
@@ -303,15 +306,6 @@ async function runAndroid(): Promise<void> {
303306 } ) ;
304307}
305308
306- /** Targeted YAML update of top-level `provider` and `plan` keys. */
307- function updateConfigYaml ( path : string , fields : { provider : ProviderId ; plan : "coding-plan" | "start-plan" } ) : void {
308- const raw = readFileSync ( path , "utf-8" ) ;
309- const parsed = parse ( raw ) ?? { } ;
310- parsed . provider = fields . provider ;
311- parsed . plan = fields . plan ;
312- writeFileSync ( path , stringify ( parsed ) , "utf-8" ) ;
313- }
314-
315309function printDebugBanner ( config : ProxyConfig , path : string , cred : Credential | null ) : void {
316310 const credShape = cred
317311 ? `${ cred . apiKey . slice ( 0 , 6 ) } ...${ cred . apiKey . slice ( - 4 ) } (${ cred . apiKey . length } chars)`
@@ -529,17 +523,3 @@ function importFromZCodeConfig(provider: ProviderId): Credential {
529523 if ( jwt ) console . log ( ` Start-plan JWT: ${ jwt . slice ( 0 , 12 ) } ...` ) ;
530524 return { apiKey, provider, jwt } ;
531525}
532-
533- function openBrowser ( url : string ) : void {
534- try {
535- if ( process . platform === "win32" ) {
536- spawn ( "cmd.exe" , [ "/c" , `start "" "${ url } "` ] , {
537- detached : true , stdio : "ignore" , windowsHide : true , windowsVerbatimArguments : true ,
538- } ) . unref ( ) ;
539- } else if ( process . platform === "darwin" ) {
540- spawn ( "open" , [ url ] , { detached : true , stdio : "ignore" } ) . unref ( ) ;
541- } else {
542- spawn ( "xdg-open" , [ url ] , { detached : true , stdio : "ignore" } ) . unref ( ) ;
543- }
544- } catch { /* user copies URL manually */ }
545- }
0 commit comments