proxitor 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +242 -84
- package/dist/add.mjs +137 -0
- package/dist/add.mjs.map +1 -0
- package/dist/browse.mjs +86 -0
- package/dist/browse.mjs.map +1 -0
- package/dist/cli.mjs +14891 -27
- package/dist/cli.mjs.map +1 -1
- package/dist/config.mjs +46 -0
- package/dist/config.mjs.map +1 -0
- package/dist/config2.mjs +73 -0
- package/dist/config2.mjs.map +1 -0
- package/dist/dist.mjs +1325 -0
- package/dist/dist.mjs.map +1 -0
- package/dist/dist2.mjs +6617 -0
- package/dist/dist2.mjs.map +1 -0
- package/dist/edit.mjs +80 -0
- package/dist/edit.mjs.map +1 -0
- package/dist/list.mjs +31 -0
- package/dist/list.mjs.map +1 -0
- package/dist/prompt.mjs +849 -0
- package/dist/prompt.mjs.map +1 -0
- package/dist/providers.mjs +279 -0
- package/dist/providers.mjs.map +1 -0
- package/dist/remove.mjs +36 -0
- package/dist/remove.mjs.map +1 -0
- package/dist/validate.mjs +25 -0
- package/dist/validate.mjs.map +1 -0
- package/dist/wizard.mjs +192 -0
- package/dist/wizard.mjs.map +1 -0
- package/package.json +6 -18
- package/dist/cli.cjs +0 -36
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.d.cts +0 -1
- package/dist/cli.d.mts +0 -1
- package/dist/index.cjs +0 -10
- package/dist/index.d.cts +0 -91
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -91
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -2
- package/dist/proxy.cjs +0 -537
- package/dist/proxy.cjs.map +0 -1
- package/dist/proxy.mjs +0 -455
- package/dist/proxy.mjs.map +0 -1
package/dist/wizard.mjs
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { n as findConfigFile, r as getXdgConfigDir } from "./cli.mjs";
|
|
2
|
+
import { confirm as le, intro as ye, isCancel as R$1, log as R, note as Ce, outro as fe, select as Ee, text as Re } from "./dist.mjs";
|
|
3
|
+
import { t as require_dist } from "./dist2.mjs";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { dirname, join, resolve } from "node:path";
|
|
7
|
+
//#region src/commands/config/wizard.ts
|
|
8
|
+
var import_dist = require_dist();
|
|
9
|
+
const DEFAULT_PORT = 8828;
|
|
10
|
+
const DEFAULT_HOST = "0.0.0.0";
|
|
11
|
+
function maskKey(key) {
|
|
12
|
+
if (key.length <= 11) return "****";
|
|
13
|
+
return `${key.slice(0, 7)}...${key.slice(-4)}`;
|
|
14
|
+
}
|
|
15
|
+
function resolveSavePath(location) {
|
|
16
|
+
switch (location) {
|
|
17
|
+
case "local": return resolve("proxitor.config.yaml");
|
|
18
|
+
case "user": return join(homedir(), ".config", "proxitor", "config.yaml");
|
|
19
|
+
case "xdg": return join(getXdgConfigDir(), "config.yaml");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function getSaveLocationOptions(_existingPath) {
|
|
23
|
+
const opts = [{
|
|
24
|
+
value: "local",
|
|
25
|
+
label: "./proxitor.config.yaml",
|
|
26
|
+
hint: "Project directory"
|
|
27
|
+
}, {
|
|
28
|
+
value: "user",
|
|
29
|
+
label: "~/.config/proxitor/config.yaml",
|
|
30
|
+
hint: "User config"
|
|
31
|
+
}];
|
|
32
|
+
if (process.env.XDG_CONFIG_HOME) opts.push({
|
|
33
|
+
value: "xdg",
|
|
34
|
+
label: "$XDG_CONFIG_HOME/proxitor/config.yaml",
|
|
35
|
+
hint: "XDG config directory"
|
|
36
|
+
});
|
|
37
|
+
return opts;
|
|
38
|
+
}
|
|
39
|
+
function detectLocation(path) {
|
|
40
|
+
const cwd = resolve(".");
|
|
41
|
+
if (path.startsWith(cwd)) return "local";
|
|
42
|
+
const userDir = join(homedir(), ".config", "proxitor");
|
|
43
|
+
if (path.startsWith(userDir)) {
|
|
44
|
+
const xdgDir = process.env.XDG_CONFIG_HOME ? join(process.env.XDG_CONFIG_HOME, "proxitor") : null;
|
|
45
|
+
if (xdgDir && path.startsWith(xdgDir)) return "xdg";
|
|
46
|
+
return "user";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function buildYaml(apiKey, port, host, existingRaw) {
|
|
50
|
+
if (existingRaw) {
|
|
51
|
+
const doc = (0, import_dist.parseDocument)(existingRaw);
|
|
52
|
+
doc.set("openrouterKey", apiKey);
|
|
53
|
+
doc.set("port", port);
|
|
54
|
+
doc.set("host", host);
|
|
55
|
+
return doc.toString();
|
|
56
|
+
}
|
|
57
|
+
return (0, import_dist.stringify)({
|
|
58
|
+
openrouterKey: apiKey,
|
|
59
|
+
port,
|
|
60
|
+
host
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function readExistingConfig(path) {
|
|
64
|
+
const raw = readFileSync(path, "utf-8");
|
|
65
|
+
const parsed = (0, import_dist.parseDocument)(raw).toJSON();
|
|
66
|
+
return {
|
|
67
|
+
raw,
|
|
68
|
+
port: typeof parsed?.port === "number" ? parsed.port : DEFAULT_PORT,
|
|
69
|
+
host: typeof parsed?.host === "string" ? parsed.host : DEFAULT_HOST,
|
|
70
|
+
apiKey: typeof parsed?.openrouterKey === "string" ? parsed.openrouterKey : ""
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async function askApiKey(currentKey) {
|
|
74
|
+
if (currentKey) R.info(`Current key: ${maskKey(currentKey)}`);
|
|
75
|
+
const apiKey = await Re({
|
|
76
|
+
message: "OpenRouter API key",
|
|
77
|
+
placeholder: "sk-or-v1-...",
|
|
78
|
+
initialValue: currentKey,
|
|
79
|
+
validate: (v) => {
|
|
80
|
+
if (!v?.trim()) return "API key is required";
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
if (R$1(apiKey)) return null;
|
|
84
|
+
Ce("You can also set the OPENROUTER_API_KEY environment variable\nto avoid storing the key in the config file.", "Tip");
|
|
85
|
+
return apiKey;
|
|
86
|
+
}
|
|
87
|
+
async function askPort(current) {
|
|
88
|
+
const input = await Re({
|
|
89
|
+
message: "Proxy port",
|
|
90
|
+
initialValue: String(current),
|
|
91
|
+
placeholder: String(DEFAULT_PORT),
|
|
92
|
+
validate: (v) => {
|
|
93
|
+
if (!v?.trim()) return void 0;
|
|
94
|
+
const n = Number.parseInt(v, 10);
|
|
95
|
+
if (Number.isNaN(n) || n < 1 || n > 65535) return "Port must be 1–65535";
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
if (R$1(input)) return null;
|
|
99
|
+
return input.trim() ? Number.parseInt(input, 10) : DEFAULT_PORT;
|
|
100
|
+
}
|
|
101
|
+
async function askHost(current) {
|
|
102
|
+
const host = await Ee({
|
|
103
|
+
message: "Listen address",
|
|
104
|
+
initialValue: current,
|
|
105
|
+
options: [{
|
|
106
|
+
value: "0.0.0.0",
|
|
107
|
+
label: "All interfaces (0.0.0.0)",
|
|
108
|
+
hint: "Default"
|
|
109
|
+
}, {
|
|
110
|
+
value: "127.0.0.1",
|
|
111
|
+
label: "Localhost only (127.0.0.1)",
|
|
112
|
+
hint: "More secure"
|
|
113
|
+
}]
|
|
114
|
+
});
|
|
115
|
+
if (R$1(host)) return null;
|
|
116
|
+
return host;
|
|
117
|
+
}
|
|
118
|
+
async function askSaveLocation(existingPath) {
|
|
119
|
+
const options = getSaveLocationOptions(existingPath);
|
|
120
|
+
const location = await Ee({
|
|
121
|
+
message: "Save config to",
|
|
122
|
+
initialValue: (existingPath ? detectLocation(existingPath) : void 0) ?? "local",
|
|
123
|
+
options
|
|
124
|
+
});
|
|
125
|
+
if (R$1(location)) return null;
|
|
126
|
+
return location;
|
|
127
|
+
}
|
|
128
|
+
async function runWizard() {
|
|
129
|
+
ye("Proxitor Setup Wizard");
|
|
130
|
+
const existingPath = findConfigFile();
|
|
131
|
+
let existingRaw;
|
|
132
|
+
let currentPort = DEFAULT_PORT;
|
|
133
|
+
let currentHost = DEFAULT_HOST;
|
|
134
|
+
let currentKey = "";
|
|
135
|
+
if (existingPath) {
|
|
136
|
+
Ce(existingPath, "Existing config found");
|
|
137
|
+
const reconfigure = await le({
|
|
138
|
+
message: "Reconfigure?",
|
|
139
|
+
initialValue: true
|
|
140
|
+
});
|
|
141
|
+
if (R$1(reconfigure) || !reconfigure) {
|
|
142
|
+
fe("Using existing configuration");
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
const existing = readExistingConfig(existingPath);
|
|
147
|
+
existingRaw = existing.raw;
|
|
148
|
+
currentPort = existing.port;
|
|
149
|
+
currentHost = existing.host;
|
|
150
|
+
currentKey = existing.apiKey;
|
|
151
|
+
} catch {}
|
|
152
|
+
}
|
|
153
|
+
const apiKey = await askApiKey(currentKey);
|
|
154
|
+
if (apiKey === null) {
|
|
155
|
+
fe("Cancelled");
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const port = await askPort(currentPort);
|
|
159
|
+
if (port === null) {
|
|
160
|
+
fe("Cancelled");
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const host = await askHost(currentHost);
|
|
164
|
+
if (host === null) {
|
|
165
|
+
fe("Cancelled");
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const location = await askSaveLocation(existingPath ?? void 0);
|
|
169
|
+
if (location === null) {
|
|
170
|
+
fe("Cancelled");
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const yaml = buildYaml(apiKey, port, host, existingRaw);
|
|
174
|
+
Ce(yaml, "Preview");
|
|
175
|
+
const save = await le({
|
|
176
|
+
message: "Save this configuration?",
|
|
177
|
+
initialValue: true
|
|
178
|
+
});
|
|
179
|
+
if (R$1(save) || !save) {
|
|
180
|
+
fe("Cancelled — no files written");
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const savePath = resolveSavePath(location);
|
|
184
|
+
const dir = dirname(savePath);
|
|
185
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
186
|
+
writeFileSync(savePath, yaml, "utf-8");
|
|
187
|
+
fe(`Config saved to ${savePath}`);
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
export { runWizard };
|
|
191
|
+
|
|
192
|
+
//# sourceMappingURL=wizard.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wizard.mjs","names":["clack.text","isCancel","clack.select","clack.confirm"],"sources":["../src/commands/config/wizard.ts"],"sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'\nimport { homedir } from 'node:os'\nimport { dirname, join, resolve } from 'node:path'\nimport * as clack from '@clack/prompts'\nimport { isCancel } from '@clack/prompts'\nimport { parseDocument, stringify } from 'yaml'\nimport { findConfigFile, getXdgConfigDir } from '../../config.js'\n\nconst DEFAULT_PORT = 8828\nconst DEFAULT_HOST = '0.0.0.0'\n\ntype SaveLocation = 'local' | 'user' | 'xdg'\n\nfunction maskKey(key: string): string {\n if (key.length <= 11) return '****'\n return `${key.slice(0, 7)}...${key.slice(-4)}`\n}\n\nfunction resolveSavePath(location: SaveLocation): string {\n switch (location) {\n case 'local':\n return resolve('proxitor.config.yaml')\n case 'user':\n return join(homedir(), '.config', 'proxitor', 'config.yaml')\n case 'xdg':\n return join(getXdgConfigDir(), 'config.yaml')\n }\n}\n\nfunction getSaveLocationOptions(_existingPath?: string) {\n const opts: { value: SaveLocation; label: string; hint: string }[] = [\n { value: 'local', label: './proxitor.config.yaml', hint: 'Project directory' },\n { value: 'user', label: '~/.config/proxitor/config.yaml', hint: 'User config' },\n ]\n\n if (process.env.XDG_CONFIG_HOME) {\n opts.push({\n value: 'xdg',\n label: '$XDG_CONFIG_HOME/proxitor/config.yaml',\n hint: 'XDG config directory',\n })\n }\n\n return opts\n}\n\nfunction detectLocation(path: string): SaveLocation | undefined {\n const cwd = resolve('.')\n if (path.startsWith(cwd)) return 'local'\n const userDir = join(homedir(), '.config', 'proxitor')\n if (path.startsWith(userDir)) {\n const xdgDir = process.env.XDG_CONFIG_HOME\n ? join(process.env.XDG_CONFIG_HOME, 'proxitor')\n : null\n if (xdgDir && path.startsWith(xdgDir)) return 'xdg'\n return 'user'\n }\n return undefined\n}\n\nfunction buildYaml(\n apiKey: string,\n port: number,\n host: string,\n existingRaw?: string,\n): string {\n if (existingRaw) {\n const doc = parseDocument(existingRaw)\n doc.set('openrouterKey', apiKey)\n doc.set('port', port)\n doc.set('host', host)\n return doc.toString()\n }\n\n return stringify({ openrouterKey: apiKey, port, host })\n}\n\nfunction readExistingConfig(path: string): {\n raw: string\n port: number\n host: string\n apiKey: string\n} {\n const raw = readFileSync(path, 'utf-8')\n const parsed = parseDocument(raw).toJSON() as Record<string, unknown>\n return {\n raw,\n port: typeof parsed?.port === 'number' ? parsed.port : DEFAULT_PORT,\n host: typeof parsed?.host === 'string' ? parsed.host : DEFAULT_HOST,\n apiKey: typeof parsed?.openrouterKey === 'string' ? parsed.openrouterKey : '',\n }\n}\n\nasync function askApiKey(currentKey: string): Promise<string | null> {\n if (currentKey) {\n clack.log.info(`Current key: ${maskKey(currentKey)}`)\n }\n const apiKey = await clack.text({\n message: 'OpenRouter API key',\n placeholder: 'sk-or-v1-...',\n initialValue: currentKey,\n validate: v => {\n if (!v?.trim()) return 'API key is required'\n return undefined\n },\n })\n if (isCancel(apiKey)) return null\n\n clack.note(\n 'You can also set the OPENROUTER_API_KEY environment variable\\nto avoid storing the key in the config file.',\n 'Tip',\n )\n return apiKey as string\n}\n\nasync function askPort(current: number): Promise<number | null> {\n const input = await clack.text({\n message: 'Proxy port',\n initialValue: String(current),\n placeholder: String(DEFAULT_PORT),\n validate: v => {\n if (!v?.trim()) return undefined\n const n = Number.parseInt(v, 10)\n if (Number.isNaN(n) || n < 1 || n > 65535) return 'Port must be 1–65535'\n return undefined\n },\n })\n if (isCancel(input)) return null\n return (input as string).trim() ? Number.parseInt(input as string, 10) : DEFAULT_PORT\n}\n\nasync function askHost(current: string): Promise<string | null> {\n const host = await clack.select({\n message: 'Listen address',\n initialValue: current as '0.0.0.0' | '127.0.0.1',\n options: [\n { value: '0.0.0.0', label: 'All interfaces (0.0.0.0)', hint: 'Default' },\n { value: '127.0.0.1', label: 'Localhost only (127.0.0.1)', hint: 'More secure' },\n ],\n })\n if (isCancel(host)) return null\n return host as string\n}\n\nasync function askSaveLocation(existingPath?: string): Promise<SaveLocation | null> {\n const options = getSaveLocationOptions(existingPath)\n const detected = existingPath ? detectLocation(existingPath) : undefined\n\n const location = await clack.select({\n message: 'Save config to',\n initialValue: detected ?? 'local',\n options,\n })\n if (isCancel(location)) return null\n return location as SaveLocation\n}\n\nexport async function runWizard(): Promise<void> {\n clack.intro('Proxitor Setup Wizard')\n\n const existingPath = findConfigFile()\n let existingRaw: string | undefined\n let currentPort = DEFAULT_PORT\n let currentHost = DEFAULT_HOST\n let currentKey = ''\n\n if (existingPath) {\n clack.note(existingPath, 'Existing config found')\n\n const reconfigure = await clack.confirm({\n message: 'Reconfigure?',\n initialValue: true,\n })\n if (isCancel(reconfigure) || !reconfigure) {\n clack.outro('Using existing configuration')\n return\n }\n\n try {\n const existing = readExistingConfig(existingPath)\n existingRaw = existing.raw\n currentPort = existing.port\n currentHost = existing.host\n currentKey = existing.apiKey\n } catch {\n // use defaults\n }\n }\n\n const apiKey = await askApiKey(currentKey)\n if (apiKey === null) {\n clack.outro('Cancelled')\n return\n }\n\n const port = await askPort(currentPort)\n if (port === null) {\n clack.outro('Cancelled')\n return\n }\n\n const host = await askHost(currentHost)\n if (host === null) {\n clack.outro('Cancelled')\n return\n }\n\n const location = await askSaveLocation(existingPath ?? undefined)\n if (location === null) {\n clack.outro('Cancelled')\n return\n }\n\n const yaml = buildYaml(apiKey, port, host, existingRaw)\n clack.note(yaml, 'Preview')\n\n const save = await clack.confirm({\n message: 'Save this configuration?',\n initialValue: true,\n })\n if (isCancel(save) || !save) {\n clack.outro('Cancelled — no files written')\n return\n }\n\n const savePath = resolveSavePath(location)\n const dir = dirname(savePath)\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true })\n }\n writeFileSync(savePath, yaml, 'utf-8')\n\n clack.outro(`Config saved to ${savePath}`)\n}\n"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "proxitor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Lightweight proxy for routing CLI requests (claude-code, codex) to OpenRouter",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
8
8
|
],
|
|
9
|
-
"exports": {
|
|
10
|
-
".": {
|
|
11
|
-
"import": {
|
|
12
|
-
"types": "./dist/index.d.mts",
|
|
13
|
-
"default": "./dist/index.mjs"
|
|
14
|
-
},
|
|
15
|
-
"require": {
|
|
16
|
-
"types": "./dist/index.d.cts",
|
|
17
|
-
"default": "./dist/index.cjs"
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
"main": "./dist/index.cjs",
|
|
22
|
-
"module": "./dist/index.mjs",
|
|
23
|
-
"types": "./dist/index.d.mts",
|
|
24
9
|
"keywords": [
|
|
25
10
|
"proxy",
|
|
26
11
|
"openrouter",
|
|
@@ -44,13 +29,16 @@
|
|
|
44
29
|
},
|
|
45
30
|
"homepage": "https://github.com/neiromaster/proxitor#readme",
|
|
46
31
|
"dependencies": {
|
|
32
|
+
"@clack/prompts": "^1.5.0",
|
|
47
33
|
"@hono/node-server": "^2.0.4",
|
|
48
|
-
"
|
|
34
|
+
"cmd-ts": "^0.15.0",
|
|
49
35
|
"conf": "^15.1.0",
|
|
50
36
|
"consola": "^3.4.2",
|
|
51
37
|
"dotenv": "^17.4.2",
|
|
52
38
|
"hono": "^4.12.23",
|
|
53
|
-
"js-yaml": "^4.2.0"
|
|
39
|
+
"js-yaml": "^4.2.0",
|
|
40
|
+
"yaml": "^2.9.0",
|
|
41
|
+
"zod": "^4.4.3"
|
|
54
42
|
},
|
|
55
43
|
"devDependencies": {
|
|
56
44
|
"@biomejs/biome": "^2.4.16",
|
package/dist/cli.cjs
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const require_proxy = require("./proxy.cjs");
|
|
3
|
-
let cac = require("cac");
|
|
4
|
-
let dotenv = require("dotenv");
|
|
5
|
-
//#region src/version.ts
|
|
6
|
-
const version = "0.1.0";
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/cli.ts
|
|
9
|
-
(0, dotenv.config)();
|
|
10
|
-
const cli = (0, cac.cac)("proxitor");
|
|
11
|
-
cli.version(version).usage("[options]").help();
|
|
12
|
-
cli.option("-p, --port <port>", "Proxy server port", { default: 8080 }).option("-h, --host <host>", "Proxy server host", { default: "0.0.0.0" }).option("-c, --config <path>", "Path to config file").option("--no-config", "Skip config file discovery").option("--openrouter-key <key>", "OpenRouter API key").option("--verbose", "Enable verbose logging");
|
|
13
|
-
const parsed = cli.parse();
|
|
14
|
-
async function main() {
|
|
15
|
-
try {
|
|
16
|
-
const config = await require_proxy.loadConfig({
|
|
17
|
-
configPath: typeof parsed.options.config === "string" ? parsed.options.config : void 0,
|
|
18
|
-
noConfig: parsed.options.config === false,
|
|
19
|
-
port: parsed.options.port,
|
|
20
|
-
host: parsed.options.host,
|
|
21
|
-
openrouterKey: parsed.options.openrouterKey,
|
|
22
|
-
verbose: parsed.options.verbose
|
|
23
|
-
});
|
|
24
|
-
require_proxy.startProxyServer(config, () => {
|
|
25
|
-
require_proxy.logger.ready(`Proxitor proxy listening on ${config.host}:${config.port}`);
|
|
26
|
-
require_proxy.logger.info(`Routing requests to OpenRouter`);
|
|
27
|
-
});
|
|
28
|
-
} catch (error) {
|
|
29
|
-
require_proxy.logger.error("Failed to start proxy:", error);
|
|
30
|
-
process.exit(1);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
main();
|
|
34
|
-
//#endregion
|
|
35
|
-
|
|
36
|
-
//# sourceMappingURL=cli.cjs.map
|
package/dist/cli.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.cjs","names":["loadConfig"],"sources":["../src/version.ts","../src/cli.ts"],"sourcesContent":["export const version = '0.1.0'\n","#!/usr/bin/env node\nimport { cac } from 'cac'\nimport { config as loadDotenv } from 'dotenv'\nimport { loadConfig } from './config.js'\nimport { logger } from './logger.js'\nimport { startProxyServer } from './proxy.js'\nimport { version } from './version.js'\n\nloadDotenv()\n\nconst cli = cac('proxitor')\n\ncli.version(version).usage('[options]').help()\n\ncli\n .option('-p, --port <port>', 'Proxy server port', { default: 8080 })\n .option('-h, --host <host>', 'Proxy server host', { default: '0.0.0.0' })\n .option('-c, --config <path>', 'Path to config file')\n .option('--no-config', 'Skip config file discovery')\n .option('--openrouter-key <key>', 'OpenRouter API key')\n .option('--verbose', 'Enable verbose logging')\n\nconst parsed = cli.parse()\n\nasync function main() {\n try {\n const config = await loadConfig({\n configPath:\n typeof parsed.options.config === 'string' ? parsed.options.config : undefined,\n noConfig: parsed.options.config === false,\n port: parsed.options.port,\n host: parsed.options.host,\n openrouterKey: parsed.options.openrouterKey,\n verbose: parsed.options.verbose,\n })\n\n startProxyServer(config, () => {\n logger.ready(`Proxitor proxy listening on ${config.host}:${config.port}`)\n logger.info(`Routing requests to OpenRouter`)\n })\n } catch (error) {\n logger.error('Failed to start proxy:', error)\n process.exit(1)\n }\n}\n\nvoid main()\n"],"mappings":";;;;;AAAA,MAAa,UAAU;;;mBCQZ;AAEX,MAAM,OAAA,GAAA,IAAA,KAAU,UAAU;AAE1B,IAAI,QAAQ,OAAO,EAAE,MAAM,WAAW,EAAE,KAAK;AAE7C,IACG,OAAO,qBAAqB,qBAAqB,EAAE,SAAS,KAAK,CAAC,EAClE,OAAO,qBAAqB,qBAAqB,EAAE,SAAS,UAAU,CAAC,EACvE,OAAO,uBAAuB,qBAAqB,EACnD,OAAO,eAAe,4BAA4B,EAClD,OAAO,0BAA0B,oBAAoB,EACrD,OAAO,aAAa,wBAAwB;AAE/C,MAAM,SAAS,IAAI,MAAM;AAEzB,eAAe,OAAO;CACpB,IAAI;EACF,MAAM,SAAS,MAAMA,cAAAA,WAAW;GAC9B,YACE,OAAO,OAAO,QAAQ,WAAW,WAAW,OAAO,QAAQ,SAAS,KAAA;GACtE,UAAU,OAAO,QAAQ,WAAW;GACpC,MAAM,OAAO,QAAQ;GACrB,MAAM,OAAO,QAAQ;GACrB,eAAe,OAAO,QAAQ;GAC9B,SAAS,OAAO,QAAQ;EAC1B,CAAC;EAED,cAAA,iBAAiB,cAAc;GAC7B,cAAA,OAAO,MAAM,+BAA+B,OAAO,KAAK,GAAG,OAAO,MAAM;GACxE,cAAA,OAAO,KAAK,gCAAgC;EAC9C,CAAC;CACH,SAAS,OAAO;EACd,cAAA,OAAO,MAAM,0BAA0B,KAAK;EAC5C,QAAQ,KAAK,CAAC;CAChB;AACF;AAEK,KAAK"}
|
package/dist/cli.d.cts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/dist/cli.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/dist/index.cjs
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_proxy = require("./proxy.cjs");
|
|
3
|
-
exports.buildProviderRouting = require_proxy.buildProviderRouting;
|
|
4
|
-
exports.createProxyServer = require_proxy.createProxyServer;
|
|
5
|
-
exports.extractModel = require_proxy.extractModel;
|
|
6
|
-
exports.loadConfig = require_proxy.loadConfig;
|
|
7
|
-
exports.matchScore = require_proxy.matchScore;
|
|
8
|
-
exports.resolveModelConfig = require_proxy.resolveModelConfig;
|
|
9
|
-
exports.toArray = require_proxy.toArray;
|
|
10
|
-
exports.tryParseBody = require_proxy.tryParseBody;
|
package/dist/index.d.cts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { ServerType } from "@hono/node-server";
|
|
2
|
-
|
|
3
|
-
//#region src/config.d.ts
|
|
4
|
-
/** Percentile cutoffs for performance thresholds */
|
|
5
|
-
type PercentileCutoffs = {
|
|
6
|
-
p50?: number;
|
|
7
|
-
p75?: number;
|
|
8
|
-
p90?: number;
|
|
9
|
-
p99?: number;
|
|
10
|
-
};
|
|
11
|
-
/** Provider sorting options */
|
|
12
|
-
type ProviderSort = 'price' | 'throughput' | 'latency' | {
|
|
13
|
-
by: 'price' | 'throughput' | 'latency';
|
|
14
|
-
partition?: 'model' | 'none';
|
|
15
|
-
};
|
|
16
|
-
/** Maximum pricing for a request */
|
|
17
|
-
type MaxPrice = {
|
|
18
|
-
prompt?: number;
|
|
19
|
-
completion?: number;
|
|
20
|
-
request?: number;
|
|
21
|
-
image?: number;
|
|
22
|
-
};
|
|
23
|
-
type ProviderConfig = {
|
|
24
|
-
/** Allow only these providers (e.g. "deepinfra" or ["anthropic", "openai"]) */only?: string | string[]; /** Try providers in this order (e.g. "anthropic" or ["openai", "together"]) */
|
|
25
|
-
order?: string | string[]; /** Ignore these providers (mirror of only — skip specific providers) */
|
|
26
|
-
ignore?: string | string[]; /** Allow fallback to other providers (default: true) */
|
|
27
|
-
allowFallbacks?: boolean; /** Sort providers by price, throughput, or latency */
|
|
28
|
-
sort?: ProviderSort; /** Filter by quantization levels (e.g. ["fp8", "int4"]) */
|
|
29
|
-
quantizations?: string[]; /** Maximum pricing to accept */
|
|
30
|
-
maxPrice?: MaxPrice; /** Only use providers that support all request parameters (default: false) */
|
|
31
|
-
requireParameters?: boolean; /** Control data collection policy: "allow" or "deny" (default: "allow") */
|
|
32
|
-
dataCollection?: 'allow' | 'deny'; /** Restrict routing to Zero Data Retention endpoints */
|
|
33
|
-
zdr?: boolean; /** Restrict routing to models that allow text distillation */
|
|
34
|
-
enforceDistillableText?: boolean; /** Preferred minimum throughput (tokens/sec) */
|
|
35
|
-
preferredMinThroughput?: number | PercentileCutoffs; /** Preferred maximum latency (seconds) */
|
|
36
|
-
preferredMaxLatency?: number | PercentileCutoffs;
|
|
37
|
-
};
|
|
38
|
-
/** Per-model override: layers on top of global config */
|
|
39
|
-
type ModelOverride = {
|
|
40
|
-
/** Override provider routing for matching models */provider?: ProviderConfig; /** Additional headers to merge for matching models */
|
|
41
|
-
headers?: Record<string, string>;
|
|
42
|
-
};
|
|
43
|
-
/** Result of merging global config with a model-specific override */
|
|
44
|
-
type ResolvedModelConfig = {
|
|
45
|
-
provider?: ProviderConfig;
|
|
46
|
-
headers?: Record<string, string>;
|
|
47
|
-
};
|
|
48
|
-
type ProxyConfig = {
|
|
49
|
-
host: string;
|
|
50
|
-
port: number;
|
|
51
|
-
openrouterKey: string;
|
|
52
|
-
openrouterBaseUrl: string;
|
|
53
|
-
verbose: boolean; /** Request body size limit (default: "50mb") */
|
|
54
|
-
bodyLimit: string; /** Provider routing configuration (global default) */
|
|
55
|
-
provider?: ProviderConfig; /** HTTP-Referer for OpenRouter attribution */
|
|
56
|
-
attributionReferer: string; /** X-Title for OpenRouter attribution */
|
|
57
|
-
attributionTitle: string; /** Custom headers to add to proxied requests (global default) */
|
|
58
|
-
headers?: Record<string, string>; /** Per-model config overrides. Keys are exact model names or prefix patterns (e.g. "claude-*") */
|
|
59
|
-
modelOverrides?: Record<string, ModelOverride>;
|
|
60
|
-
};
|
|
61
|
-
type LoadConfigOptions = {
|
|
62
|
-
configPath?: string;
|
|
63
|
-
noConfig?: boolean;
|
|
64
|
-
host?: string;
|
|
65
|
-
openrouterKey?: string;
|
|
66
|
-
port?: number;
|
|
67
|
-
verbose?: boolean;
|
|
68
|
-
};
|
|
69
|
-
/** Build the provider routing object for OpenRouter request body injection */
|
|
70
|
-
declare function buildProviderRouting(provider?: ProviderConfig): Record<string, unknown> | undefined;
|
|
71
|
-
/** Score a pattern against a model name. Higher = better match. -1 = no match. */
|
|
72
|
-
declare function matchScore(pattern: string, modelName: string): number;
|
|
73
|
-
/** Resolve the effective config for a given model by merging global defaults with the best-matching override */
|
|
74
|
-
declare function resolveModelConfig(config: ProxyConfig, modelName?: string): ResolvedModelConfig;
|
|
75
|
-
declare function loadConfig(options: LoadConfigOptions): Promise<ProxyConfig>;
|
|
76
|
-
//#endregion
|
|
77
|
-
//#region src/proxy/inject.d.ts
|
|
78
|
-
/** Extract the model name from a raw request body. Returns undefined if not parseable or absent. */
|
|
79
|
-
declare function extractModel(rawBody: ArrayBuffer): string | undefined;
|
|
80
|
-
//#endregion
|
|
81
|
-
//#region src/proxy.d.ts
|
|
82
|
-
declare function createProxyServer(config: ProxyConfig, onReady?: () => void): ServerType;
|
|
83
|
-
//#endregion
|
|
84
|
-
//#region src/utils.d.ts
|
|
85
|
-
/** Normalize a single string or array of strings to an array. Returns undefined for empty arrays. */
|
|
86
|
-
declare function toArray(value: string | string[] | undefined): string[] | undefined;
|
|
87
|
-
/** Try to parse an ArrayBuffer as JSON. Returns undefined on failure or empty body. */
|
|
88
|
-
declare function tryParseBody(raw: ArrayBuffer): Record<string, unknown> | undefined;
|
|
89
|
-
//#endregion
|
|
90
|
-
export { type ModelOverride, type ProviderConfig, type ProxyConfig, type ResolvedModelConfig, buildProviderRouting, createProxyServer, extractModel, loadConfig, matchScore, resolveModelConfig, toArray, tryParseBody };
|
|
91
|
-
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/config.ts","../src/proxy/inject.ts","../src/proxy.ts","../src/utils.ts"],"mappings":";;;;KAOY,iBAAA;EACV,GAAA;EACA,GAAA;EACA,GAAA;EACA,GAAA;AAAA;;KAIU,YAAA;EAIN,EAAA;EAAwC,SAAS;AAAA;AARlD;AAAA,KAWO,QAAA;EACV,MAAA;EACA,UAAA;EACA,OAAA;EACA,KAAA;AAAA;AAAA,KAGU,cAAA;iFAEV,IAAA,sBARA;EAUA,KAAA,sBARA;EAUA,MAAA,sBATK;EAWL,cAAA,YARU;EAUV,IAAA,GAAO,YAAA;EAEP,aAAA,aAEW;EAAX,QAAA,GAAW,QAAA,EAYoB;EAV/B,iBAAA,YAUgD;EARhD,cAAA,qBAdA;EAgBA,GAAA,YAZA;EAcA,sBAAA,YAZO;EAcP,sBAAA,YAAkC,iBAAA,EAVlC;EAYA,mBAAA,YAA+B,iBAAA;AAAA;;KAIrB,aAAA;EARV,oDAUA,QAAA,GAAW,cAAA,EARuB;EAUlC,OAAA,GAAU,MAAM;AAAA;;KAIN,mBAAA;EACV,QAAA,GAAW,cAAA;EACX,OAAA,GAAU,MAAM;AAAA;AAAA,KAGN,WAAA;EACV,IAAA;EACA,IAAA;EACA,aAAA;EACA,iBAAA;EACA,OAAA,WAdgB;EAgBhB,SAAA,UAZ6B;EAc7B,QAAA,GAAW,cAAA,EAZK;EAchB,kBAAA,UAfW;EAiBX,gBAAA,UAhBU;EAkBV,OAAA,GAAU,MAAA,kBAlBM;EAoBhB,cAAA,GAAiB,MAAA,SAAe,aAAA;AAAA;AAAA,KAc7B,iBAAA;EACH,UAAA;EACA,QAAA;EACA,IAAA;EACA,aAAA;EACA,IAAA;EACA,OAAA;AAAA;;iBAwBc,oBAAA,CACd,QAAA,GAAW,cAAA,GACV,MAAM;;iBA0BO,UAAA,CAAW,OAAA,UAAiB,SAAiB;;iBAW7C,kBAAA,CACd,MAAA,EAAQ,WAAA,EACR,SAAA,YACC,mBAAmB;AAAA,iBAgCA,UAAA,CAAW,OAAA,EAAS,iBAAA,GAAoB,OAAA,CAAQ,WAAA;;;;iBC5MtD,YAAA,CAAa,OAAoB,EAAX,WAAW;;;iBC0JjC,iBAAA,CAAkB,MAAA,EAAQ,WAAA,EAAa,OAAA,gBAAuB,UAAU;;;;iBC5JxE,OAAA,CAAQ,KAAoC;;iBAO5C,YAAA,CAAa,GAAA,EAAK,WAAA,GAAc,MAAM"}
|
package/dist/index.d.mts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { ServerType } from "@hono/node-server";
|
|
2
|
-
|
|
3
|
-
//#region src/config.d.ts
|
|
4
|
-
/** Percentile cutoffs for performance thresholds */
|
|
5
|
-
type PercentileCutoffs = {
|
|
6
|
-
p50?: number;
|
|
7
|
-
p75?: number;
|
|
8
|
-
p90?: number;
|
|
9
|
-
p99?: number;
|
|
10
|
-
};
|
|
11
|
-
/** Provider sorting options */
|
|
12
|
-
type ProviderSort = 'price' | 'throughput' | 'latency' | {
|
|
13
|
-
by: 'price' | 'throughput' | 'latency';
|
|
14
|
-
partition?: 'model' | 'none';
|
|
15
|
-
};
|
|
16
|
-
/** Maximum pricing for a request */
|
|
17
|
-
type MaxPrice = {
|
|
18
|
-
prompt?: number;
|
|
19
|
-
completion?: number;
|
|
20
|
-
request?: number;
|
|
21
|
-
image?: number;
|
|
22
|
-
};
|
|
23
|
-
type ProviderConfig = {
|
|
24
|
-
/** Allow only these providers (e.g. "deepinfra" or ["anthropic", "openai"]) */only?: string | string[]; /** Try providers in this order (e.g. "anthropic" or ["openai", "together"]) */
|
|
25
|
-
order?: string | string[]; /** Ignore these providers (mirror of only — skip specific providers) */
|
|
26
|
-
ignore?: string | string[]; /** Allow fallback to other providers (default: true) */
|
|
27
|
-
allowFallbacks?: boolean; /** Sort providers by price, throughput, or latency */
|
|
28
|
-
sort?: ProviderSort; /** Filter by quantization levels (e.g. ["fp8", "int4"]) */
|
|
29
|
-
quantizations?: string[]; /** Maximum pricing to accept */
|
|
30
|
-
maxPrice?: MaxPrice; /** Only use providers that support all request parameters (default: false) */
|
|
31
|
-
requireParameters?: boolean; /** Control data collection policy: "allow" or "deny" (default: "allow") */
|
|
32
|
-
dataCollection?: 'allow' | 'deny'; /** Restrict routing to Zero Data Retention endpoints */
|
|
33
|
-
zdr?: boolean; /** Restrict routing to models that allow text distillation */
|
|
34
|
-
enforceDistillableText?: boolean; /** Preferred minimum throughput (tokens/sec) */
|
|
35
|
-
preferredMinThroughput?: number | PercentileCutoffs; /** Preferred maximum latency (seconds) */
|
|
36
|
-
preferredMaxLatency?: number | PercentileCutoffs;
|
|
37
|
-
};
|
|
38
|
-
/** Per-model override: layers on top of global config */
|
|
39
|
-
type ModelOverride = {
|
|
40
|
-
/** Override provider routing for matching models */provider?: ProviderConfig; /** Additional headers to merge for matching models */
|
|
41
|
-
headers?: Record<string, string>;
|
|
42
|
-
};
|
|
43
|
-
/** Result of merging global config with a model-specific override */
|
|
44
|
-
type ResolvedModelConfig = {
|
|
45
|
-
provider?: ProviderConfig;
|
|
46
|
-
headers?: Record<string, string>;
|
|
47
|
-
};
|
|
48
|
-
type ProxyConfig = {
|
|
49
|
-
host: string;
|
|
50
|
-
port: number;
|
|
51
|
-
openrouterKey: string;
|
|
52
|
-
openrouterBaseUrl: string;
|
|
53
|
-
verbose: boolean; /** Request body size limit (default: "50mb") */
|
|
54
|
-
bodyLimit: string; /** Provider routing configuration (global default) */
|
|
55
|
-
provider?: ProviderConfig; /** HTTP-Referer for OpenRouter attribution */
|
|
56
|
-
attributionReferer: string; /** X-Title for OpenRouter attribution */
|
|
57
|
-
attributionTitle: string; /** Custom headers to add to proxied requests (global default) */
|
|
58
|
-
headers?: Record<string, string>; /** Per-model config overrides. Keys are exact model names or prefix patterns (e.g. "claude-*") */
|
|
59
|
-
modelOverrides?: Record<string, ModelOverride>;
|
|
60
|
-
};
|
|
61
|
-
type LoadConfigOptions = {
|
|
62
|
-
configPath?: string;
|
|
63
|
-
noConfig?: boolean;
|
|
64
|
-
host?: string;
|
|
65
|
-
openrouterKey?: string;
|
|
66
|
-
port?: number;
|
|
67
|
-
verbose?: boolean;
|
|
68
|
-
};
|
|
69
|
-
/** Build the provider routing object for OpenRouter request body injection */
|
|
70
|
-
declare function buildProviderRouting(provider?: ProviderConfig): Record<string, unknown> | undefined;
|
|
71
|
-
/** Score a pattern against a model name. Higher = better match. -1 = no match. */
|
|
72
|
-
declare function matchScore(pattern: string, modelName: string): number;
|
|
73
|
-
/** Resolve the effective config for a given model by merging global defaults with the best-matching override */
|
|
74
|
-
declare function resolveModelConfig(config: ProxyConfig, modelName?: string): ResolvedModelConfig;
|
|
75
|
-
declare function loadConfig(options: LoadConfigOptions): Promise<ProxyConfig>;
|
|
76
|
-
//#endregion
|
|
77
|
-
//#region src/proxy/inject.d.ts
|
|
78
|
-
/** Extract the model name from a raw request body. Returns undefined if not parseable or absent. */
|
|
79
|
-
declare function extractModel(rawBody: ArrayBuffer): string | undefined;
|
|
80
|
-
//#endregion
|
|
81
|
-
//#region src/proxy.d.ts
|
|
82
|
-
declare function createProxyServer(config: ProxyConfig, onReady?: () => void): ServerType;
|
|
83
|
-
//#endregion
|
|
84
|
-
//#region src/utils.d.ts
|
|
85
|
-
/** Normalize a single string or array of strings to an array. Returns undefined for empty arrays. */
|
|
86
|
-
declare function toArray(value: string | string[] | undefined): string[] | undefined;
|
|
87
|
-
/** Try to parse an ArrayBuffer as JSON. Returns undefined on failure or empty body. */
|
|
88
|
-
declare function tryParseBody(raw: ArrayBuffer): Record<string, unknown> | undefined;
|
|
89
|
-
//#endregion
|
|
90
|
-
export { type ModelOverride, type ProviderConfig, type ProxyConfig, type ResolvedModelConfig, buildProviderRouting, createProxyServer, extractModel, loadConfig, matchScore, resolveModelConfig, toArray, tryParseBody };
|
|
91
|
-
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/config.ts","../src/proxy/inject.ts","../src/proxy.ts","../src/utils.ts"],"mappings":";;;;KAOY,iBAAA;EACV,GAAA;EACA,GAAA;EACA,GAAA;EACA,GAAA;AAAA;;KAIU,YAAA;EAIN,EAAA;EAAwC,SAAS;AAAA;AARlD;AAAA,KAWO,QAAA;EACV,MAAA;EACA,UAAA;EACA,OAAA;EACA,KAAA;AAAA;AAAA,KAGU,cAAA;iFAEV,IAAA,sBARA;EAUA,KAAA,sBARA;EAUA,MAAA,sBATK;EAWL,cAAA,YARU;EAUV,IAAA,GAAO,YAAA;EAEP,aAAA,aAEW;EAAX,QAAA,GAAW,QAAA,EAYoB;EAV/B,iBAAA,YAUgD;EARhD,cAAA,qBAdA;EAgBA,GAAA,YAZA;EAcA,sBAAA,YAZO;EAcP,sBAAA,YAAkC,iBAAA,EAVlC;EAYA,mBAAA,YAA+B,iBAAA;AAAA;;KAIrB,aAAA;EARV,oDAUA,QAAA,GAAW,cAAA,EARuB;EAUlC,OAAA,GAAU,MAAM;AAAA;;KAIN,mBAAA;EACV,QAAA,GAAW,cAAA;EACX,OAAA,GAAU,MAAM;AAAA;AAAA,KAGN,WAAA;EACV,IAAA;EACA,IAAA;EACA,aAAA;EACA,iBAAA;EACA,OAAA,WAdgB;EAgBhB,SAAA,UAZ6B;EAc7B,QAAA,GAAW,cAAA,EAZK;EAchB,kBAAA,UAfW;EAiBX,gBAAA,UAhBU;EAkBV,OAAA,GAAU,MAAA,kBAlBM;EAoBhB,cAAA,GAAiB,MAAA,SAAe,aAAA;AAAA;AAAA,KAc7B,iBAAA;EACH,UAAA;EACA,QAAA;EACA,IAAA;EACA,aAAA;EACA,IAAA;EACA,OAAA;AAAA;;iBAwBc,oBAAA,CACd,QAAA,GAAW,cAAA,GACV,MAAM;;iBA0BO,UAAA,CAAW,OAAA,UAAiB,SAAiB;;iBAW7C,kBAAA,CACd,MAAA,EAAQ,WAAA,EACR,SAAA,YACC,mBAAmB;AAAA,iBAgCA,UAAA,CAAW,OAAA,EAAS,iBAAA,GAAoB,OAAA,CAAQ,WAAA;;;;iBC5MtD,YAAA,CAAa,OAAoB,EAAX,WAAW;;;iBC0JjC,iBAAA,CAAkB,MAAA,EAAQ,WAAA,EAAa,OAAA,gBAAuB,UAAU;;;;iBC5JxE,OAAA,CAAQ,KAAoC;;iBAO5C,YAAA,CAAa,GAAA,EAAK,WAAA,GAAc,MAAM"}
|
package/dist/index.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { a as buildProviderRouting, c as resolveModelConfig, l as toArray, o as loadConfig, r as extractModel, s as matchScore, t as createProxyServer, u as tryParseBody } from "./proxy.mjs";
|
|
2
|
-
export { buildProviderRouting, createProxyServer, extractModel, loadConfig, matchScore, resolveModelConfig, toArray, tryParseBody };
|