feat(collections): create studio collections for AI if detected#3709
feat(collections): create studio collections for AI if detected#3709
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
📝 WalkthroughWalkthroughAdds automatic nuxt-studio configuration when the Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/utils/config.ts (1)
68-78:⚠️ Potential issue | 🟠 MajorPreserve the default content collection when auto-adding the studio collection.
Because
resolveStudioCollection()runs beforehasNoCollections, a project with no user-defined collections but AI enabled will end up with only the studio collection—skipping both the default content collection and the warning. That changes existing behavior and can break content indexing.✅ Suggested fix (keep default content + studio when no user collections exist)
- // If nuxt-studio is installed, automatically configure studio collection - if (hasNuxtModule('nuxt-studio')) { - resolveStudioCollection(nuxt, collectionsConfig) - } - - const hasNoCollections = Object.keys(collectionsConfig || {}).length === 0 - if (hasNoCollections) { + const hasUserCollections = Object.keys(collectionsConfig || {}).length > 0 + + // If nuxt-studio is installed, automatically configure studio collection + if (hasNuxtModule('nuxt-studio')) { + resolveStudioCollection(nuxt, collectionsConfig) + } + + if (!hasUserCollections) { logger.warn('No content configuration found, falling back to default collection. In order to have full control over your collections, create the config file in project root. See: https://content.nuxt.com/docs/getting-started/installation') } - const collections = resolveCollections(hasNoCollections ? defaultConfig.collections : collectionsConfig) + const collections = resolveCollections( + !hasUserCollections + ? { ...defaultConfig.collections, ...collectionsConfig } + : collectionsConfig, + )
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@src/utils/config.ts`:
- Around line 73-79: finalCollectionsConfig currently aliases the module-level
defaultConfig.collections when hasNoCollections is true, and
resolveStudioCollection mutates it; to fix, ensure you create a fresh copy of
the default collections before any mutation: when hasNoCollections is true,
clone defaultConfig.collections into a new object (deep clone via
structuredClone or a utility) and assign that to finalCollectionsConfig, then
call resolveStudioCollection(nuxt, finalCollectionsConfig) and
resolveCollections(finalCollectionsConfig) so the module-level
defaultConfig.collections is never mutated by resolveStudioCollection.
- Around line 73-77: The call to hasNuxtModule currently relies on global
context; update the check to pass the available nuxt instance as the second
argument so it uses the local Nuxt context. Specifically, change the condition
that checks hasNuxtModule(...) to call hasNuxtModule('nuxt-studio', nuxt) so the
local nuxt is used when deciding whether to call
resolveStudioCollection(finalCollectionsConfig, ...) (reference symbols:
hasNuxtModule, nuxt, finalCollectionsConfig, resolveStudioCollection).
🔗 Linked issue
❓ Type of change
📚 Description
Adds automatic detection and configuration of Studio AI context collections when
nuxt-studiois installed.What it does
When Nuxt Studio is installed with AI features enabled (
studio.ai.apiKeyconfigured), the Content module automatically:studiocollection for AI context files (configurable viastudio.ai.context.collection).studio/**files from all other collections to prevent conflicts{ rawbody: string }for storing raw markdown contextImplementation
src/utils/studio.ts- ContainsresolveStudioCollection()utilitysrc/utils/config.ts- Detectsnuxt-studioand applies configuration during collection loadingConfiguration
Studio module can configure the collection:
📝 Checklist