Files
knowledge-governance/internal/governance/source_catalog.go
T
姚章浩 63f3b2c503 feat(governance): policy-driven ingestion from catalog annotations
Annotation in 来源与目录 is now the only import decision surface:
- migration 000033: catalog_import_intents (durable, rescan-proof per-file
  intent with locator snapshot + fetch lifecycle), source_items.policy_state,
  planned publication state, ui_setting_revisions.ingestion_concurrency
- marking fans a folder decision out to per-file intents, materializes
  versioned items, reuses already-verified local bytes (compare, don't pull),
  and plans one publication per routed KB; blocked retires planned rows
  while live publications stay untouched (需下架 shows in the KB diff)
- artifact.fetch worker lane (scripts/artifact_fetch.py): DingTalk export
  tree/live box API, AList /api/fs/get direct download with SSO-redirect
  fail-closed, PP ledger via locator hash; content-level dedupe on sha256
- 开始处理 promotes planned->pending inside the claim-time concurrency budget
  from system settings; claims enforce it in SQL
- monitor overview rebuilt as knowledge-base diff: planned/needs_removal per
  KB + fetch pipeline summary; frontend lanes 待入库/需下架 replace the
  deprecated snapshot change-set confirmation
- spool: images (png/jpg/gif/bmp/webp) accepted, ppt/pptx rejected in favour
  of PDF twins; DingTalk PPT resolves its converted PDF pair
2026-09-30 10:54:07 +08:00

169 lines
5.8 KiB
Go

package governance
import "time"
type CatalogSource struct {
ConnectionID string `json:"connection_id"`
SourceType SourceType `json:"source_type"`
Name string `json:"name"`
RootNodeID string `json:"root_node_id"`
FolderCount int `json:"folder_count"`
FileCount int `json:"file_count"`
ObservedAt time.Time `json:"observed_at"`
SnapshotOnly bool `json:"snapshot_only"`
SnapshotStatus string `json:"snapshot_status"`
LastRefreshDurationMS int64 `json:"last_refresh_duration_ms"`
}
type CatalogBreadcrumb struct {
NodeID string `json:"node_id"`
Name string `json:"name"`
}
type CatalogNode struct {
NodeID string `json:"node_id"`
ParentNodeID string `json:"parent_node_id,omitempty"`
NodeType string `json:"node_type"`
Name string `json:"name"`
DirectChildCount int `json:"direct_child_count"`
SubtreeFileCount int `json:"subtree_file_count"`
SubtreeBytes int64 `json:"subtree_bytes"`
SizeBytes *int64 `json:"size_bytes,omitempty"`
ModifiedAt *time.Time `json:"modified_at,omitempty"`
ContentSHA256 *string `json:"content_sha256,omitempty"`
Visibility string `json:"visibility"`
ImportedCount int `json:"imported_count"`
ParsedCount int `json:"parsed_count"`
ActiveCount int `json:"active_count"`
FailedCount int `json:"failed_count"`
RoutableCount int `json:"routable_count"`
}
type CatalogNodeFilter struct {
ConnectionID string
ParentNodeID string
Limit int
Offset int
}
type CatalogNodePage struct {
Current CatalogNode `json:"current"`
Breadcrumbs []CatalogBreadcrumb `json:"breadcrumbs"`
Items []CatalogNode `json:"items"`
Total int `json:"total"`
Limit int `json:"limit"`
Offset int `json:"offset"`
}
type CatalogSnapshot struct {
SnapshotID string `json:"snapshot_id"`
ConnectionID string `json:"connection_id"`
RootNodeID string `json:"root_node_id"`
SourceName string `json:"source_name"`
NodeCount int `json:"node_count"`
FolderCount int `json:"folder_count"`
FileCount int `json:"file_count"`
ObservedAt time.Time `json:"observed_at"`
CreatedAt time.Time `json:"created_at"`
IsHead bool `json:"is_head"`
}
type CatalogSnapshotPage struct {
Items []CatalogSnapshot `json:"items"`
Total int `json:"total"`
Limit int `json:"limit"`
Offset int `json:"offset"`
}
type CatalogSnapshotNodeFilter struct {
ConnectionID string
SnapshotID string
ParentNodeID string
Limit int
Offset int
}
type CatalogRouteRequest struct {
ConnectionID string
NodeIDs []string
Visibility Visibility
TargetKnowledgeBaseID string
TargetKnowledgeBaseIDs []string
OperatorRef string
Reason string
Now time.Time
}
// CatalogRouteFile is one selected file plus the metadata snapshot the policy
// fulfillment path needs to materialize and fetch it later.
type CatalogRouteFile struct {
NodeID string
Name string
RelativePath string
SizeBytes *int64
ModifiedAt *time.Time
ContentSHA256 *string
LocatorHash string
Direct bool
}
// CatalogRouteResult describes the desired-state write only. Policy fulfillment
// records intents, queues artifact fetches and plans publications; counts tell
// the operator what will show up in 解析监控.
type CatalogRouteResult struct {
SelectedFiles int `json:"selected_files"`
IntentsRecorded int `json:"intents_recorded"`
FetchQueued int `json:"fetch_queued"`
PlannedPublications int `json:"planned_publications"`
BlockedItems int `json:"blocked_items"`
UnboundFiles int `json:"unbound_files"`
}
type CatalogChangeSetFilter struct {
ConnectionID string
Action string
Limit int
Offset int
}
type CatalogChangeSet struct {
ID string `json:"id"`
ConnectionID string `json:"connection_id"`
SourceName string `json:"source_name"`
State string `json:"state"`
AddCount int `json:"add_count"`
UpdateCount int `json:"update_count"`
MoveCount int `json:"move_count"`
MoveScopeCount int `json:"move_scope_count"`
DeleteCount int `json:"delete_count"`
NoChangeCount int `json:"no_change_count"`
CreatedAt time.Time `json:"created_at"`
}
type CatalogChangeItem struct {
Action string `json:"action"`
Title string `json:"title"`
OldPath string `json:"old_path,omitempty"`
NewPath string `json:"new_path,omitempty"`
OldSizeBytes *int64 `json:"old_size_bytes,omitempty"`
NewSizeBytes *int64 `json:"new_size_bytes,omitempty"`
OldModified *time.Time `json:"old_modified_at,omitempty"`
NewModified *time.Time `json:"new_modified_at,omitempty"`
OldContentSHA256 string `json:"old_content_sha256,omitempty"`
NewContentSHA256 string `json:"new_content_sha256,omitempty"`
ReasonCode string `json:"reason_code"`
Seq int64 `json:"seq"`
OldScope string `json:"old_scope,omitempty"`
NewScope string `json:"new_scope,omitempty"`
OldVersionID string `json:"old_version_id,omitempty"`
NewVersionID string `json:"new_version_id,omitempty"`
}
type CatalogChangeSetDetail struct {
CatalogChangeSet
Items []CatalogChangeItem `json:"items"`
Total int `json:"total"`
Limit int `json:"limit"`
Offset int `json:"offset"`
}