附录 A:JSON-RPC 接口清单
本附录是 drsg serve 所暴露 JSON-RPC 2.0 方法的参考。位于
crates/dr-strange-web/openrpc.json 的 OpenRPC schema 是权威来源:服务端会从
rpc.discover 返回它,各 SDK 也由它生成。
每一条目都列出方法名、访问层级(read / write / admin;在单一共享令牌下,
三者用的是同一个令牌)、一行摘要及其参数。参数写作 name 类型,类型一律是 JSON
值;! 标记必填参数。Properties 是属性映射的方言({"$vector":[…]}、
{"$desc":…,"$value":…}、{"$bytes":[…]},以及用于自身键以 $ 开头的嵌套映射的
{"$map":{…}};整数必须能放进有符号 64 位),NodeRef 则指一个节点 id 或一个外部键。
发现与数据库
rpc.discover· read —— OpenRPC 服务描述。参数:无。db.stats· read —— 平面/节点/边计数、标签、边类型、索引、提交数、磁盘占用、内存占用(进程常驻集,以及已加载插件持有的字节数)。参数:无。db.catalog· read —— 跨所有平面的软 schema 目录。参数:无。db.mount· admin —— 把另一个数据库的平面与本数据库的一同提供服务(issue #44)。该目录必须已经是一个数据库,且必须位于[server] mount_root之下;被其他进程持有的存储会被拒绝。参数:path、as?(为该挂载的平面名加前缀)。db.unmount· admin —— 停止提供某个挂载,并释放其存储的锁。freed说明该锁在调用返回之前是否已经释放:仍在进行中的折叠会持有它直到完成。名称不存在时如实报告,而不是报错。参数:name。db.mounts· read —— 本实例提供了什么:每个挂载及其目录与平面,以及每个平面所记录的源码树。参数:无。
平面
plane.list· read —— 每个平面及其 id、名称、计数、属性。参数:无。plane.catalog· read —— 单个平面的软 schema。参数:planestring!。plane.indexes· read —— 某个平面上已声明的检索索引。参数:planestring!。plane.history· read —— 时间旅行窗口(仅原生后端)。参数:无。plane.create· admin —— 创建一个空平面。参数:namestring!,propertiesProperties。plane.rename· admin —— 重命名一个平面。参数:planestring!,tostring!。plane.set_props· admin —— 替换一个平面的属性映射。参数:planestring!,propertiesProperties!。plane.delete· admin —— 删除一个平面及其内容。参数:planestring!。plane.attach· admin —— 记录本平面可以询问的平面:本实例上的平面,或由另一个 drsg 提供服务的平面(url)。参数:planestring!,namestring!,urlstring,asstring,bothboolean。plane.detach· admin —— 按名称移除一个附着;名称不存在时为空操作。参数:planestring!,namestring!。plane.attachments· read —— 本平面记录的附着;不会联系任何一方。参数:planestring!。
节点与边
node.get· read —— 按 id 或外部键获取一个节点。参数:planestring!,idinteger,keystring。node.create· write —— 新增一个节点(可选键与标签)。参数:planestring!,keystring,labelsarray,propertiesProperties。node.update· write —— 修补属性(set/unset)与标签。参数:planestring!,idinteger,keystring,setProperties,unsetarray,labelsarray。node.delete· write —— 删除一个节点,并级联其边。参数:planestring!,idinteger,keystring。edge.create· write —— 在两个节点间新增一条有向边。参数:planestring!,srcNodeRef!,dstNodeRef!,typestring!,propertiesProperties。edge.update· write —— 修补属性(set/unset)或类型。参数:planestring!,edgeinteger!,setProperties,unsetarray,typestring。edge.delete· write —— 删除一条边。参数:planestring!,edgeinteger!。
查询与检索
plane.neighbors· read —— 一跳扩展,以{node, edge}id 对返回。参数:planestring!,idinteger!,directionstring,typestring,as_ofinteger,as_of_msinteger。plane.query· read —— 运行一个序列化的逻辑计划。参数:planestring!,planobject!,as_ofinteger,as_of_msinteger。plane.cypher· write —— 运行一条 openCypher 子集语句(写门控)。参数:planestring!,querystring!,embedstring,paramsobject。plane.find· read —— 对一个平面的文本或语义搜索。参数:planestring!,qstring!,limitinteger,semanticboolean,providerstring,embed_modelstring,as_ofinteger,as_of_msinteger。plane.search· read —— 在某个属性上的向量 top-k。参数:planestring!,propertystring!,queryarray!,labelstring,kinteger,metricstring。plane.hybrid· read —— 融合的向量 + 关键词 + 图邻近度检索。参数:planestring!,qstring!,labelstring,vector_propstring,keyword_propstring,metricstring,graph_hopsinteger,graph_decaynumber,w_vectornumber,w_keywordnumber,w_graphnumber,kinteger,candidatesinteger,providerstring,embed_modelstring。plane.algo· read —— 作用于一个平面或某个标签子集的图算法。参数:planestring!,algostring!,labelstring,limitinteger,dampingnumber,max_itersinteger,tolerancenumber,srcinteger,dstinteger,dirstring,weightstring,max_levelsinteger,min_gainnumber。plane.ask· read —— 自然语言查询 → 计划 → 执行。参数:planestring!,questionstring!,dry_runboolean,max_attemptsinteger,limitinteger,providerstring,modelstring,embed_providerstring,embed_modelstring。graph.seed· read —— 一块由若干节点及其诱导边构成的初始画布。参数:planestring!,labelstring,limitinteger,orderstring(scan|degree|pagerank,默认scan),as_ofinteger,as_of_msinteger。指定排序时,返回的是得分最高的节点而非扫描时最先遇到的那些,并附带其scores。若要取骨架,建议用degree:PageRank 会把权重汇聚到汇点,不适合这个用途。graph.expand· read —— 围绕某个节点的、防枢纽的一跳邻域。参数:planestring!,idinteger!,directionstring,typestring,limitinteger,as_ofinteger,as_of_msinteger。
索引与导入
index.ensure· admin —— 在(标签, 属性)上声明一个向量或关键词索引。参数:planestring!,labelstring!,propertystring!,kindstring,metricstring,languagestring。digest.run· write —— 经由 LLM 从文本抽取节点/边方案(dry-run)。参数:planestring!,textstring!,chatstring,embedstring,modelstring,embed_modelstring,sourcestring,no_embedboolean,linkboolean,concurrencyinteger,chunk_charsinteger,modestring(coarse|fine|super,默认fine——见第 3 章;super的输入 token 用量约为 15 倍)。digest.write· write —— 写入一个先前算得的方案(不调用 LLM)。方案中已被本平面占用的键默认跳过——蒸馏把每个实体都当作新的提出,因此提到已知的东西是常态。参数:planestring!,nodesarray!,edgesarray,on_conflictstring(error/skip/update,默认skip)。plane.vectorize· write —— 为平面中的每个节点生成向量嵌入(文本未变的节点会跳过),并按标签确保embedding上的向量索引。提供方密钥来自服务端环境。参数:planestring!,embedstring,embed_modelstring,metricstring。
插件
plugin.list· read —— 已安装的预处理插件,与drsg plugin list --json输出同一种记录。参数:无。plugin.catalog· read —— 官方目录,读取自 extensions 仓库的catalog.json而非编译进二进制,因此插件发布不需要 drsg 发布。返回{stale, schema, source, plugins};每个条目带有name、version、claims、url、sha256与compat(ok、needs_host、other_contract),可与plugin.list关联比对。缓存一小时;stale: true表示抓取失败,返回的是服务端保留的最后一份副本。参数:无。plugin.install· write —— 从http(s)URL 下载、校验、固定哈希并存入插件(RPC 上拒绝服务器本地路径)。参数:urlstring!。plugin.remove· write —— 按名称卸载插件。参数:namestring!。
WebSocket 订阅
/ws 端点应答上述相同的请求/响应方法,并额外支持变更流(以下为 WebSocket 专有):
plane.watch· 客户端 → 服务端 —— 订阅某个平面的变更。参数:planestring!,labelstring。plane.unwatch· 客户端 → 服务端 —— 停止订阅。参数:无。plane.change· 服务端 → 客户端 —— 一个已提交的变更集。字段:plane,seq,truncated,changes。
错误码
| 码 | 含义 |
|---|---|
-32700 | 解析错误 |
-32600 | 无效请求 |
-32601 | 方法未找到 |
-32602 | 无效参数 |
-32000 | 应用错误(错误平面、悬挂端点、冲突……) |
-32001 | 未授权(凭据缺失或无效) |