Remove config file deployment path
This commit is contained in:
@@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"server": {
|
|
||||||
"host": "0.0.0.0",
|
|
||||||
"port": 24731
|
|
||||||
},
|
|
||||||
"proxy": {
|
|
||||||
"apiKey": "replace-this-token"
|
|
||||||
},
|
|
||||||
"providers": {
|
|
||||||
"openai": {
|
|
||||||
"apiKey": "ai-integrations-openai-api-key",
|
|
||||||
"baseURL": "https://ai-integrations-openai-base-url/v1"
|
|
||||||
},
|
|
||||||
"anthropic": {
|
|
||||||
"apiKey": "ai-integrations-anthropic-api-key",
|
|
||||||
"baseURL": "https://ai-integrations-anthropic-base-url"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"logging": {
|
|
||||||
"level": "info",
|
|
||||||
"pretty": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
Standalone TypeScript API server with file-based configuration.
|
Standalone TypeScript API server with CLI-only deployment configuration.
|
||||||
|
|
||||||
## Stack
|
## Stack
|
||||||
|
|
||||||
@@ -11,16 +11,22 @@ Standalone TypeScript API server with file-based configuration.
|
|||||||
- **TypeScript version**: 5.9
|
- **TypeScript version**: 5.9
|
||||||
- **API framework**: Express 5
|
- **API framework**: Express 5
|
||||||
- **Build**: esbuild
|
- **Build**: esbuild
|
||||||
- **Config**: `config.json` by default, or `--config ./path.json`
|
|
||||||
|
|
||||||
## Provider Endpoints
|
## Provider Endpoints
|
||||||
|
|
||||||
Do not configure this proxy with public official provider endpoints. Agents should populate `providers.openai.baseURL` and `providers.anthropic.baseURL` with the internal endpoints supplied by their runtime/integration, along with the matching internal tokens.
|
Use Replit AI Integrations endpoints through CLI flags:
|
||||||
|
|
||||||
|
- `--openai-base-url`
|
||||||
|
- `--openai-api-key`
|
||||||
|
- `--anthropic-base-url`
|
||||||
|
- `--anthropic-api-key`
|
||||||
|
|
||||||
|
Never use public official provider endpoints.
|
||||||
|
|
||||||
## Key Commands
|
## Key Commands
|
||||||
|
|
||||||
- `pnpm dev` — run API server locally
|
- `pnpm install --ignore-workspace` — install dependencies without joining a parent workspace
|
||||||
- `pnpm dev -- --config ./config.local.json` — run with a custom config file
|
- `pnpm dev` — run API server locally on port `24731`
|
||||||
- `pnpm run typecheck` — typecheck the server
|
- `pnpm run typecheck` — typecheck the server
|
||||||
- `pnpm run build` — typecheck and build `dist/index.mjs`
|
- `pnpm run build` — typecheck and build `dist/index.mjs`
|
||||||
- `pnpm start` — run the built server
|
- `pnpm start` — run the built server
|
||||||
|
|||||||
+1
-95
@@ -1,6 +1,3 @@
|
|||||||
import { existsSync, readFileSync } from "node:fs";
|
|
||||||
import path from "node:path";
|
|
||||||
|
|
||||||
export interface ProviderConfig {
|
export interface ProviderConfig {
|
||||||
baseURL?: string;
|
baseURL?: string;
|
||||||
apiKey?: string;
|
apiKey?: string;
|
||||||
@@ -42,80 +39,6 @@ const DEFAULT_CONFIG: AppConfig = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
||||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
function stringValue(value: unknown): string | undefined {
|
|
||||||
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
function booleanValue(value: unknown): boolean | undefined {
|
|
||||||
return typeof value === "boolean" ? value : undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
function numberValue(value: unknown): number | undefined {
|
|
||||||
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
function providerConfig(value: unknown): ProviderConfig {
|
|
||||||
if (!isRecord(value)) return {};
|
|
||||||
return {
|
|
||||||
...(stringValue(value["baseURL"]) ? { baseURL: stringValue(value["baseURL"]) } : {}),
|
|
||||||
...(stringValue(value["apiKey"]) ? { apiKey: stringValue(value["apiKey"]) } : {}),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function mergeConfig(raw: unknown): AppConfig {
|
|
||||||
if (!isRecord(raw)) return DEFAULT_CONFIG;
|
|
||||||
|
|
||||||
const server = isRecord(raw["server"]) ? raw["server"] : {};
|
|
||||||
const proxy = isRecord(raw["proxy"]) ? raw["proxy"] : {};
|
|
||||||
const providers = isRecord(raw["providers"]) ? raw["providers"] : {};
|
|
||||||
const logging = isRecord(raw["logging"]) ? raw["logging"] : {};
|
|
||||||
|
|
||||||
const port = numberValue(server["port"]) ?? DEFAULT_CONFIG.server.port;
|
|
||||||
if (!Number.isInteger(port) || port <= 0) {
|
|
||||||
throw new Error(`Invalid config value "server.port": ${port}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
server: {
|
|
||||||
host: stringValue(server["host"]) ?? DEFAULT_CONFIG.server.host,
|
|
||||||
port,
|
|
||||||
},
|
|
||||||
proxy: {
|
|
||||||
apiKey: stringValue(proxy["apiKey"]) ?? DEFAULT_CONFIG.proxy.apiKey,
|
|
||||||
},
|
|
||||||
providers: {
|
|
||||||
openai: providerConfig(providers["openai"]),
|
|
||||||
anthropic: providerConfig(providers["anthropic"]),
|
|
||||||
},
|
|
||||||
logging: {
|
|
||||||
level: stringValue(logging["level"]) ?? DEFAULT_CONFIG.logging.level,
|
|
||||||
pretty: booleanValue(logging["pretty"]) ?? DEFAULT_CONFIG.logging.pretty,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function configPathFromArgv(): string {
|
|
||||||
const configArgIndex = process.argv.findIndex((arg) => arg === "--config");
|
|
||||||
if (configArgIndex >= 0) {
|
|
||||||
const value = process.argv[configArgIndex + 1];
|
|
||||||
if (!value) {
|
|
||||||
throw new Error("Missing value after --config");
|
|
||||||
}
|
|
||||||
return path.resolve(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
const inlineArg = process.argv.find((arg) => arg.startsWith("--config="));
|
|
||||||
if (inlineArg) {
|
|
||||||
return path.resolve(inlineArg.slice("--config=".length));
|
|
||||||
}
|
|
||||||
|
|
||||||
return path.resolve("config.json");
|
|
||||||
}
|
|
||||||
|
|
||||||
function argValue(name: string): string | undefined {
|
function argValue(name: string): string | undefined {
|
||||||
const longName = `--${name}`;
|
const longName = `--${name}`;
|
||||||
const index = process.argv.findIndex((arg) => arg === longName);
|
const index = process.argv.findIndex((arg) => arg === longName);
|
||||||
@@ -170,21 +93,4 @@ function applyArgOverrides(base: AppConfig): AppConfig {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadConfig(): AppConfig {
|
export const config = applyArgOverrides(DEFAULT_CONFIG);
|
||||||
const filePath = configPathFromArgv();
|
|
||||||
if (!existsSync(filePath)) {
|
|
||||||
return applyArgOverrides(DEFAULT_CONFIG);
|
|
||||||
}
|
|
||||||
|
|
||||||
let parsed: unknown;
|
|
||||||
try {
|
|
||||||
parsed = JSON.parse(readFileSync(filePath, "utf8"));
|
|
||||||
} catch (err) {
|
|
||||||
const message = err instanceof Error ? err.message : String(err);
|
|
||||||
throw new Error(`Could not read config file ${filePath}: ${message}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return applyArgOverrides(mergeConfig(parsed));
|
|
||||||
}
|
|
||||||
|
|
||||||
export const config = loadConfig();
|
|
||||||
|
|||||||
+1
-1
@@ -494,7 +494,7 @@ function errorMessage(err: unknown): string {
|
|||||||
function providerNotConfigured(res: Response, provider: "openai" | "anthropic"): void {
|
function providerNotConfigured(res: Response, provider: "openai" | "anthropic"): void {
|
||||||
res.status(503).json({
|
res.status(503).json({
|
||||||
error: {
|
error: {
|
||||||
message: `${provider} provider is not configured. Add providers.${provider}.apiKey and providers.${provider}.baseURL, or pass the matching CLI flags. Use Replit AI Integrations endpoints, not public provider endpoints.`,
|
message: `${provider} provider is not configured. Pass the matching Replit AI Integrations CLI flags, not public provider endpoints.`,
|
||||||
type: "server_error",
|
type: "server_error",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user