Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions packages/cli/src/cli.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import React from "react";
import { render } from "ink";
import { setShellIfWindows } from "@vegamo/deepcode-core";
import { checkForNpmUpdate, promptForPendingUpdate, type PackageInfo } from "./common/update-check";
import { APP_NAME, APP_VERSION } from "./common/package-info";
import { AppContainer } from "./ui";

const args = process.argv.slice(2);
const packageInfo = readPackageInfo();
const packageInfo: PackageInfo = { name: APP_NAME, version: APP_VERSION };

if (args.includes("--version") || args.includes("-v")) {
process.stdout.write(`${packageInfo.version || "unknown"}\n`);
process.stdout.write(`${APP_VERSION}\n`);
process.exit(0);
}

Expand Down Expand Up @@ -129,15 +130,3 @@ function configureWindowsShell(): void {
process.exit(1);
}
}

function readPackageInfo(): PackageInfo {
try {
const pkg = require("../package.json") as { name?: unknown; version?: unknown };
return {
name: typeof pkg.name === "string" ? pkg.name : "@vegamo/deepcode-cli",
version: typeof pkg.version === "string" ? pkg.version : "",
};
} catch {
return { name: "@vegamo/deepcode-cli", version: "" };
}
}
8 changes: 7 additions & 1 deletion packages/core/src/common/openai-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import * as path from "path";
import OpenAI from "openai";
import { Agent, fetch as undiciFetch } from "undici";
import { resolveCurrentSettings } from "../settings";
import { APP_VERSION } from "./package-info";

// Custom undici Agent with a 180-second keepAlive timeout. The default
// global fetch (undici) only keeps connections alive for 4 seconds, which
// is too short for a CLI where the user may spend 10–30 seconds reading
// output between prompts. By passing a dedicated Agent to undiciFetch we
// keep connections reusable for three minutes after the last request.
const keepAliveAgent = new Agent({ keepAliveTimeout: 180_000 });
const USER_AGENT = `deepcode-cli/${APP_VERSION}`;

// Module-level cache for the OpenAI client instance. The client itself is
// a stateless fetch wrapper, so it is safe to share across calls as long as
Expand Down Expand Up @@ -73,7 +75,11 @@ export function createOpenAIClient(projectRoot: string = process.cwd()): {
apiKey: settings.apiKey,
baseURL: settings.baseURL || undefined,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
fetch: (url: any, init: any) => undiciFetch(url, { ...init, dispatcher: keepAliveAgent }),
fetch: (url: any, init: any) => {
const headers = new Headers(init?.headers);
headers.set("User-Agent", USER_AGENT);
return undiciFetch(url, { ...init, headers, dispatcher: keepAliveAgent });
},
});
cachedOpenAIKey = cacheKey;

Expand Down
3 changes: 3 additions & 0 deletions src/common/package-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import pkg from "../../package.json" with { type: "json" };
export const APP_NAME: string = pkg.name || "@vegamo/deepcode-cli";
export const APP_VERSION: string = pkg.version || "unknown";