含旁路创建位点回填治愈(seed/merge/AI 摄取):migrate 的三条 UPDATE 抽成 backfillMissingIRI,seedIfEmpty 灌入后、mergeExecute 提交后、ai.ApplySuggestion 落库后(runIngest 单点,覆盖 AI 摄取/km 抽取/连接批量抽取)各调一次治愈空值。 Co-Authored-By: Claude Opus 4.8 <[email protected]>
206 lines
9.5 KiB
Go
206 lines
9.5 KiB
Go
package main
|
||
|
||
import "time"
|
||
|
||
// ============ 本体语义层模型(参考 Palantir Ontology) ============
|
||
|
||
// ObjectType 对象类型:现实世界实体/事件的 Schema 定义。
|
||
type ObjectType struct {
|
||
ID int64 `json:"id"`
|
||
APIName string `json:"api_name"`
|
||
DisplayName string `json:"display_name"`
|
||
Description string `json:"description"`
|
||
Icon string `json:"icon"`
|
||
Group string `json:"group"`
|
||
// IRI 全局标识(GB/T 48000.3-2026):命名空间 + "#" + api_name,创建即固化。
|
||
IRI string `json:"iri,omitempty"`
|
||
TitleProperty string `json:"title_property"` // 主标题对应 property.api_name
|
||
SubtitleProperty string `json:"subtitle_property"` // 副标题对应 property.api_name
|
||
Color string `json:"color"` // UI 标识色
|
||
PrimaryKey string `json:"primary_key"` // 主键字段名,默认 'pk'
|
||
// 数据分级(2026-09-07):Property 为空 = 该类型不启用分级
|
||
ClassificationProperty string `json:"classification_property,omitempty"`
|
||
ClassificationLevels []string `json:"classification_levels,omitempty"`
|
||
ClassificationDefault string `json:"classification_default,omitempty"`
|
||
CreatedAt time.Time `json:"created_at"`
|
||
UpdatedAt time.Time `json:"updated_at"`
|
||
Properties []Property `json:"properties,omitempty"`
|
||
}
|
||
|
||
// Property 属性:对象类型的特征字段。
|
||
type Property struct {
|
||
ID int64 `json:"id"`
|
||
ObjectID int64 `json:"object_type_id"`
|
||
APIName string `json:"api_name"`
|
||
DisplayName string `json:"display_name"`
|
||
DataType string `json:"data_type"` // string/integer/number/boolean/date/datetime/enum/json/text
|
||
Required bool `json:"required"`
|
||
EnumValues []string `json:"enum_values,omitempty"`
|
||
Description string `json:"description"`
|
||
Format string `json:"format"` // 日期格式 / 数字精度 / 字符串正则
|
||
DefaultValue interface{} `json:"default_value"` // 默认值(任意 JSON)
|
||
Indexable bool `json:"indexable"` // 关键字检索
|
||
VectorIndex bool `json:"vector_index"` // 向量索引(语义检索)
|
||
BackingColumn string `json:"backing_column"` // 物化层用
|
||
// 字段级敏感度(2026-09-07):值取自所属类型的 classification_levels 词汇,
|
||
// 高于主体可见上限时该字段对主体 redact(与 FieldPolicy 并行生效)
|
||
Sensitivity string `json:"sensitivity,omitempty"`
|
||
// IRI 全局标识(GB/T 48000.3-2026):按属性名全局拼接,同名属性跨类型共享 IRI
|
||
IRI string `json:"iri,omitempty"`
|
||
}
|
||
|
||
// LinkType 链接类型:两个对象类型之间的关系边。
|
||
type LinkType struct {
|
||
ID int64 `json:"id"`
|
||
APIName string `json:"api_name"`
|
||
DisplayName string `json:"display_name"`
|
||
SourceType string `json:"source_type"`
|
||
TargetType string `json:"target_type"`
|
||
Cardinality string `json:"cardinality"` // one_to_many / many_to_many / one_to_one
|
||
Description string `json:"description"`
|
||
Directional bool `json:"directional"` // 是否单向(默认 false = 双向)
|
||
SourceProperty string `json:"source_property"` // 源端 key 字段(默认 pk)
|
||
TargetProperty string `json:"target_property"` // 目标端 key 字段(默认 pk)
|
||
// IRI 全局标识(GB/T 48000.3-2026):命名空间 + "#" + api_name,创建即固化
|
||
IRI string `json:"iri,omitempty"`
|
||
}
|
||
|
||
// ActionType 动作类型(动力层):对对象/属性/链接进行修改的预定义操作。
|
||
// 完整契约(Palantir Ontology 对标 2026-08-24):
|
||
// - Params: form schema 数组,每条 {name, type, required, default, enum, validation, description}
|
||
// - SubmissionCriteria: 执行前校验(object_status_in / required_grant 等)
|
||
// - SideEffects: 执行后触发(webhooks / cascade_actions / notifications)
|
||
// - ImplFunctionID: FBA —— 非空时整条 Action 由 Function 实现
|
||
// - ReturnType: 返回类型(string / object_ref / array 等)
|
||
type ActionType struct {
|
||
ID int64 `json:"id"`
|
||
APIName string `json:"api_name"`
|
||
DisplayName string `json:"display_name"`
|
||
Description string `json:"description"`
|
||
Params string `json:"params"` // form schema(JSON 字符串)
|
||
SubmissionCriteria string `json:"submission_criteria"` // JSON 字符串
|
||
SideEffects string `json:"side_effects"` // JSON 字符串
|
||
ImplFunctionID *int64 `json:"impl_function_id"` // FBA;可空
|
||
ImplFunctionName string `json:"impl_function_name"` // JOIN 出来,便于 UI 显示
|
||
ReturnType string `json:"return_type"`
|
||
WhenToSuggest []string `json:"when_to_suggest"`
|
||
LLMToolDescription string `json:"llm_tool_description"`
|
||
}
|
||
|
||
// Object 对象实例:对象类型的一个具体实体(数字孪生中的一个节点)。
|
||
type Object struct {
|
||
ID int64 `json:"id"`
|
||
ObjectID int64 `json:"object_type_id"`
|
||
TypeAPIName string `json:"type"` // 冗余存储,便于连接器按类型查询
|
||
PK string `json:"pk"` // 该实例在所属类型下的唯一主键
|
||
Properties map[string]interface{} `json:"properties"`
|
||
CreatedAt time.Time `json:"created_at"`
|
||
UpdatedAt time.Time `json:"updated_at"`
|
||
// 实例治理(2026-09-05):软删除墓碑 + 别名归并
|
||
Deleted bool `json:"deleted"`
|
||
SameAs string `json:"same_as"` // 非空 = 该实例是重复实体,canonical 指向同类型另一个 pk
|
||
// 生效分级(2026-09-07):空 = 未分级(视为最低,对任何主体可见)
|
||
Classification string `json:"classification,omitempty"`
|
||
}
|
||
|
||
// Link 链接实例:两个对象实例之间的具体关系。
|
||
type Link struct {
|
||
ID int64 `json:"id"`
|
||
LinkType string `json:"type"` // link type api_name
|
||
SourceType string `json:"source_type"`
|
||
SourcePK string `json:"source_pk"`
|
||
TargetType string `json:"target_type"`
|
||
TargetPK string `json:"target_pk"`
|
||
Properties map[string]interface{} `json:"properties,omitempty"` // 边属性(任职起止时间等)
|
||
CreatedAt time.Time `json:"created_at"`
|
||
}
|
||
|
||
// ============ AI 摄取相关 ============
|
||
|
||
// Ingestion AI 摄取任务记录。
|
||
type Ingestion struct {
|
||
ID int64 `json:"id"`
|
||
Title string `json:"title"`
|
||
RawText string `json:"raw_text"`
|
||
Directive string `json:"directive"` // 用户的更新要求
|
||
Mode string `json:"mode"` // auto(直接应用) / review(仅建议)
|
||
Status string `json:"status"` // pending / applied / failed / reviewed
|
||
Provider string `json:"provider"` // openai / heuristic
|
||
ResultJSON string `json:"result_json"`
|
||
Summary string `json:"summary"`
|
||
CreatedAt time.Time `json:"created_at"`
|
||
AppliedAt *time.Time `json:"applied_at"`
|
||
}
|
||
|
||
// AISuggestion AI 抽取结果结构(与后端抽取提示词对齐)。
|
||
type AISuggestion struct {
|
||
ObjectTypes []AISuggestedType `json:"object_types"`
|
||
LinkTypes []AISuggestedLink `json:"link_types"`
|
||
ActionTypes []AISuggestedAction `json:"action_types"`
|
||
Objects []AISuggestedObject `json:"objects"`
|
||
Links []AISuggestedLinkInst `json:"links"`
|
||
Summary string `json:"summary"`
|
||
}
|
||
|
||
type AISuggestedType struct {
|
||
APIName string `json:"api_name"`
|
||
DisplayName string `json:"display_name"`
|
||
Description string `json:"description"`
|
||
Group string `json:"group"`
|
||
Icon string `json:"icon"`
|
||
Properties []AISuggestedProp `json:"properties"`
|
||
}
|
||
type AISuggestedProp struct {
|
||
APIName string `json:"api_name"`
|
||
DisplayName string `json:"display_name"`
|
||
DataType string `json:"data_type"`
|
||
Required bool `json:"required"`
|
||
EnumValues []string `json:"enum_values"`
|
||
Description string `json:"description"`
|
||
}
|
||
type AISuggestedLink struct {
|
||
APIName string `json:"api_name"`
|
||
DisplayName string `json:"display_name"`
|
||
SourceType string `json:"source_type"`
|
||
TargetType string `json:"target_type"`
|
||
Cardinality string `json:"cardinality"`
|
||
Description string `json:"description"`
|
||
}
|
||
type AISuggestedAction struct {
|
||
APIName string `json:"api_name"`
|
||
DisplayName string `json:"display_name"`
|
||
Description string `json:"description"`
|
||
Params string `json:"params"`
|
||
}
|
||
type AISuggestedObject struct {
|
||
Type string `json:"type"`
|
||
PK string `json:"pk"`
|
||
Properties map[string]interface{} `json:"properties"`
|
||
}
|
||
type AISuggestedLinkInst struct {
|
||
Type string `json:"type"`
|
||
SourceType string `json:"source_type"`
|
||
SourcePK string `json:"source_pk"`
|
||
TargetType string `json:"target_type"`
|
||
TargetPK string `json:"target_pk"`
|
||
}
|
||
|
||
// ============ 连接器 / MCP ============
|
||
|
||
// ConnectorObjectType 连接器精简视图:应用只关心类型名+属性。
|
||
type ConnectorObjectType struct {
|
||
APIName string `json:"api_name"`
|
||
DisplayName string `json:"display_name"`
|
||
Description string `json:"description"`
|
||
// IRI 全局标识(GB/T 48000.3-2026):连接器/MCP 读路径同样回显
|
||
IRI string `json:"iri,omitempty"`
|
||
Properties []Property `json:"properties"`
|
||
}
|
||
|
||
// MCPTool MCP 工具清单中的单个工具描述(供 WorkBuddy 等接入)。
|
||
type MCPTool struct {
|
||
Name string `json:"name"`
|
||
Description string `json:"description"`
|
||
InputSchema map[string]interface{} `json:"inputSchema"`
|
||
}
|