Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

1.4 KB
Raw Blame
/**
 * Per-plugin opt-in for `script-src 'unsafe-eval'` in the workbench sandbox.
 *
 * WebGL graphics engines generate their uniform/UBO sync code with
 * `new Function` (PixiJS 8 refuses to even construct a renderer when that
 * throws), so a plugin whose UI renders through such an engine needs
 * unsafe-eval or its visual surfaces never initialize. The sandbox keeps the
 * directive off by default and the user grants it one plugin at a time, the
 * same way AI tool access and data reads are granted.
 */

const MAX_GRANTED_PLUGINS = 64;

export function normalizePluginGraphicsEngineIds(value: unknown): string[] {
  if (!Array.isArray(value)) return [];
  const ids = new Set<string>();
  for (const entry of value) {
    if (typeof entry !== "string") continue;
    const id = entry.trim();
    if (!id) continue;
    ids.add(id);
    if (ids.size >= MAX_GRANTED_PLUGINS) break;
  }
  return [...ids];
}

export function isPluginGraphicsEngineEnabled(ids: readonly string[] | undefined, pluginId: string): boolean {
  return !!pluginId && (ids || []).includes(pluginId);
}

export function withPluginGraphicsEngineEnabled(ids: readonly string[] | undefined, pluginId: string, enabled: boolean): string[] {
  const current = normalizePluginGraphicsEngineIds(ids).filter((id) => id !== pluginId);
  if (!enabled || !pluginId) return current;
  return [...current, pluginId].slice(0, MAX_GRANTED_PLUGINS);
}