Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

7.0 KB
Raw Blame
//
//  Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//

package entity

import "time"

// FileCommit represents a snapshot commit for a workspace folder (like git commit).
type FileCommit struct {
	ID        string  `gorm:"column:id;primaryKey;size:32" json:"id"`
	FolderID  string  `gorm:"column:folder_id;size:32;not null;index" json:"folder_id"`
	ParentID  *string `gorm:"column:parent_id;size:32;index" json:"parent_id,omitempty"`
	Message   string  `gorm:"column:message;size:512;not null;default:''" json:"message"`
	AuthorID  string  `gorm:"column:author_id;size:32;not null;index" json:"author_id"`
	FileCount int     `gorm:"column:file_count;default:0" json:"file_count"`
	TreeState *string `gorm:"column:tree_state;type:longtext" json:"tree_state,omitempty"`
	Title     *string `gorm:"column:title;size:255" json:"title,omitempty"`
	Comments  *string `gorm:"column:comments;type:longtext" json:"comments,omitempty"`
	BaseModel
}

// TableName returns the table name for FileCommit model.
func (FileCommit) TableName() string {
	return "file_commit"
}

// FileCommitItem represents a single file change within a commit.
//
// Python declares the same pair unique and Peewee names it
// file_commit_item_commit_id_file_id. Both runtimes match an existing index by
// column set rather than by name, so the two names are equivalent and one of
// them appearing in the database is not a bug. See the "Shared database schema"
// section of AGENTS.md before renaming either.
type FileCommitItem struct {
	ID                   string  `gorm:"column:id;primaryKey;size:32" json:"id"`
	Seq                  uint    `gorm:"column:seq;index" json:"seq,omitempty"`
	CommitID             string  `gorm:"column:commit_id;size:32;not null;uniqueIndex:idx_commit_file" json:"commit_id"`
	FileID               string  `gorm:"column:file_id;size:255;not null;uniqueIndex:idx_commit_file" json:"file_id"`
	Operation            string  `gorm:"column:operation;size:16;not null;index" json:"operation"`
	OldHash              *string `gorm:"column:old_hash;size:64;index" json:"old_hash,omitempty"`
	NewHash              *string `gorm:"column:new_hash;size:64;index" json:"new_hash,omitempty"`
	OldLocation          *string `gorm:"column:old_location;size:255" json:"old_location,omitempty"`
	NewLocation          *string `gorm:"column:new_location;size:255" json:"new_location,omitempty"`
	OldName              *string `gorm:"column:old_name;size:255" json:"old_name,omitempty"`
	NewName              *string `gorm:"column:new_name;size:255" json:"new_name,omitempty"`
	Diff                 *string `gorm:"column:diff;type:longtext" json:"diff,omitempty"`
	ContentAfterStorage  *string `gorm:"column:content_after_storage;size:16;index" json:"content_after_storage,omitempty"`
	ContentAfterLocation *string `gorm:"column:content_after_location;size:512" json:"content_after_location,omitempty"`
	SlugKwd              *string `gorm:"column:slug_kwd;size:512;index" json:"slug_kwd,omitempty"`
	PageTypeKwd          *string `gorm:"column:page_type_kwd;size:32;index" json:"page_type_kwd,omitempty"`

	BaseModel
}

// TableName returns the table name for FileCommitItem model.
func (FileCommitItem) TableName() string {
	return "file_commit_item"
}

// TreeNode represents a file node in the commit tree state snapshot.
type TreeNode struct {
	ID       string      `json:"id"`
	Name     string      `json:"name"`
	Type     string      `json:"type"` // "file" or "folder"
	Hash     string      `json:"hash,omitempty"`
	Location string      `json:"location,omitempty"`
	Size     int64       `json:"size,omitempty"`
	Status   string      `json:"status"` // "1" = active, "0" = deleted
	Children []*TreeNode `json:"children,omitempty"`
}

// FileChange represents a file change in a commit request.
type FileChange struct {
	FileID    string `json:"file_id"`
	FileName  string `json:"file_name"`
	Operation string `json:"operation"` // "add", "modify", "delete", "rename"
	Content   string `json:"content,omitempty"`
	OldName   string `json:"old_name,omitempty"`
	NewName   string `json:"new_name,omitempty"`
}

// CommitResponse is the API response for a commit.
type CommitResponse struct {
	ID         string  `json:"id"`
	FolderID   string  `json:"folder_id"`
	ParentID   *string `json:"parent_id,omitempty"`
	Message    string  `json:"message"`
	AuthorID   string  `json:"author_id"`
	FileCount  int     `json:"file_count"`
	TreeState  *string `json:"tree_state,omitempty"`
	CreateTime *int64  `json:"create_time,omitempty"`
}

// DiffEntry represents a single diff entry between two commits.
type DiffEntry struct {
	FileID      string  `json:"file_id"`
	FileName    string  `json:"file_name"`
	Operation   string  `json:"operation"`
	OldHash     *string `json:"old_hash,omitempty"`
	NewHash     *string `json:"new_hash,omitempty"`
	OldLocation *string `json:"old_location,omitempty"`
	NewLocation *string `json:"new_location,omitempty"`
}

// VersionEntry represents a single version in a file's version history.
type VersionEntry struct {
	CommitID   string `json:"commit_id"`
	Operation  string `json:"operation"`
	Hash       string `json:"hash"`
	CreateTime *int64 `json:"create_time,omitempty"`
	Message    string `json:"message"`
}

// WikiPageCommit is one artifact-page history entry served by
// /datasets/{dataset_id}/commits?slug=<page_type>/<slug>. It mirrors the
// Python list_page_commits row shape consumed by the wiki version-history UI.
type WikiPageCommit struct {
	ID           string     `json:"id"`
	Title        string     `json:"title"`
	Comments     string     `json:"comments"`
	UserID       string     `json:"user_id"`
	CreateTime   *int64     `json:"create_time,omitempty"`
	CreateDate   *time.Time `json:"create_date,omitempty"`
	UserNickname string     `json:"user_nickname"`
}

// WikiPageCommitDetail is the artifact-page commit detail returned by the
// dataset commit endpoint. It mirrors Python's flat response shape consumed
// by the wiki version-history UI.
type WikiPageCommitDetail struct {
	ID           string     `json:"id"`
	TenantID     string     `json:"tenant_id"`
	KBID         string     `json:"kb_id"`
	PageType     string     `json:"page_type_kwd"`
	Slug         string     `json:"slug"`
	UserID       *string    `json:"user_id"`
	UserNickname string     `json:"user_nickname"`
	Title        string     `json:"title"`
	Comments     string     `json:"comments"`
	Diff         string     `json:"diff"`
	ContentAfter string     `json:"content_after"`
	CreateTime   *int64     `json:"create_time,omitempty"`
	CreateDate   *time.Time `json:"create_date,omitempty"`
}