@objectstack/knowledge-ragflow 17.0.0-rc.0 → 17.0.0-rc.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,334 @@
1
1
  # @objectstack/knowledge-ragflow
2
2
 
3
+ ## 17.0.0-rc.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [430dcc2]
8
+ - Updated dependencies [e6ac4bd]
9
+ - Updated dependencies [80334c7]
10
+ - Updated dependencies [ce5242c]
11
+ - Updated dependencies [a7163ea]
12
+ - Updated dependencies [e6e9379]
13
+ - Updated dependencies [98877c9]
14
+ - Updated dependencies [98877c9]
15
+ - Updated dependencies [e6b1b69]
16
+ - Updated dependencies [ad047d2]
17
+ - Updated dependencies [2826d1e]
18
+ - Updated dependencies [5a84d41]
19
+ - Updated dependencies [20b1a9e]
20
+ - Updated dependencies [203a449]
21
+ - Updated dependencies [ac37fc6]
22
+ - Updated dependencies [4820f55]
23
+ - Updated dependencies [462d9c4]
24
+ - Updated dependencies [7d21581]
25
+ - Updated dependencies [f2445c9]
26
+ - Updated dependencies [23338c3]
27
+ - Updated dependencies [5b843fb]
28
+ - Updated dependencies [b4487aa]
29
+ - Updated dependencies [65ca83a]
30
+ - Updated dependencies [67bf2e2]
31
+ - Updated dependencies [c6d1cb4]
32
+ - Updated dependencies [462b713]
33
+ - Updated dependencies [36030ff]
34
+ - Updated dependencies [6117f7b]
35
+ - Updated dependencies [e533b0b]
36
+ - Updated dependencies [cdf4d9a]
37
+ - Updated dependencies [aee1806]
38
+ - Updated dependencies [c13350b]
39
+ - Updated dependencies [c13350b]
40
+ - Updated dependencies [9ca2d85]
41
+ - Updated dependencies [c13350b]
42
+ - Updated dependencies [891d345]
43
+ - Updated dependencies [a52e2ef]
44
+ - Updated dependencies [5293114]
45
+ - Updated dependencies [20bc357]
46
+ - Updated dependencies [5966c2a]
47
+ - Updated dependencies [2382580]
48
+ - Updated dependencies [d9fa683]
49
+ - Updated dependencies [3c7bcc0]
50
+ - Updated dependencies [4b6cac7]
51
+ - Updated dependencies [7631964]
52
+ - Updated dependencies [ac471a0]
53
+ - Updated dependencies [60ae58e]
54
+ - Updated dependencies [ce92674]
55
+ - Updated dependencies [9f601e8]
56
+ - Updated dependencies [51c5227]
57
+ - Updated dependencies [a4a85c8]
58
+ - Updated dependencies [07a4e26]
59
+ - Updated dependencies [ec975f1]
60
+ - Updated dependencies [eb4204b]
61
+ - Updated dependencies [4f13be2]
62
+ - Updated dependencies [61cc079]
63
+ - Updated dependencies [0e96e46]
64
+ - Updated dependencies [d52d4fe]
65
+ - Updated dependencies [742cebb]
66
+ - Updated dependencies [9fd9ae7]
67
+ - Updated dependencies [ce92674]
68
+ - Updated dependencies [cf2c9b7]
69
+ - Updated dependencies [833b512]
70
+ - Updated dependencies [0f9faa2]
71
+ - Updated dependencies [7cf42fe]
72
+ - Updated dependencies [5966c2a]
73
+ - Updated dependencies [f78dd83]
74
+ - Updated dependencies [a2cd18a]
75
+ - Updated dependencies [4638aaa]
76
+ - Updated dependencies [0222d3c]
77
+ - Updated dependencies [071d0dc]
78
+ - Updated dependencies [0a936ea]
79
+ - Updated dependencies [023c00b]
80
+ - Updated dependencies [155507e]
81
+ - Updated dependencies [7bba90b]
82
+ - Updated dependencies [7e05d8e]
83
+ - Updated dependencies [061406d]
84
+ - Updated dependencies [c1f344b]
85
+ - Updated dependencies [9c93465]
86
+ - Updated dependencies [ebb209c]
87
+ - Updated dependencies [63b33e6]
88
+ - Updated dependencies [2a44c1d]
89
+ - Updated dependencies [695cfbd]
90
+ - Updated dependencies [7445149]
91
+ - Updated dependencies [071d0dc]
92
+ - Updated dependencies [0848bea]
93
+ - Updated dependencies [d51bed2]
94
+ - Updated dependencies [b8b3c64]
95
+ - Updated dependencies [0c0fbd9]
96
+ - Updated dependencies [f3141d8]
97
+ - Updated dependencies [5a84d41]
98
+ - Updated dependencies [fd3013a]
99
+ - Updated dependencies [21676eb]
100
+ - Updated dependencies [e336549]
101
+ - Updated dependencies [d40f43a]
102
+ - Updated dependencies [e5e7ee0]
103
+ - Updated dependencies [a2ebea2]
104
+ - Updated dependencies [800bdb0]
105
+ - Updated dependencies [04f1182]
106
+ - Updated dependencies [5647006]
107
+ - Updated dependencies [38f7e4f]
108
+ - Updated dependencies [c57f3cf]
109
+ - Updated dependencies [97faca3]
110
+ - Updated dependencies [ad5fe25]
111
+ - Updated dependencies [ea90179]
112
+ - Updated dependencies [ce92674]
113
+ - Updated dependencies [5ef0b5b]
114
+ - Updated dependencies [48fbacb]
115
+ - Updated dependencies [355e951]
116
+ - Updated dependencies [dadb43f]
117
+ - @objectstack/spec@17.0.0-rc.2
118
+ - @objectstack/core@17.0.0-rc.2
119
+ - @objectstack/service-knowledge@17.0.0-rc.2
120
+
121
+ ## 17.0.0-rc.1
122
+
123
+ ### Patch Changes
124
+
125
+ - 2e836de: chore(packaging): CHANGELOG.md ships in every npm tarball (#4261)
126
+
127
+ The AGENTS.md post-task checklist requires breaking changesets to carry their
128
+ FROM → TO migration because "this text ships to consumers as `CHANGELOG.md`
129
+ inside the npm package and is what an upgrading agent greps after the tombstone
130
+ error." That delivery path was severed for 68 of the 69 publishable packages:
131
+ npm packs `package.json` / `README*` / `LICENSE*` unconditionally but — unlike
132
+ older npm versions — not `CHANGELOG.md`, and the canonical
133
+ `"files": ["dist", "README.md"]` whitelist never named it. Measured on npm
134
+ 10.9.7: `npm pack --dry-run` on `@objectstack/types` shipped 3 files while its
135
+ 70KB `CHANGELOG.md` stayed behind. Only `@objectstack/spec` listed it
136
+ explicitly.
137
+
138
+ The tombstone-error scenario is precisely the one where the repo is out of
139
+ reach — the upgrading agent has `node_modules` and nothing else — so the
140
+ migration text has to ride in the tarball. Every publishable package now
141
+ declares `CHANGELOG.md` in `files`, and the canonical whitelist is
142
+ `["dist", "README.md", "CHANGELOG.md"]`.
143
+
144
+ The other half is the gate: `check:published-files` gains a fifth invariant,
145
+ COMPLETE — a whitelist that fails to cover `CHANGELOG.md` fails the
146
+ always-required lint job, so the next package cannot silently sever the path
147
+ again. `@objectstack/spec`'s per-package EXTRA_ENTRIES exemption dissolves
148
+ into the canonical set.
149
+
150
+ Consumer-visible change: one more file per install (the package's changelog,
151
+ e.g. 70.8KB for `@objectstack/types`), and `grep -r "removed key"
152
+ node_modules/@objectstack/*/CHANGELOG.md` now finds the migration it was
153
+ promised.
154
+
155
+ - cc2de0e: chore(packaging): 20 packages stop publishing their sources, tests and build tooling (#4248)
156
+
157
+ These 20 packages declared no `files` field, so npm fell back to packing the
158
+ whole package directory. `npm pack --dry-run` on `@objectstack/plugin-webhooks`
159
+ listed **21 files** — 15 under `src/`, three of them unit tests
160
+ (`auto-enqueuer.test.ts`, `bootstrap-declared-webhooks.test.ts`, …), plus the
161
+ build-time `scripts/i18n-extract.config.ts`. `dist/` lands on top of that at
162
+ publish time rather than instead of it, so consumers were installing the
163
+ TypeScript sources and the test suite alongside the artifact they asked for.
164
+
165
+ Each now declares `"files": ["dist", "README.md"]`, matching the 29 packages
166
+ that already did. Nothing a consumer imports moves: every `main` / `types` /
167
+ `exports` target in all 20 already resolved inside `dist/`, which the new
168
+ `check:published-files` guard verifies rather than assumes. The visible change
169
+ is a smaller install and a smaller dependency-scanning surface — `npm pack` on
170
+ `@objectstack/plugin-webhooks` now yields 2 files plus `dist/`.
171
+
172
+ The other half of the fix is the gate. Half the packages declaring `files` and
173
+ half not was the #3786 shape — a hand-copied convention with nothing enforcing
174
+ it, where whoever forgets the line gets no signal at all. `check:published-files`
175
+ (new, wired into the always-required `lint` job) holds every non-private
176
+ workspace package to four invariants: `files` is **declared**; it is
177
+ **sufficient** (covers every entry point, so tightening a whitelist cannot ship
178
+ a package that fails to resolve); it is **minimal** (admits no test, test-harness
179
+ config or build script); and anything beyond `dist` + `README.md` is
180
+ **registered** with a reason, reconciled in both directions so a stale exemption
181
+ is an error rather than dead text. `@objectstack/spec` is the one package with
182
+ registered extras — its `.zod.ts` sources, JSON Schemas, liveness ledgers and
183
+ `CHANGELOG.md` are product, not build input.
184
+
185
+ This also closes an assumption #4206 was resting on. Excluding `<pkg>/scripts/**`
186
+ from the docs-drift implementation test is sound only while no package publishes
187
+ `scripts/` as runtime code; that held, but it held because someone read all three
188
+ offenders by hand. It is now checked on every PR.
189
+
190
+ - Updated dependencies [6a67d7a]
191
+ - Updated dependencies [0ecc656]
192
+ - Updated dependencies [06772eb]
193
+ - Updated dependencies [270650f]
194
+ - Updated dependencies [3aef718]
195
+ - Updated dependencies [1ea6bce]
196
+ - Updated dependencies [c1dcacd]
197
+ - Updated dependencies [ad303ed]
198
+ - Updated dependencies [32ccb23]
199
+ - Updated dependencies [f5a4ef0]
200
+ - Updated dependencies [2d3e255]
201
+ - Updated dependencies [7d7521f]
202
+ - Updated dependencies [5dc4d02]
203
+ - Updated dependencies [05154a1]
204
+ - Updated dependencies [9b6fe7c]
205
+ - Updated dependencies [8c711fb]
206
+ - Updated dependencies [09e4547]
207
+ - Updated dependencies [91f4c78]
208
+ - Updated dependencies [820eff9]
209
+ - Updated dependencies [8d895ff]
210
+ - Updated dependencies [f6472d7]
211
+ - Updated dependencies [78caf51]
212
+ - Updated dependencies [62a789b]
213
+ - Updated dependencies [789ad63]
214
+ - Updated dependencies [2af1988]
215
+ - Updated dependencies [0af50a3]
216
+ - Updated dependencies [2e836de]
217
+ - Updated dependencies [12a19a8]
218
+ - Updated dependencies [41dcda3]
219
+ - Updated dependencies [c8124e5]
220
+ - Updated dependencies [a1a4140]
221
+ - Updated dependencies [217e2e6]
222
+ - Updated dependencies [86a71d1]
223
+ - Updated dependencies [d5c75e2]
224
+ - Updated dependencies [03d26f7]
225
+ - Updated dependencies [4384921]
226
+ - Updated dependencies [3c628ce]
227
+ - Updated dependencies [7cb922e]
228
+ - Updated dependencies [1d22114]
229
+ - Updated dependencies [b5f9397]
230
+ - Updated dependencies [ed77493]
231
+ - Updated dependencies [58a03d2]
232
+ - Updated dependencies [dc530b4]
233
+ - Updated dependencies [e59786e]
234
+ - Updated dependencies [bcf1112]
235
+ - Updated dependencies [9774b78]
236
+ - Updated dependencies [b07d829]
237
+ - Updated dependencies [a648e96]
238
+ - Updated dependencies [a47ac06]
239
+ - Updated dependencies [e4c61a7]
240
+ - Updated dependencies [cc60165]
241
+ - Updated dependencies [081aa6f]
242
+ - Updated dependencies [91f4c78]
243
+ - Updated dependencies [e8d0c21]
244
+ - Updated dependencies [45dc446]
245
+ - Updated dependencies [c1d44f7]
246
+ - Updated dependencies [ab9fb5c]
247
+ - Updated dependencies [f985b3f]
248
+ - Updated dependencies [9a4932a]
249
+ - Updated dependencies [f9fc874]
250
+ - Updated dependencies [011b386]
251
+ - Updated dependencies [7777e8f]
252
+ - Updated dependencies [507b92a]
253
+ - Updated dependencies [7309c81]
254
+ - Updated dependencies [20bc1ec]
255
+ - Updated dependencies [90c2b15]
256
+ - Updated dependencies [42eeb7d]
257
+ - Updated dependencies [01e124d]
258
+ - Updated dependencies [7ce02eb]
259
+ - Updated dependencies [a13827e]
260
+ - Updated dependencies [7733604]
261
+ - Updated dependencies [40e420f]
262
+ - Updated dependencies [d13004a]
263
+ - Updated dependencies [be7360c]
264
+ - Updated dependencies [5b47ab5]
265
+ - Updated dependencies [b09d8d9]
266
+ - Updated dependencies [b09d8d9]
267
+ - Updated dependencies [8675db6]
268
+ - Updated dependencies [b09d8d9]
269
+ - Updated dependencies [3eb1b2b]
270
+ - Updated dependencies [59b85c0]
271
+ - Updated dependencies [6e357ed]
272
+ - Updated dependencies [d6938bf]
273
+ - Updated dependencies [31e0be9]
274
+ - Updated dependencies [4bfd455]
275
+ - Updated dependencies [ffd2ce2]
276
+ - Updated dependencies [62f8017]
277
+ - Updated dependencies [a831df1]
278
+ - Updated dependencies [f752ee3]
279
+ - Updated dependencies [a1b61e0]
280
+ - Updated dependencies [cd6b9f2]
281
+ - Updated dependencies [2cb6d3c]
282
+ - Updated dependencies [af2a095]
283
+ - Updated dependencies [ec796d5]
284
+ - Updated dependencies [e87fea1]
285
+ - Updated dependencies [c65e529]
286
+ - Updated dependencies [3ca34c1]
287
+ - Updated dependencies [239c3a3]
288
+ - Updated dependencies [94a0bbc]
289
+ - Updated dependencies [d6bfb3d]
290
+ - Updated dependencies [a2266a6]
291
+ - Updated dependencies [d25a0ec]
292
+ - Updated dependencies [667b83e]
293
+ - Updated dependencies [627b188]
294
+ - Updated dependencies [8d4eae7]
295
+ - Updated dependencies [857a6cf]
296
+ - Updated dependencies [65a3a84]
297
+ - Updated dependencies [ccd9397]
298
+ - Updated dependencies [bca935b]
299
+ - Updated dependencies [d92c72d]
300
+ - Updated dependencies [c54c822]
301
+ - Updated dependencies [8dcc0f5]
302
+ - Updated dependencies [75b9e51]
303
+ - Updated dependencies [0a2f233]
304
+ - Updated dependencies [8621cdd]
305
+ - Updated dependencies [6f23667]
306
+ - Updated dependencies [5d21a48]
307
+ - Updated dependencies [19365b7]
308
+ - Updated dependencies [b7ed26d]
309
+ - Updated dependencies [b3a3d83]
310
+ - Updated dependencies [7a55913]
311
+ - Updated dependencies [35accbf]
312
+ - Updated dependencies [6038de7]
313
+ - Updated dependencies [eb95d97]
314
+ - Updated dependencies [e4c2dc8]
315
+ - Updated dependencies [1bd2795]
316
+ - Updated dependencies [8186a70]
317
+ - Updated dependencies [a329cca]
318
+ - Updated dependencies [6eec18c]
319
+ - Updated dependencies [4d7bebf]
320
+ - Updated dependencies [821ac7a]
321
+ - Updated dependencies [8f81731]
322
+ - Updated dependencies [8b50cb3]
323
+ - Updated dependencies [8c2db68]
324
+ - Updated dependencies [22b5e54]
325
+ - Updated dependencies [0166bd5]
326
+ - Updated dependencies [9b702dc]
327
+ - Updated dependencies [ab16331]
328
+ - @objectstack/spec@17.0.0-rc.1
329
+ - @objectstack/core@17.0.0-rc.1
330
+ - @objectstack/service-knowledge@17.0.0-rc.1
331
+
3
332
  ## 17.0.0-rc.0
4
333
 
5
334
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@objectstack/knowledge-ragflow",
3
- "version": "17.0.0-rc.0",
3
+ "version": "17.0.0-rc.2",
4
4
  "license": "Apache-2.0",
5
5
  "description": "RAGFlow knowledge adapter for ObjectStack — production-grade RAG via the Apache 2.0 RAGFlow REST API.",
6
6
  "main": "dist/index.js",
@@ -13,12 +13,12 @@
13
13
  }
14
14
  },
15
15
  "dependencies": {
16
- "@objectstack/service-knowledge": "17.0.0-rc.0",
17
- "@objectstack/core": "17.0.0-rc.0",
18
- "@objectstack/spec": "17.0.0-rc.0"
16
+ "@objectstack/core": "17.0.0-rc.2",
17
+ "@objectstack/service-knowledge": "17.0.0-rc.2",
18
+ "@objectstack/spec": "17.0.0-rc.2"
19
19
  },
20
20
  "devDependencies": {
21
- "@types/node": "^26.1.1",
21
+ "@types/node": "^26.1.2",
22
22
  "typescript": "^6.0.3",
23
23
  "vitest": "^4.1.10"
24
24
  },
@@ -28,6 +28,11 @@
28
28
  "rag",
29
29
  "ragflow"
30
30
  ],
31
+ "files": [
32
+ "dist",
33
+ "README.md",
34
+ "CHANGELOG.md"
35
+ ],
31
36
  "scripts": {
32
37
  "build": "tsup --config ../../../tsup.config.ts",
33
38
  "dev": "tsc -w",
@@ -1,22 +0,0 @@
1
-
2
- > @objectstack/knowledge-ragflow@17.0.0-rc.0 build /home/runner/work/objectstack/objectstack/packages/plugins/knowledge-ragflow
3
- > tsup --config ../../../tsup.config.ts
4
-
5
- CLI Building entry: src/index.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v8.5.1
8
- CLI Using tsup config: /home/runner/work/objectstack/objectstack/tsup.config.ts
9
- CLI Target: es2020
10
- CLI Cleaning output folder
11
- ESM Build start
12
- CJS Build start
13
- ESM dist/index.mjs 6.41 KB
14
- ESM dist/index.mjs.map 15.10 KB
15
- ESM ⚡️ Build success in 72ms
16
- CJS dist/index.js 7.49 KB
17
- CJS dist/index.js.map 15.14 KB
18
- CJS ⚡️ Build success in 72ms
19
- DTS Build start
20
- DTS ⚡️ Build success in 12816ms
21
- DTS dist/index.d.mts 2.39 KB
22
- DTS dist/index.d.ts 2.39 KB
@@ -1,160 +0,0 @@
1
- // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
2
-
3
- import { describe, it, expect } from 'vitest';
4
- import { KnowledgeRagflowAdapter, type FetchLike } from '../index';
5
- import type { KnowledgeSource, KnowledgeDocument } from '@objectstack/spec/ai';
6
-
7
- const source: KnowledgeSource = {
8
- id: 'docs',
9
- label: 'Docs',
10
- adapter: 'ragflow',
11
- source: { kind: 'http', urls: ['https://docs.example.com'] } as KnowledgeSource['source'],
12
- options: { datasetId: 'ds_42' },
13
- };
14
-
15
- function fakeFetch(handler: (url: string, init?: any) => unknown): { fetch: FetchLike; calls: Array<{ url: string; init: any }> } {
16
- const calls: Array<{ url: string; init: any }> = [];
17
- const fetch: FetchLike = async (url, init) => {
18
- calls.push({ url, init });
19
- const out = await Promise.resolve(handler(url, init));
20
- const body = typeof out === 'string' ? out : JSON.stringify(out ?? {});
21
- return {
22
- ok: true,
23
- status: 200,
24
- statusText: 'OK',
25
- text: async () => body,
26
- json: async () => JSON.parse(body),
27
- };
28
- };
29
- return { fetch, calls };
30
- }
31
-
32
- describe('KnowledgeRagflowAdapter', () => {
33
- it('rejects sources without datasetId', async () => {
34
- const { fetch } = fakeFetch(() => ({}));
35
- const a = new KnowledgeRagflowAdapter({ endpoint: 'http://x', apiKey: 'k', fetch });
36
- const bad: KnowledgeSource = { ...source, options: {} as Record<string, unknown> };
37
- await expect(a.search('q', { source: bad, topK: 1 })).rejects.toThrow(/datasetId/);
38
- });
39
-
40
- it('upsert deletes-then-creates chunks and stamps objectstack metadata', async () => {
41
- const { fetch, calls } = fakeFetch((url) => {
42
- if (url.includes('/api/v1/retrieval')) return { code: 0, data: { chunks: [] } };
43
- return { code: 0, data: {} };
44
- });
45
- const a = new KnowledgeRagflowAdapter({ endpoint: 'http://r', apiKey: 'k', fetch });
46
- const doc: KnowledgeDocument = {
47
- id: 'd1',
48
- sourceId: 'docs',
49
- sourceRecordId: 'rec_1',
50
- content: 'hello world',
51
- title: 'Greeting',
52
- metadata: { topic: 'intro' },
53
- };
54
- await a.upsert([doc], { source });
55
- // First call: lookup existing chunks; second: create chunk
56
- const createCall = calls.find((c) => c.url.endsWith('/api/v1/datasets/ds_42/chunks') && c.init.method === 'POST');
57
- expect(createCall).toBeDefined();
58
- const body = JSON.parse(createCall!.init.body);
59
- expect(body.content).toBe('hello world');
60
- expect(body.metadata.objectstack_doc_id).toBe('d1');
61
- expect(body.metadata.objectstack_record_id).toBe('rec_1');
62
- expect(body.metadata.objectstack_source_id).toBe('docs');
63
- expect(body.metadata.topic).toBe('intro');
64
- });
65
-
66
- it('search maps ragflow chunks to KnowledgeHit shape', async () => {
67
- const { fetch, calls } = fakeFetch(() => ({
68
- code: 0,
69
- data: {
70
- chunks: [
71
- {
72
- id: 'c1',
73
- content: 'snippet one',
74
- similarity: 0.91,
75
- metadata: { objectstack_doc_id: 'd1', objectstack_record_id: 'rec_1', title: 'T1' },
76
- },
77
- {
78
- id: 'c2',
79
- content: 'snippet two',
80
- similarity: 0.7,
81
- metadata: { objectstack_doc_id: 'd2' },
82
- },
83
- ],
84
- },
85
- }));
86
- const a = new KnowledgeRagflowAdapter({ endpoint: 'http://r', apiKey: 'k', fetch });
87
- const hits = await a.search('hello', { source, topK: 5 });
88
- expect(hits).toHaveLength(2);
89
- expect(hits[0]).toMatchObject({
90
- chunkId: 'c1',
91
- documentId: 'd1',
92
- sourceId: 'docs',
93
- sourceRecordId: 'rec_1',
94
- score: 0.91,
95
- snippet: 'snippet one',
96
- title: 'T1',
97
- });
98
- expect(hits[1].sourceRecordId).toBeUndefined();
99
- // Authorization header present
100
- const last = calls.at(-1)!;
101
- expect(last.init.headers.authorization).toBe('Bearer k');
102
- });
103
-
104
- it('search honours rerankModel + similarityThreshold + filter', async () => {
105
- const { fetch, calls } = fakeFetch(() => ({ code: 0, data: { chunks: [] } }));
106
- const a = new KnowledgeRagflowAdapter({ endpoint: 'http://r', apiKey: 'k', fetch });
107
- const s: KnowledgeSource = {
108
- ...source,
109
- options: { datasetId: 'ds_42', rerankModel: 'bge-reranker', similarityThreshold: 0.6 },
110
- };
111
- await a.search('q', { source: s, topK: 3, filter: { tag: 'a' } });
112
- const body = JSON.parse(calls[0].init.body);
113
- expect(body.rerank_id).toBe('bge-reranker');
114
- expect(body.similarity_threshold).toBe(0.6);
115
- expect(body.metadata_condition).toEqual({ tag: 'a' });
116
- expect(body.top_k).toBe(3);
117
- });
118
-
119
- it('delete looks up chunks then issues DELETE with chunk_ids', async () => {
120
- const { fetch, calls } = fakeFetch((url) => {
121
- if (url.includes('/api/v1/retrieval')) {
122
- return { code: 0, data: { chunks: [{ id: 'c1' }, { id: 'c2' }] } };
123
- }
124
- return { code: 0, data: {} };
125
- });
126
- const a = new KnowledgeRagflowAdapter({ endpoint: 'http://r', apiKey: 'k', fetch });
127
- await a.delete(['d1'], { source });
128
- const del = calls.find((c) => c.init.method === 'DELETE');
129
- expect(del).toBeDefined();
130
- expect(JSON.parse(del!.init.body)).toEqual({ chunk_ids: ['c1', 'c2'] });
131
- });
132
-
133
- it('healthCheck pings dataset list', async () => {
134
- const { fetch } = fakeFetch(() => ({ code: 0, data: { datasets: [] } }));
135
- const a = new KnowledgeRagflowAdapter({ endpoint: 'http://r', apiKey: 'k', fetch });
136
- const h = await a.healthCheck();
137
- expect(h.ok).toBe(true);
138
- });
139
-
140
- it('healthCheck reports failure when request throws', async () => {
141
- const fetch: FetchLike = async () => {
142
- throw new Error('boom');
143
- };
144
- const a = new KnowledgeRagflowAdapter({ endpoint: 'http://r', apiKey: 'k', fetch });
145
- const h = await a.healthCheck();
146
- expect(h.ok).toBe(false);
147
- expect(h.message).toMatch(/boom/);
148
- });
149
-
150
- it('throws on non-zero RAGFlow error code', async () => {
151
- const { fetch } = fakeFetch(() => ({ code: 102, message: 'bad request' }));
152
- const a = new KnowledgeRagflowAdapter({ endpoint: 'http://r', apiKey: 'k', fetch });
153
- await expect(a.search('q', { source, topK: 1 })).rejects.toThrow(/bad request/);
154
- });
155
-
156
- it('constructor validates endpoint and apiKey', () => {
157
- expect(() => new KnowledgeRagflowAdapter({ endpoint: '', apiKey: 'k', fetch: (async () => ({}) as any) })).toThrow(/endpoint/);
158
- expect(() => new KnowledgeRagflowAdapter({ endpoint: 'http://x', apiKey: '', fetch: (async () => ({}) as any) })).toThrow(/apiKey/);
159
- });
160
- });
package/src/index.ts DELETED
@@ -1,307 +0,0 @@
1
- // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
2
-
3
- import type { Plugin, PluginContext } from '@objectstack/core';
4
- import type {
5
- IKnowledgeAdapter,
6
- IKnowledgeService,
7
- AdapterContext,
8
- AdapterSearchOptions,
9
- } from '@objectstack/spec/contracts';
10
- import type {
11
- KnowledgeDocument,
12
- KnowledgeHit,
13
- KnowledgeSource,
14
- } from '@objectstack/spec/ai';
15
- import { KNOWLEDGE_SERVICE } from '@objectstack/spec/contracts';
16
-
17
- /**
18
- * Subset of `fetch` used by the adapter. Inject in tests; defaults to
19
- * the global `fetch`.
20
- */
21
- export type FetchLike = (
22
- input: string,
23
- init?: {
24
- method?: string;
25
- headers?: Record<string, string>;
26
- body?: string;
27
- signal?: AbortSignal;
28
- },
29
- ) => Promise<{
30
- ok: boolean;
31
- status: number;
32
- statusText: string;
33
- text(): Promise<string>;
34
- json(): Promise<unknown>;
35
- }>;
36
-
37
- export interface KnowledgeRagflowAdapterOptions {
38
- /** RAGFlow endpoint, e.g. `http://localhost:9380`. */
39
- endpoint: string;
40
- /** RAGFlow API key (Bearer token). */
41
- apiKey: string;
42
- /** Adapter id. @default 'ragflow' */
43
- id?: string;
44
- /** Override `fetch` for tests. */
45
- fetch?: FetchLike;
46
- /** Request timeout in milliseconds. @default 30000 */
47
- timeoutMs?: number;
48
- }
49
-
50
- interface RagflowSourceOptions {
51
- datasetId: string;
52
- /** Optional rerank model id (overrides dataset default). */
53
- rerankModel?: string;
54
- /** Optional similarity threshold passed through to RAGFlow. */
55
- similarityThreshold?: number;
56
- /** Optional vector vs keyword weight in [0,1]. */
57
- vectorSimilarityWeight?: number;
58
- }
59
-
60
- function extractRagflowOptions(source: KnowledgeSource): RagflowSourceOptions {
61
- const opts = ((source as unknown as { options?: Record<string, unknown> }).options ?? {}) as
62
- Record<string, unknown>;
63
- const datasetId = opts.datasetId;
64
- if (typeof datasetId !== 'string' || !datasetId) {
65
- throw new Error(
66
- `RAGFlow adapter requires source.options.datasetId on source '${source.id}'`,
67
- );
68
- }
69
- return {
70
- datasetId,
71
- rerankModel: typeof opts.rerankModel === 'string' ? opts.rerankModel : undefined,
72
- similarityThreshold:
73
- typeof opts.similarityThreshold === 'number' ? opts.similarityThreshold : undefined,
74
- vectorSimilarityWeight:
75
- typeof opts.vectorSimilarityWeight === 'number'
76
- ? opts.vectorSimilarityWeight
77
- : undefined,
78
- };
79
- }
80
-
81
- /**
82
- * RAGFlow adapter. Maps {@link KnowledgeDocument} upserts to the
83
- * dataset's chunk API, delegates retrieval to `/api/v1/retrieval`, and
84
- * returns {@link KnowledgeHit}s with `sourceRecordId` preserved so the
85
- * orchestrator can run a permission re-check.
86
- */
87
- export class KnowledgeRagflowAdapter implements IKnowledgeAdapter {
88
- readonly id: string;
89
- private readonly endpoint: string;
90
- private readonly apiKey: string;
91
- private readonly fetchImpl: FetchLike;
92
- private readonly timeoutMs: number;
93
-
94
- constructor(opts: KnowledgeRagflowAdapterOptions) {
95
- if (!opts.endpoint) throw new Error('RAGFlow adapter: endpoint required');
96
- if (!opts.apiKey) throw new Error('RAGFlow adapter: apiKey required');
97
- this.id = opts.id ?? 'ragflow';
98
- this.endpoint = opts.endpoint.replace(/\/+$/, '');
99
- this.apiKey = opts.apiKey;
100
- this.fetchImpl = opts.fetch ?? ((globalThis as { fetch?: FetchLike }).fetch as FetchLike);
101
- this.timeoutMs = opts.timeoutMs ?? 30000;
102
- if (!this.fetchImpl) {
103
- throw new Error('RAGFlow adapter: no fetch available; pass options.fetch');
104
- }
105
- }
106
-
107
- async upsert(docs: KnowledgeDocument[], ctx: AdapterContext): Promise<void> {
108
- const { datasetId } = extractRagflowOptions(ctx.source);
109
- // RAGFlow models documents in two layers: documents (file-like) and
110
- // chunks (text blocks). We treat each KnowledgeDocument as a single
111
- // chunk-set: delete existing chunks with the same external id, then
112
- // upload as `content` chunks tagged with our document id.
113
- for (const doc of docs) {
114
- await this.deleteChunksByDocumentId(datasetId, doc.id);
115
- await this.request(`/api/v1/datasets/${datasetId}/chunks`, {
116
- method: 'POST',
117
- body: JSON.stringify({
118
- content: doc.content,
119
- // RAGFlow accepts arbitrary metadata used for filtering at
120
- // retrieval time. We always stamp `objectstack_doc_id` so
121
- // delete() can find these chunks again.
122
- important_keywords: doc.title ? [doc.title] : undefined,
123
- metadata: {
124
- ...(doc.metadata ?? {}),
125
- objectstack_doc_id: doc.id,
126
- objectstack_source_id: doc.sourceId,
127
- objectstack_record_id: doc.sourceRecordId,
128
- title: doc.title,
129
- },
130
- }),
131
- });
132
- }
133
- }
134
-
135
- async delete(documentIds: string[], ctx: AdapterContext): Promise<void> {
136
- const { datasetId } = extractRagflowOptions(ctx.source);
137
- for (const id of documentIds) {
138
- await this.deleteChunksByDocumentId(datasetId, id);
139
- }
140
- }
141
-
142
- async search(query: string, opts: AdapterSearchOptions): Promise<KnowledgeHit[]> {
143
- const { datasetId, rerankModel, similarityThreshold, vectorSimilarityWeight } =
144
- extractRagflowOptions(opts.source);
145
- const body: Record<string, unknown> = {
146
- question: query,
147
- dataset_ids: [datasetId],
148
- top_k: opts.topK,
149
- keyword: true,
150
- };
151
- if (rerankModel) body.rerank_id = rerankModel;
152
- if (typeof similarityThreshold === 'number') body.similarity_threshold = similarityThreshold;
153
- if (typeof vectorSimilarityWeight === 'number')
154
- body.vector_similarity_weight = vectorSimilarityWeight;
155
- if (opts.filter) body.metadata_condition = { ...opts.filter };
156
-
157
- const res = await this.request('/api/v1/retrieval', {
158
- method: 'POST',
159
- body: JSON.stringify(body),
160
- });
161
- const data = (res?.data ?? {}) as { chunks?: RagflowChunkHit[] };
162
- const chunks = data.chunks ?? [];
163
- return chunks.slice(0, opts.topK).map<KnowledgeHit>((c) => {
164
- const md = (c.metadata ?? {}) as Record<string, unknown>;
165
- const docId =
166
- (md.objectstack_doc_id as string | undefined) ??
167
- c.document_id ??
168
- c.doc_id ??
169
- c.id;
170
- const recordId = md.objectstack_record_id as string | undefined;
171
- return {
172
- chunkId: c.id ?? `${docId}#${c.position ?? 0}`,
173
- documentId: docId ?? c.id ?? 'unknown',
174
- sourceId: opts.source.id,
175
- sourceRecordId: recordId,
176
- score: c.similarity ?? c.score ?? 0,
177
- snippet: c.content ?? c.content_with_weight ?? '',
178
- title: (md.title as string | undefined) ?? c.document_name,
179
- metadata: md,
180
- };
181
- });
182
- }
183
-
184
- async healthCheck(): Promise<{ ok: boolean; message?: string }> {
185
- try {
186
- await this.request('/api/v1/datasets?page=1&page_size=1', { method: 'GET' });
187
- return { ok: true };
188
- } catch (err) {
189
- return { ok: false, message: err instanceof Error ? err.message : String(err) };
190
- }
191
- }
192
-
193
- private async deleteChunksByDocumentId(datasetId: string, docId: string): Promise<void> {
194
- // Find chunks with our stamped metadata, then delete by chunk id.
195
- const found = (await this.request(`/api/v1/retrieval`, {
196
- method: 'POST',
197
- body: JSON.stringify({
198
- question: docId,
199
- dataset_ids: [datasetId],
200
- top_k: 256,
201
- keyword: false,
202
- metadata_condition: { objectstack_doc_id: docId },
203
- }),
204
- })) as { data?: { chunks?: Array<{ id?: string }> } };
205
- const ids = (found.data?.chunks ?? [])
206
- .map((c) => c.id)
207
- .filter((x): x is string => typeof x === 'string');
208
- if (ids.length === 0) return;
209
- await this.request(`/api/v1/datasets/${datasetId}/chunks`, {
210
- method: 'DELETE',
211
- body: JSON.stringify({ chunk_ids: ids }),
212
- });
213
- }
214
-
215
- private async request(
216
- path: string,
217
- init: { method: string; body?: string },
218
- ): Promise<{ data?: unknown; code?: number; message?: string }> {
219
- const controller = new AbortController();
220
- const t = setTimeout(() => controller.abort(), this.timeoutMs);
221
- try {
222
- const res = await this.fetchImpl(`${this.endpoint}${path}`, {
223
- method: init.method,
224
- headers: {
225
- 'content-type': 'application/json',
226
- authorization: `Bearer ${this.apiKey}`,
227
- },
228
- body: init.body,
229
- signal: controller.signal,
230
- });
231
- const raw = await res.text();
232
- let parsed: { data?: unknown; code?: number; message?: string } = {};
233
- if (raw) {
234
- try {
235
- parsed = JSON.parse(raw) as typeof parsed;
236
- } catch {
237
- if (!res.ok) {
238
- throw new Error(
239
- `RAGFlow ${init.method} ${path} → ${res.status} ${res.statusText}: ${raw.slice(0, 200)}`,
240
- );
241
- }
242
- }
243
- }
244
- if (!res.ok || (typeof parsed.code === 'number' && parsed.code !== 0 && parsed.code !== 200)) {
245
- throw new Error(
246
- `RAGFlow ${init.method} ${path} → ${res.status} ${res.statusText}${
247
- parsed.message ? ` (${parsed.message})` : ''
248
- }`,
249
- );
250
- }
251
- return parsed;
252
- } finally {
253
- clearTimeout(t);
254
- }
255
- }
256
- }
257
-
258
- interface RagflowChunkHit {
259
- id?: string;
260
- document_id?: string;
261
- doc_id?: string;
262
- document_name?: string;
263
- content?: string;
264
- content_with_weight?: string;
265
- similarity?: number;
266
- score?: number;
267
- position?: number;
268
- metadata?: Record<string, unknown>;
269
- }
270
-
271
- /* ---------------------------------------------------------------- */
272
- /* Kernel plugin glue */
273
- /* ---------------------------------------------------------------- */
274
-
275
- export interface KnowledgeRagflowPluginOptions extends KnowledgeRagflowAdapterOptions {}
276
-
277
- export class KnowledgeRagflowPlugin implements Plugin {
278
- name = 'com.objectstack.plugin.knowledge-ragflow';
279
- version = '0.1.0';
280
- type = 'standard';
281
-
282
- private readonly adapter: KnowledgeRagflowAdapter;
283
-
284
- constructor(opts: KnowledgeRagflowPluginOptions) {
285
- this.adapter = new KnowledgeRagflowAdapter(opts);
286
- }
287
-
288
- async init(_ctx: PluginContext): Promise<void> {
289
- // No-op: actual registration happens in start() once service is available.
290
- }
291
-
292
- async start(ctx: PluginContext): Promise<void> {
293
- let svc: IKnowledgeService | undefined;
294
- try {
295
- svc = ctx.getService<IKnowledgeService>(KNOWLEDGE_SERVICE);
296
- } catch {
297
- ctx.logger.warn?.(
298
- 'KnowledgeRagflowPlugin: IKnowledgeService not registered — install KnowledgeServicePlugin first.',
299
- );
300
- return;
301
- }
302
- svc.registerAdapter(this.adapter.id, this.adapter);
303
- ctx.logger.info?.(
304
- `KnowledgeRagflowPlugin: adapter '${this.adapter.id}' registered (endpoint=${(this.adapter as unknown as { endpoint: string }).endpoint}).`,
305
- );
306
- }
307
- }
package/tsconfig.json DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.json",
3
- "compilerOptions": {
4
- "target": "ES2020",
5
- "module": "ES2020",
6
- "moduleResolution": "bundler",
7
- "declaration": true,
8
- "outDir": "./dist",
9
- "strict": true,
10
- "esModuleInterop": true,
11
- "skipLibCheck": true,
12
- "noUnusedLocals": false,
13
- "noUnusedParameters": false,
14
- "forceConsistentCasingInFileNames": true,
15
- "types": ["node"],
16
- "rootDir": "./src"
17
- },
18
- "include": ["src/**/*"],
19
- "exclude": ["node_modules", "dist"]
20
- }
package/vitest.config.ts DELETED
@@ -1,25 +0,0 @@
1
- // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
2
-
3
- import { defineConfig } from 'vitest/config';
4
- import path from 'path';
5
-
6
- export default defineConfig({
7
- test: {
8
- globals: true,
9
- environment: 'node',
10
- },
11
- resolve: {
12
- alias: {
13
- '@objectstack/core': path.resolve(__dirname, '../../core/src/index.ts'),
14
- '@objectstack/service-knowledge': path.resolve(__dirname, '../../services/service-knowledge/src/index.ts'),
15
- '@objectstack/spec/ai': path.resolve(__dirname, '../../spec/src/ai/index.ts'),
16
- '@objectstack/spec/contracts': path.resolve(__dirname, '../../spec/src/contracts/index.ts'),
17
- '@objectstack/spec/data': path.resolve(__dirname, '../../spec/src/data/index.ts'),
18
- '@objectstack/spec/kernel': path.resolve(__dirname, '../../spec/src/kernel/index.ts'),
19
- '@objectstack/spec/system': path.resolve(__dirname, '../../spec/src/system/index.ts'),
20
- // [ADR-0105 D1] Reached transitively via `@objectstack/types` (tenancy posture).
21
- '@objectstack/spec/security': path.resolve(__dirname, '../../spec/src/security/index.ts'),
22
- '@objectstack/spec': path.resolve(__dirname, '../../spec/src/index.ts'),
23
- },
24
- },
25
- });