Background
The Xpert AI plugin system allows developers to extend platform functionality via plugins. Using Lark Docs as an example, we aim to achieve the following scenarios:- System Integration: Connect Lark app credentials such as AppID and AppSecret for authentication.
- Document Loading: Retrieve document content from Lark folders or document APIs.
- Knowledge Management: Convert documents into structured content usable by Xpert AI’s knowledge base and agents.
- Extension Strategies: Implement extension points for integration, document sources, and document transformation via strategy interfaces.
1. Clone the Plugin Template
We provide a starter template for plugin development to quickly build new plugins:nx to create a new plugin library. Here, packages/lark is the plugin code directory, and @xpert-ai/plugin-lark is the npm package name:
✅ This generates a plugin named @xpert-ai/plugin-lark that will handle all Lark Docs integration features.
2. Plugin Entry Code
The plugin entry code mainly includes meta info, config, and lifecycle functions (register/onStart/onStop).Key Points
- meta: Defines basic plugin info (name, version, category, keywords, etc.).
- config: Describes the plugin config schema, allowing users to input config in the UI (reserved for future use).
- register: Registers
LarkModule, mounting the plugin to the NestJS module system. - onStart/onStop: Plugin lifecycle callbacks.
3. NestJS Module Structure
The plugin is essentially a NestJS module (LarkModule), which registers various strategy classes, controllers, or services.
✅ TheStrategyclasses are extension points, for example:
LarkIntegrationStrategy: Handles integration with the Lark system.LarkSourceStrategy: Defines how to load documents from Lark.LarkDocTransformerStrategy: Defines how to transform documents into a format usable by the knowledge base.
4. API Interfaces
Controllers expose the plugin’s REST APIs. For example, testing the Lark connection./lark/test endpoint (currently the default path for testing integration connectivity, will be unified later), the system validates the configuration (checks if AppID/AppSecret are valid).
5. Plugin Extension Points
5.1 System Integration Extension
System integration strategyLarkIntegrationStrategy handles Lark app credential validation and bot info retrieval.
Key logic:
✅ Here, LarkClient wraps Lark OpenAPI requests.
5.2 Document Source Extension
Document source strategyLarkSourceStrategy defines how to fetch document lists from Lark.
- Config params: folder token, document type (docx/sheet/file, etc.).
- Loading logic: Calls
client.listDriveFiles(folderToken), returnsDocument[].
5.3 Document Transformation Extension
Document transformation strategyLarkDocTransformerStrategy defines how to convert document content into knowledge base entries.
- Calls Lark API to get document body.
- Splits body into
Documentobjects (for vectorization). - Outputs in
IKnowledgeDocumentformat.
5.4 Client Wrapper
All API requests are wrapped byLarkClient, which unifies @larksuiteoapi/node-sdk functionality and provides methods like:
getBotInfo()Get bot infolistDriveFiles(folderToken)List folder contentsgetDocumentContent(docToken)Get document bodygetAllDocsInFolder(folderToken)Recursively get all documents
6. Development Workflow Summary
- Prepare template: Clone the plugin template and generate the project.
- Write entry code: Define plugin meta, config, and lifecycle.
-
Build module: Register controllers and strategy classes in
LarkModule. -
Implement strategies:
- Integration strategy: Handle AppID/Secret validation.
- Source strategy: Fetch documents from Lark.
- Transformation strategy: Convert documents to knowledge base content.
- Wrap client: Manage Lark API calls in a unified way.
-
Test API: Use
/lark/testto verify integration.
7. Build, Release, and npm Publish Workflow
After developing the@xpert-ai/plugin-lark plugin, you can use Nx’s build and release toolchain to build and publish it to npm. The process includes:
7.1 Build the Plugin
Run the build command:-
This uses Nx’s builder (TypeScript compiler
tscby default) to compile source code to JavaScript. -
Build output goes to:
-
The output directory contains the publishable artifacts (
index.js, type declarations.d.ts, etc.).
7.2 Version Management
To ensure proper npm package iteration, maintain the plugin version number. It’s recommended to use Nx’s release workflow for automatic version management:Auto bump version
patch: Patch version (e.g. 1.0.0 → 1.0.1)minor: Minor version (e.g. 1.0.0 → 1.1.0)major: Major version (e.g. 1.0.0 → 2.0.0)
- Update the
versioninpackage.json. - Update
CHANGELOG.md. - Generate the corresponding Git tag.
If not usingnx release, you can manually edit theversionfield inpackage.json.
7.3 Publish to npm
After building and bumping the version, run the publish command:--access publicSpecifies the package as public (suitable for packages under the@xpert-ainpm scope).--otp=<code>If your npm account has 2FA enabled, enter a one-time password (OTP).
⚠️ Before publishing, make sure the following fields inpackage.jsonare correct:
main: Points to the build output entry, e.g."dist/index.js"types: Points to type declarations, e.g."dist/index.d.ts"files: Only includes files to be published (e.g."dist/**/*")publishConfig: Can define default publish access (e.g."access": "public")
7.4 Final Workflow Example
Summing up, the full workflow to publish@xpert-ai/plugin-lark is:
@xpert-ai/plugin-lark version on npm. 🎉
8. Final Usage
After plugin development, you can use it in the Xpert AI platform to:- Configure Lark AppID/AppSecret
- Select document folders and types
- Automatically load Lark Docs content
- Convert documents into knowledge base entries, supporting AI conversations and agent analysis