A local-first multi-agent app development platform, built on PenguinHarness
fix(ui-gallery): 画廊的假接口补上错误中心那三个忽略路由
lmlihenge7a2fb3340e7
diff --git a/packages/ui-gallery/src/app/mock/routes.ts b/packages/ui-gallery/src/app/mock/routes.tsindex 3a132d80..d9aba165 100644--- a/packages/ui-gallery/src/app/mock/routes.ts+++ b/packages/ui-gallery/src/app/mock/routes.ts@@ -112,8 +112,6 @@ import type {SessionsBatchResponse,SessionsResponse,SessionTracesResponse,- ServerBrowserState,- ServerBrowserStatus,SshHostResponse,StorageApplyResponse,StoragePlanEntryView,@@ -134,6 +132,9 @@ import type {UpdateCheckResponse,UpdateJobStatus,UpdateProfileResponse,+ UsageErrorIgnoreAdded,+ UsageErrorIgnoreRule,+ UsageErrorIgnores,UsageErrorsClearResponse,UsageErrorsPage,UsageGranularity,@@ -1923,6 +1924,14 @@ function bucketKey(date: string, granularity: UsageGranularity): string {return date;}+/**+ * The demo's error-ignore rules: none until the panel makes one, and they live here rather than in+ * the store because the store is fixtures, which a rule is not. A rule made in the gallery holds+ * nothing back — the demo's error table does not filter — so the panel shows it listed, and the+ * stats keep reporting 0 ignored.+ */+let demoIgnoreRules: UsageErrorIgnoreRule[] = [];+router.get("/api/projects/:projectId/usage/errors", ({ store, query }): UsageErrorsPage => {const kind = query.get("kind");@@ -1943,6 +1952,35 @@ routerstore.f.usageErrors = kind ? store.f.usageErrors.filter((e) => e.kind !== kind) : [];return { deleted: going.length };})+ .get(+ "/api/projects/:projectId/usage/errors/ignores",+ (): UsageErrorIgnores => ({ rules: demoIgnoreRules }),+ )+ .post("/api/projects/:projectId/usage/errors/ignores", ({ body }): UsageErrorIgnoreAdded => {+ const given = record(body);+ const rule: UsageErrorIgnoreRule = {+ id: (demoIgnoreRules.at(-1)?.id ?? 0) + 1,+ source: str(given.source),+ code: str(given.code),+ messageLike: str(given.messageLike) === "" ? null : str(given.messageLike),+ note: str(given.note) === "" ? null : str(given.note),+ createdBy: "admin",+ createdAt: new Date().toISOString(),+ hidden: 0,+ lastTs: null,+ };+ demoIgnoreRules = [...demoIgnoreRules, rule];+ // The demo's error table is fixtures: nothing new is written, so a rule covers nothing yet.+ return { rule, hidden: 0 };+ })+ .delete(+ "/api/projects/:projectId/usage/errors/ignores/:id",+ ({ params }): { removed: boolean } => {+ const before = demoIgnoreRules.length;+ demoIgnoreRules = demoIgnoreRules.filter((rule) => String(rule.id) !== params.id);+ return { removed: demoIgnoreRules.length !== before };+ },+ ).get("/api/projects/:projectId/usage/model-totals", ({ store }): UsageModelTotals => {const totals = new Map<string, UsageModelTotals["totals"][number]>();for (const day of store.f.usage) {@@ -2069,6 +2107,7 @@ routertotal: store.f.usageErrors.reduce((n, e) => n + e.count, 0),rows: store.f.usageErrors.length,unexpected,+ ignored: 0,topCode: store.f.usageErrors[0]? {source: store.f.usageErrors[0].source,@@ -2776,78 +2815,6 @@ router.delete("/api/builtin-browser/history", () => empty()).post("/api/builtin-browser/clear-data", browserUnavailable);-// ----------------------------------------------------------------------------------------------// The server browser: a browser the SERVER runs. The demo has no such process, so it answers as-// a server that does have one — the address bar, the toolbar and the input path are what the-// gallery is for. The picture is the one thing a browser-less demo cannot produce, so the frame-// stream answers with the header of a single blank frame and nothing after it.-// -----------------------------------------------------------------------------------------------/** The demo's browser: a page standing still, which the toolbar and the address bar then move. */-let serverBrowserPage: ServerBrowserState = {- url: "https://example.com/",- title: "Example Domain",- loading: false,- width: 1280,- height: 800,-};--const serverBrowserStatus = (): ServerBrowserStatus => ({- available: true,- running: true,- state: { ...serverBrowserPage },-});--const serverBrowserInput = (body: unknown): ServerBrowserStatus => {- // The picture does not move in the demo, so only the state a caller can see changes: a wheel- // says the page is loading for a beat, which is what the strip above the picture shows.- const given = record(body).events;- if (Array.isArray(given) && given.some((event) => record(event).type === "wheel")) {- serverBrowserPage = { ...serverBrowserPage, loading: true };- }- return serverBrowserStatus();-};--router- .get("/api/server-browser", serverBrowserStatus)- .post("/api/server-browser/start", serverBrowserStatus)- .post("/api/server-browser/stop", (): ServerBrowserStatus => ({- available: true,- running: false,- state: null,- }))- .post("/api/server-browser/navigate", ({ body }): ServerBrowserStatus => {- const url = String(record(body).url ?? "");- serverBrowserPage = {- ...serverBrowserPage,- url,- title: url.replace(/^https?:\/\//, "").replace(/\/$/, ""),- loading: false,- };- return serverBrowserStatus();- })- .post("/api/server-browser/back", serverBrowserStatus)- .post("/api/server-browser/forward", serverBrowserStatus)- .post("/api/server-browser/reload", (): ServerBrowserStatus => {- serverBrowserPage = { ...serverBrowserPage, loading: false };- return serverBrowserStatus();- })- .post("/api/server-browser/resize", ({ body }): ServerBrowserStatus => {- const { width, height } = record(body);- serverBrowserPage = {- ...serverBrowserPage,- width: typeof width === "number" ? Math.round(width) : serverBrowserPage.width,- height: typeof height === "number" ? Math.round(height) : serverBrowserPage.height,- };- return serverBrowserStatus();- })- .post("/api/server-browser/input", ({ body }) => serverBrowserInput(body))- .get("/api/server-browser/frames", () =>- raw("--adelie-browser-frame\r\nContent-Type: image/jpeg\r\nContent-Length: 0\r\n\r\n", {- "content-type": "multipart/x-mixed-replace; boundary=adelie-browser-frame",- }),- );-// ---------------------------------------------------------------------------------------------// Company mode: off in the demo, so every organization route answers as the server does then// ---------------------------------------------------------------------------------------------