From 061eef5214573c16e0854279c472c1c247735110 Mon Sep 17 00:00:00 2001 From: weichen Date: Wed, 30 Sep 2026 01:06:04 +0000 Subject: [PATCH] Add the owner field to tenant-scoped domain contracts Details (original message): Add the owner field to tenant-scoped domain contracts (project, conversation, run, artifact, knowledge) --- data.go | 1 + model.go | 6 ++++++ ts/types.ts | 10 +++++----- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/data.go b/data.go index 2fefe06..58d701c 100644 --- a/data.go +++ b/data.go @@ -99,6 +99,7 @@ type ParserDesc struct { // KnowledgeDoc 是检索语料的一条文档(来自 ingest 或插件知识库,带来源标记)。 type KnowledgeDoc struct { ID ID `json:"id"` + Owner ID `json:"owner,omitempty"` // 空 = 共享(插件级)知识 ProjectID ID `json:"projectId,omitempty"` // 空 = 插件级知识库 Source string `json:"source"` // upload | artifact | plugin: Title string `json:"title"` diff --git a/model.go b/model.go index a161277..b69c892 100644 --- a/model.go +++ b/model.go @@ -14,8 +14,11 @@ type ID = string // ---- 项目与会话 ---- +// Owner 是租户标识(多租户主线,设计 D5/D16):空串 = 单租户默认(嵌入式档/ +// 未启用认证时的隐式 owner)。API 层强制 owner 过滤,跨租户访问一律 NotFound。 type Project struct { ID ID `json:"id"` + Owner ID `json:"owner,omitempty"` Name string `json:"name"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` @@ -25,6 +28,7 @@ type Project struct { type Conversation struct { ID ID `json:"id"` ProjectID ID `json:"projectId"` + Owner ID `json:"owner,omitempty"` // 冗余自项目,查询过滤用 Title string `json:"title"` ProfileID ID `json:"profileId,omitempty"` // 空为默认画像 CreatedAt time.Time `json:"createdAt"` @@ -157,6 +161,7 @@ type Run struct { ParentRunID ID `json:"parentRunId,omitempty"` ConversationID ID `json:"conversationId"` ProjectID ID `json:"projectId"` + Owner ID `json:"owner,omitempty"` // 冗余自会话 Kind RunKind `json:"kind"` ProfileID ID `json:"profileId,omitempty"` Status RunStatus `json:"status"` @@ -181,6 +186,7 @@ type Usage struct { type Artifact struct { ID ID `json:"id"` ProjectID ID `json:"projectId"` + Owner ID `json:"owner,omitempty"` // 冗余自项目 Name string `json:"name"` Kind string `json:"kind"` MIME string `json:"mime,omitempty"` diff --git a/ts/types.ts b/ts/types.ts index 2cf85b7..cad5b4e 100644 --- a/ts/types.ts +++ b/ts/types.ts @@ -7,12 +7,12 @@ export type ID = string; // ---- 领域模型 ---- export interface Project { - id: ID; name: string; createdAt: string; updatedAt: string; + id: ID; owner?: ID; name: string; createdAt: string; updatedAt: string; settings?: Record; } export interface Conversation { - id: ID; projectId: ID; title: string; profileId?: ID; + id: ID; projectId: ID; owner?: ID; title: string; profileId?: ID; createdAt: string; updatedAt: string; } @@ -52,14 +52,14 @@ export interface Usage { } export interface Run { - id: ID; parentRunId?: ID; conversationId: ID; projectId: ID; + id: ID; parentRunId?: ID; conversationId: ID; projectId: ID; owner?: ID; kind: RunKind; profileId?: ID; status: RunStatus; phase?: RunPhase; agentName?: string; createdAt: string; endedAt?: string; usage?: Usage; error?: { code: string; message: string }; } export interface Artifact { - id: ID; projectId: ID; name: string; kind: string; mime?: string; + id: ID; projectId: ID; owner?: ID; name: string; kind: string; mime?: string; size: number; sourceRun?: ID; createdAt: string; updatedAt: string; } @@ -202,7 +202,7 @@ export interface ParsedDocument { } export interface RetrievalHit { - doc: { id: ID; projectId?: ID; source: string; title: string; ref?: string; chunk: string; createdAt: string }; + doc: { id: ID; owner?: ID; projectId?: ID; source: string; title: string; ref?: string; chunk: string; createdAt: string }; score: number; kind: 'fulltext' | 'vector' | 'plugin'; }