Skip to content

Self-improving AI Employees for everyone

feat(icons): resolver dispatches /api/schemas/nodes/.../icon paths

trohitg4c3fab1f662f
diff --git a/client/src/assets/icons/index.test.ts b/client/src/assets/icons/index.test.ts
index 8e401d11..2f32299f 100644
--- a/client/src/assets/icons/index.test.ts
+++ b/client/src/assets/icons/index.test.ts
@@ -71,4 +71,14 @@ describe('resolveIcon', () => {
it('returns null for unknown asset keys (visible gap, not silent fallback)', () => {
expect(resolveIcon('asset:nonexistent-icon-xyz')).toBeNull();
});
+
+ it('prefixes /api/ icon paths with PYTHON_BASE_URL (RFC §6.5 — backend-served icons)', () => {
+ // Per-plugin icon.svg endpoint emitted by BaseNode._metadata_dict
+ // when the plugin folder has a co-located icon. Resolver prefixes
+ // PYTHON_BASE_URL so dev (Vite:3000 → backend:3010) and prod
+ // (same-origin, empty prefix) both hit the right server.
+ const resolved = resolveIcon('/api/schemas/nodes/aiAgent/icon');
+ expect(resolved).not.toBeNull();
+ expect(resolved).toMatch(/\/api\/schemas\/nodes\/aiAgent\/icon$/);
+ });
});
diff --git a/client/src/assets/icons/index.ts b/client/src/assets/icons/index.ts
index f4460a76..6596bf1d 100644
--- a/client/src/assets/icons/index.ts
+++ b/client/src/assets/icons/index.ts
@@ -28,6 +28,8 @@
import * as React from 'react';
import * as Lucide from 'lucide-react';
+
+import { API_CONFIG } from '../../config/api';
// Deep imports of just the brand icons we expose via `lobehub:<brand>`.
// A namespace import (`import * as Lobehub`) would re-evaluate the package
// index, which re-exports antd-using feature modules (Editor / Dashboard /
@@ -78,9 +80,13 @@ export const ICON_REGISTRY: Readonly<Record<string, string>> = Object.fromEntrie
/**
* Resolve a backend-declared icon string to something renderable.
* Contract:
- * `asset:<key>` → look up in ICON_REGISTRY (filesystem-derived)
- * `data:...` → pass through
- * otherwise → render as-is (emoji / short text / URL)
+ * `asset:<key>` → look up in ICON_REGISTRY (filesystem-derived)
+ * `/api/...` → prefix with PYTHON_BASE_URL (backend-served icon
+ * via GET /api/schemas/nodes/<type>/icon — RFC §6.5)
+ * `data:...` → pass through
+ * `http(s)://...` → pass through
+ * other `/...` → pass through (already same-origin)
+ * otherwise → render as-is (emoji / short text)
* Returns `null` when the icon string is empty or an unknown asset key,
* so callers can apply their own fallback.
*/
@@ -92,6 +98,13 @@ export const resolveIcon = (icon: string | undefined | null): string | null => {
// the author rather than masked by a fallback emoji.
return ICON_REGISTRY[icon.slice('asset:'.length)] ?? null;
}
+ if (icon.startsWith('/api/')) {
+ // Backend-served icon endpoint. In dev the FE runs on Vite:3000 and
+ // the backend on :3010, so a bare relative path would hit the Vite
+ // server. Prefix with PYTHON_BASE_URL (empty string in prod, full
+ // localhost URL in dev) so the browser fetches the right origin.
+ return `${API_CONFIG.PYTHON_BASE_URL}${icon}`;
+ }
if (icon.startsWith('data:') || icon.startsWith('http://') || icon.startsWith('https://') || icon.startsWith('/')) {
return icon;
}