You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@casbin.apache.org by hs...@apache.org on 2026/08/25 16:37:50 UTC

(casbin-gateway) branch master updated (98c0ae1 -> ba06c3a)

This is an automated email from the ASF dual-hosted git repository.

hsluoyz pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/casbin-gateway.git


    from 98c0ae1  docs(readme): show the four main pages as screenshots
     new 3a4d2c5  docs(readme): say that prompts are recorded in full by default
     new dc9a209  feat(agent): discover an agent by the state directory it left behind
     new ba06c3a  fix(web): stop rendering a failed load as an empty listing

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 README.md                                 | 10 +++---
 README_zh.md                              | 10 +++---
 agent/scan_common.go                      | 51 +++++++++++++++++++++++++++++++
 agent/scan_darwin.go                      |  1 +
 agent/scan_linux.go                       |  1 +
 agent/scan_windows.go                     |  1 +
 web/src/components/shared/data-table.tsx  | 14 +++++++--
 web/src/components/shared/empty-state.tsx | 40 +++++++++++++++++++++++-
 web/src/locales/en/data.json              |  4 ++-
 web/src/locales/zh/data.json              |  4 ++-
 web/src/pages/CertListPage.tsx            | 28 ++++++++++-------
 web/src/pages/HomePage.tsx                | 40 +++++++++++++++++++++---
 web/src/pages/LlmRecordsPage.tsx          |  6 ++--
 web/src/pages/NodeListPage.tsx            | 26 ++++++++++------
 web/src/pages/ProviderListPage.tsx        | 24 +++++++++++----
 web/src/pages/RecordListPage.tsx          | 28 ++++++++++-------
 web/src/pages/RuleListPage.tsx            | 28 ++++++++++-------
 web/src/pages/SiteListPage.tsx            | 22 ++++++++-----
 18 files changed, 258 insertions(+), 80 deletions(-)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@casbin.apache.org
For additional commands, e-mail: commits-help@casbin.apache.org


(casbin-gateway) 01/03: docs(readme): say that prompts are recorded in full by default

Posted by hs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hsluoyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/casbin-gateway.git

commit 3a4d2c5e9bcc32ca8bf6abb7e02d272d43dea7c7
Author: Yang Luo <hs...@gmail.com>
AuthorDate: Wed Aug 26 00:36:39 2026 +0800

    docs(readme): say that prompts are recorded in full by default
    
    The README said nothing about a relayed request was stored until it was
    asked for, and listed llmRecordMode as defaulting to "off". Both the
    shipped conf/app.conf and the fallback in GetLlmRecordMode have been
    "full" — the whole request body, prompt included — so a reader who
    installed on the strength of that sentence got the opposite of it.
    
    Document what the code does, and point at the setting from the table.
    The same claim was in the LLM Records empty state, which now describes
    the state it is shown in rather than implying a default.
---
 README.md                        | 10 +++++-----
 README_zh.md                     | 10 +++++-----
 web/src/locales/en/data.json     |  2 +-
 web/src/locales/zh/data.json     |  2 +-
 web/src/pages/LlmRecordsPage.tsx |  6 +++---
 5 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/README.md b/README.md
index f410a91..de33a72 100644
--- a/README.md
+++ b/README.md
@@ -178,7 +178,7 @@ Everything is optional. Settings are changed on the **Settings** page of the web
 | `driverName` / `dataSourceName` | `sqlite` / `./data/casbin-gateway.db` | Where data is stored |
 | `gatewayEnabled` | `false` | Turns the reverse-proxy WAF on |
 | `gatewayHttpPort` / `gatewayHttpsPort` | `80` / `443` | Ports the proxy listens on |
-| `llmRecordMode` | `off` | How much of each relayed LLM request is kept |
+| `llmRecordMode` | `full` | How much of each relayed LLM request is kept — including the prompt, see [Recording prompts](#recording-prompts) |
 | `apiKeyEncryptionKey` | empty | Encrypts provider API keys at rest (AES-256-GCM) |
 | `casdoorEndpoint` | empty | Switches sign-in over to [Casdoor](https://casdoor.org) SSO |
 
@@ -205,12 +205,12 @@ A previous Gateway still holding one of these ports is stopped first, so a resta
 
 ### Recording prompts
 
-Nothing about a relayed request is stored until you ask for it, because a prompt can carry anything that was pasted into it. **Record metadata** and **Record metadata and bodies**, the buttons on the LLM Records page, turn it on for the next request; the Settings page holds the same choice and the limits around it, seeded from:
+**Every relayed request is recorded in full from the first one, prompt included.** That is what the LLM Records page is made of, and none of it leaves this machine — but a prompt carries whatever was pasted into it, so if that is not what you want, this is the setting to change before you route an agent through Gateway. The picker at the top of the LLM Records page switches between **Recording off**, **Record metadata** and **Record metadata and bodies**, and takes effect from the next r [...]
 
 ```ini
-; "off" keeps nothing, "metadata" records who called which model with which
-; outcome, "full" also stores the request body — which is what LLM Records needs
-; to show prompts, messages and tool schemas.
+; The default is "full": it stores the request body, which is what LLM Records
+; needs to show prompts, messages and tool schemas. "metadata" records only who
+; called which model with which outcome, and "off" keeps nothing at all.
 llmRecordMode = "full"
 llmRecordRetentionDays = 30
 llmRecordMaxRecords = 10000
diff --git a/README_zh.md b/README_zh.md
index cc5528f..1bfe0be 100644
--- a/README_zh.md
+++ b/README_zh.md
@@ -176,7 +176,7 @@ podman compose up -d
 | `driverName` / `dataSourceName` | `sqlite` / `./data/casbin-gateway.db` | 数据存放位置 |
 | `gatewayEnabled` | `false` | 打开反向代理 WAF |
 | `gatewayHttpPort` / `gatewayHttpsPort` | `80` / `443` | 代理监听的端口 |
-| `llmRecordMode` | `off` | 每次转发的 LLM 请求保留多少内容 |
+| `llmRecordMode` | `full` | 每次转发的 LLM 请求保留多少内容 —— 包含提示词正文,见[记录提示词](#记录提示词) |
 | `apiKeyEncryptionKey` | 空 | 加密存储 Provider 的 API Key(AES-256-GCM) |
 | `casdoorEndpoint` | 空 | 把登录切换到 [Casdoor](https://casdoor.org) SSO |
 
@@ -203,12 +203,12 @@ Gateway 启动时会打印它实际在做什么,所以可以直接看结果而
 
 ### 记录提示词
 
-在你主动要求之前,转发请求的内容一概不存储,因为提示词里可能粘进任何东西。LLM Records 页面上的 **只记录元数据** 和 **记录元数据和正文** 两个按钮会从下一次请求起打开记录;设置页面里有同样的选项和相关的上限,它们的初始值来自:
+**从第一个请求起,每次转发的请求都会被完整记录下来,包括提示词正文。** LLM Records 页面就是拿这些内容做出来的,它们也不会离开这台机器 —— 但提示词里粘进过什么它就带着什么,所以如果你不想要这样,在把 Agent 接进 Gateway 之前就该先改掉这个设置。LLM Records 页面顶部的选择框可以在 **不记录**、**只记录元数据** 和 **记录元数据和正文** 之间切换,从下一次请求起生效;设置页面里有同样的选项和相关的上限,它们的初始值来自:
 
 ```ini
-; "off" 什么都不留,"metadata" 记录谁调用了哪个模型、结果如何,
-; "full" 还会存下请求体 —— 这是 LLM Records 展示提示词、消息和
-; 工具 schema 所需要的。
+; 默认是 "full":它会存下请求体,这是 LLM Records 展示提示词、消息和
+; 工具 schema 所需要的。"metadata" 只记录谁调用了哪个模型、结果如何,
+; "off" 则什么都不留。
 llmRecordMode = "full"
 llmRecordRetentionDays = 30
 llmRecordMaxRecords = 10000
diff --git a/web/src/locales/en/data.json b/web/src/locales/en/data.json
index d60db29..900f9f4 100644
--- a/web/src/locales/en/data.json
+++ b/web/src/locales/en/data.json
@@ -465,7 +465,7 @@
     "Record metadata": "Record metadata",
     "Record metadata and bodies": "Record metadata and bodies",
     "Recording is off": "Recording is off",
-    "Recording is off detail": "Nothing is recorded until you ask for it, because prompts can carry sensitive data. Metadata is who called which model with which outcome; bodies are the prompts themselves.",
+    "Recording is off detail": "Recording is turned off, so nothing about a relayed request is being kept. Metadata is who called which model with which outcome; bodies are the prompts themselves.",
     "Recording is on": "Recording is on",
     "Recording off": "Recording off",
     "Records were dropped": "{count} records were dropped because the write queue was full. Raise llmRecordQueueCapacity if this keeps happening.",
diff --git a/web/src/locales/zh/data.json b/web/src/locales/zh/data.json
index 0561c1d..a1459c2 100644
--- a/web/src/locales/zh/data.json
+++ b/web/src/locales/zh/data.json
@@ -465,7 +465,7 @@
     "Record metadata": "只记录元数据",
     "Record metadata and bodies": "记录元数据和正文",
     "Recording is off": "记录功能已关闭",
-    "Recording is off detail": "除非你主动开启,否则不会记录任何内容,因为提示词可能包含敏感数据。元数据是谁调用了哪个模型、结果如何;正文则是提示词本身。",
+    "Recording is off detail": "记录已关闭,转发请求的内容一概不会被保留。元数据是谁调用了哪个模型、结果如何;正文就是提示词本身。",
     "Recording is on": "已开启记录",
     "Recording off": "关闭记录",
     "Records were dropped": "有 {count} 条记录因写入队列已满而被丢弃。如持续出现,请调大 llmRecordQueueCapacity。",
diff --git a/web/src/pages/LlmRecordsPage.tsx b/web/src/pages/LlmRecordsPage.tsx
index 70b9baf..7a039e3 100644
--- a/web/src/pages/LlmRecordsPage.tsx
+++ b/web/src/pages/LlmRecordsPage.tsx
@@ -230,9 +230,9 @@ export default function LlmRecordsPage({account}: {account: Account}) {
     });
   }, [isAdmin]);
 
-  // Recording is off until someone asks for it. The Settings page holds the
-  // same field; changing it here is the shortcut, and it applies to the next
-  // request rather than the next restart.
+  // Recording is on by default, so this is mostly the way it gets turned down.
+  // The Settings page holds the same field; changing it here is the shortcut,
+  // and it applies to the next request rather than the next restart.
   const setRecordMode = (mode: string) => {
     setChangingMode(true);
     SettingBackend.getSetting()


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@casbin.apache.org
For additional commands, e-mail: commits-help@casbin.apache.org


(casbin-gateway) 02/03: feat(agent): discover an agent by the state directory it left behind

Posted by hs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hsluoyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/casbin-gateway.git

commit dc9a209e700194ec0f124fc5f47a57262e0cd864
Author: Yang Luo <hs...@gmail.com>
AuthorDate: Wed Aug 26 00:36:48 2026 +0800

    feat(agent): discover an agent by the state directory it left behind
    
    Discovery matched executables only: a launcher on PATH, an npm package,
    a winget or homebrew entry. An agent installed some other way was
    reported as not installed even with its home directory sitting there,
    which is what happened to Claude Code — the agent the README opens with.
    
    A fingerprint already names that directory, but only to read a version
    out of it. Treat a non-empty one as its own signal, and record it as an
    installation with no launcher: Start stays disabled through the CanStart
    it already reports, while providers, skills and MCP servers work, since
    those are read through the home directory rather than the program.
    
    Only when nothing matched the agent anywhere. A state directory is also
    left in the home of every service account an agent sandboxes itself
    into, and those are not installations to list beside your own.
---
 agent/scan_common.go  | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 agent/scan_darwin.go  |  1 +
 agent/scan_linux.go   |  1 +
 agent/scan_windows.go |  1 +
 4 files changed, 54 insertions(+)

diff --git a/agent/scan_common.go b/agent/scan_common.go
index ed7e483..dd78532 100644
--- a/agent/scan_common.go
+++ b/agent/scan_common.go
@@ -29,6 +29,11 @@ import (
 	"github.com/apache/casbin-gateway/internal/hermes"
 )
 
+// InstallMethodConfig marks an agent found by the state directory it left in a
+// home rather than by a program. Nothing can be launched from it, but its
+// configuration is on disk and is what most of Gateway acts on.
+const InstallMethodConfig = "config"
+
 // maxPackageJSONSize limits reads from glob-matched manifests.
 const maxPackageJSONSize = 1024 * 1024
 
@@ -165,6 +170,52 @@ func stampAgentId(installations []Installation, mark int, agentId string) {
 	}
 }
 
+// scanStateDirs reports an agent that left its state directory in a home while
+// none of the install layouts matched it anywhere: installed by a package
+// manager Gateway does not scan, on a PATH it cannot see, or run through a
+// wrapper. Providers, skills and MCP servers are read and written through the
+// home directory rather than the program, so leaving these out reports "not
+// installed" for an agent someone uses every day.
+//
+// `found` is what this fingerprint matched already, and one hit anywhere is
+// enough to stop: a state directory is also left in the home of every service
+// account an agent sandboxes itself into, and those are not installations
+// anyone wants listed next to their own.
+func scanStateDirs(fingerprint *Fingerprint, homes []homeDir, found []Installation) []Installation {
+	if fingerprint.StateDir == "" || len(found) > 0 {
+		return nil
+	}
+
+	installations := []Installation{}
+	for _, home := range homes {
+		path := filepath.Join(home.path, "."+fingerprint.StateDir)
+		if !hasEntries(path) {
+			continue
+		}
+		installations = append(installations, Installation{
+			AgentId:       fingerprint.ID,
+			Name:          fingerprint.DisplayName,
+			Path:          path,
+			InstallMethod: InstallMethodConfig,
+			Owner:         home.owner,
+		})
+	}
+	return installations
+}
+
+// hasEntries reports a directory that holds something. An empty one is what an
+// uninstall leaves behind, and is not evidence that the agent was ever set up.
+func hasEntries(path string) bool {
+	dir, err := os.Open(path)
+	if err != nil {
+		return false
+	}
+	defer dir.Close()
+
+	names, err := dir.Readdirnames(1)
+	return err == nil && len(names) > 0
+}
+
 // dedupeInstallations returns unique installations ordered by owner and path.
 func dedupeInstallations(installations []Installation) []Installation {
 	seen := map[string]bool{}
diff --git a/agent/scan_darwin.go b/agent/scan_darwin.go
index 4b76dab..63236ec 100644
--- a/agent/scan_darwin.go
+++ b/agent/scan_darwin.go
@@ -50,6 +50,7 @@ func scan(ctx context.Context) []Installation {
 			installations = append(installations, scanDarwinSystemNpm(ctx, fingerprint, prefix)...)
 		}
 		stampAgentId(installations, mark, fingerprint.ID)
+		installations = append(installations, scanStateDirs(fingerprint, homes, installations[mark:])...)
 		fillMissingVersions(installations, mark, fingerprint)
 	}
 	for _, home := range homes {
diff --git a/agent/scan_linux.go b/agent/scan_linux.go
index ecb7bbc..08bbb29 100644
--- a/agent/scan_linux.go
+++ b/agent/scan_linux.go
@@ -51,6 +51,7 @@ func scan(ctx context.Context) []Installation {
 		installations = append(installations, scanSystemPackages(ctx, fingerprint)...)
 		installations = append(installations, scanHomebrew(ctx, fingerprint)...)
 		stampAgentId(installations, mark, fingerprint.ID)
+		installations = append(installations, scanStateDirs(fingerprint, homes, installations[mark:])...)
 		fillMissingVersions(installations, mark, fingerprint)
 	}
 	for _, home := range homes {
diff --git a/agent/scan_windows.go b/agent/scan_windows.go
index addf750..436bc88 100644
--- a/agent/scan_windows.go
+++ b/agent/scan_windows.go
@@ -59,6 +59,7 @@ func scan(ctx context.Context) []Installation {
 		installations = append(installations, scanMachineWinget(ctx, fingerprint)...)
 		installations = append(installations, scanMachinePrograms(ctx, fingerprint)...)
 		stampAgentId(installations, mark, fingerprint.ID)
+		installations = append(installations, scanStateDirs(fingerprint, homes, installations[mark:])...)
 		fillMissingVersions(installations, mark, fingerprint)
 	}
 	for _, home := range homes {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@casbin.apache.org
For additional commands, e-mail: commits-help@casbin.apache.org


(casbin-gateway) 03/03: fix(web): stop rendering a failed load as an empty listing

Posted by hs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hsluoyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/casbin-gateway.git

commit ba06c3adf6be7ba997c3237b3dd32e998677b57a
Author: Yang Luo <hs...@gmail.com>
AuthorDate: Wed Aug 26 00:36:57 2026 +0800

    fix(web): stop rendering a failed load as an empty listing
    
    A listing that failed showed an error toast for a few seconds and then
    the empty state, so "you have no providers yet" and "the providers could
    not be read" looked the same. On a tool that holds your API keys the
    first one is alarming, and it was the wrong thing to say. The home page
    told anyone whose scan failed to install an agent they already have.
    
    Split the two: DataTable takes an error and renders it with a retry
    instead of the empty state, and the pages that draw their own empty
    state gate it on the load having succeeded. Data already on screen stays
    there behind an alert, since a failed refresh leaves it stale, not gone.
    
    Five listings called .then() with no .catch(), so a request that threw
    never cleared the loading flag and left the table on its skeleton.
---
 web/src/components/shared/data-table.tsx  | 14 +++++++++--
 web/src/components/shared/empty-state.tsx | 40 ++++++++++++++++++++++++++++++-
 web/src/locales/en/data.json              |  2 ++
 web/src/locales/zh/data.json              |  2 ++
 web/src/pages/CertListPage.tsx            | 28 +++++++++++++---------
 web/src/pages/HomePage.tsx                | 40 +++++++++++++++++++++++++++----
 web/src/pages/NodeListPage.tsx            | 26 ++++++++++++--------
 web/src/pages/ProviderListPage.tsx        | 24 ++++++++++++++-----
 web/src/pages/RecordListPage.tsx          | 28 +++++++++++++---------
 web/src/pages/RuleListPage.tsx            | 28 +++++++++++++---------
 web/src/pages/SiteListPage.tsx            | 22 ++++++++++-------
 11 files changed, 189 insertions(+), 65 deletions(-)

diff --git a/web/src/components/shared/data-table.tsx b/web/src/components/shared/data-table.tsx
index 1822cbf..50e32a1 100644
--- a/web/src/components/shared/data-table.tsx
+++ b/web/src/components/shared/data-table.tsx
@@ -31,7 +31,7 @@ import {Button} from "@/components/ui/button";
 import {Input} from "@/components/ui/input";
 import {Skeleton} from "@/components/ui/skeleton";
 import {Table, TableBody, TableCell, TableHead, TableHeader, TableRow} from "@/components/ui/table";
-import {EmptyState} from "@/components/shared/empty-state";
+import {EmptyState, ErrorState} from "@/components/shared/empty-state";
 
 export type SortOrder = "ascend" | "descend" | undefined;
 
@@ -109,6 +109,10 @@ export interface DataTableProps<T> {
   onSort?: (field: string, order: SortOrder) => void;
   emptyText?: React.ReactNode;
   emptyIcon?: React.ComponentType<{className?: string}>;
+  /** Why the listing is empty when it is empty because the load failed. */
+  error?: string;
+  /** Reloads the listing from the error state. */
+  onRetry?: () => void;
   onRowClick?: (record: T) => void;
   expandable?: {
     rowExpandable?: (record: T) => boolean;
@@ -140,6 +144,8 @@ export function DataTable<T>({
   onSort,
   emptyText,
   emptyIcon,
+  error,
+  onRetry,
   onRowClick,
   expandable,
   dense = false,
@@ -324,7 +330,11 @@ export function DataTable<T>({
           ) : rows.length === 0 ? (
             <TableRow className="hover:bg-transparent">
               <TableCell colSpan={columns.length + (expandable ? 1 : 0)} className="p-0">
-                <EmptyState icon={emptyIcon} title={emptyText ?? i18next.t("general:No data")} />
+                {error ? (
+                  <ErrorState error={error} onRetry={onRetry} />
+                ) : (
+                  <EmptyState icon={emptyIcon} title={emptyText ?? i18next.t("general:No data")} />
+                )}
               </TableCell>
             </TableRow>
           ) : (
diff --git a/web/src/components/shared/empty-state.tsx b/web/src/components/shared/empty-state.tsx
index d556764..478b41f 100644
--- a/web/src/components/shared/empty-state.tsx
+++ b/web/src/components/shared/empty-state.tsx
@@ -13,8 +13,10 @@
 // limitations under the License.
 
 import * as React from "react";
-import {Inbox} from "lucide-react";
+import {Inbox, RefreshCw, TriangleAlert} from "lucide-react";
+import i18next from "i18next";
 
+import {Button} from "@/components/ui/button";
 import {cn} from "@/lib/utils";
 
 export function EmptyState({
@@ -42,3 +44,39 @@ export function EmptyState({
     </div>
   );
 }
+
+/**
+ * What a listing shows when it could not be read. A load that failed must never
+ * fall through to EmptyState: "you have no providers" and "the providers could
+ * not be read" look the same there, and the first one is alarming to be told
+ * about an account that holds your API keys.
+ */
+export function ErrorState({
+  title,
+  error,
+  onRetry,
+  className,
+}: {
+  title?: React.ReactNode;
+  error?: React.ReactNode;
+  onRetry?: () => void;
+  className?: string;
+}) {
+  return (
+    <div className={cn("flex flex-col items-center justify-center gap-2 px-6 py-14 text-center", className)}>
+      <div className="bg-destructive/10 text-destructive flex size-10 items-center justify-center rounded-full">
+        <TriangleAlert className="size-5" />
+      </div>
+      <p className="text-sm font-medium">{title ?? i18next.t("general:Could not load this")}</p>
+      {error ? <p className="text-muted-foreground max-w-sm text-xs break-words">{error}</p> : null}
+      {onRetry ? (
+        <div className="mt-2">
+          <Button variant="outline" size="sm" onClick={onRetry}>
+            <RefreshCw />
+            {i18next.t("general:Retry")}
+          </Button>
+        </div>
+      ) : null}
+    </div>
+  );
+}
diff --git a/web/src/locales/en/data.json b/web/src/locales/en/data.json
index 900f9f4..bba9d67 100644
--- a/web/src/locales/en/data.json
+++ b/web/src/locales/en/data.json
@@ -321,6 +321,7 @@
     "Copied to clipboard": "Copied to clipboard",
     "Copy": "Copy",
     "Could not check for updates": "Could not check for updates",
+    "Could not load this": "Could not load this",
     "Count": "Count",
     "Create time": "Create time",
     "Created time": "Created time",
@@ -378,6 +379,7 @@
     "Request Count Over Time": "Request Count Over Time",
     "Restarting into the new version": "Restarting into the new version",
     "Restore": "Restore",
+    "Retry": "Retry",
     "Rules": "Rules",
     "Save": "Save",
     "Search": "Search",
diff --git a/web/src/locales/zh/data.json b/web/src/locales/zh/data.json
index a1459c2..0693f81 100644
--- a/web/src/locales/zh/data.json
+++ b/web/src/locales/zh/data.json
@@ -321,6 +321,7 @@
     "Copied to clipboard": "已复制到剪贴板",
     "Copy": "复制",
     "Could not check for updates": "检查更新失败",
+    "Could not load this": "加载失败",
     "Count": "计数",
     "Create time": "创建时间",
     "Created time": "创建时间",
@@ -378,6 +379,7 @@
     "Request Count Over Time": "请求数趋势",
     "Restarting into the new version": "正在重启到新版本",
     "Restore": "复原",
+    "Retry": "重试",
     "Rules": "规则",
     "Save": "保存",
     "Search": "搜索",
diff --git a/web/src/pages/CertListPage.tsx b/web/src/pages/CertListPage.tsx
index fd4a98a..698a5ee 100644
--- a/web/src/pages/CertListPage.tsx
+++ b/web/src/pages/CertListPage.tsx
@@ -60,6 +60,7 @@ export default function CertListPage({account}: {account: Account}) {
   const [data, setData] = React.useState<Cert[]>([]);
   const [total, setTotal] = React.useState(0);
   const [loading, setLoading] = React.useState(false);
+  const [error, setError] = React.useState("");
   const [page, setPage] = React.useState(1);
   const [pageSize, setPageSize] = React.useState(20);
   const [addOpen, setAddOpen] = React.useState(false);
@@ -70,17 +71,20 @@ export default function CertListPage({account}: {account: Account}) {
   const fetchCerts = React.useCallback(
     (nextPage = page, nextPageSize = pageSize) => {
       setLoading(true);
-      CertBackend.getCerts(account.name, nextPage, nextPageSize).then(res => {
-        setLoading(false);
-        if (res.status === "ok") {
-          setData(res.data ?? []);
-          setTotal(res.data2 ?? 0);
-          setPage(nextPage);
-          setPageSize(nextPageSize);
-        } else {
-          Setting.showMessage("error", `${i18next.t("general:Failed to get data")}: ${res.msg}`);
-        }
-      });
+      CertBackend.getCerts(account.name, nextPage, nextPageSize)
+        .then(res => {
+          if (res.status === "ok") {
+            setData(res.data ?? []);
+            setTotal(res.data2 ?? 0);
+            setPage(nextPage);
+            setPageSize(nextPageSize);
+            setError("");
+          } else {
+            setError(res.msg || i18next.t("general:Failed to get data"));
+          }
+        })
+        .catch(err => setError(err.message || String(err)))
+        .then(() => setLoading(false));
     },
     [account.name, page, pageSize],
   );
@@ -285,6 +289,8 @@ export default function CertListPage({account}: {account: Account}) {
         dataSource={data}
         rowKey={record => `${record.owner}/${record.name}`}
         loading={loading}
+        error={error}
+        onRetry={() => fetchCerts()}
         serverPagination={{
           page: page,
           pageSize: pageSize,
diff --git a/web/src/pages/HomePage.tsx b/web/src/pages/HomePage.tsx
index e5882e7..cdf4790 100644
--- a/web/src/pages/HomePage.tsx
+++ b/web/src/pages/HomePage.tsx
@@ -21,7 +21,7 @@ import * as LlmRecordBackend from "@/backend/LlmRecordBackend";
 import * as ProviderBackend from "@/backend/ProviderBackend";
 import * as Setting from "@/Setting";
 import {AgentGridCard} from "@/components/AgentGridCard";
-import {EmptyState} from "@/components/shared/empty-state";
+import {EmptyState, ErrorState} from "@/components/shared/empty-state";
 import {Loading} from "@/components/shared/loading";
 import {UnauthorizedResult} from "@/components/shared/misc";
 import {PageContainer, PageHeader} from "@/components/shared/page-header";
@@ -67,6 +67,10 @@ export default function HomePage({account}: {account: Account}) {
   const [recording, setRecording] = React.useState(true);
   // False until the first listing lands, so "no providers" never flashes.
   const [loaded, setLoaded] = React.useState(false);
+  // A listing that failed must not read as "you have no providers": that says
+  // the accounts holding your API keys are gone when the request simply
+  // dropped.
+  const [providerError, setProviderError] = React.useState("");
   // The sessions feed is only worth polling once something is being watched.
   const watching = agents.some(agent => agent.patched);
   const {activity} = useAgentSessions(isAdmin && watching, "", refreshMs);
@@ -76,8 +80,15 @@ export default function HomePage({account}: {account: Account}) {
       return;
     }
     ProviderBackend.getProviders(account.name)
-      .then(res => setProviders(res.status === "ok" ? (res.data ?? []) : []))
-      .catch(() => setProviders([]))
+      .then(res => {
+        if (res.status === "ok") {
+          setProviders(res.data ?? []);
+          setProviderError("");
+        } else {
+          setProviderError(res.msg || i18next.t("provider:Failed to get providers"));
+        }
+      })
+      .catch(failure => setProviderError(failure.message || String(failure)))
       .then(() => setLoaded(true));
 
     // What is already known paints at once; the refresh then asks only the
@@ -160,9 +171,22 @@ export default function HomePage({account}: {account: Account}) {
         }
       />
 
-      {error ? <MessageAlert title={error} /> : null}
+      {/* With no agents to show, the failure is the whole page and is rendered
+          below instead; here it sits above the cards that are still on screen. */}
+      {error !== "" && agents.length > 0 ? <MessageAlert title={error} /> : null}
 
-      {loaded && providers.length === 0 ? (
+      {providerError !== "" ? (
+        <MessageAlert
+          title={i18next.t("provider:Failed to get providers")}
+          description={providerError}
+          action={
+            <Button variant="outline" size="sm" onClick={loadProviders}>
+              <RefreshCw />
+              {i18next.t("general:Retry")}
+            </Button>
+          }
+        />
+      ) : loaded && providers.length === 0 ? (
         <MessageAlert
           variant="info"
           title={i18next.t("provider:No providers yet")}
@@ -180,6 +204,12 @@ export default function HomePage({account}: {account: Account}) {
 
       {!scanned ? (
         <Loading tip={i18next.t("agent:Scan")} />
+      ) : error !== "" && agents.length === 0 ? (
+        // A scan that failed is not a machine without agents, and telling
+        // someone to install one they already have is the wrong instruction.
+        <Card className="py-0">
+          <ErrorState title={i18next.t("agent:Failed to scan agents")} error={error} onRetry={refresh} />
+        </Card>
       ) : agents.length === 0 ? (
         <Card className="py-0">
           <EmptyState
diff --git a/web/src/pages/NodeListPage.tsx b/web/src/pages/NodeListPage.tsx
index 4b819c0..e75a1ea 100644
--- a/web/src/pages/NodeListPage.tsx
+++ b/web/src/pages/NodeListPage.tsx
@@ -45,6 +45,7 @@ export default function NodeListPage({account}: {account: Account}) {
   const navigate = useNavigate();
   const [data, setData] = React.useState<Node[]>([]);
   const [loading, setLoading] = React.useState(false);
+  const [error, setError] = React.useState("");
   const [authorized, setAuthorized] = React.useState(true);
   const [addOpen, setAddOpen] = React.useState(false);
   const [adding, setAdding] = React.useState(false);
@@ -53,16 +54,19 @@ export default function NodeListPage({account}: {account: Account}) {
 
   const fetchNodes = React.useCallback(() => {
     setLoading(true);
-    NodeBackend.getNodes(account.name).then(res => {
-      setLoading(false);
-      if (res.status === "ok") {
-        setData(res.data ?? []);
-      } else if (Setting.isResponseDenied(res)) {
-        setAuthorized(false);
-      } else {
-        Setting.showMessage("error", res.msg);
-      }
-    });
+    NodeBackend.getNodes(account.name)
+      .then(res => {
+        if (res.status === "ok") {
+          setData(res.data ?? []);
+          setError("");
+        } else if (Setting.isResponseDenied(res)) {
+          setAuthorized(false);
+        } else {
+          setError(res.msg || i18next.t("general:Failed to get data"));
+        }
+      })
+      .catch(err => setError(err.message || String(err)))
+      .then(() => setLoading(false));
   }, [account.name]);
 
   React.useEffect(() => {
@@ -210,6 +214,8 @@ export default function NodeListPage({account}: {account: Account}) {
         dataSource={data}
         rowKey={record => `${record.owner}/${record.name}`}
         loading={loading}
+        error={error}
+        onRetry={() => fetchNodes()}
         pageSize={20}
         searchable
         title={i18next.t("general:Nodes")}
diff --git a/web/src/pages/ProviderListPage.tsx b/web/src/pages/ProviderListPage.tsx
index 7639dab..43698af 100644
--- a/web/src/pages/ProviderListPage.tsx
+++ b/web/src/pages/ProviderListPage.tsx
@@ -33,10 +33,12 @@ import {ProviderModelsField} from "@/components/ProviderModelsField";
 import {ProviderSourcePicker, sourceTitle} from "@/components/ProviderSourcePicker";
 import {ProviderTestField, useProviderTest} from "@/components/ProviderTestField";
 import {type SortOrder} from "@/components/shared/data-table";
+import {ErrorState} from "@/components/shared/empty-state";
 import {Field, FormDialog} from "@/components/shared/form-dialog";
 import {PageContainer, PageHeader} from "@/components/shared/page-header";
 import {PasswordInput} from "@/components/shared/password-input";
 import {SearchSelect, SimpleSelect} from "@/components/shared/simple-select";
+import {MessageAlert} from "@/components/ui/alert";
 import {Badge} from "@/components/ui/badge";
 import {Button} from "@/components/ui/button";
 import {Card, CardContent, CardDescription, CardHeader, CardTitle} from "@/components/ui/card";
@@ -110,6 +112,10 @@ export default function ProviderListPage({account}: {account: Account}) {
   const [total, setTotal] = React.useState(0);
   const [loading, setLoading] = React.useState(false);
   const [loaded, setLoaded] = React.useState(false);
+  // Empty because there is nothing, or empty because the listing failed? The
+  // two must never render the same: being told that an account which holds your
+  // API keys has no providers is alarming when it is really a dropped request.
+  const [error, setError] = React.useState("");
   const [page, setPage] = React.useState(1);
   const [pageSize, setPageSize] = React.useState(10);
   const [sort, setSort] = React.useState<{field: string; order: SortOrder}>({
@@ -140,22 +146,21 @@ export default function ProviderListPage({account}: {account: Account}) {
         nextSort.order ?? "",
       )
         .then(res => {
-          setLoading(false);
-          setLoaded(true);
           if (res.status === "ok") {
             setData(res.data ?? []);
             setTotal(res.data2 ?? 0);
             setPage(nextPage);
             setPageSize(nextPageSize);
             setSort(nextSort);
+            setError("");
           } else {
-            Setting.showMessage("error", `${i18next.t("provider:Failed to get providers")}: ${res.msg}`);
+            setError(res.msg || i18next.t("provider:Failed to get providers"));
           }
         })
-        .catch(error => {
+        .catch(failure => setError(failure.message || String(failure)))
+        .then(() => {
           setLoading(false);
           setLoaded(true);
-          Setting.showMessage("error", `${i18next.t("provider:Failed to get providers")}: ${error}`);
         });
     },
     [account.name, page, pageSize, sort],
@@ -331,7 +336,11 @@ export default function ProviderListPage({account}: {account: Account}) {
         }
       />
 
-      {loaded && data.length === 0 ? (
+      {error !== "" && data.length === 0 ? (
+        <Card>
+          <ErrorState error={error} onRetry={() => fetchProviders()} />
+        </Card>
+      ) : loaded && error === "" && data.length === 0 ? (
         <Card>
           <CardHeader>
             <CardTitle className="flex items-center gap-2">
@@ -346,6 +355,9 @@ export default function ProviderListPage({account}: {account: Account}) {
         </Card>
       ) : (
         <div className="space-y-3">
+          {/* A refresh that failed leaves the last good listing on screen: the
+              providers below are stale, not gone. */}
+          {error !== "" ? <MessageAlert title={i18next.t("provider:Failed to get providers")} description={error} /> : null}
           <div className="flex flex-wrap items-center justify-between gap-2">
             <p className="text-muted-foreground text-sm">
               {`${total} ${i18next.t("provider:Providers")}`}
diff --git a/web/src/pages/RecordListPage.tsx b/web/src/pages/RecordListPage.tsx
index 0e1738e..0d37f23 100644
--- a/web/src/pages/RecordListPage.tsx
+++ b/web/src/pages/RecordListPage.tsx
@@ -54,6 +54,7 @@ export default function RecordListPage({account}: {account: Account}) {
   const [data, setData] = React.useState<GatewayRecord[]>([]);
   const [total, setTotal] = React.useState(0);
   const [loading, setLoading] = React.useState(false);
+  const [error, setError] = React.useState("");
   const [page, setPage] = React.useState(1);
   const [pageSize, setPageSize] = React.useState(10);
   const [addOpen, setAddOpen] = React.useState(false);
@@ -63,17 +64,20 @@ export default function RecordListPage({account}: {account: Account}) {
   const fetchRecords = React.useCallback(
     (nextPage = page, nextPageSize = pageSize) => {
       setLoading(true);
-      RecordBackend.getRecords(account.name, nextPage, nextPageSize).then(res => {
-        setLoading(false);
-        if (res.status === "ok") {
-          setData(res.data ?? []);
-          setTotal(res.data2 ?? 0);
-          setPage(nextPage);
-          setPageSize(nextPageSize);
-        } else {
-          Setting.showMessage("error", `${i18next.t("general:Failed to get data")}: ${res.msg}`);
-        }
-      });
+      RecordBackend.getRecords(account.name, nextPage, nextPageSize)
+        .then(res => {
+          if (res.status === "ok") {
+            setData(res.data ?? []);
+            setTotal(res.data2 ?? 0);
+            setPage(nextPage);
+            setPageSize(nextPageSize);
+            setError("");
+          } else {
+            setError(res.msg || i18next.t("general:Failed to get data"));
+          }
+        })
+        .catch(err => setError(err.message || String(err)))
+        .then(() => setLoading(false));
     },
     [account.name, page, pageSize],
   );
@@ -218,6 +222,8 @@ export default function RecordListPage({account}: {account: Account}) {
         dataSource={data}
         rowKey={record => String(record.id)}
         loading={loading}
+        error={error}
+        onRetry={() => fetchRecords()}
         serverPagination={{
           page: page,
           pageSize: pageSize,
diff --git a/web/src/pages/RuleListPage.tsx b/web/src/pages/RuleListPage.tsx
index aa5db1c..6833e60 100644
--- a/web/src/pages/RuleListPage.tsx
+++ b/web/src/pages/RuleListPage.tsx
@@ -57,6 +57,7 @@ export default function RuleListPage({account}: {account: Account}) {
   const [data, setData] = React.useState<Rule[]>([]);
   const [total, setTotal] = React.useState(0);
   const [loading, setLoading] = React.useState(false);
+  const [error, setError] = React.useState("");
   const [page, setPage] = React.useState(1);
   const [pageSize, setPageSize] = React.useState(10);
   const [addOpen, setAddOpen] = React.useState(false);
@@ -67,17 +68,20 @@ export default function RuleListPage({account}: {account: Account}) {
   const fetchRules = React.useCallback(
     (nextPage = page, nextPageSize = pageSize) => {
       setLoading(true);
-      RuleBackend.getRules(account.name, nextPage, nextPageSize).then(res => {
-        setLoading(false);
-        if (res.status === "ok") {
-          setData(res.data ?? []);
-          setTotal(res.data2 ?? 0);
-          setPage(nextPage);
-          setPageSize(nextPageSize);
-        } else {
-          Setting.showMessage("error", `${i18next.t("general:Failed to get data")}: ${res.msg}`);
-        }
-      });
+      RuleBackend.getRules(account.name, nextPage, nextPageSize)
+        .then(res => {
+          if (res.status === "ok") {
+            setData(res.data ?? []);
+            setTotal(res.data2 ?? 0);
+            setPage(nextPage);
+            setPageSize(nextPageSize);
+            setError("");
+          } else {
+            setError(res.msg || i18next.t("general:Failed to get data"));
+          }
+        })
+        .catch(err => setError(err.message || String(err)))
+        .then(() => setLoading(false));
     },
     [account.name, page, pageSize],
   );
@@ -244,6 +248,8 @@ export default function RuleListPage({account}: {account: Account}) {
         dataSource={data}
         rowKey={record => `${record.owner}/${record.name}`}
         loading={loading}
+        error={error}
+        onRetry={() => fetchRules()}
         serverPagination={{
           page: page,
           pageSize: pageSize,
diff --git a/web/src/pages/SiteListPage.tsx b/web/src/pages/SiteListPage.tsx
index 5f4dca2..245f8cc 100644
--- a/web/src/pages/SiteListPage.tsx
+++ b/web/src/pages/SiteListPage.tsx
@@ -70,6 +70,7 @@ export default function SiteListPage({account}: {account: Account}) {
   const navigate = useNavigate();
   const [data, setData] = React.useState<Site[]>([]);
   const [loading, setLoading] = React.useState(false);
+  const [error, setError] = React.useState("");
   const [gatewayStatus, setGatewayStatus] = React.useState<GatewayStatus | null>(null);
   const [switchingGateway, setSwitchingGateway] = React.useState(false);
   const [addOpen, setAddOpen] = React.useState(false);
@@ -79,14 +80,17 @@ export default function SiteListPage({account}: {account: Account}) {
 
   const fetchSites = React.useCallback(() => {
     setLoading(true);
-    SiteBackend.getSites(account.name).then(res => {
-      setLoading(false);
-      if (res.status === "ok") {
-        setData(res.data ?? []);
-      } else {
-        Setting.showMessage("error", `${i18next.t("general:Failed to get data")}: ${res.msg}`);
-      }
-    });
+    SiteBackend.getSites(account.name)
+      .then(res => {
+        if (res.status === "ok") {
+          setData(res.data ?? []);
+          setError("");
+        } else {
+          setError(res.msg || i18next.t("general:Failed to get data"));
+        }
+      })
+      .catch(err => setError(err.message || String(err)))
+      .then(() => setLoading(false));
   }, [account.name]);
 
   const loadGatewayStatus = React.useCallback(() => {
@@ -412,6 +416,8 @@ export default function SiteListPage({account}: {account: Account}) {
         dataSource={data}
         rowKey={record => `${record.owner}/${record.name}`}
         loading={loading}
+        error={error}
+        onRetry={() => fetchSites()}
         pageSize={20}
         searchable
         title={i18next.t("general:Sites")}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@casbin.apache.org
For additional commands, e-mail: commits-help@casbin.apache.org