History

refactor(repo): adopt src/features convention, controller RouteRegistrar, shared validation

- frontend: src/features/{agent,recipes,discover,settings,usage,plugins,setup,logs,dashboard}; src/ui reduced to primitives; src/components retired; agent trees merged (lib/agent + hooks/agent + app/agent/_components -> features/agent) - controller: RouteRegistrar type across modules, core/validation.ts body helpers, studio provider routes split out - shared API route helpers (app/api/_lib/route-helpers.ts), themes data/API split, lib/types consolidated to recipes.ts + system.ts - structure validator rewritten to enforce the new layering Verified: check:quality (incl. production build), controller integration 49/49, frontend e2e 155/155, contracts check.

seroxdesign committed 5 months ago

Commit c9d1ea51 parent 8d0aacf334 files · +2556 −2495Browse files

Showing the changes to controller/src/modules/system (4 of 334 files). Show all

Unified · Split

4 files
  1. controller/src/modules/system/logs-routes.ts +2 −3
  2. controller/src/modules/system/metrics-routes.ts +2 −2
  3. controller/src/modules/system/routes.ts +4 −7
  4. controller/src/modules/system/usage-routes.ts +2 −2
controller/src/modules/system/logs-routes.ts+2−3
@@ -1,9 +1,8 @@
1import type { Hono } from "hono";
2import { spawn, spawnSync } from "node:child_process";1import { spawn, spawnSync } from "node:child_process";
3import { unlinkSync } from "node:fs";2import { unlinkSync } from "node:fs";
4import { createInterface } from "node:readline";3import { createInterface } from "node:readline";
5import { PassThrough } from "node:stream";4import { PassThrough } from "node:stream";
6import type { AppContext } from "../../types/context";5import type { RouteRegistrar } from "../../http/route-registrar";
7import { badRequest, notFound } from "../../core/errors";6import { badRequest, notFound } from "../../core/errors";
8import { observeControllerFunction } from "../../core/function-observability";7import { observeControllerFunction } from "../../core/function-observability";
9import { streamAsyncStrings, buildSseHeaders, withSseHeartbeat } from "../../http/sse";8import { streamAsyncStrings, buildSseHeaders, withSseHeartbeat } from "../../http/sse";
@@ -21,7 +20,7 @@ import { · 11 unmodified lines
21 tailFileLines,20 tailFileLines,
22} from "../../core/log-files";21} from "../../core/log-files";
23 22
24export const registerLogsRoutes = (app: Hono, context: AppContext): void => {23export const registerLogsRoutes: RouteRegistrar = (app, context) => {
25 let lastCleanupAt = 0;24 let lastCleanupAt = 0;
26 25
27 const maybeCleanup = (): void => {26 const maybeCleanup = (): void => {
controller/src/modules/system/metrics-routes.ts+2−2
@@ -1,6 +1,6 @@
1import type { Hono } from "hono";
2import { performance } from "node:perf_hooks";1import { performance } from "node:perf_hooks";
3import { observeControllerFunction } from "../../core/function-observability";2import { observeControllerFunction } from "../../core/function-observability";
3import type { RouteRegistrar } from "../../http/route-registrar";
4import type { AppContext } from "../../types/context";4import type { AppContext } from "../../types/context";
5import { getGpuInfo } from "./platform/gpu";5import { getGpuInfo } from "./platform/gpu";
6import { fetchInference } from "../../services/inference/inference-client";6import { fetchInference } from "../../services/inference/inference-client";
@@ -241,7 +241,7 @@ const buildCurrentMetrics = async (context: AppContext): Promise<Record<string, · 234 unmodified lines
241 };241 };
242};242};
243 243
244export const registerMonitoringRoutes = (app: Hono, context: AppContext): void => {244export const registerMonitoringRoutes: RouteRegistrar = (app, context) => {
245 app.get("/metrics", async (_ctx) => {245 app.get("/metrics", async (_ctx) => {
246 const current = await observeControllerFunction(246 const current = await observeControllerFunction(
247 context,247 context,
controller/src/modules/system/routes.ts+4−7
@@ -1,11 +1,11 @@
1import type { Hono } from "hono";
2import { connect } from "node:net";1import { connect } from "node:net";
3import { hostname } from "node:os";2import { hostname } from "node:os";
4import { existsSync, readFileSync } from "node:fs";3import { existsSync, readFileSync } from "node:fs";
5import { join, resolve, sep } from "node:path";4import { join, resolve, sep } from "node:path";
6import type { AppContext } from "../../types/context";5import type { RouteRegistrar } from "../../http/route-registrar";
7import type { SystemConfigResponse } from "../models/types";6import type { SystemConfigResponse } from "../models/types";
8import { badRequest, notFound } from "../../core/errors";7import { badRequest, notFound } from "../../core/errors";
8import { parseJsonObjectBody } from "../../core/validation";
9import { observeControllerFunction } from "../../core/function-observability";9import { observeControllerFunction } from "../../core/function-observability";
10import { estimateWeightsSizeBytes } from "../models/model-browser";10import { estimateWeightsSizeBytes } from "../models/model-browser";
11import { getGpuInfo } from "./platform/gpu";11import { getGpuInfo } from "./platform/gpu";
@@ -21,7 +21,7 @@ import { · 9 unmodified lines
21 SYSTEM_SERVICE_CHECK_HOST,21 SYSTEM_SERVICE_CHECK_HOST,
22} from "./configs";22} from "./configs";
23 23
24export const registerSystemRoutes = (app: Hono, context: AppContext): void => {24export const registerSystemRoutes: RouteRegistrar = (app, context) => {
25 const checkService = (25 const checkService = (
26 host: string,26 host: string,
27 port: number,27 port: number,
@@ -87,10 +87,7 @@ export const registerSystemRoutes = (app: Hono, context: AppContext): void => { · 59 unmodified lines
87 });87 });
88 88
89 app.post("/vram-calculator", async (ctx) => {89 app.post("/vram-calculator", async (ctx) => {
90 const body = await ctx.req.json().catch(() => ({}));90 const body = await parseJsonObjectBody(ctx);
91 if (!body || typeof body !== "object") {
92 throw badRequest("Invalid payload");
93 }
94 91
95 const model = typeof body["model"] === "string" ? body["model"].trim() : "";92 const model = typeof body["model"] === "string" ? body["model"].trim() : "";
96 const contextLength = Number(body["context_length"] ?? 0);93 const contextLength = Number(body["context_length"] ?? 0);
controller/src/modules/system/usage-routes.ts+2−2
@@ -1,5 +1,5 @@
1import type { Hono } from "hono";
2import { observeControllerFunction } from "../../core/function-observability";1import { observeControllerFunction } from "../../core/function-observability";
2import type { RouteRegistrar } from "../../http/route-registrar";
3import type { AppContext } from "../../types/context";3import type { AppContext } from "../../types/context";
4import { getUsageFromPiSessions } from "./usage/pi-sessions";4import { getUsageFromPiSessions } from "./usage/pi-sessions";
5import { emptyResponse } from "./usage/usage-utilities";5import { emptyResponse } from "./usage/usage-utilities";
@@ -20,7 +20,7 @@ const collectKnownModels = async (context: AppContext): Promise<Set<string>> => · 14 unmodified lines
20 return knownModels;20 return knownModels;
21};21};
22 22
23export const registerUsageRoutes = (app: Hono, context: AppContext): void => {23export const registerUsageRoutes: RouteRegistrar = (app, context) => {
24 app.get("/usage", async (ctx) => {24 app.get("/usage", async (ctx) => {
25 try {25 try {
26 const knownModels = await observeControllerFunction(context, "usage.collectKnownModels", () =>26 const knownModels = await observeControllerFunction(context, "usage.collectKnownModels", () =>

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t