Skip to content

Conversation

@0xbbjoker
Copy link
Contributor

@0xbbjoker 0xbbjoker commented Oct 23, 2025

Note

Introduce a configurable plugin factory with core and headless modes, update docs and programmatic usage, add export tests, and bump version.

  • Core/API:
    • Add createKnowledgePlugin(config) with flags: enableUI, enableRoutes, enableActions, enableTests.
    • Provide preconfigured exports: knowledgePlugin (full), knowledgePluginHeadless, knowledgePluginCore.
    • Keep default export to knowledgePlugin; explicitly export KnowledgeService and knowledgeProvider.
  • Docs:
    • Add installation modes (Full, Headless, Core) and custom configuration examples.
    • Update programmatic usage (service retrieval via runtime.getService, getKnowledge usage, UUID handling, agentId-scoped IDs) and add cloud runtime example.
  • Tests:
    • New __tests__/plugin-exports.test.ts validating exports and configuration behaviors.
  • Version:
    • Bump package version to 1.5.12.

Written by Cursor Bugbot for commit fee53ba. This will update automatically on new commits. Configure here.

Summary by CodeRabbit

  • New Features

    • Added multiple plugin installation modes: Full, Headless, Core, and Custom Configuration variants for flexible deployment scenarios.
    • Introduced configurable plugin factory enabling selective feature toggles (UI, routes, actions, tests).
  • Documentation

    • Expanded README with installation mode examples and cloud/custom runtime usage guide.
  • Tests

    • Added comprehensive plugin variant and export verification tests.
  • Chores

    • Version bump to 1.5.12.

@coderabbitai
Copy link

coderabbitai bot commented Oct 23, 2025

Walkthrough

This PR introduces a configurable plugin factory pattern enabling multiple deployment variants. Three preset configurations are added (Full, Headless, Core) with toggleable features for UI, routes, actions, and tests. Documentation is expanded to explain installation modes and usage across deployment scenarios.

Changes

Cohort / File(s) Summary
Plugin Factory & Presets
src/index.ts
Introduced KnowledgePluginConfig interface with feature toggles (enableUI, enableRoutes, enableActions, enableTests). Added createKnowledgePlugin() factory function. Replaced static plugin with three presets: knowledgePluginCore (minimal), knowledgePluginHeadless (service + actions), knowledgePlugin (full default). Updated exports to include factory, presets, KnowledgeService, knowledgeProvider, and types.
Plugin Export Tests
__tests__/plugin-exports.test.ts
New test file verifying availability and shape of exported plugin variants, factory function behavior with custom configurations, KnowledgeService and knowledgeProvider exports, and feature toggle assertions across plugin presets.
Documentation
README.md
Added Installation Modes section with Full, Headless, Core, and Custom Configuration examples. Updated usage examples referencing knowledge plugin modes and clarified default behaviors. Introduced Cloud/Custom Runtime Usage section. Updated agent-scoped identifiers and context field mappings.
Version Metadata
package.json
Bumped version from 1.5.11 to 1.5.12.

Sequence Diagram

sequenceDiagram
    participant User
    participant Factory as createKnowledgePlugin()
    participant Plugin
    participant Features as Conditional Features

    User->>Factory: Call with config (enableUI, enableRoutes, etc.)
    Factory->>Plugin: Create base Plugin instance
    
    alt enableUI = true
        Factory->>Features: Attach UI routes
        Features->>Plugin: Add routes
    end
    
    alt enableActions = true
        Factory->>Features: Attach actions
        Features->>Plugin: Add actions
    end
    
    alt enableTests = true
        Factory->>Features: Attach test suite
        Features->>Plugin: Add tests
    end
    
    Factory->>User: Return configured Plugin
    
    Note over User,Plugin: Presets created via factory:<br/>- knowledgePluginCore (all features off)<br/>- knowledgePluginHeadless (actions on)<br/>- knowledgePlugin (all features on)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

The primary complexity lies in src/index.ts with the introduction of the factory pattern and conditional feature attachment logic. The corresponding test coverage in __tests__/plugin-exports.test.ts is comprehensive but follows a consistent pattern. Documentation updates are straightforward. Review requires verification of factory correctness, preset configurations, export correctness, and alignment between factory behavior and test assertions.

Poem

🐰 Hoppy plugins, modular and free,
Three flavors configured with glee—
Full or headless or core so sleek,
A factory makes it unique each week,
Toggle and test the knowledge we seek!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "feat: add flexible deployment modes for different environments" accurately captures the core objective of this changeset. The main code changes in src/index.ts introduce a configurable KnowledgePluginConfig interface and createKnowledgePlugin factory function that enable users to create plugin variants tailored to different deployment scenarios: knowledgePluginCore for cloud-only environments, knowledgePluginHeadless for service-based deployments, and the full knowledgePlugin for complete functionality. The README updates further reinforce this by documenting Installation Modes (Full, Headless, Core, and Custom) and their respective use cases. The title is specific, clear, and directly reflects the primary change—introducing pluggable configuration to support flexible deployment across different environments.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/plugin-knowledge-deployment-modes

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cursor
Copy link

cursor bot commented Oct 23, 2025

Bug: README UUID Example Error

The README.md examples for addKnowledge incorrectly show clientDocumentId: '' as UUID. An empty string isn't a valid UUID, which could lead to type or runtime errors for users. This is further complicated by a conflicting comment suggesting the ID is auto-generated.

Additional Locations (1)

Fix in Cursor Fix in Web

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (4)
README.md (3)

72-83: Clarify plugin registration: string vs object.

Explicitly note both supported forms to avoid confusion:

  • String form (auto‑loader): '@elizaos/plugin-knowledge'
  • Object form (direct import): knowledgePlugin

Add a short note like: “You can register by package name (string) or by importing the plugin object. Both are supported.”


146-151: Tighten wording about API keys/providers.

“ No environment variables or API keys needed.” can mislead—an AI provider plugin (OpenAI/Anthropic/Google/OpenRouter) and its keys are required for embeddings.

Suggest: “No additional keys beyond your existing AI provider plugin. Ensure at least one AI provider plugin is configured with a valid API key.”


254-286: Programmatic example: avoid '' as UUID casts; show omit/auto‑gen.

Use an optional field or explicit undefined instead of a cast.

-const result = await knowledgeService.addKnowledge({
-  agentId: runtime.agentId,
-  clientDocumentId: '' as UUID, // Auto-generated based on content
+const result = await knowledgeService.addKnowledge({
+  agentId: runtime.agentId,
+  // Omit to auto-generate:
+  // clientDocumentId: undefined,
   content: documentContent,
   contentType: 'application/pdf',
   originalFilename: 'document.pdf',
   worldId: runtime.agentId,
   roomId: runtime.agentId,
   entityId: runtime.agentId,

Optionally add an import hint for types if needed: import type { UUID } from '@elizaos/core';.

src/index.ts (1)

67-78: Eager imports prevent tree-shaking; optional refactors recommended for bundle optimization.

Routes, actions, and tests are imported statically at module load (lines 10–12), so bundlers include them regardless of configuration. Even with knowledgePluginCore, these modules ship in the bundle. Conditional checks at runtime (lines 80, 88, 93) don't prevent their inclusion.

Consider one of these refactors when optimizing bundle size:

  • Lazy import inside the factory (requires async createKnowledgePlugin and dynamic import('./routes'), import('./actions'), import('./tests')).
  • Separate build entrypoints (core/headless/full) with "sideEffects": false in package.json for tree‑shaking.
  • Move tests behind a separate export to exclude them from default variants.

Also applies to: 79–86, 92–96, 100–121, 122–132, 146–147

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 33680de and fee53ba.

📒 Files selected for processing (4)
  • README.md (3 hunks)
  • __tests__/plugin-exports.test.ts (1 hunks)
  • package.json (1 hunks)
  • src/index.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Cursor Bugbot
🔇 Additional comments (3)
package.json (2)

49-65: Add Vite to devDependencies; proposed patch is redundant.

Vite is genuinely missing and will cause build failures. However, the proposed patch is incorrect:

  • tsup.config.ts already has clean: false and dts: true, so the --dts --no-clean flags in the patch are redundant.
  • vite.config.ts already has emptyOutDir: false, so the separate outDir suggestion is unnecessary.
  • Both tools are configured to coexist in the same dist directory without clobbering each other.

Required fix:

  "devDependencies": {
+   "vite": "^5.4.10",

No build script changes are needed; the existing config files already handle the output correctly.

Likely an incorrect or invalid review comment.


26-28: Add "sideEffects": false to enable tree-shaking, but do not move react/react-dom to peerDependencies.

The core library code (src/*.ts) has no React imports—React is only used in src/frontend/ which is not bundled. Consumers using enableUI: false already get a headless plugin. Moving react to peerDependencies would break existing consumers (including the default case where enableUI=true) and introduce a breaking change. The current architecture already supports headless usage; sideEffects: false alone is sufficient to let bundlers optimize.

__tests__/plugin-exports.test.ts (1)

1-1: Bun is available in CI, but tests are not run before publishing.

The CI workflow explicitly sets up Bun (oven-sh/setup-bun@v2) and uses it for installation and building. However, no test step exists in the workflow before the package is published to npm. Tests in __tests__/ import from bun:test, but CI never invokes them. Either:

  • Add a test step before publishing (e.g., run: bun test or run: elizaos test), or
  • Confirm that tests are validated elsewhere (e.g., in a separate PR workflow) before merging to 1.x

Comment on lines +2 to +11
import {
knowledgePlugin,
knowledgePluginCore,
knowledgePluginHeadless,
createKnowledgePlugin,
KnowledgeService,
knowledgeProvider,
type KnowledgePluginConfig,
} from '../src/index';

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove unused type import and add a default export parity test.

  • Drop the unused KnowledgePluginConfig type import.
  • Add a quick check that the default export equals the named knowledgePlugin.
-import {
-  knowledgePlugin,
-  knowledgePluginCore,
-  knowledgePluginHeadless,
-  createKnowledgePlugin,
-  KnowledgeService,
-  knowledgeProvider,
-  type KnowledgePluginConfig,
-} from '../src/index';
+import knowledgeDefault, {
+  knowledgePlugin,
+  knowledgePluginCore,
+  knowledgePluginHeadless,
+  createKnowledgePlugin,
+  KnowledgeService,
+  knowledgeProvider,
+} from '../src/index';
@@
 describe('Knowledge Plugin Exports', () => {
+  it('default export equals named knowledgePlugin', () => {
+    expect(knowledgeDefault).toBe(knowledgePlugin);
+  });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import {
knowledgePlugin,
knowledgePluginCore,
knowledgePluginHeadless,
createKnowledgePlugin,
KnowledgeService,
knowledgeProvider,
type KnowledgePluginConfig,
} from '../src/index';
import knowledgeDefault, {
knowledgePlugin,
knowledgePluginCore,
knowledgePluginHeadless,
createKnowledgePlugin,
KnowledgeService,
knowledgeProvider,
} from '../src/index';
describe('Knowledge Plugin Exports', () => {
it('default export equals named knowledgePlugin', () => {
expect(knowledgeDefault).toBe(knowledgePlugin);
});
🤖 Prompt for AI Agents
In __tests__/plugin-exports.test.ts around lines 2 to 11, remove the unused
named type import "KnowledgePluginConfig" from the import list and add a small
parity test that asserts the module's default export is equal to the named
export "knowledgePlugin"; update imports accordingly (drop the type) and append
a test (e.g., expect(require('../src').default).toBe(knowledgePlugin) or import
default and compare) to validate default export equality.

Comment on lines +57 to +66
* @example
* // Browser-only mode (no routes)
* const plugin = createKnowledgePlugin({
* enableRoutes: false,
* });
*
* @example
* // Full mode (default)
* const plugin = createKnowledgePlugin();
*/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fix the “Browser‑only mode (no routes)” example.

With defaults, enableUI is true, so routes will still be attached due to (enableUI || enableRoutes). Update the example label and options:

- * @example
- * // Browser-only mode (no routes)
- * const plugin = createKnowledgePlugin({
- *   enableRoutes: false,
- * });
+ * @example
+ * // Headless (no UI, no routes)
+ * const plugin = createKnowledgePlugin({
+ *   enableUI: false,
+ *   enableRoutes: false,
+ * });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
* @example
* // Browser-only mode (no routes)
* const plugin = createKnowledgePlugin({
* enableRoutes: false,
* });
*
* @example
* // Full mode (default)
* const plugin = createKnowledgePlugin();
*/
* @example
* // Headless (no UI, no routes)
* const plugin = createKnowledgePlugin({
* enableUI: false,
* enableRoutes: false,
* });
*
* @example
* // Full mode (default)
* const plugin = createKnowledgePlugin();
*/
🤖 Prompt for AI Agents
In src/index.ts around lines 57 to 66, the example labeled "Browser-only mode
(no routes)" is incorrect because enableUI defaults to true and routes are
attached when (enableUI || enableRoutes); update the example label and options
so both UI and routes are disabled — e.g., change the comment to "Browser-only
mode (no UI, no routes)" and pass { enableUI: false, enableRoutes: false } in
the createKnowledgePlugin call.

@0xbbjoker 0xbbjoker merged commit 13426d3 into 1.x Oct 23, 2025
2 checks passed
@0xbbjoker 0xbbjoker deleted the feat/plugin-knowledge-deployment-modes branch October 23, 2025 15:20
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.

1 participant