## Palantir Ontology 对标(10 项) P0 核心契约: - when_to_suggest JSONB + llm_tool_description TEXT 加到 function_types/action_types - Action 完整契约: submission_criteria / side_effects / impl_function_id / return_type - FBA (Function-backed Action) 执行链: /api/v1/objects/:type/:pk/actions/:action - /api/v1/ontology/suggestions 提示调度端点 P1 元原语补全: - Object Type UX: title_property / subtitle_property / color / primary_key - Property 字段元数据: format / default_value / indexable / vector_index / backing_column - Link Type: directional + 独立 link_properties 子表 - Interface Type: shared_properties + parent_interface_id 多态 - Property extended types: geoshape / geopoint / media / timeseries / timestamp P2 数据管道层: - materializations / materialization_rows 物化层 + 60s ticker scheduler - backing_sources 同步源元数据 + 投影字段映射 AI 提示词升级: - ai/prompt.go 抽出 250+ 行静态 systemPrompt - 动态上下文注入: 每次 Suggest 前查 db 拉已注册类型清单 - Suggestion struct 扩展 22 字段 ## ON CONFLICT 漏 source 修复(4 处) - handlers_objects createObject/updateObject: COALESCE(NULLIF(EXCLUDED.source,''), objects.source) - handlers_km upsertObject + ai.ApplySuggestion: SET source=EXCLUDED.source - 表名必须限定 objects.source, 否则报 ambiguous ## xeo mobileApi 端到端导入 - /api/v1/ai/ingest raw_text 改用 json.dumps 转义, 修复 ingestion_id=56 failed - 1179 实例 + 1672 links + 1806 物化行 - 占位: 5 TrustedDataSpace + 158 MemberOrg - 5 类 Materialization 配好(mat_xeo_dataproduct 等) ## 文档 - docs/update/2026-08-24.md: 10 节迁移 + 增量 11 节 - .gitignore: 加 web/vite.config.js.timestamp-*.mjs Refs: docs/update/2026-08-24.md
185 lines
8.0 KiB
Go
185 lines
8.0 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"`
|
||
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'
|
||
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"` // 物化层用
|
||
}
|
||
|
||
// 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)
|
||
}
|
||
|
||
// 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"`
|
||
}
|
||
|
||
// 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"`
|
||
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"`
|
||
Properties []Property `json:"properties"`
|
||
}
|
||
|
||
// MCPTool MCP 工具清单中的单个工具描述(供 WorkBuddy 等接入)。
|
||
type MCPTool struct {
|
||
Name string `json:"name"`
|
||
Description string `json:"description"`
|
||
InputSchema map[string]interface{} `json:"inputSchema"`
|
||
}
|