Skip to content

feat(sharepoint): add SharePoint context source support#341

Open
Aryan1718 wants to merge 1 commit into
Kaelio:mainfrom
Aryan1718:sharepoint
Open

feat(sharepoint): add SharePoint context source support#341
Aryan1718 wants to merge 1 commit into
Kaelio:mainfrom
Aryan1718:sharepoint

Conversation

@Aryan1718

@Aryan1718 Aryan1718 commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds a new sharepoint context-source driver to ktx. It supports ingesting Markdown and Word documents from a
Microsoft Graph drive folder, covering both SharePoint document libraries and OneDrive folders through the same
drive_id + folder_id model.

The implementation includes connection parsing, credential resolution, Graph-based folder traversal, staged ingest
output, CLI setup and verification flows, runtime skill wiring, documentation, and test coverage.

What was added

New sharepoint context-source driver

Added a new adapter under packages/cli/src/context/ingest/adapters/sharepoint/ with behavior aligned to the existing
ingest stack:

  • Supports driver: sharepoint

  • Ingests .md and .docx files only

  • Traverses a Microsoft Graph drive folder, with optional recursion

  • Stages output as:

    • manifest.json
    • per-document metadata.json
    • per-document page.md
  • Uses stable compact staged directory names derived from document title and item ID

Microsoft Graph authentication and connection resolution

Added SharePoint connection resolution using Azure AD client credentials:

  • Resolves tenant_id_ref, client_id_ref, and client_secret_ref
  • Enforces env: references only for these credential fields
  • Exchanges credentials against the tenant-specific Microsoft identity token endpoint
  • Produces a lean pull config with resolved credentials plus driveId and folderId

Graph-based file discovery and download

Implemented a lightweight Graph client using native fetch:

  • Token acquisition
  • Folder children pagination
  • Recursive traversal of nested folders
  • File download for supported document types
  • Optional site-to-drive lookup during setup and verification when a site ID is provided

Document conversion and normalization

Added content handling for both supported formats:

  • .md files are preserved as authored Markdown with line-ending normalization
  • .docx files are converted to Markdown using mammoth
  • Converted Markdown is normalized for cleaner headings, lists, and pipe-table output
  • A leading H1 is added when converted Word content does not begin with one

CLI and runtime integration

Integrated the new source across user-facing CLI flows:

  • ktx connection can verify SharePoint credentials and folder access
  • ktx setup and source setup now support SharePoint-specific prompts and flags
  • Added runtime skill wiring through sharepoint_synthesize
  • Registered the driver in schemas, adapter resolution, public ingest mapping, and local ingest entrypoints

Documentation

Updated docs for configuration and usage:

  • docs-site/content/docs/integrations/context-sources.mdx
  • docs-site/content/docs/configuration/ktx-yaml.mdx

Also documented required Microsoft Graph application permissions with admin consent:

  • Files.Read.All
  • Sites.Read.All

Testing

Added targeted coverage for the new SharePoint surface, including:

  • schema validation for sharepoint connection config
  • env-based credential resolution and error handling
  • Graph token acquisition, pagination, traversal, and download behavior
  • optional site-drive discovery
  • Markdown passthrough and .docx conversion behavior
  • staged output layout, manifest contents, and metadata generation
  • adapter detection, chunking, and scope description
  • setup flow, connection verification, and driver registration

Verification

Verified with:

  • targeted Vitest suites for SharePoint ingest, setup, connection, and schema coverage
  • pnpm --filter @kaelio/ktx run type-check
  • pnpm run dead-code

Result:

  • SharePoint-specific implementation and tests passed
  • Type-check passed
  • Dead-code checks passed

Close #171

@vercel

vercel Bot commented Jul 4, 2026

Copy link
Copy Markdown

@Aryan1718 is attempting to deploy a commit to the Kaelio Team on Vercel.

A member of the Team first needs to authorize it.

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.

Add SharePoint / OneDrive context source

1 participant