Skip to main content
LarkSourceStrategy is mainly responsible for document source loading logic—fetching folders and document data from the Lark Docs API, and converting them into unified Document objects for use in knowledge base / AI vectorization. Full code below (imports omitted):

1. Class Declaration & Decorators

  • @DocumentSourceStrategy(LarkName)
    Registers this class as a document source strategy with provider name LarkName (“lark”).
    The Xpert AI system will automatically detect and invoke it.
  • @Injectable()
    Allows the class to be injected (standard NestJS usage).
  • Implements interface: IDocumentSourceStrategy<LarkDocumentsParams>
    Ensures the class provides required methods like validateConfig, loadDocuments, etc.

2. Permission Definition

Explanation:
  • The plugin requires access to Lark integration info (AppID, Secret, etc.) at runtime.
  • The system checks if the user has authorized the plugin to access Lark.

3. Metadata Definition

  • name/category: Identifies this as an online document source.
  • label: UI display name (English/Chinese).
  • configSchema: Defines user-configurable parameters:
    • folderToken: Folder token (required).
    • types: Array of document types to load, default is docx.
  • icon: Plugin icon for UI display.

4. Config Validation

  • Checks if folderToken is present.
  • Throws an error if the folder token is not configured.

5. Document Loading Method

Logic steps:
  1. Check for integration info; throw error if missing.
  2. Validate config (must have folderToken).
  3. Initialize LarkClient, call listDriveFiles(folderToken) to get folder contents.
  4. Filter documents by types.
  5. Convert each document to a LangChain Document object:
    • id: document token
    • pageContent: document title and URL
    • metadata: extra info (token, title, url, creation time)
✅ The output is a list of documents, each containing basic info and link only.

6. Single Document Loading

Purpose:
  • Further loads the full content of a single document when needed.
  • Uses getDocumentContent(docToken) to fetch the complete document content.
  • Returns a new Document object with pageContent as the document body.

7. Design Summary

  • permissions: Declares dependency on Lark integration permissions.
  • meta: Provides UI config schema, defines folderToken and document types input.
  • validateConfig: Ensures config is valid.
  • loadDocuments: Gets document list from folder, generates document summary.
  • loadDocument: Loads full content of a single document as needed.
The overall logic converts Lark Drive API data structures into LangChain Document objects, preparing them for downstream AI knowledge base processing.