@lakphy/local-router 0.1.0 → 0.1.2
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/dist/cli.js +39 -11
- package/dist/entry.js +37 -9
- package/dist/web/assets/index-CSD009q8.js +190 -0
- package/dist/web/assets/index-MPUGUNQ3.css +2 -0
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/web/assets/index-BbfScfK-.js +0 -190
- package/dist/web/assets/index-D7k-VsmO.css +0 -2
package/dist/cli.js
CHANGED
|
@@ -7974,7 +7974,6 @@ import { parseArgs } from "util";
|
|
|
7974
7974
|
|
|
7975
7975
|
// src/index.ts
|
|
7976
7976
|
import { readFileSync as readFileSync3 } from "fs";
|
|
7977
|
-
import { resolve as resolve4 } from "path";
|
|
7978
7977
|
|
|
7979
7978
|
// node_modules/.bun/hono@4.12.5/node_modules/hono/dist/utils/html.js
|
|
7980
7979
|
var HtmlEscapedCallbackPhase = {
|
|
@@ -10827,6 +10826,7 @@ async function buildLogEventDetail(id, parsed, location, context) {
|
|
|
10827
10826
|
},
|
|
10828
10827
|
upstream: {
|
|
10829
10828
|
targetUrl: maskedEvent.target_url,
|
|
10829
|
+
proxyUrl: maskedEvent.proxy_url ?? null,
|
|
10830
10830
|
providerRequestId: maskedEvent.provider_request_id,
|
|
10831
10831
|
errorType: maskedEvent.error_type,
|
|
10832
10832
|
errorMessage: maskedEvent.error_message,
|
|
@@ -11662,6 +11662,20 @@ function extractProviderRequestId(headers) {
|
|
|
11662
11662
|
}
|
|
11663
11663
|
return null;
|
|
11664
11664
|
}
|
|
11665
|
+
function maskUrlCredentials(rawUrl) {
|
|
11666
|
+
try {
|
|
11667
|
+
const parsed = new URL(rawUrl);
|
|
11668
|
+
if (!parsed.username && !parsed.password)
|
|
11669
|
+
return rawUrl;
|
|
11670
|
+
if (parsed.username)
|
|
11671
|
+
parsed.username = "****";
|
|
11672
|
+
if (parsed.password)
|
|
11673
|
+
parsed.password = "****";
|
|
11674
|
+
return parsed.toString();
|
|
11675
|
+
} catch {
|
|
11676
|
+
return rawUrl;
|
|
11677
|
+
}
|
|
11678
|
+
}
|
|
11665
11679
|
|
|
11666
11680
|
// src/openapi.ts
|
|
11667
11681
|
var openAPISpec = {
|
|
@@ -12814,7 +12828,7 @@ function buildResponseHeaders(upstream) {
|
|
|
12814
12828
|
});
|
|
12815
12829
|
return headers;
|
|
12816
12830
|
}
|
|
12817
|
-
function buildLogEvent(logMeta, targetUrl, tsEnd, overrides) {
|
|
12831
|
+
function buildLogEvent(logMeta, targetUrl, proxyUrl, tsEnd, overrides) {
|
|
12818
12832
|
return {
|
|
12819
12833
|
request_id: logMeta.requestId,
|
|
12820
12834
|
ts_start: new Date(logMeta.tsStart).toISOString(),
|
|
@@ -12827,7 +12841,8 @@ function buildLogEvent(logMeta, targetUrl, tsEnd, overrides) {
|
|
|
12827
12841
|
provider: logMeta.provider,
|
|
12828
12842
|
model_in: logMeta.modelIn,
|
|
12829
12843
|
model_out: logMeta.modelOut,
|
|
12830
|
-
target_url: targetUrl,
|
|
12844
|
+
target_url: maskUrlCredentials(targetUrl),
|
|
12845
|
+
proxy_url: proxyUrl ? maskUrlCredentials(proxyUrl) : null,
|
|
12831
12846
|
is_stream: logMeta.isStream,
|
|
12832
12847
|
upstream_status: 0,
|
|
12833
12848
|
content_type_req: logMeta.contentTypeReq,
|
|
@@ -12884,7 +12899,7 @@ async function proxyRequest(c2, options) {
|
|
|
12884
12899
|
});
|
|
12885
12900
|
} catch (err) {
|
|
12886
12901
|
if (shouldLog) {
|
|
12887
|
-
logger?.writeEvent(buildLogEvent(logMeta, options.targetUrl, Date.now(), {
|
|
12902
|
+
logger?.writeEvent(buildLogEvent(logMeta, options.targetUrl, proxy, Date.now(), {
|
|
12888
12903
|
error_type: err instanceof Error ? err.constructor.name : "UnknownError",
|
|
12889
12904
|
error_message: err instanceof Error ? err.message : String(err),
|
|
12890
12905
|
...requestBody !== undefined && { request_body: requestBody }
|
|
@@ -12924,7 +12939,7 @@ async function proxyRequest(c2, options) {
|
|
|
12924
12939
|
});
|
|
12925
12940
|
console.error("[logger] \u6D41\u5F0F\u65E5\u5FD7\u5904\u7406\u5931\u8D25:", err);
|
|
12926
12941
|
} finally {
|
|
12927
|
-
logger?.writeEvent(buildLogEvent(logMeta, options.targetUrl, Date.now(), {
|
|
12942
|
+
logger?.writeEvent(buildLogEvent(logMeta, options.targetUrl, proxy, Date.now(), {
|
|
12928
12943
|
upstream_status: upstreamRes.status,
|
|
12929
12944
|
content_type_res: contentTypeRes,
|
|
12930
12945
|
response_headers: responseHeaders,
|
|
@@ -12955,7 +12970,7 @@ async function proxyRequest(c2, options) {
|
|
|
12955
12970
|
if (logger?.bodyPolicy !== "off") {
|
|
12956
12971
|
eventOverrides.response_body = responseText;
|
|
12957
12972
|
}
|
|
12958
|
-
logger?.writeEvent(buildLogEvent(logMeta, options.targetUrl, Date.now(), eventOverrides));
|
|
12973
|
+
logger?.writeEvent(buildLogEvent(logMeta, options.targetUrl, proxy, Date.now(), eventOverrides));
|
|
12959
12974
|
return new Response(responseText, {
|
|
12960
12975
|
status: upstreamRes.status,
|
|
12961
12976
|
headers: responseHeaders
|
|
@@ -13062,6 +13077,18 @@ function createOpenaiResponsesRoutes(routeType, store) {
|
|
|
13062
13077
|
return routes;
|
|
13063
13078
|
}
|
|
13064
13079
|
|
|
13080
|
+
// src/runtime-assets.ts
|
|
13081
|
+
import { fileURLToPath } from "url";
|
|
13082
|
+
function resolveBundledAssetPath(relativePath) {
|
|
13083
|
+
return fileURLToPath(new URL(relativePath, import.meta.url));
|
|
13084
|
+
}
|
|
13085
|
+
function getBundledSchemaPath() {
|
|
13086
|
+
return resolveBundledAssetPath("../config.schema.json");
|
|
13087
|
+
}
|
|
13088
|
+
function getBundledWebRoot() {
|
|
13089
|
+
return resolveBundledAssetPath("../dist/web/");
|
|
13090
|
+
}
|
|
13091
|
+
|
|
13065
13092
|
// src/index.ts
|
|
13066
13093
|
var ROUTE_REGISTRY = {
|
|
13067
13094
|
"openai-completions": {
|
|
@@ -13140,7 +13167,7 @@ function createAdminApiRoutes(store, registerCleanup) {
|
|
|
13140
13167
|
const CRYPTO_SESSION_TTL_MS = 2 * 60 * 1000;
|
|
13141
13168
|
const CRYPTO_SESSION_MAX = 512;
|
|
13142
13169
|
const ajv = new import__2020.default({ allErrors: true, strict: false });
|
|
13143
|
-
const schemaPath =
|
|
13170
|
+
const schemaPath = getBundledSchemaPath();
|
|
13144
13171
|
const schemaJson = JSON.parse(readFileSync3(schemaPath, "utf-8"));
|
|
13145
13172
|
const validateBySchema = ajv.compile(schemaJson);
|
|
13146
13173
|
const pruneExpiredCryptoSessions = (now = Date.now()) => {
|
|
@@ -13676,11 +13703,12 @@ function createApp(store, options) {
|
|
|
13676
13703
|
console.log(`\u5DF2\u6CE8\u518C\u7BA1\u7406\u9762\u677F\u4EE3\u7406: /admin -> ${adminDevServerOrigin}/admin`);
|
|
13677
13704
|
} else {
|
|
13678
13705
|
app.all("/admin", (c2) => c2.redirect("/admin/", 308));
|
|
13706
|
+
const bundledWebRoot = getBundledWebRoot();
|
|
13679
13707
|
const adminStatic = serveStatic2({
|
|
13680
|
-
root:
|
|
13708
|
+
root: bundledWebRoot,
|
|
13681
13709
|
rewriteRequestPath: (path) => path.replace(/^\/admin/, "")
|
|
13682
13710
|
});
|
|
13683
|
-
const adminIndex = serveStatic2({ root:
|
|
13711
|
+
const adminIndex = serveStatic2({ root: bundledWebRoot, path: "./index.html" });
|
|
13684
13712
|
app.use("/admin/*", adminStatic);
|
|
13685
13713
|
app.get("/admin/*", async (c2, next) => {
|
|
13686
13714
|
if (c2.req.path.startsWith("/admin/assets/") || /\.[^/]+$/.test(c2.req.path)) {
|
|
@@ -13737,7 +13765,7 @@ function startServer(options) {
|
|
|
13737
13765
|
// src/cli/runtime.ts
|
|
13738
13766
|
import { existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as readFileSync4, rmSync, writeFileSync as writeFileSync4 } from "fs";
|
|
13739
13767
|
import { homedir as homedir2 } from "os";
|
|
13740
|
-
import { join as join9, resolve as
|
|
13768
|
+
import { join as join9, resolve as resolve4 } from "path";
|
|
13741
13769
|
function getRuntimeDirs() {
|
|
13742
13770
|
const root2 = join9(homedir2(), ".local-router");
|
|
13743
13771
|
return {
|
|
@@ -13784,7 +13812,7 @@ function clearRuntimeFiles() {
|
|
|
13784
13812
|
rmSync(files.state, { force: true });
|
|
13785
13813
|
}
|
|
13786
13814
|
function resolveConfigArgPath(pathValue) {
|
|
13787
|
-
return
|
|
13815
|
+
return resolve4(pathValue);
|
|
13788
13816
|
}
|
|
13789
13817
|
|
|
13790
13818
|
// src/cli/process.ts
|
package/dist/entry.js
CHANGED
|
@@ -6741,7 +6741,6 @@ var require_2020 = __commonJS((exports, module) => {
|
|
|
6741
6741
|
|
|
6742
6742
|
// src/index.ts
|
|
6743
6743
|
import { readFileSync as readFileSync3 } from "fs";
|
|
6744
|
-
import { resolve as resolve4 } from "path";
|
|
6745
6744
|
|
|
6746
6745
|
// node_modules/.bun/hono@4.12.5/node_modules/hono/dist/utils/html.js
|
|
6747
6746
|
var HtmlEscapedCallbackPhase = {
|
|
@@ -10811,6 +10810,7 @@ async function buildLogEventDetail(id, parsed, location, context) {
|
|
|
10811
10810
|
},
|
|
10812
10811
|
upstream: {
|
|
10813
10812
|
targetUrl: maskedEvent.target_url,
|
|
10813
|
+
proxyUrl: maskedEvent.proxy_url ?? null,
|
|
10814
10814
|
providerRequestId: maskedEvent.provider_request_id,
|
|
10815
10815
|
errorType: maskedEvent.error_type,
|
|
10816
10816
|
errorMessage: maskedEvent.error_message,
|
|
@@ -11646,6 +11646,20 @@ function extractProviderRequestId(headers) {
|
|
|
11646
11646
|
}
|
|
11647
11647
|
return null;
|
|
11648
11648
|
}
|
|
11649
|
+
function maskUrlCredentials(rawUrl) {
|
|
11650
|
+
try {
|
|
11651
|
+
const parsed = new URL(rawUrl);
|
|
11652
|
+
if (!parsed.username && !parsed.password)
|
|
11653
|
+
return rawUrl;
|
|
11654
|
+
if (parsed.username)
|
|
11655
|
+
parsed.username = "****";
|
|
11656
|
+
if (parsed.password)
|
|
11657
|
+
parsed.password = "****";
|
|
11658
|
+
return parsed.toString();
|
|
11659
|
+
} catch {
|
|
11660
|
+
return rawUrl;
|
|
11661
|
+
}
|
|
11662
|
+
}
|
|
11649
11663
|
|
|
11650
11664
|
// src/openapi.ts
|
|
11651
11665
|
var openAPISpec = {
|
|
@@ -12798,7 +12812,7 @@ function buildResponseHeaders(upstream) {
|
|
|
12798
12812
|
});
|
|
12799
12813
|
return headers;
|
|
12800
12814
|
}
|
|
12801
|
-
function buildLogEvent(logMeta, targetUrl, tsEnd, overrides) {
|
|
12815
|
+
function buildLogEvent(logMeta, targetUrl, proxyUrl, tsEnd, overrides) {
|
|
12802
12816
|
return {
|
|
12803
12817
|
request_id: logMeta.requestId,
|
|
12804
12818
|
ts_start: new Date(logMeta.tsStart).toISOString(),
|
|
@@ -12811,7 +12825,8 @@ function buildLogEvent(logMeta, targetUrl, tsEnd, overrides) {
|
|
|
12811
12825
|
provider: logMeta.provider,
|
|
12812
12826
|
model_in: logMeta.modelIn,
|
|
12813
12827
|
model_out: logMeta.modelOut,
|
|
12814
|
-
target_url: targetUrl,
|
|
12828
|
+
target_url: maskUrlCredentials(targetUrl),
|
|
12829
|
+
proxy_url: proxyUrl ? maskUrlCredentials(proxyUrl) : null,
|
|
12815
12830
|
is_stream: logMeta.isStream,
|
|
12816
12831
|
upstream_status: 0,
|
|
12817
12832
|
content_type_req: logMeta.contentTypeReq,
|
|
@@ -12868,7 +12883,7 @@ async function proxyRequest(c2, options) {
|
|
|
12868
12883
|
});
|
|
12869
12884
|
} catch (err) {
|
|
12870
12885
|
if (shouldLog) {
|
|
12871
|
-
logger?.writeEvent(buildLogEvent(logMeta, options.targetUrl, Date.now(), {
|
|
12886
|
+
logger?.writeEvent(buildLogEvent(logMeta, options.targetUrl, proxy, Date.now(), {
|
|
12872
12887
|
error_type: err instanceof Error ? err.constructor.name : "UnknownError",
|
|
12873
12888
|
error_message: err instanceof Error ? err.message : String(err),
|
|
12874
12889
|
...requestBody !== undefined && { request_body: requestBody }
|
|
@@ -12908,7 +12923,7 @@ async function proxyRequest(c2, options) {
|
|
|
12908
12923
|
});
|
|
12909
12924
|
console.error("[logger] \u6D41\u5F0F\u65E5\u5FD7\u5904\u7406\u5931\u8D25:", err);
|
|
12910
12925
|
} finally {
|
|
12911
|
-
logger?.writeEvent(buildLogEvent(logMeta, options.targetUrl, Date.now(), {
|
|
12926
|
+
logger?.writeEvent(buildLogEvent(logMeta, options.targetUrl, proxy, Date.now(), {
|
|
12912
12927
|
upstream_status: upstreamRes.status,
|
|
12913
12928
|
content_type_res: contentTypeRes,
|
|
12914
12929
|
response_headers: responseHeaders,
|
|
@@ -12939,7 +12954,7 @@ async function proxyRequest(c2, options) {
|
|
|
12939
12954
|
if (logger?.bodyPolicy !== "off") {
|
|
12940
12955
|
eventOverrides.response_body = responseText;
|
|
12941
12956
|
}
|
|
12942
|
-
logger?.writeEvent(buildLogEvent(logMeta, options.targetUrl, Date.now(), eventOverrides));
|
|
12957
|
+
logger?.writeEvent(buildLogEvent(logMeta, options.targetUrl, proxy, Date.now(), eventOverrides));
|
|
12943
12958
|
return new Response(responseText, {
|
|
12944
12959
|
status: upstreamRes.status,
|
|
12945
12960
|
headers: responseHeaders
|
|
@@ -13046,6 +13061,18 @@ function createOpenaiResponsesRoutes(routeType, store) {
|
|
|
13046
13061
|
return routes;
|
|
13047
13062
|
}
|
|
13048
13063
|
|
|
13064
|
+
// src/runtime-assets.ts
|
|
13065
|
+
import { fileURLToPath } from "url";
|
|
13066
|
+
function resolveBundledAssetPath(relativePath) {
|
|
13067
|
+
return fileURLToPath(new URL(relativePath, import.meta.url));
|
|
13068
|
+
}
|
|
13069
|
+
function getBundledSchemaPath() {
|
|
13070
|
+
return resolveBundledAssetPath("../config.schema.json");
|
|
13071
|
+
}
|
|
13072
|
+
function getBundledWebRoot() {
|
|
13073
|
+
return resolveBundledAssetPath("../dist/web/");
|
|
13074
|
+
}
|
|
13075
|
+
|
|
13049
13076
|
// src/index.ts
|
|
13050
13077
|
var ROUTE_REGISTRY = {
|
|
13051
13078
|
"openai-completions": {
|
|
@@ -13124,7 +13151,7 @@ function createAdminApiRoutes(store, registerCleanup) {
|
|
|
13124
13151
|
const CRYPTO_SESSION_TTL_MS = 2 * 60 * 1000;
|
|
13125
13152
|
const CRYPTO_SESSION_MAX = 512;
|
|
13126
13153
|
const ajv = new import__2020.default({ allErrors: true, strict: false });
|
|
13127
|
-
const schemaPath =
|
|
13154
|
+
const schemaPath = getBundledSchemaPath();
|
|
13128
13155
|
const schemaJson = JSON.parse(readFileSync3(schemaPath, "utf-8"));
|
|
13129
13156
|
const validateBySchema = ajv.compile(schemaJson);
|
|
13130
13157
|
const pruneExpiredCryptoSessions = (now = Date.now()) => {
|
|
@@ -13660,11 +13687,12 @@ function createApp(store, options) {
|
|
|
13660
13687
|
console.log(`\u5DF2\u6CE8\u518C\u7BA1\u7406\u9762\u677F\u4EE3\u7406: /admin -> ${adminDevServerOrigin}/admin`);
|
|
13661
13688
|
} else {
|
|
13662
13689
|
app.all("/admin", (c2) => c2.redirect("/admin/", 308));
|
|
13690
|
+
const bundledWebRoot = getBundledWebRoot();
|
|
13663
13691
|
const adminStatic = serveStatic2({
|
|
13664
|
-
root:
|
|
13692
|
+
root: bundledWebRoot,
|
|
13665
13693
|
rewriteRequestPath: (path) => path.replace(/^\/admin/, "")
|
|
13666
13694
|
});
|
|
13667
|
-
const adminIndex = serveStatic2({ root:
|
|
13695
|
+
const adminIndex = serveStatic2({ root: bundledWebRoot, path: "./index.html" });
|
|
13668
13696
|
app.use("/admin/*", adminStatic);
|
|
13669
13697
|
app.get("/admin/*", async (c2, next) => {
|
|
13670
13698
|
if (c2.req.path.startsWith("/admin/assets/") || /\.[^/]+$/.test(c2.req.path)) {
|