More version simplifiction. (#810)
This commit is contained in:
parent
63757d6a7a
commit
680f4cdd61
|
@ -175,7 +175,7 @@ export async function loadCliConfig(
|
||||||
debugMode,
|
debugMode,
|
||||||
);
|
);
|
||||||
|
|
||||||
const userAgent = await createUserAgent();
|
const userAgent = `GeminiCLI/${getCliVersion()}/(${process.platform}; ${process.arch})`;
|
||||||
const apiKeyForServer = geminiApiKey || googleApiKey || '';
|
const apiKeyForServer = geminiApiKey || googleApiKey || '';
|
||||||
const useVertexAI = hasGeminiApiKey ? false : undefined;
|
const useVertexAI = hasGeminiApiKey ? false : undefined;
|
||||||
|
|
||||||
|
@ -193,8 +193,6 @@ export async function loadCliConfig(
|
||||||
originalModel = checkResult.originalModelIfSwitched;
|
originalModel = checkResult.originalModelIfSwitched;
|
||||||
modelToUse = checkResult.effectiveModel;
|
modelToUse = checkResult.effectiveModel;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// logger.debug('API key not available during config load. Skipping model availability check.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const configParams: ConfigParameters = {
|
const configParams: ConfigParameters = {
|
||||||
|
@ -237,8 +235,3 @@ export async function loadCliConfig(
|
||||||
finalModel: modelToUse,
|
finalModel: modelToUse,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createUserAgent(): Promise<string> {
|
|
||||||
const cliVersion = await getCliVersion();
|
|
||||||
return `GeminiCLI/${cliVersion} Node.js/${process.version} (${process.platform}; ${process.arch})`;
|
|
||||||
}
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ import { render } from 'ink';
|
||||||
import { App } from './ui/App.js';
|
import { App } from './ui/App.js';
|
||||||
import { loadCliConfig } from './config/config.js';
|
import { loadCliConfig } from './config/config.js';
|
||||||
import { readStdin } from './utils/readStdin.js';
|
import { readStdin } from './utils/readStdin.js';
|
||||||
import { getCliVersion } from './utils/version.js';
|
|
||||||
import { sandbox_command, start_sandbox } from './utils/sandbox.js';
|
import { sandbox_command, start_sandbox } from './utils/sandbox.js';
|
||||||
import { LoadedSettings, loadSettings } from './config/settings.js';
|
import { LoadedSettings, loadSettings } from './config/settings.js';
|
||||||
import { themeManager } from './ui/themes/theme-manager.js';
|
import { themeManager } from './ui/themes/theme-manager.js';
|
||||||
|
@ -101,14 +100,11 @@ export async function main() {
|
||||||
|
|
||||||
// Render UI, passing necessary config values. Check that there is no command line question.
|
// Render UI, passing necessary config values. Check that there is no command line question.
|
||||||
if (process.stdin.isTTY && input?.length === 0) {
|
if (process.stdin.isTTY && input?.length === 0) {
|
||||||
const cliVersion = await getCliVersion();
|
|
||||||
|
|
||||||
render(
|
render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<App
|
<App
|
||||||
config={config}
|
config={config}
|
||||||
settings={settings}
|
settings={settings}
|
||||||
cliVersion={cliVersion}
|
|
||||||
startupWarnings={startupWarnings}
|
startupWarnings={startupWarnings}
|
||||||
/>
|
/>
|
||||||
</React.StrictMode>,
|
</React.StrictMode>,
|
||||||
|
|
|
@ -217,7 +217,6 @@ describe('App UI', () => {
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
settings={mockSettings}
|
||||||
cliVersion="1.0.0"
|
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
|
@ -234,7 +233,6 @@ describe('App UI', () => {
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
settings={mockSettings}
|
||||||
cliVersion="1.0.0"
|
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
|
@ -255,7 +253,6 @@ describe('App UI', () => {
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
settings={mockSettings}
|
||||||
cliVersion="1.0.0"
|
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
|
@ -276,7 +273,6 @@ describe('App UI', () => {
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
settings={mockSettings}
|
||||||
cliVersion="1.0.0"
|
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
|
@ -297,7 +293,6 @@ describe('App UI', () => {
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
settings={mockSettings}
|
||||||
cliVersion="1.0.0"
|
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
|
@ -317,7 +312,6 @@ describe('App UI', () => {
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
settings={mockSettings}
|
||||||
cliVersion="1.0.0"
|
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
|
@ -338,7 +332,6 @@ describe('App UI', () => {
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
settings={mockSettings}
|
||||||
cliVersion="1.0.0"
|
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
|
@ -368,7 +361,6 @@ describe('App UI', () => {
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
settings={mockSettings}
|
||||||
cliVersion="1.0.0"
|
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
|
@ -383,7 +375,6 @@ describe('App UI', () => {
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
settings={mockSettings}
|
||||||
cliVersion="1.0.0"
|
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
|
|
|
@ -55,16 +55,10 @@ const CTRL_C_PROMPT_DURATION_MS = 1000;
|
||||||
interface AppProps {
|
interface AppProps {
|
||||||
config: Config;
|
config: Config;
|
||||||
settings: LoadedSettings;
|
settings: LoadedSettings;
|
||||||
cliVersion: string;
|
|
||||||
startupWarnings?: string[];
|
startupWarnings?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const App = ({
|
export const App = ({ config, settings, startupWarnings = [] }: AppProps) => {
|
||||||
config,
|
|
||||||
settings,
|
|
||||||
cliVersion,
|
|
||||||
startupWarnings = [],
|
|
||||||
}: AppProps) => {
|
|
||||||
const { history, addItem, clearItems } = useHistory();
|
const { history, addItem, clearItems } = useHistory();
|
||||||
const {
|
const {
|
||||||
consoleMessages,
|
consoleMessages,
|
||||||
|
@ -196,7 +190,6 @@ export const App = ({
|
||||||
openThemeDialog,
|
openThemeDialog,
|
||||||
performMemoryRefresh,
|
performMemoryRefresh,
|
||||||
toggleCorgiMode,
|
toggleCorgiMode,
|
||||||
cliVersion,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const { streamingState, submitQuery, initError, pendingHistoryItems } =
|
const { streamingState, submitQuery, initError, pendingHistoryItems } =
|
||||||
|
|
|
@ -115,7 +115,6 @@ describe('useSlashCommandProcessor', () => {
|
||||||
mockOpenThemeDialog,
|
mockOpenThemeDialog,
|
||||||
mockPerformMemoryRefresh,
|
mockPerformMemoryRefresh,
|
||||||
mockCorgiMode,
|
mockCorgiMode,
|
||||||
'test-version',
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
return result.current;
|
return result.current;
|
||||||
|
@ -253,8 +252,8 @@ describe('useSlashCommandProcessor', () => {
|
||||||
description?: string,
|
description?: string,
|
||||||
sandboxEnvVar?: string,
|
sandboxEnvVar?: string,
|
||||||
seatbeltProfileVar?: string,
|
seatbeltProfileVar?: string,
|
||||||
|
cliVersion?: string,
|
||||||
) => {
|
) => {
|
||||||
const cliVersion = 'test-version';
|
|
||||||
const osVersion = 'test-platform test-node-version';
|
const osVersion = 'test-platform test-node-version';
|
||||||
let sandboxEnvStr = 'no sandbox';
|
let sandboxEnvStr = 'no sandbox';
|
||||||
if (sandboxEnvVar && sandboxEnvVar !== 'sandbox-exec') {
|
if (sandboxEnvVar && sandboxEnvVar !== 'sandbox-exec') {
|
||||||
|
@ -293,12 +292,14 @@ Add any other context about the problem here.
|
||||||
it('should call open with the correct GitHub issue URL and return true', async () => {
|
it('should call open with the correct GitHub issue URL and return true', async () => {
|
||||||
process.env.SANDBOX = 'gemini-sandbox';
|
process.env.SANDBOX = 'gemini-sandbox';
|
||||||
process.env.SEATBELT_PROFILE = 'test_profile';
|
process.env.SEATBELT_PROFILE = 'test_profile';
|
||||||
|
process.env.CLI_VERSION = 'test-version';
|
||||||
const { handleSlashCommand } = getProcessor();
|
const { handleSlashCommand } = getProcessor();
|
||||||
const bugDescription = 'This is a test bug';
|
const bugDescription = 'This is a test bug';
|
||||||
const expectedUrl = getExpectedUrl(
|
const expectedUrl = getExpectedUrl(
|
||||||
bugDescription,
|
bugDescription,
|
||||||
process.env.SANDBOX,
|
process.env.SANDBOX,
|
||||||
process.env.SEATBELT_PROFILE,
|
process.env.SEATBELT_PROFILE,
|
||||||
|
process.env.CLI_VERSION,
|
||||||
);
|
);
|
||||||
let commandResult: SlashCommandActionReturn | boolean = false;
|
let commandResult: SlashCommandActionReturn | boolean = false;
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
|
|
|
@ -14,6 +14,7 @@ import { Message, MessageType, HistoryItemWithoutId } from '../types.js';
|
||||||
import { createShowMemoryAction } from './useShowMemoryCommand.js';
|
import { createShowMemoryAction } from './useShowMemoryCommand.js';
|
||||||
import { GIT_COMMIT_INFO } from '../../generated/git-commit.js';
|
import { GIT_COMMIT_INFO } from '../../generated/git-commit.js';
|
||||||
import { formatMemoryUsage } from '../utils/formatters.js';
|
import { formatMemoryUsage } from '../utils/formatters.js';
|
||||||
|
import { getCliVersion } from '../../utils/version.js';
|
||||||
|
|
||||||
export interface SlashCommandActionReturn {
|
export interface SlashCommandActionReturn {
|
||||||
shouldScheduleTool?: boolean;
|
shouldScheduleTool?: boolean;
|
||||||
|
@ -46,7 +47,6 @@ export const useSlashCommandProcessor = (
|
||||||
openThemeDialog: () => void,
|
openThemeDialog: () => void,
|
||||||
performMemoryRefresh: () => Promise<void>,
|
performMemoryRefresh: () => Promise<void>,
|
||||||
toggleCorgiMode: () => void,
|
toggleCorgiMode: () => void,
|
||||||
cliVersion: string,
|
|
||||||
) => {
|
) => {
|
||||||
const addMessage = useCallback(
|
const addMessage = useCallback(
|
||||||
(message: Message) => {
|
(message: Message) => {
|
||||||
|
@ -193,7 +193,7 @@ export const useSlashCommandProcessor = (
|
||||||
name: 'about',
|
name: 'about',
|
||||||
description: 'Show version info',
|
description: 'Show version info',
|
||||||
action: (_mainCommand, _subCommand, _args) => {
|
action: (_mainCommand, _subCommand, _args) => {
|
||||||
const osVersion = `${process.platform} ${process.version}`;
|
const osVersion = process.platform;
|
||||||
let sandboxEnv = 'no sandbox';
|
let sandboxEnv = 'no sandbox';
|
||||||
if (process.env.SANDBOX && process.env.SANDBOX !== 'sandbox-exec') {
|
if (process.env.SANDBOX && process.env.SANDBOX !== 'sandbox-exec') {
|
||||||
sandboxEnv = process.env.SANDBOX;
|
sandboxEnv = process.env.SANDBOX;
|
||||||
|
@ -201,7 +201,7 @@ export const useSlashCommandProcessor = (
|
||||||
sandboxEnv = `sandbox-exec (${process.env.SEATBELT_PROFILE || 'unknown'})`;
|
sandboxEnv = `sandbox-exec (${process.env.SEATBELT_PROFILE || 'unknown'})`;
|
||||||
}
|
}
|
||||||
const modelVersion = config?.getModel() || 'Unknown';
|
const modelVersion = config?.getModel() || 'Unknown';
|
||||||
|
const cliVersion = getCliVersion();
|
||||||
addMessage({
|
addMessage({
|
||||||
type: MessageType.ABOUT,
|
type: MessageType.ABOUT,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
|
@ -231,6 +231,7 @@ export const useSlashCommandProcessor = (
|
||||||
}
|
}
|
||||||
const modelVersion = config?.getModel() || 'Unknown';
|
const modelVersion = config?.getModel() || 'Unknown';
|
||||||
const memoryUsage = formatMemoryUsage(process.memoryUsage().rss);
|
const memoryUsage = formatMemoryUsage(process.memoryUsage().rss);
|
||||||
|
const cliVersion = getCliVersion();
|
||||||
|
|
||||||
const diagnosticInfo = `
|
const diagnosticInfo = `
|
||||||
## Describe the bug
|
## Describe the bug
|
||||||
|
@ -299,7 +300,6 @@ Add any other context about the problem here.
|
||||||
addMessage,
|
addMessage,
|
||||||
toggleCorgiMode,
|
toggleCorgiMode,
|
||||||
config,
|
config,
|
||||||
cliVersion,
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -4,31 +4,6 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { readPackageUp } from 'read-package-up';
|
export function getCliVersion(): string {
|
||||||
import { fileURLToPath } from 'node:url';
|
return process.env.CLI_VERSION || process.version;
|
||||||
import { dirname } from 'node:path';
|
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
|
||||||
const __dirname = dirname(__filename);
|
|
||||||
|
|
||||||
let cliVersion: string | undefined;
|
|
||||||
|
|
||||||
export async function getCliVersion(): Promise<string> {
|
|
||||||
if (cliVersion) {
|
|
||||||
return cliVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.env.CLI_VERSION) {
|
|
||||||
cliVersion = process.env.CLI_VERSION;
|
|
||||||
return cliVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const readUpResult = await readPackageUp({ cwd: __dirname });
|
|
||||||
cliVersion = readUpResult?.packageJson.version || 'unknown';
|
|
||||||
} catch (_e) {
|
|
||||||
cliVersion = 'unknown';
|
|
||||||
}
|
|
||||||
|
|
||||||
return cliVersion;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -316,10 +316,9 @@ function findEnvFile(startDir: string): string | null {
|
||||||
|
|
||||||
export function loadEnvironment(): void {
|
export function loadEnvironment(): void {
|
||||||
const envFilePath = findEnvFile(process.cwd());
|
const envFilePath = findEnvFile(process.cwd());
|
||||||
if (!envFilePath) {
|
if (envFilePath) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
dotenv.config({ path: envFilePath });
|
dotenv.config({ path: envFilePath });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createServerConfig(params: ConfigParameters): Config {
|
export function createServerConfig(params: ConfigParameters): Config {
|
||||||
|
|
Loading…
Reference in New Issue