Skip to content

feat: attach knowledge bases to a Context document#228

Open
mogenshoj wants to merge 7 commits into
mainfrom
feat/knowledge-bases
Open

feat: attach knowledge bases to a Context document#228
mogenshoj wants to merge 7 commits into
mainfrom
feat/knowledge-bases

Conversation

@mogenshoj

Copy link
Copy Markdown

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, defaults true) — let agents query all content
    directly.

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 / groqFilter unchanged — 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
hidden behaviour caused.

Knowledge-base picker

A custom input (KnowledgeBaseInput) for the knowledgeBaseIds field:

  • Resolves the organizationId from the project, then fetches the org's
    knowledge bases from the Sanity Context (Atlas) API
    ({apiHost}/vX/context/organizations/{org}/knowledge-bases).
  • Multi-select by name + description; knowledge bases that aren't yet built
    (state other than ready / review) are shown disabled.
  • Loading / error (with retry) / empty states.
  • Stores the selected ids only.

Data fetching (atlas.ts, useKnowledgeBases.ts) follows the rxjs/useObservable
pattern 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 readOnly through the existing content-filter input so that when
direct 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 project
    host — guards the CORS regression), cursor pagination, org resolution.

Notes

  • The document is the single source of truth for what tools an agent gets; the
    consumer (context-mcp) resolves ids → knowledge-base tools. See the companion
    context-mcp PR.
  • Attaching is allowed for ready and review knowledge bases; only unbuilt
    states are blocked.
image

@vercel

vercel Bot commented Jun 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agent-context-ecommerce-example Ready Ready Preview, Comment Jun 17, 2026 7:57am

Request Review

@mogenshoj mogenshoj changed the title feat: add knowledge bases feat: attach knowledge bases to a Context document Jun 3, 2026
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for context (packages/context)

Status Category Percentage Covered / Total
🔵 Lines 30.56% 199 / 651
🔵 Statements 31.4% 222 / 707
🔵 Functions 21.46% 44 / 205
🔵 Branches 24.45% 158 / 646
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/context/src/studio/context-document/contextSchema.ts 46.15% 0% 0% 46.15% 52-98
packages/context/src/studio/context-document/groq-filter-input/GroqFilterInput.tsx 4.16% 0% 0% 4.68% 58-359
packages/context/src/studio/context-document/knowledge-base-input/KnowledgeBaseInput.tsx 4.76% 0% 0% 5.26% 18-130
packages/context/src/studio/context-document/knowledge-base-input/atlas.ts 95% 91.66% 75% 93.75% 44
packages/context/src/studio/context-document/knowledge-base-input/useKnowledgeBases.ts 5.55% 0% 0% 6.25% 29-80
Generated in workflow #603 for commit 3421124 by the Vitest Coverage Report Action

Comment thread packages/context/src/studio/context-document/contextSchema.ts Outdated
@torbratsberg torbratsberg marked this pull request as ready for review June 4, 2026 13:49
@mogenshoj mogenshoj requested a review from torbratsberg June 15, 2026 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants