WeKnora/frontend/src/api
Leo Dawn a3c7be10ca
fix(agent): scope the @Skill and @MCP pickers to the agent that will run (#3475)
* fix(agent): scope the @Skill and @MCP pickers to the agent that will run

Both pickers listed the caller's own workspace, but a shared agent invokes its
OWNER's skills and MCP services. The two never line up, so for every shared
agent:

  * @Skill was always empty, in every skills mode. GET /skills resolves the
    sandbox config with (tenant, id), and the agent's config id does not exist
    in the borrower's workspace - effectiveTenantSkills short-circuits before
    it reads a single skill row. The response still reported
    skills_available: true, so the category appeared with nothing under it.
  * @MCP in "selected" mode was empty for the same reason: the preset holds the
    owner's service ids, which match nothing in the borrower's catalog.
  * @MCP in "all" mode was worse than empty. isMCPAllowedByAgent returns true
    for every enabled service, so the picker offered the BORROWER's own
    services; resolvePerRequestMCPScope then intersected the mention against
    the agent's preset, found nothing, and dropped it with only a warning.

Resolve the agent when the request carries agent_id + agent_source_tenant_id
and read its resources where they live. Only an explicit source workspace takes
the share path, so an own-agent request is byte-for-byte unchanged; built-in
agent ids exist in every workspace, and falling back to a share lookup without
one would let an org member take over the caller's default agent, exactly as
session.Handler.resolveAgent already documents.

Both endpoints serve only what the agent can actually invoke:

  * skills: the sandbox config comes from the agent, never from the query, so a
    borrower cannot name another config in the owner's workspace and enumerate
    it; "selected" narrows to the configured names and a disabled picker never
    reaches the owner's inventory at all.
  * MCP: the agent's explicit preset and nothing else, because that is exactly
    what resolvePerRequestMCPScope accepts for a shared agent. "all" therefore
    offers nothing rather than offering services every mention would drop.
    Whether "all" should become mentionable is a separate decision about that
    guard, not about the picker.

The cross-workspace MCP rows use a narrowed response built field by field.
NewMCPServiceResponse reveals endpoint URL, headers, env vars and stdio command
to an Admin, and a borrower can be an Admin of their own workspace - that shape
must be narrow by construction, not by role.

On the client the two lists now follow the selected agent: their cache keys
carry it, and the chat input refetches on a switch behind a request token, so a
slow response for the agent the user just left cannot overwrite the picker with
another workspace's services.

* fix(agent): check the c.Error return on the shared-agent picker paths

golangci-lint judges pull requests on the lines they introduce, so the
repository's older bare c.Error calls are grandfathered while these three are
not. Match the _ = c.Error form already used in mcp_service.go.
2026-09-21 13:02:34 +08:00
..
agent refactor(models): rebuild vendor integration on protocol + catalog + vendor layers (#3470) 2026-09-20 21:28:23 +08:00
auth fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
chat feat(session): in-place rewind with workspace checkpoint reset (#3469) 2026-09-20 21:01:00 +08:00
chunker feat(frontend): chunking debug panel with live preview 2026-05-06 17:17:07 +08:00
datasource fix(datasource): validate replacement credentials before saving 2026-09-14 17:37:53 +08:00
embed feat(i18n): add Japanese (ja-JP) locale support (#3080) 2026-09-07 19:20:41 +08:00
initialization refactor(rerank): move the wire formats into protocol packages, and correct the vendor facts (#3488) 2026-09-21 10:36:26 +08:00
knowledge-base feat(frontend): show overall progress for knowledge file uploads (#3399) 2026-09-18 16:43:59 +08:00
model refactor(models): rebuild vendor integration on protocol + catalog + vendor layers (#3470) 2026-09-20 21:28:23 +08:00
organization fix: align client sessions and integration request handling (#3305) 2026-09-16 16:20:57 +08:00
skill fix(agent): scope the @Skill and @MCP pickers to the agent that will run (#3475) 2026-09-21 13:02:34 +08:00
system fix(skills): upgrade outdated sandbox skills without rolling back the catalog or taking them offline (#3406) 2026-09-18 20:27:43 +08:00
tenant feat: support updating API key configuration 2026-08-12 11:43:03 +08:00
wiki feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
artifacts.ts feat(artifacts): let users delete generated files (#3447) 2026-09-20 13:01:46 +08:00
chat-history.ts feat: implement chat history and retrieval settings 2026-03-09 11:46:56 +08:00
env-vars.ts ui(sandbox): redesign personal sandbox secrets settings 2026-08-27 16:55:09 +08:00
mcp-endpoint.ts feat(mcp): add built-in MCP server with per-workspace endpoints (#3371) 2026-09-17 22:40:05 +08:00
mcp-service.ts fix(agent): scope the @Skill and @MCP pickers to the agent that will run (#3475) 2026-09-21 13:02:34 +08:00
memory.ts feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
message-suggestion.ts feat(agent): add question suggestions with after-answer follow-ups 2026-07-14 11:17:25 +08:00
retrieval.ts feat: implement chat history and retrieval settings 2026-03-09 11:46:56 +08:00
storage-backend.ts feat(storage): add multi-instance storage backends per workspace 2026-07-15 14:54:39 +08:00
user-favorites.ts feat(favorites): implement user favorites and recents functionality 2026-05-18 17:28:58 +08:00
vector-store.ts feat(retriever): activate OpenSearch k-NN driver (PR 3 of 3) 2026-05-29 16:32:27 +08:00
web-search-provider.ts feat(web-search): add Serply provider 2026-09-17 12:25:09 +08:00
web-search.ts feat(web-search): refactor web search provider 2026-03-31 20:22:34 +08:00