Add CopilotKit retrieval integration cookbook example - #367
Add CopilotKit retrieval integration cookbook example#367PrinceThummar011 wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new self-contained cookbook example under examples/cookbook/copilotkit/ demonstrating how to ground a CopilotKit in-app copilot using Moss retrieval via a secure Next.js App Router API route, with a mock fallback for running without credentials.
Changes:
- Introduces a Next.js App Router app with a CopilotKit runtime endpoint and a Moss query endpoint (mock + real mode).
- Adds a reusable
useMossRetrievalhook wiring CopilotKit actions to the Moss query route. - Provides a dashboard-style UI plus setup docs and environment templates for quick local iteration.
Reviewed changes
Copilot reviewed 12 out of 14 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| examples/cookbook/copilotkit/tsconfig.json | TypeScript configuration for the Next.js cookbook project. |
| examples/cookbook/copilotkit/README.md | Setup + usage documentation describing the CopilotKit ↔ Moss handoff. |
| examples/cookbook/copilotkit/package.json | Declares the example’s Next/CopilotKit/Moss dependencies and scripts. |
| examples/cookbook/copilotkit/next.config.ts | Configures Next.js server externals for Moss native bindings. |
| examples/cookbook/copilotkit/next-env.d.ts | Next.js TypeScript ambient type references for the cookbook. |
| examples/cookbook/copilotkit/app/use-moss-retrieval.ts | Client hook registering the CopilotKit retrieval action and calling /api/moss/query. |
| examples/cookbook/copilotkit/app/page.tsx | Interactive dashboard UI + grounded CopilotChat integration. |
| examples/cookbook/copilotkit/app/layout.tsx | App layout and global style imports. |
| examples/cookbook/copilotkit/app/globals.css | Dark-theme styling and CopilotKit UI overrides. |
| examples/cookbook/copilotkit/app/api/moss/query/route.ts | Server-side Moss query endpoint with mock fallback and response shaping. |
| examples/cookbook/copilotkit/app/api/copilotkit/route.ts | CopilotKit runtime endpoint backed by OpenAI. |
| examples/cookbook/copilotkit/.gitignore | Ignores node/Next build artifacts and local env. |
| examples/cookbook/copilotkit/.env.example | Documents required/optional environment variables for the cookbook. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
Hi @HarshaNalluru @r4ghu — this PR has gone through several rounds of Copilot AI review and feedback has been addressed (input validation, logging, docs accuracy, etc. across the last few commits). The Copilot re-review attempt just failed due to a quota limit on my end, but I don't think that should block things further. Could one of you take a look when you get a chance? It's currently blocked on needing at least 1 approving review from a code owner. Happy to address any additional feedback quickly. Thanks! |
| try { | ||
| const { searchParams } = new URL(request.url); | ||
| const query = (searchParams.get("query") ?? "").trim(); | ||
| const indexName = searchParams.get("indexName") || process.env.MOSS_INDEX_NAME; |
There was a problem hiding this comment.
BLOCKING This lets a browser request choose which secret-backed Moss index to query:
const indexName = searchParams.get("indexName") || process.env.MOSS_INDEX_NAME;Anyone who can reach /api/moss/query can query any index in the configured Moss project if they know or guess its name. Keep the index selection on the server side, or validate it against a server-side allowlist after authenticating the user, e.g. const indexName = process.env.MOSS_INDEX_NAME;.
| } | ||
|
|
||
| // MOCK MODE FALLBACK | ||
| if (isMockMode || !mossClient) { |
There was a problem hiding this comment.
BLOCKING This falls back to sample data even when real Moss credentials were supplied but client initialization failed:
if (isMockMode || !mossClient) {That can make a misconfigured production demo answer with the built-in refund/contact mock docs instead of failing visibly. Only use mock mode when credentials are actually absent/placeholders; if !mossClient after real credentials, return a 500 such as MossClient failed to initialize.
Codex reviewThe new cookbook example is close, but the Moss query route currently weakens the server-side security boundary and can silently serve mock data when real Moss setup is broken. |
Summary
Adds a cookbook example demonstrating how to ground CopilotKit in-app
copilots with Moss's sub-10ms retrieval, so React apps can answer
questions using the user's own data.
Closes #340
What's included
examples/cookbook/copilotkit/— a minimal working example showing:results CopilotKit can ground responses on
action
(no secrets committed)
Why
React apps using CopilotKit need a way to answer from private/custom
data instead of relying only on the model's built-in knowledge. This
example follows the same pattern as the existing Vercel AI SDK
integration and the
daytonacookbook example already in this repo.Testing
(once before final cleanup, once after) to confirm nothing broke
response grounding
work from a clean clone
Notes for reviewers
Structure mirrors
examples/cookbook/daytona/for consistency withother cookbook examples in the repo.