Files
kbdb-graph-plugin/src/types.ts
T
Leo efe8e165cf feat: KBDB-graph 插件獨立 — 全面改寫成走基本盤 API(API-as-Wall)
按 leo 鐵律(2026-06-14)把插件從「直接 SQL 操作基本盤表」改寫成
「只透過基本盤 arcrun/kbdb HTTP API 讀寫」。零建表、零 migration、零 SQL。

- 新增 src/lib/kbdb-client.ts:唯一對外通道,封裝 entries/templates/records API
- 新增 src/lib/templates.ts:triplet/entity template 定義(替代建表)
- 改寫 21 個違規 action(triplet/graph/entity/search)→ 走 client,圖在插件層記憶體組裝
- 移除所有 migrations、D1/Vectorize/AI 綁定;embedding/語意搜尋歸基本盤 optional 模組
- index.ts 只掛 triplets/graph/entities/search 路由;基本盤路由歸 arcrun/kbdb
- 測試改走 mock client(純 node);裁剪 CLAUDE.md 只留 graph 插件 + 鐵律
- 修正 SDD design.md「讀現狀推翻鐵律」的錯誤判斷(共用 D1 → API-as-Wall)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 20:59:41 +08:00

58 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// KBDB Worker 型別定義
export type Bindings = {
// 插件不碰 DB/Vectorize/AI — 全走基本盤 APIAPI-as-Wall)。
// 語意搜尋/embedding 屬基本盤 optional embed 模組,不在插件。
KBDB_BASE_URL?: string; // 基本盤 arcrun/kbdb API 網址(leo: 可設定,先留空)
KBDB_INTERNAL_TOKEN?: string;
ENVIRONMENT: string;
API_KEY?: string;
};
// Hono Context 變數:auth middleware 設定,route handler 使用
export type Variables = {
namespace: string | null; // null = internal(無限制),string = partner 的 org_namespace
partner_id: string; // 'internal' 或 partner record_id
};
export type EntityType = 'person' | 'event' | 'product' | 'market' | 'org';
export type Triplet = {
id: string;
subject: string;
predicate: string;
object: string;
source_block_id: string | null;
confidence: number;
clusters: string[]; // 所屬的知識群集,用於跨領域偵測
bridge_score: number; // 跨越的 cluster 數量,Scout 發現指標
subject_entity_type: EntityType | null; // 主體 entity 類型(人格疊加局勢分析用)
object_entity_type: EntityType | null; // 客體 entity 類型
created_at: number;
updated_at: number;
};
// 圖遍歷結果
export type GraphNode = {
node: string;
level: number;
edges: Triplet[];
};
// --- Entity Normalization 型別 ---
export type Entity = {
id: string;
canonical: string;
aliases: string[];
};
export type PendingAlias = {
id: string;
raw_name: string;
candidate_entity_id: string;
candidate_canonical: string;
similarity: number;
created_at: number;
};