LibreChat/client
Danny Avila 3f1bde4831 🪆 feat: Compose Agent Scope and Active-State Filters in $ Popover (#12708)
* feat: compose per-agent scope and per-user active-state filters in $ popover

Stack two runtime-truth filters on top of the existing `isUserInvocable`
check so the `$` skill popover matches what will actually be available at
turn time:

- Per-agent skill scope from `agent.skills` (resolved via useChatContext
  + useAgentsMapContext), mirroring backend `scopeSkillIds` semantics:
  `undefined`/`null` → no scope, `[]` → empty, non-empty → intersection.
- Per-user ownership-aware active state via `useSkillActiveState().isActive`.

The filters are composed in a pure, exported `filterSkillsForPopover`
helper so the agent-scope ∩ active ∩ invocable matrix can be unit-tested
without rendering the component. Short-circuits on cheapest check first
(agent scope → active → invocation mode).

Backend still enforces both filters at runtime; this PR is a UX mirror so
users do not see popover entries that would be filtered out by the time
the LLM turn begins.

* refactor: thread agentId into SkillsCommand as a prop

Drop the direct `useChatContext()` call inside SkillsCommand in favor of
receiving `agentId` from ChatForm. The parent already subscribes to the
conversation via its single useChatContext call, and SkillsCommand is
wrapped in React.memo — threading the id as a prop means the popover only
re-renders when agent_id actually changes instead of on every unrelated
conversation-shape mutation. Mirrors the pattern AttachFileChat already
uses for `conversation` / `agentId`.

No behavior change; filter semantics and test coverage are identical.

* fix: fail closed when agent skill scope cannot be resolved

Previously, if `conversation.agent_id` was set but the agents map had no
entry for it (hydration pending, query failure, or missing VIEW access),
the popover treated the scope as `undefined` and showed the full ACL
catalog. That leaks options the backend will reject at turn time, the
opposite of what this phase is meant to do.

Distinguish the unresolved cases ("map undefined" and "agent not in map")
from the intentionally-unconfigured case ("agent exists, no `skills`
field") and return `[]` for the former, preserving the backend semantics
of `scopeSkillIds` only for the latter. Adds two tests covering both
fail-closed branches.

* fix: surface agent.skills in list projection and treat ephemeral ids as unscoped

Two holes flagged on the earlier fail-closed commit:

1. The list-agents projection in `getListAgentsByAccess` omitted the
   `skills` field, so `agentsMap[agentId].skills` was always undefined
   and the popover fell back to the full ACL catalog for every scoped
   agent — the opposite of this phase's intent. Add `skills: 1` to the
   projection and lock it in with a new test.

2. Conversations can carry ephemeral agent ids (e.g. `ephemeral` after
   switching off the agents endpoint) that intentionally don't live in
   the agents map. The prior fail-closed branch blanked the popover in
   those cases. Treat anything that doesn't start with `agent_` as
   unscoped via the existing `isEphemeralAgent` helper so the popover
   shows the full ACL-visible catalog, matching how no-agent convos
   already behave.

Frontend: 18 tests pass (adds one ephemeral-id case).
Backend: 10 getListAgentsByAccess tests pass (adds one projection case).

* refactor: pass through hydration race, only fail closed when map is authoritative

Split the two "cannot resolve scope" cases that were previously collapsed
onto the same fail-closed branch:

- `agentsMap === undefined` means the agents list query has not settled
  yet. Return `undefined` (full catalog). The map typically hydrates well
  before the first `$` open, and the backend still scopes at turn time —
  blanking the popover during a sub-second race produces worse UX with
  no security benefit.
- `agentsMap` is populated but the agent is absent means the agent was
  deleted or the user's VIEW access was revoked mid-session. That is
  authoritative missing state, so keep the fail-closed behavior — the
  full catalog would be misleading.

Updates the associated test case to assert the hydration-race path now
shows the catalog, and rewrites the in-code comment to distinguish the
two branches.

* refactor: drop `as string` in agent scope memo by tightening the guard

`isEphemeralAgent` returns true for null/undefined so the original code
was runtime-safe, but its signature returns plain `boolean` rather than
a type predicate, so TypeScript never narrowed `agentId` to `string` and
the subsequent map lookup required an `as string` assertion. Split the
guard into `!agentId || isEphemeralAgent(agentId)` so the narrowing falls
out naturally and the assertion can be removed.

No behavior change; 18 tests pass.
2026-04-25 04:02:00 -04:00
..
public 🎨 chore: Update Agent Tool with new SVG assets (#12065) 2026-03-04 09:28:19 -05:00
scripts
src 🪆 feat: Compose Agent Scope and Active-State Filters in $ Popover (#12708) 2026-04-25 04:02:00 -04:00
test 🧑‍🎨 refactor: Prompts/Sidebar styles for improved UI Consistency (#12426) 2026-04-09 00:02:31 -04:00
babel.config.cjs 🧑‍🎨 refactor: Prompts/Sidebar styles for improved UI Consistency (#12426) 2026-04-09 00:02:31 -04:00
check_updates.sh
index.html
jest.config.cjs v0.8.5 (#12727) 2026-04-22 13:10:19 -07:00
nginx.conf 📬 docs: Add Forwarded Headers to Nginx SSL Proxy Template (#12379) 2026-03-25 13:04:19 -04:00
package.json 📜 feat: Skills UI + Initial E2E CRUD / Sharing (#12580) 2026-04-25 04:02:00 -04:00
postcss.config.cjs
tailwind.config.cjs style(MCP): Enhance dialog accessibility and styling consistency (#11585) 2026-02-11 22:08:40 -05:00
tsconfig.json 📦 chore: Update TypeScript Config for TS v7 (#12794) 2026-04-23 12:51:03 -04:00
vite.config.ts 📜 feat: Skills UI + Initial E2E CRUD / Sharing (#12580) 2026-04-25 04:02:00 -04:00