feat: attach knowledge bases to a Context document#228
Open
mogenshoj wants to merge 7 commits into
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Coverage Report for context (packages/context)
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
torbratsberg
reviewed
Jun 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds knowledge-base support to the
sanity.agentContext(Sanity Context)document. Editors can attach one or more knowledge bases to a Context and
control whether agents may also query content directly with GROQ. The document
stores only knowledge-base ids; their slug/name/description are resolved at
runtime by the consumer (context-mcp), so nothing goes stale.
Schema
Two new fields on
contextSchema:knowledgeBaseIds(array<string>) — the attached knowledge bases.Rendered by a custom picker (below) rather than free text.
groqEnabled(boolean, defaultstrue) — let agents query all contentdirectly.
The GROQ toggle and the existing Content filter are grouped into one
collapsible "Direct content access" fieldset, so the relationship is
explicit. The fields stay top-level in the document (fieldsets are visual only),
so consumers read
groqEnabled/groqFilterunchanged — no data migration.The content filter is now shown read-only (greyed in place) when querying is
off, instead of being hidden — this removes the layout jump the previous
hiddenbehaviour caused.Knowledge-base picker
A custom input (
KnowledgeBaseInput) for theknowledgeBaseIdsfield:organizationIdfrom the project, then fetches the org'sknowledge bases from the Sanity Context (Atlas) API
(
{apiHost}/vX/context/organizations/{org}/knowledge-bases).(state other than
ready/review) are shown disabled.Data fetching (
atlas.ts,useKnowledgeBases.ts) follows the rxjs/useObservablepattern already used by the Insights dashboard. The Context API endpoints are
global (not project-hostname routed), so the client is reconfigured with
useProjectHostname: false+apiVersion: 'vX'and given version-less paths —otherwise the request resolves to a doubled-version, project-host URL that
CORS-fails.
GroqFilterInput
Threaded
readOnlythrough the existing content-filter input so that whendirect querying is off, the filter is genuinely inert (type chips can't be
removed, search/add controls disabled, GROQ textarea read-only), not just
visually greyed.
Tests
contextSchema.test.ts— the two new fields (types, defaults).atlas.test.ts— URL construction (version-less, org-scoped, no projecthost — guards the CORS regression), cursor pagination, org resolution.
Notes
consumer (context-mcp) resolves ids → knowledge-base tools. See the companion
context-mcp PR.
readyandreviewknowledge bases; only unbuiltstates are blocked.