Documentation
¶
Index ¶
- Variables
- func NewConnectorHTTPClient(timeout time.Duration) *http.Client
- func SanitizeFileName(name string) string
- func ValidateConnectorBaseURL(rawURL string) error
- func ValidateSyncSchedule(schedule string) error
- type Connector
- type ConnectorMetadata
- type ConnectorRegistry
- type FullStreamingConnector
- type FullSyncWithCursor
- type PartialFetchError
- type Scheduler
- type StreamHandler
- type StreamingConnector
Constants ¶
This section is empty.
Variables ¶
var ( // Connector errors ErrConnectorNil = errors.New("connector is nil") ErrConnectorTypeEmpty = errors.New("connector type is empty") ErrConnectorNotFound = errors.New("connector type not found in registry") // DataSource errors ErrDataSourceNotFound = errors.New("data source not found") ErrDataSourceInvalid = errors.New("data source configuration is invalid") ErrDataSourceNotActive = errors.New("data source is not active") // Configuration errors ErrInvalidConfig = errors.New("invalid configuration") ErrInvalidCredentials = errors.New("invalid credentials") // Sync errors ErrSyncFailed = errors.New("sync operation failed") ErrSyncCanceled = errors.New("sync operation was canceled") ErrFetchFailed = errors.New("failed to fetch items from source") ErrResourceNotFound = errors.New("resource not found in source system") // Knowledge base errors ErrKnowledgeBaseNotFound = errors.New("knowledge base not found") // Sync log errors ErrSyncLogNotFound = errors.New("sync log not found") )
Error definitions for datasource operations
var ConnectorMetadataRegistry = map[string]ConnectorMetadata{ types.ConnectorTypeFeishu: { Type: types.ConnectorTypeFeishu, Name: "Feishu (飞书)", Description: "Sync documents, wikis, and content from Feishu", Priority: 0, AuthType: "oauth2", Capabilities: []string{"incremental", "deletion_sync"}, }, types.ConnectorTypeLark: { Type: types.ConnectorTypeLark, Name: "Lark", Description: "Sync documents, wikis, and content from Lark (Feishu international)", Priority: 0, AuthType: "oauth2", Capabilities: []string{"incremental", "deletion_sync"}, }, types.ConnectorTypeFeishuDrive: { Type: types.ConnectorTypeFeishuDrive, Name: "Feishu Drive (飞书云盘)", Description: "Sync documents and files from a Feishu Drive folder", Priority: 0, AuthType: "oauth2", Capabilities: []string{"incremental", "deletion_sync"}, }, types.ConnectorTypeLarkDrive: { Type: types.ConnectorTypeLarkDrive, Name: "Lark Drive", Description: "Sync documents and files from a Lark Drive folder", Priority: 0, AuthType: "oauth2", Capabilities: []string{"incremental", "deletion_sync"}, }, types.ConnectorTypeNotion: { Type: types.ConnectorTypeNotion, Name: "Notion", Description: "Sync pages and databases from Notion", Priority: 1, AuthType: "api_key", Capabilities: []string{"incremental"}, }, types.ConnectorTypeConfluence: { Type: types.ConnectorTypeConfluence, Name: "Confluence", Description: "Sync spaces and pages from Atlassian Confluence", Priority: 2, AuthType: "api_key", Capabilities: []string{"incremental", "deletion_sync"}, }, types.ConnectorTypeYuque: { Type: types.ConnectorTypeYuque, Name: "Yuque (语雀)", Description: "Sync knowledge bases and documents from Yuque", Priority: 3, AuthType: "api_key", Capabilities: []string{"incremental"}, }, types.ConnectorTypeIMA: { Type: types.ConnectorTypeIMA, Name: "Tencent IMA (ima.qq.com)", Description: "Sync knowledge bases and documents from Tencent IMA", Priority: 3, AuthType: "api_key", Capabilities: []string{"incremental", "deletion_sync"}, }, types.ConnectorTypeGitHub: { Type: types.ConnectorTypeGitHub, Name: "GitHub", Description: "Sync repositories, wikis, and issues from GitHub", Priority: 4, AuthType: "oauth2", Capabilities: []string{"incremental"}, }, types.ConnectorTypeGoogleDrive: { Type: types.ConnectorTypeGoogleDrive, Name: "Google Drive", Description: "Sync documents and files from Google Drive", Priority: 5, AuthType: "oauth2", Capabilities: []string{"incremental"}, }, types.ConnectorTypeOneDrive: { Type: types.ConnectorTypeOneDrive, Name: "OneDrive / SharePoint", Description: "Sync documents and files from Microsoft OneDrive", Priority: 6, AuthType: "oauth2", Capabilities: []string{"incremental"}, }, types.ConnectorTypeDingTalk: { Type: types.ConnectorTypeDingTalk, Name: "DingTalk (钉钉)", Description: "Sync online documents from DingTalk knowledge bases", Priority: 7, AuthType: "oauth2", Capabilities: []string{"incremental", "deletion_sync"}, }, types.ConnectorTypeWebCrawler: { Type: types.ConnectorTypeWebCrawler, Name: "Web Crawler (Sitemap)", Description: "Crawl websites via Sitemap.xml", Priority: 9, AuthType: "none", Capabilities: []string{}, }, types.ConnectorTypeSlack: { Type: types.ConnectorTypeSlack, Name: "Slack", Description: "Sync channel messages and files from Slack", Priority: 10, AuthType: "oauth2", Capabilities: []string{"incremental"}, }, types.ConnectorTypeIMAP: { Type: types.ConnectorTypeIMAP, Name: "Email (IMAP)", Description: "Sync email content from IMAP servers", Priority: 11, AuthType: "password", Capabilities: []string{}, }, types.ConnectorTypeRSS: { Type: types.ConnectorTypeRSS, Name: "RSS / Atom Feed", Description: "Sync articles from RSS/Atom feeds", Priority: 12, AuthType: "custom", Capabilities: []string{"incremental"}, }, types.ConnectorTypeGitLab: { Type: types.ConnectorTypeGitLab, Name: "GitLab", Description: "Sync files from GitLab projects", Priority: 8, AuthType: "token", Capabilities: []string{"incremental", "hierarchical"}, }, types.ConnectorTypeSeafile: { Type: types.ConnectorTypeSeafile, Name: "Seafile", Description: "Sync folders and files from Seafile libraries", Priority: 13, AuthType: "token", Capabilities: []string{"incremental", "hierarchical", "deletion_sync"}, }, }
GetConnectorMetadata returns metadata for all available connectors This is used by the frontend to display connector options
Functions ¶
func NewConnectorHTTPClient ¶
NewConnectorHTTPClient returns an HTTP client with redirect and dial-time SSRF guards.
func SanitizeFileName ¶
SanitizeFileName replaces filesystem-hostile punctuation and limits a source title to 200 bytes without splitting a UTF-8 rune. Empty titles use "untitled". Whitespace, control characters and extension handling remain the caller's policy; this helper does not validate filenames or repair malformed input.
func ValidateConnectorBaseURL ¶
ValidateConnectorBaseURL checks a connector API base URL against the SSRF policy. Empty rawURL is allowed; callers apply their own default before issuing requests.
func ValidateSyncSchedule ¶
ValidateSyncSchedule accepts the same syntax as the scheduler. An empty schedule disables automatic sync and remains valid for manual-only sources.
Types ¶
type Connector ¶
type Connector interface {
// Type returns the connector type identifier (e.g., "feishu", "notion")
Type() string
// Validate verifies that the provided configuration is valid by testing connectivity
// and checking credentials. Returns error if validation fails.
Validate(ctx context.Context, config *types.DataSourceConfig) error
// ListResources lists available resources that can be synced (documents, spaces, folders, etc.)
// Returns a list of Resource objects that the user can select for syncing.
//
// parentID controls lazy (on-demand) loading of hierarchical resources:
// - parentID == "" → return the top-level resources (e.g. Feishu wiki spaces).
// - parentID != "" → return only the direct children of that resource.
// Connectors whose listing is already flat or returns the full tree in a single
// call may ignore parentID for the root call and return an empty slice for any
// non-empty parentID.
ListResources(ctx context.Context, config *types.DataSourceConfig, parentID string) ([]types.Resource, error)
// ResolveResourceAncestors resolves, for each of the given resource IDs, the
// ExternalIDs of every ancestor whose direct children must be loaded so a
// lazily-loaded picker can reveal a pre-existing (possibly deeply nested)
// selection. The returned set is deduplicated and unordered.
//
// It exists so connectors that load their tree one level at a time (e.g. the
// Feishu wiki) can expose, in O(depth) per selection, the path back to the
// root without re-traversing the whole tree. Connectors that already return
// the full tree (Notion) or a flat list (Yuque) have nothing to reveal and
// return an empty slice.
ResolveResourceAncestors(
ctx context.Context, config *types.DataSourceConfig, resourceIDs []string,
) ([]string, error)
// FetchAll performs a full sync of the specified resources.
// Returns all items from the given resource IDs.
FetchAll(ctx context.Context, config *types.DataSourceConfig, resourceIDs []string) ([]types.FetchedItem, error)
// FetchIncremental performs an incremental sync based on the provided cursor.
// Returns items that have changed since the last sync, a new cursor for the next sync,
// and an error if the operation fails.
FetchIncremental(ctx context.Context, config *types.DataSourceConfig, cursor *types.SyncCursor) ([]types.FetchedItem, *types.SyncCursor, error)
}
Connector is the interface that all external data source connectors must implement. Each connector (Feishu, Notion, Confluence, etc.) provides an implementation of this interface.
type ConnectorMetadata ¶
type ConnectorMetadata struct {
Type string `json:"type"`
Name string `json:"name"`
Description string `json:"description"`
Icon string `json:"icon,omitempty"`
Priority int `json:"priority"` // Priority order for UI display (lower = higher priority)
AuthType string `json:"auth_type"` // "oauth2", "api_key", "token", etc.
Capabilities []string `json:"capabilities"` // "incremental", "webhook", "deletion_sync", etc.
}
ConnectorMetadata provides metadata about available connectors
func ListAvailableConnectors ¶
func ListAvailableConnectors() []ConnectorMetadata
ListAvailableConnectors returns all available connector metadata sorted by priority
type ConnectorRegistry ¶
type ConnectorRegistry struct {
// contains filtered or unexported fields
}
ConnectorRegistry manages the registration and lookup of available connectors
func NewConnectorRegistry ¶
func NewConnectorRegistry() *ConnectorRegistry
NewConnectorRegistry creates a new connector registry
func (*ConnectorRegistry) Get ¶
func (r *ConnectorRegistry) Get(connectorType string) (Connector, error)
Get retrieves a connector by type
func (*ConnectorRegistry) List ¶
func (r *ConnectorRegistry) List() []string
List returns all registered connector types
func (*ConnectorRegistry) Register ¶
func (r *ConnectorRegistry) Register(connector Connector) error
Register registers a connector with the registry
type FullStreamingConnector ¶
type FullStreamingConnector interface {
StreamingConnector
FetchFullStream(
ctx context.Context, config *types.DataSourceConfig,
cursor *types.SyncCursor, h StreamHandler,
) (*types.SyncCursor, error)
}
FullStreamingConnector lets a streaming connector re-fetch every item while retaining the previous cursor exclusively for safe deletion reconciliation.
type FullSyncWithCursor ¶
type FullSyncWithCursor interface {
FetchAllFromCursor(
ctx context.Context,
config *types.DataSourceConfig,
resourceIDs []string,
cursor *types.SyncCursor,
) ([]types.FetchedItem, *types.SyncCursor, error)
}
FullSyncWithCursor is optional. The batch sync path uses it for ForceFull and sync_mode=full so a connector can re-fetch every document while still reconciling deletions against the previous cursor. Connectors that omit it keep FetchAll's no-cursor behaviour and therefore cannot emit deletions on a full sync.
type PartialFetchError ¶
type PartialFetchError struct {
Details []string
}
PartialFetchError indicates that some resources were fetched successfully but others failed. The caller should process Items (if any), persist an updated cursor when provided, and surface Details to the user as a partial sync.
func (*PartialFetchError) Error ¶
func (e *PartialFetchError) Error() string
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler manages cron-based periodic sync for data sources.
robfig/cron fires at absolute wall-clock times (e.g. "0 0 * * * *" always fires at the top of every hour regardless of when the process started). So multiple instances will fire at the same moment. Dedup is handled by two layers:
- HasRunningSync — if a previous sync is still running, skip (prevent overlap).
- asynq.TaskID — deterministic ID per (dataSourceID, minute). Redis ensures only one task with a given ID is enqueued. Losers get ErrTaskIDConflict.
func NewScheduler ¶
func NewScheduler( dsRepo interfaces.DataSourceRepository, syncLogRepo interfaces.SyncLogRepository, taskEnqueuer interfaces.TaskEnqueuer, ) *Scheduler
NewScheduler creates a new Scheduler.
func (*Scheduler) AddOrUpdate ¶
func (s *Scheduler) AddOrUpdate(ds *types.DataSource) error
AddOrUpdate registers (or re-registers) a cron entry for the given data source.
func (*Scheduler) EntryCount ¶
EntryCount returns the number of active cron entries (for testing/monitoring).
func (*Scheduler) Start ¶
Start loads all active data sources from the database and registers their cron schedules. Then starts the cron runner in the background.
func (*Scheduler) Stop ¶
func (s *Scheduler) Stop()
Stop gracefully stops the cron runner and waits for running jobs to finish.
func (*Scheduler) StopWithin ¶
StopWithin is Stop with a bound. timeout <= 0 waits until in-flight jobs finish. A positive timeout lets shutdown continue so one long sync cannot hold every later cleanup hook, including child-process reaping.
type StreamHandler ¶
type StreamHandler interface {
// Emit ingests a single fetched item. Returning an error aborts the
// stream: the connector stops fetching and propagates the error, since a
// failed ingest means the sync is failing and further API calls are wasted.
Emit(ctx context.Context, item types.FetchedItem) error
// Checkpoint persists the cursor reached so far. The cursor is only valid
// for the duration of the call (the connector may keep mutating its backing
// maps afterwards), so implementations must serialize it synchronously.
//
// The cursor MUST be a complete resumable snapshot, not a delta: resuming
// from it must reproduce all progress so far. This is what lets the service
// treat a checkpoint as a safe restart point and, for a full sync, drop the
// prior baseline without losing already-synced state.
Checkpoint(ctx context.Context, cursor *types.SyncCursor) error
}
StreamHandler receives items and progress checkpoints emitted during a streaming fetch. The service implements it to ingest each item as it arrives (bounding memory to one item instead of the whole wiki) and to persist the connector cursor at page boundaries, so a sync that times out mid-traversal resumes from the last checkpoint instead of restarting from scratch (Tencent/WeKnora#2136).
type StreamingConnector ¶
type StreamingConnector interface {
Connector
// FetchStream walks the configured resources starting from cursor (nil =
// from the beginning / full sync), calling h.Emit for each changed item and
// h.Checkpoint at page boundaries. It returns the final cursor for the next
// sync. Nodes already recorded in cursor at their current edit time are
// skipped, which is what makes a resumed sync converge.
FetchStream(
ctx context.Context, config *types.DataSourceConfig,
cursor *types.SyncCursor, h StreamHandler,
) (*types.SyncCursor, error)
}
StreamingConnector is an optional interface. Connectors that implement it let the service interleave fetch→ingest→checkpoint so a large sync persists incrementally and resumes after a timeout, rather than holding every item in memory and losing all progress on retry. Connectors that do not implement it fall back to FetchAll / FetchIncremental unchanged.
Directories
¶
| Path | Synopsis |
|---|---|
|
connector
|
|
|
confluence
Package confluence imports Confluence Server/Data Center and Cloud spaces as Markdown.
|
Package confluence imports Confluence Server/Data Center and Cloud spaces as Markdown. |
|
dingtalk
Package dingtalk implements the DingTalk document data source connector.
|
Package dingtalk implements the DingTalk document data source connector. |
|
feishu/core
Package feishu implements the Feishu (飞书/Lark) data source connector for WeKnora.
|
Package feishu implements the Feishu (飞书/Lark) data source connector for WeKnora. |
|
ima
Package ima implements the WeKnora data source connector for Tencent IMA (ima.qq.com), syncing documents and files out of IMA knowledge bases via the /openapi/wiki/v1 OpenAPI.
|
Package ima implements the WeKnora data source connector for Tencent IMA (ima.qq.com), syncing documents and files out of IMA knowledge bases via the /openapi/wiki/v1 OpenAPI. |
|
notion
Package notion implements the Notion data source connector for WeKnora.
|
Package notion implements the Notion data source connector for WeKnora. |
|
rss
Package rss implements the RSS/Atom data source connector for WeKnora.
|
Package rss implements the RSS/Atom data source connector for WeKnora. |
|
seafile
Package seafile implements the WeKnora data source connector for Seafile Server (community edition 10.0.1, api2).
|
Package seafile implements the WeKnora data source connector for Seafile Server (community edition 10.0.1, api2). |
|
yuque
Package yuque implements the Yuque (语雀) data source connector for WeKnora.
|
Package yuque implements the Yuque (语雀) data source connector for WeKnora. |