@finddatatechnology/yongyi-client 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ladder.d.ts CHANGED
@@ -22,7 +22,33 @@ export interface LadderMemory {
22
22
  }
23
23
  /** 集群记忆客户端三面(/digest、/pages 读、/pages 写)。 */
24
24
  export interface ClusterMemoryClient extends LadderMemory {
25
- writeDigest(project: string, title: string, body: string): Promise<any>;
25
+ writeDigest(project: string, title: string, body: string, opts?: WriteDigestOptions): Promise<any>;
26
+ /**
27
+ * 按 metadata 读页(establish-agent-role-and-fitness-plane 6.2 / 7.2):
28
+ * fd-memory 的 `GET /pages` 早已支持 `meta=key:value` 过滤(`add-agent-memory-
29
+ * foundation`),但客户端从没暴露过——于是 paas 只能读「全部页」再自己筛,
30
+ * 而那是把服务端的结构化过滤降级成客户端字符串匹配。
31
+ */
32
+ readPages(filter?: ReadPagesFilter): Promise<MemoryPage[]>;
33
+ }
34
+ /**
35
+ * 写入的可选面(纯增量:不传 = 与既有 `{project,title,body}` 逐字节相同)。
36
+ *
37
+ * `metadata` 是 fd-memory 的一等字段(标量或标量数组),**不是**新契约:
38
+ * 服务的 enum 注释明写「Categories go in metadata」。这也是为什么本变更
39
+ * 不需要新增 `type` 车道——`observation` / `competence` 不是新档位,
40
+ * 是 note 页上的一个 metadata 键。
41
+ */
42
+ export interface WriteDigestOptions {
43
+ metadata?: Record<string, unknown>;
44
+ /** 显式更正:被取代的页 id(服务端 ignore 未知 id,拼错不阻塞写入)。 */
45
+ supersedes?: string[];
46
+ }
47
+ export interface ReadPagesFilter {
48
+ project?: string;
49
+ limit?: number;
50
+ /** `{key: value}` → 逐个 `meta=key:value`(数组值取 contains 语义)。 */
51
+ metadata?: Record<string, unknown>;
26
52
  }
27
53
  export interface ClusterClientOptions {
28
54
  url: string;
package/dist/ladder.js CHANGED
@@ -43,16 +43,47 @@ export function createClusterMemoryClient(opts) {
43
43
  const doc = await r.json();
44
44
  return Array.isArray(doc?.pages) ? doc.pages : [];
45
45
  },
46
- async writeDigest(project, title, body) {
46
+ async writeDigest(project, title, body, opts) {
47
+ // 不传 opts ⇒ 请求体与改前逐字节相同(既有调用方零迁移)。
48
+ const payload = { project, title, body };
49
+ if (opts?.metadata && Object.keys(opts.metadata).length)
50
+ payload.metadata = opts.metadata;
51
+ if (Array.isArray(opts?.supersedes) && opts.supersedes.length)
52
+ payload.supersedes = opts.supersedes;
47
53
  const r = await fetchWithTimeout(`${url}/pages`, {
48
54
  method: "POST",
49
55
  headers: { authorization: `Bearer ${token}`, "content-type": "application/json" },
50
- body: JSON.stringify({ project, title, body }),
56
+ body: JSON.stringify(payload),
51
57
  }, { fetchImpl });
52
58
  if (!r.ok)
53
59
  throw new Error(`pages HTTP ${r.status}`);
54
60
  return await r.json();
55
61
  },
62
+ /**
63
+ * 按 metadata 读页。参数拼装与服务端 `filterParamsOf` 同规:
64
+ * 值为对象/数组时 JSON 编码(服务端会尝试解析,解析失败按字符串),
65
+ * 字符串原样——这样 `{kind:"observation"}` 与 `{kind:"o\"b"}` 都能往返。
66
+ */
67
+ async readPages(filter = {}) {
68
+ const qs = new URLSearchParams();
69
+ if (filter.project)
70
+ qs.set("project", filter.project);
71
+ const lim = filter.limit;
72
+ if (typeof lim === "number" && Number.isInteger(lim) && lim > 0)
73
+ qs.set("limit", String(lim));
74
+ for (const [k, v] of Object.entries(filter.metadata ?? {})) {
75
+ if (v === undefined || v === null)
76
+ continue;
77
+ qs.append("meta", `${k}:${typeof v === "string" ? v : JSON.stringify(v)}`);
78
+ }
79
+ const r = await fetchWithTimeout(`${url}/pages?${qs.toString()}`, {
80
+ headers: { authorization: `Bearer ${token}` },
81
+ }, { fetchImpl });
82
+ if (!r.ok)
83
+ throw new Error(`pages HTTP ${r.status}`);
84
+ const doc = await r.json();
85
+ return Array.isArray(doc?.pages) ? doc.pages : [];
86
+ },
56
87
  // digest 读面(add-cluster-digest-injection):服务端渲染块——一次机会、
57
88
  // 不重试(调用方的阶梯在任何失败时降级标题列表)。
58
89
  //
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finddatatechnology/yongyi-client",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "description": "永忆(YongYi / fd-memory)客户端 SDK:召回注入阶梯、纪律文本单源、五类事实捕获、令牌铸造缓存、/observe 上报。零运行时依赖,只以 fetch 打内核 HTTP 面。",
6
6
  "main": "./dist/index.js",