mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-07-11 16:53:45 +00:00
Lets operators declare programmatic tool-approval hooks in config instead of code, so the
registerToolApprovalHook seam is usable without a custom build.
- Config (data-provider): `endpoints.agents.toolApproval.hooks[]`, each entry
`{ module, matcher?, options? }`. `module` is a bare package name or a path (resolved
against the app root); its default export is a builder `(options?) => ToolApprovalHookFactory`.
- Loader (@librechat/api `loadToolApprovalHooks`): imports each module, builds the factory
with the entry's options, and registers it (with its optional tool-name matcher). Reload-
safe (each call first unregisters its previous batch, leaving code-registered hooks alone)
and robust — an unimportable module / non-function export / throwing builder is logged and
skipped, never crashing startup or blocking the other hooks. Importer is injectable for tests.
- Startup (api/server/index.js): loads the configured hooks once after appConfig resolves.
SECURITY: modules are dynamically imported + executed in-process; this is admin-level config,
documented as trusted-code-only.
Tests: 9 loader cases (default/no-default export, options passthrough, bad-export skip,
builder-returns-non-function skip, import-failure resilience, continue-past-bad-entry,
reload de-dup). Full HITL suite green (80).
|
||
|---|---|---|
| .. | ||
| app | ||
| cache | ||
| config | ||
| db | ||
| models | ||
| server | ||
| strategies | ||
| test | ||
| utils | ||
| jest.config.js | ||
| jsconfig.json | ||
| package.json | ||
| typedefs.js | ||