Compare commits
10 Commits
22bd329ee3
...
da856261f3
| Author | SHA1 | Date | |
|---|---|---|---|
| da856261f3 | |||
| 5463862d32 | |||
| 934ab43ccc | |||
| c5eca5bdb9 | |||
| 9a19c87251 | |||
| 554ab93df2 | |||
| 878cd1eb3c | |||
| 424b691fef | |||
| 0078ee7e58 | |||
| bee5dc1e01 |
@@ -0,0 +1,6 @@
|
|||||||
|
run = "pnpm dev"
|
||||||
|
onBoot = "pnpm install --ignore-workspace"
|
||||||
|
|
||||||
|
[deployment]
|
||||||
|
build = "pnpm install --ignore-workspace && pnpm run build"
|
||||||
|
run = "pnpm start"
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"server": {
|
|
||||||
"host": "0.0.0.0",
|
|
||||||
"port": 8080
|
|
||||||
},
|
|
||||||
"proxy": {
|
|
||||||
"apiKey": "replace-this-token"
|
|
||||||
},
|
|
||||||
"providers": {
|
|
||||||
"openai": {
|
|
||||||
"apiKey": "internal-openai-token",
|
|
||||||
"baseURL": "https://your-internal-openai-endpoint/v1"
|
|
||||||
},
|
|
||||||
"anthropic": {
|
|
||||||
"apiKey": "internal-anthropic-token",
|
|
||||||
"baseURL": "https://your-internal-anthropic-endpoint"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"logging": {
|
|
||||||
"level": "info",
|
|
||||||
"pretty": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"packageManager": "pnpm@10.33.2",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "tsx src/index.ts",
|
"dev": "tsx src/index.ts",
|
||||||
"build": "tsc --noEmit && node build.mjs",
|
"build": "tsc --noEmit && node build.mjs",
|
||||||
|
|||||||
@@ -1,64 +1,78 @@
|
|||||||
# Agent Runbook
|
# Agent Runbook
|
||||||
|
|
||||||
Run this repository as a standalone app. Do not add it to a parent workspace. Do not move it into `artifacts/`. Do not edit source files for setup.
|
This app is already prepared for one-shot deployment. Follow these commands exactly unless one fails.
|
||||||
|
|
||||||
## Setup
|
Do not add this repo to a parent workspace. Do not move it into `artifacts/`. Do not edit source files. Do not edit `package.json`. Do not create `config.json` or a `/tmp` config file for deployment. Do not inspect or free unrelated ports.
|
||||||
|
|
||||||
|
## Replit
|
||||||
|
|
||||||
|
The repo includes `.replit`, so after import the Run button starts the app with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm dev
|
||||||
|
```
|
||||||
|
|
||||||
|
The `.replit` `onBoot` command installs dependencies with:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm install --ignore-workspace
|
||||||
|
```
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
Run from this repository root:
|
Run from this repository root:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pnpm install --ignore-workspace
|
pnpm install --ignore-workspace
|
||||||
|
```
|
||||||
|
|
||||||
|
Use the available `pnpm`. This repo intentionally has no `packageManager` pin.
|
||||||
|
|
||||||
|
## Start
|
||||||
|
|
||||||
|
```bash
|
||||||
pnpm dev
|
pnpm dev
|
||||||
```
|
```
|
||||||
|
|
||||||
If plain `pnpm` is unavailable, use `corepack pnpm` for the same commands. Do not edit `package.json`.
|
When Replit AI Integrations are provisioned, the app reads these variables automatically:
|
||||||
|
|
||||||
The app runs without `config.json`:
|
- `AI_INTEGRATIONS_OPENAI_BASE_URL`
|
||||||
|
- `AI_INTEGRATIONS_OPENAI_API_KEY`
|
||||||
|
- `AI_INTEGRATIONS_ANTHROPIC_BASE_URL`
|
||||||
|
- `AI_INTEGRATIONS_ANTHROPIC_API_KEY`
|
||||||
|
|
||||||
- host: `0.0.0.0`
|
Provider CLI flags are still supported for manual overrides:
|
||||||
- port: `8080`
|
|
||||||
- bearer token: `dev-proxy-key`
|
|
||||||
|
|
||||||
## Optional Provider Config
|
```bash
|
||||||
|
pnpm dev -- \
|
||||||
Do not create `config.json` unless internal provider endpoints/tokens are available.
|
--openai-base-url "<ai-integrations-openai-base-url>" \
|
||||||
|
--openai-api-key "<ai-integrations-openai-api-key>" \
|
||||||
If they are available, create `config.json` in one write with this shape:
|
--anthropic-base-url "<ai-integrations-anthropic-base-url>" \
|
||||||
|
--anthropic-api-key "<ai-integrations-anthropic-api-key>"
|
||||||
```json
|
|
||||||
{
|
|
||||||
"server": {
|
|
||||||
"host": "0.0.0.0",
|
|
||||||
"port": 8080
|
|
||||||
},
|
|
||||||
"proxy": {
|
|
||||||
"apiKey": "dev-proxy-key"
|
|
||||||
},
|
|
||||||
"providers": {
|
|
||||||
"openai": {
|
|
||||||
"apiKey": "",
|
|
||||||
"baseURL": ""
|
|
||||||
},
|
|
||||||
"anthropic": {
|
|
||||||
"apiKey": "",
|
|
||||||
"baseURL": ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"logging": {
|
|
||||||
"level": "info",
|
|
||||||
"pretty": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Fill only `providers.openai.apiKey`, `providers.openai.baseURL`, `providers.anthropic.apiKey`, and `providers.anthropic.baseURL`. Use internal endpoints only. Never use public official provider endpoints.
|
Use Replit AI Integrations endpoints only. Never use public official provider endpoints. Do not print provider tokens.
|
||||||
|
|
||||||
|
## Defaults
|
||||||
|
|
||||||
|
- host: `0.0.0.0`
|
||||||
|
- port: `3000`
|
||||||
|
- bearer token: `dev-proxy-key`
|
||||||
|
|
||||||
|
These can be overridden with CLI flags or environment variables:
|
||||||
|
|
||||||
|
- `--host` or `HOST`
|
||||||
|
- `--port` or `PORT`
|
||||||
|
- `--proxy-api-key` or `PROXY_API_KEY`
|
||||||
|
|
||||||
## Verify
|
## Verify
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -s http://localhost:8080/api/healthz
|
curl -s http://localhost:3000/api/healthz
|
||||||
curl -s http://localhost:8080/dashboard | head
|
curl -s http://localhost:3000/dashboard | head
|
||||||
curl -s -H "Authorization: Bearer dev-proxy-key" http://localhost:8080/v1/models
|
curl -s -H "Authorization: Bearer dev-proxy-key" http://localhost:3000/v1/models
|
||||||
```
|
```
|
||||||
|
|
||||||
Expected without provider config: dashboard, health, and model list work; chat completions return `503`.
|
Expected without provider flags: dashboard, health, and model list work; chat completions return `503`.
|
||||||
|
|
||||||
|
Report only the local URL and verification results.
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
Standalone TypeScript API server with file-based configuration.
|
Standalone TypeScript API server with Replit run and deployment configuration.
|
||||||
|
|
||||||
## Stack
|
## Stack
|
||||||
|
|
||||||
@@ -11,20 +11,46 @@ 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. The app reads these environment variables automatically:
|
||||||
|
|
||||||
|
- `AI_INTEGRATIONS_OPENAI_BASE_URL`
|
||||||
|
- `AI_INTEGRATIONS_OPENAI_API_KEY`
|
||||||
|
- `AI_INTEGRATIONS_ANTHROPIC_BASE_URL`
|
||||||
|
- `AI_INTEGRATIONS_ANTHROPIC_API_KEY`
|
||||||
|
|
||||||
|
CLI flags are still available for manual overrides:
|
||||||
|
|
||||||
|
- `--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 `3000`
|
||||||
- `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
|
||||||
|
|
||||||
|
## Replit Configuration
|
||||||
|
|
||||||
|
- `.replit` `run` uses `pnpm dev`
|
||||||
|
- `.replit` `onBoot` uses `pnpm install --ignore-workspace`
|
||||||
|
- deployment build uses `pnpm install --ignore-workspace && pnpm run build`
|
||||||
|
- deployment run uses `pnpm start`
|
||||||
|
|
||||||
|
## Server Overrides
|
||||||
|
|
||||||
|
- `--host` or `HOST`
|
||||||
|
- `--port` or `PORT`
|
||||||
|
- `--proxy-api-key` or `PROXY_API_KEY`
|
||||||
|
|
||||||
## Routes
|
## Routes
|
||||||
|
|
||||||
- `/` and `/dashboard` — static model dashboard
|
- `/` and `/dashboard` — static model dashboard
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
Clone and run https://git.komnenos.me/springfw/random-proxy in ./random-proxy.
|
||||||
|
|
||||||
|
Goal: get the app running once, with Replit AI Integrations wired, on port 3000.
|
||||||
|
|
||||||
|
Do not:
|
||||||
|
- add it to a parent workspace
|
||||||
|
- move it into artifacts/
|
||||||
|
- modify source files
|
||||||
|
- edit package.json
|
||||||
|
- create config.json or /tmp config files
|
||||||
|
- inspect/free unrelated ports
|
||||||
|
- use nohup/setsid/background shell tricks
|
||||||
|
- run chat-completion smoke tests unless asked
|
||||||
|
|
||||||
|
Steps:
|
||||||
|
|
||||||
|
1. Clone into ./random-proxy.
|
||||||
|
|
||||||
|
2. Provision/use Replit AI Integrations for:
|
||||||
|
- OpenAI
|
||||||
|
- Anthropic
|
||||||
|
|
||||||
|
3. Open ./random-proxy and use the configured Replit Run button.
|
||||||
|
|
||||||
|
4. Wait briefly, then verify:
|
||||||
|
|
||||||
|
curl -s http://localhost:3000/api/healthz
|
||||||
|
curl -s http://localhost:3000/dashboard | head
|
||||||
|
curl -s -H "Authorization: Bearer dev-proxy-key" http://localhost:3000/v1/models
|
||||||
|
|
||||||
|
Report only:
|
||||||
|
- local URL
|
||||||
|
- whether OpenAI and Anthropic AI Integrations were wired
|
||||||
|
- verification results
|
||||||
+46
-72
@@ -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;
|
||||||
@@ -27,7 +24,7 @@ export interface AppConfig {
|
|||||||
const DEFAULT_CONFIG: AppConfig = {
|
const DEFAULT_CONFIG: AppConfig = {
|
||||||
server: {
|
server: {
|
||||||
host: "0.0.0.0",
|
host: "0.0.0.0",
|
||||||
port: 8080,
|
port: 3000,
|
||||||
},
|
},
|
||||||
proxy: {
|
proxy: {
|
||||||
apiKey: "dev-proxy-key",
|
apiKey: "dev-proxy-key",
|
||||||
@@ -42,95 +39,72 @@ const DEFAULT_CONFIG: AppConfig = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
function argValue(name: string): string | undefined {
|
||||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
const longName = `--${name}`;
|
||||||
|
const index = process.argv.findIndex((arg) => arg === longName);
|
||||||
|
if (index >= 0) {
|
||||||
|
const value = process.argv[index + 1];
|
||||||
|
return value && !value.startsWith("--") ? value : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function stringValue(value: unknown): string | undefined {
|
const inlineArg = process.argv.find((arg) => arg.startsWith(`${longName}=`));
|
||||||
return typeof value === "string" && value.length > 0 ? value : undefined;
|
return inlineArg ? inlineArg.slice(longName.length + 1) : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function booleanValue(value: unknown): boolean | undefined {
|
function argFlag(name: string): boolean {
|
||||||
return typeof value === "boolean" ? value : undefined;
|
return process.argv.includes(`--${name}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function numberValue(value: unknown): number | undefined {
|
function envValue(name: string): string | undefined {
|
||||||
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
const value = process.env[name];
|
||||||
|
return value && value.length > 0 ? value : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function providerConfig(value: unknown): ProviderConfig {
|
function applyArgOverrides(base: AppConfig): AppConfig {
|
||||||
if (!isRecord(value)) return {};
|
const rawPort = argValue("port") ?? envValue("PORT");
|
||||||
return {
|
const port = rawPort === undefined ? base.server.port : Number(rawPort);
|
||||||
...(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) {
|
if (!Number.isInteger(port) || port <= 0) {
|
||||||
throw new Error(`Invalid config value "server.port": ${port}`);
|
throw new Error(`Invalid port value: ${rawPort}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const host = argValue("host") ?? envValue("HOST") ?? base.server.host;
|
||||||
|
const proxyApiKey = argValue("proxy-api-key") ?? envValue("PROXY_API_KEY") ?? base.proxy.apiKey;
|
||||||
|
const openaiBaseURL = argValue("openai-base-url") ?? envValue("AI_INTEGRATIONS_OPENAI_BASE_URL");
|
||||||
|
const openaiApiKey = argValue("openai-api-key") ?? envValue("AI_INTEGRATIONS_OPENAI_API_KEY");
|
||||||
|
const anthropicBaseURL =
|
||||||
|
argValue("anthropic-base-url") ?? envValue("AI_INTEGRATIONS_ANTHROPIC_BASE_URL");
|
||||||
|
const anthropicApiKey =
|
||||||
|
argValue("anthropic-api-key") ?? envValue("AI_INTEGRATIONS_ANTHROPIC_API_KEY");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
server: {
|
server: {
|
||||||
host: stringValue(server["host"]) ?? DEFAULT_CONFIG.server.host,
|
host,
|
||||||
port,
|
port,
|
||||||
},
|
},
|
||||||
proxy: {
|
proxy: {
|
||||||
apiKey: stringValue(proxy["apiKey"]) ?? DEFAULT_CONFIG.proxy.apiKey,
|
apiKey: proxyApiKey,
|
||||||
},
|
},
|
||||||
providers: {
|
providers: {
|
||||||
openai: providerConfig(providers["openai"]),
|
openai: {
|
||||||
anthropic: providerConfig(providers["anthropic"]),
|
...base.providers.openai,
|
||||||
|
...(openaiBaseURL ? { baseURL: openaiBaseURL } : {}),
|
||||||
|
...(openaiApiKey ? { apiKey: openaiApiKey } : {}),
|
||||||
|
},
|
||||||
|
anthropic: {
|
||||||
|
...base.providers.anthropic,
|
||||||
|
...(anthropicBaseURL ? { baseURL: anthropicBaseURL } : {}),
|
||||||
|
...(anthropicApiKey ? { apiKey: anthropicApiKey } : {}),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
logging: {
|
logging: {
|
||||||
level: stringValue(logging["level"]) ?? DEFAULT_CONFIG.logging.level,
|
level: argValue("log-level") ?? base.logging.level,
|
||||||
pretty: booleanValue(logging["pretty"]) ?? DEFAULT_CONFIG.logging.pretty,
|
pretty: argFlag("pretty-logs")
|
||||||
|
? true
|
||||||
|
: argFlag("no-pretty-logs")
|
||||||
|
? false
|
||||||
|
: base.logging.pretty,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function configPathFromArgv(): string {
|
export const config = applyArgOverrides(DEFAULT_CONFIG);
|
||||||
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 loadConfig(): AppConfig {
|
|
||||||
const filePath = configPathFromArgv();
|
|
||||||
if (!existsSync(filePath)) {
|
|
||||||
return 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 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 to config.json. Use the internal endpoint supplied by your runtime or agent, not the public provider endpoint.`,
|
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