@jini-ai/search 0.0.0-stage → 0.6.10
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/LICENSE +201 -0
- package/README.md +76 -2
- package/dist/api.d.ts +92 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +2 -0
- package/dist/api.js.map +1 -0
- package/dist/contract.d.ts +219 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +46 -0
- package/dist/contract.js.map +1 -0
- package/dist/contribution.d.ts +61 -0
- package/dist/contribution.d.ts.map +1 -0
- package/dist/contribution.js +124 -0
- package/dist/contribution.js.map +1 -0
- package/dist/digest.d.ts +13 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +55 -0
- package/dist/digest.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/indexer.d.ts +50 -0
- package/dist/indexer.d.ts.map +1 -0
- package/dist/indexer.js +402 -0
- package/dist/indexer.js.map +1 -0
- package/dist/ports.d.ts +194 -0
- package/dist/ports.d.ts.map +1 -0
- package/dist/ports.js +2 -0
- package/dist/ports.js.map +1 -0
- package/dist/registry.d.ts +33 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +81 -0
- package/dist/registry.js.map +1 -0
- package/dist/service.d.ts +37 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +118 -0
- package/dist/service.js.map +1 -0
- package/dist/testkit/assert.d.ts +14 -0
- package/dist/testkit/assert.d.ts.map +1 -0
- package/dist/testkit/assert.js +20 -0
- package/dist/testkit/assert.js.map +1 -0
- package/dist/testkit/conformance.d.ts +32 -0
- package/dist/testkit/conformance.d.ts.map +1 -0
- package/dist/testkit/conformance.js +453 -0
- package/dist/testkit/conformance.js.map +1 -0
- package/dist/testkit/fakes.d.ts +56 -0
- package/dist/testkit/fakes.d.ts.map +1 -0
- package/dist/testkit/fakes.js +114 -0
- package/dist/testkit/fakes.js.map +1 -0
- package/dist/testkit/index.d.ts +9 -0
- package/dist/testkit/index.d.ts.map +1 -0
- package/dist/testkit/index.js +9 -0
- package/dist/testkit/index.js.map +1 -0
- package/dist/testkit/memory-provider.d.ts +23 -0
- package/dist/testkit/memory-provider.d.ts.map +1 -0
- package/dist/testkit/memory-provider.js +237 -0
- package/dist/testkit/memory-provider.js.map +1 -0
- package/dist/tokens.d.ts +9 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +12 -0
- package/dist/tokens.js.map +1 -0
- package/dist/tools.d.ts +74 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +194 -0
- package/dist/tools.js.map +1 -0
- package/package.json +75 -3
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { encodeSearchKey } from '../contract.js';
|
|
2
|
+
/**
|
|
3
|
+
* An {@link HttpClientPort} answering from `handle` (which may throw or reject to simulate a
|
|
4
|
+
* transport fault) and recording each request before handling it.
|
|
5
|
+
* @complexity O(1) per request plus `handle`.
|
|
6
|
+
*/
|
|
7
|
+
export function createFakeHttpClient(required, _optional = {}) {
|
|
8
|
+
const requests = [];
|
|
9
|
+
return {
|
|
10
|
+
requests,
|
|
11
|
+
async send({ request }, optional = {}) {
|
|
12
|
+
requests.push(request);
|
|
13
|
+
return required.handle({ request, ...(optional.redirect === undefined ? {} : { redirect: optional.redirect }) });
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** An {@link HttpClientPort} whose every send rejects, as a down network does. */
|
|
18
|
+
export function createUnavailableHttpClient(_required = {}, optional = {}) {
|
|
19
|
+
const message = optional.message ?? 'network unavailable';
|
|
20
|
+
return { send: async () => { throw new Error(message); } };
|
|
21
|
+
}
|
|
22
|
+
const STATUSES = ['pending', 'indexed', 'unknown', 'failed'];
|
|
23
|
+
const targetId = (target) => JSON.stringify([target.siteId, target.providerId, target.generation]);
|
|
24
|
+
const sameTarget = (a, b) => a !== null && targetId(a) === targetId(b);
|
|
25
|
+
function createIndexState() {
|
|
26
|
+
const rows = new Map();
|
|
27
|
+
const watermarks = new Map();
|
|
28
|
+
const rowId = (target, key) => `${targetId(target)}|${encodeSearchKey({ key })}`;
|
|
29
|
+
const rowsOf = (target) => [...rows.values()].filter(row => sameTarget(row.target, target));
|
|
30
|
+
return {
|
|
31
|
+
async get({ target, key }) { return rows.get(rowId(target, key)) ?? null; },
|
|
32
|
+
async put({ row }) { rows.set(rowId(row.target, row.key), Object.freeze({ ...row })); },
|
|
33
|
+
async settle({ row, expected }) {
|
|
34
|
+
const stored = rows.get(rowId(row.target, row.key));
|
|
35
|
+
// Compare-and-swap: only the settle that still sees the row it observed may replace it.
|
|
36
|
+
if (stored?.revision !== expected.revision || (stored.taskId ?? null) !== expected.taskId)
|
|
37
|
+
return false;
|
|
38
|
+
rows.set(rowId(row.target, row.key), Object.freeze({ ...row }));
|
|
39
|
+
return true;
|
|
40
|
+
},
|
|
41
|
+
async listByStatus({ target, statuses, limit }, { failedBelowAttempts = Infinity } = {}) {
|
|
42
|
+
const actionable = (row) => !(row.status === 'failed' && row.attempts >= failedBelowAttempts);
|
|
43
|
+
return rowsOf(target).filter(row => statuses.includes(row.status) && actionable(row)).slice(0, limit);
|
|
44
|
+
},
|
|
45
|
+
async counts({ target }) {
|
|
46
|
+
const counts = Object.fromEntries(STATUSES.map(status => [status, 0]));
|
|
47
|
+
for (const row of rowsOf(target))
|
|
48
|
+
counts[row.status] += 1;
|
|
49
|
+
return counts;
|
|
50
|
+
},
|
|
51
|
+
async getWatermark({ target, collection }) { return watermarks.get(`${targetId(target)}|${collection}`) ?? null; },
|
|
52
|
+
async putWatermark({ target, collection, cursor, done }) {
|
|
53
|
+
watermarks.set(`${targetId(target)}|${collection}`, cursor === undefined ? { done } : { cursor, done });
|
|
54
|
+
},
|
|
55
|
+
async deleteTarget({ target }) {
|
|
56
|
+
for (const [id, row] of rows)
|
|
57
|
+
if (sameTarget(row.target, target))
|
|
58
|
+
rows.delete(id);
|
|
59
|
+
const prefix = `${targetId(target)}|`;
|
|
60
|
+
for (const id of watermarks.keys())
|
|
61
|
+
if (id.startsWith(prefix))
|
|
62
|
+
watermarks.delete(id);
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function createTargets(initial) {
|
|
67
|
+
const sites = new Map(initial.map(target => [target.siteId, { active: target, building: null }]));
|
|
68
|
+
let retired = [];
|
|
69
|
+
const current = (siteId) => sites.get(siteId) ?? { active: null, building: null };
|
|
70
|
+
return {
|
|
71
|
+
async get({ siteId }) { return { ...current(siteId) }; },
|
|
72
|
+
async setBuilding({ target }) { sites.set(target.siteId, { active: current(target.siteId).active, building: target }); },
|
|
73
|
+
async promote({ siteId, expected }) {
|
|
74
|
+
const { active, building } = current(siteId);
|
|
75
|
+
// Compare-and-swap: only the caller that still sees the stored building may promote it.
|
|
76
|
+
if (!sameTarget(building, expected))
|
|
77
|
+
return false;
|
|
78
|
+
sites.set(siteId, { active: building, building: null });
|
|
79
|
+
// Recorded in the same step as the switch, so the replaced index is dropped even after a crash.
|
|
80
|
+
if (active !== null)
|
|
81
|
+
retired = [...retired, active];
|
|
82
|
+
return { replaced: active };
|
|
83
|
+
},
|
|
84
|
+
async listRetired({ siteId }) { return retired.filter(target => target.siteId === siteId); },
|
|
85
|
+
async forgetRetired({ target }) { retired = retired.filter(entry => !sameTarget(entry, target)); },
|
|
86
|
+
async clearBuilding({ siteId }) { sites.set(siteId, { active: current(siteId).active, building: null }); },
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* In-memory {@link SearchIndexStatePort} and {@link SearchTargetPort} (two ports, because both
|
|
91
|
+
* name a `get`). `promote` is a real compare-and-swap on the stored `building` pointer.
|
|
92
|
+
* @param optional.active - Targets that start active, one per site.
|
|
93
|
+
* @complexity get/put O(1); listByStatus/counts/deleteTarget O(rows).
|
|
94
|
+
*/
|
|
95
|
+
export function createInMemorySearchState(_required = {}, optional = {}) {
|
|
96
|
+
return { indexState: createIndexState(), targets: createTargets(optional.active ?? []) };
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* An access port that answers `visibleKeys` with a predicate per requested key.
|
|
100
|
+
* @complexity O(keys) predicate calls.
|
|
101
|
+
*/
|
|
102
|
+
export function createPredicateAccessPort(required, _optional = {}) {
|
|
103
|
+
return {
|
|
104
|
+
async visibleKeys({ siteId, keys, audiences }) {
|
|
105
|
+
return new Set(keys.filter(key => required.isVisible({ siteId, key, audiences })).map(key => encodeSearchKey({ key })));
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/** An access port under which exactly the listed keys are visible (to every audience). */
|
|
110
|
+
export function createStaticAccessPort(required, _optional = {}) {
|
|
111
|
+
const visible = new Set(required.visible.map(key => encodeSearchKey({ key })));
|
|
112
|
+
return createPredicateAccessPort({ isVisible: ({ key }) => visible.has(encodeSearchKey({ key })) });
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=fakes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fakes.js","sourceRoot":"","sources":["../../src/testkit/fakes.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,eAAe,EAA0B,MAAM,gBAAgB,CAAC;AAWzE;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAClC,QAAyJ,EACzJ,YAAmC,EAAE;IAErC,MAAM,QAAQ,GAAkB,EAAE,CAAC;IACnC,OAAO;QACL,QAAQ;QACR,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,EAAE,QAAQ,GAAG,EAAE;YACnC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACvB,OAAO,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,QAAQ,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAA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C,EAAE;IAErC,OAAO;QACL,KAAK,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE;YAC3C,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,eAAe,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QAC1H,CAAC;KACF,CAAC;AACJ,CAAC;AAED,0FAA0F;AAC1F,MAAM,UAAU,sBAAsB,CAAC,QAA4D,EAAE,YAAmC,EAAE;IACxI,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,eAAe,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/E,OAAO,yBAAyB,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;AACtG,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file `@jini-ai/search/testkit`: the provider conformance kit, the in-memory reference provider
|
|
3
|
+
* and DI fakes. Test-only; nothing here belongs in a running host.
|
|
4
|
+
*/
|
|
5
|
+
export * from './assert.js';
|
|
6
|
+
export * from './conformance.js';
|
|
7
|
+
export * from './memory-provider.js';
|
|
8
|
+
export * from './fakes.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testkit/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file `@jini-ai/search/testkit`: the provider conformance kit, the in-memory reference provider
|
|
3
|
+
* and DI fakes. Test-only; nothing here belongs in a running host.
|
|
4
|
+
*/
|
|
5
|
+
export * from './assert.js';
|
|
6
|
+
export * from './conformance.js';
|
|
7
|
+
export * from './memory-provider.js';
|
|
8
|
+
export * from './fakes.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testkit/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type SearchProvider, type SearchProviderContext } from '../contract.js';
|
|
2
|
+
export interface InMemorySearchProviderOptions {
|
|
3
|
+
readonly id?: string;
|
|
4
|
+
readonly label?: string;
|
|
5
|
+
readonly acceptsRestricted?: boolean;
|
|
6
|
+
readonly asyncIndexing?: boolean;
|
|
7
|
+
readonly typoTolerance?: boolean;
|
|
8
|
+
readonly locales?: readonly string[] | 'any';
|
|
9
|
+
readonly maxBatch?: number;
|
|
10
|
+
/** `false` turns every call for that context into `unknown`/`provider_unavailable`. */
|
|
11
|
+
readonly available?: (required: {
|
|
12
|
+
readonly ctx: SearchProviderContext;
|
|
13
|
+
}) => boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The reference provider. Case-insensitive word matching over title + body (every query word must
|
|
17
|
+
* match), plain-text snippet windows with highlight ranges, versioned tombstones, cursor = offset.
|
|
18
|
+
* With `asyncIndexing`, a non-stale write answers `pending` with a task id and becomes visible only
|
|
19
|
+
* when that task (and every earlier one) is settled by the next `awaitTask` call.
|
|
20
|
+
* @complexity Writes O(batch); queries O(documents in the index × words).
|
|
21
|
+
*/
|
|
22
|
+
export declare function createInMemorySearchProvider(_required?: Record<string, never>, optional?: InMemorySearchProviderOptions): SearchProvider;
|
|
23
|
+
//# sourceMappingURL=memory-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-provider.d.ts","sourceRoot":"","sources":["../../src/testkit/memory-provider.ts"],"names":[],"mappings":"AAYA,OAAO,EAGY,KAAK,cAAc,EAAE,KAAK,qBAAqB,EAEjE,MAAM,gBAAgB,CAAC;AAiBxB,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IACrC,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IACjC,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,KAAK,CAAC;IAC7C,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,uFAAuF;IACvF,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,qBAAqB,CAAA;KAAE,KAAK,OAAO,CAAC;CACrF;AAmHD;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAAC,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAM,EAAE,QAAQ,GAAE,6BAAkC,GAAG,cAAc,CA8GhJ"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The in-memory REFERENCE search provider. It exists so the conformance kit has something
|
|
3
|
+
* real to run against in tests, and as a readable executable statement of the contract's write and
|
|
4
|
+
* query semantics.
|
|
5
|
+
*
|
|
6
|
+
* It is NOT the built-in provider: the owner builds the real built-in (`id: 'builtin'`) on the host's
|
|
7
|
+
* storage kernel with its own tables and migration, and it must pass the same conformance kit. Never
|
|
8
|
+
* register this one in a running host — all state lives in one process's memory.
|
|
9
|
+
*/
|
|
10
|
+
import { providerOk, providerRejected, providerUnknown, } from '@jini-ai/core/provider-registry';
|
|
11
|
+
import { encodeSearchKey, } from '../contract.js';
|
|
12
|
+
const DEFAULT_LIMIT = 10;
|
|
13
|
+
const MAX_LIMIT = 100;
|
|
14
|
+
const SNIPPET_LEAD = 40;
|
|
15
|
+
const SNIPPET_LENGTH = 160;
|
|
16
|
+
/** Typo tolerance (when enabled) allows one edit on words of at least this length. */
|
|
17
|
+
const TYPO_MIN_LENGTH = 5;
|
|
18
|
+
const WORD = /[\p{L}\p{N}]+/gu;
|
|
19
|
+
const words = (text) => (text.toLowerCase().match(WORD) ?? []);
|
|
20
|
+
/** True when `a` and `b` are at most one insertion, deletion or substitution apart. */
|
|
21
|
+
function withinOneEdit(a, b) {
|
|
22
|
+
if (Math.abs(a.length - b.length) > 1)
|
|
23
|
+
return false;
|
|
24
|
+
let i = 0;
|
|
25
|
+
while (i < a.length && a[i] === b[i])
|
|
26
|
+
i += 1;
|
|
27
|
+
// Skip one char of the longer word (or one of each when equal length) and compare the rests.
|
|
28
|
+
const restA = a.length >= b.length ? a.slice(i + 1) : a.slice(i);
|
|
29
|
+
const restB = b.length >= a.length ? b.slice(i + 1) : b.slice(i);
|
|
30
|
+
return restA === restB;
|
|
31
|
+
}
|
|
32
|
+
function makeMatcher(required) {
|
|
33
|
+
const { terms, typoTolerance } = required;
|
|
34
|
+
return word => terms.some(term => term === word || (typoTolerance && term.length >= TYPO_MIN_LENGTH && withinOneEdit(term, word)));
|
|
35
|
+
}
|
|
36
|
+
/** Plain-text excerpt around the first matching word, with every matching word in it highlighted. */
|
|
37
|
+
function snippetOf(required) {
|
|
38
|
+
const { body, matches } = required;
|
|
39
|
+
const located = [...body.matchAll(WORD)].map(found => ({ start: found.index, end: found.index + found[0].length, hit: matches(found[0].toLowerCase()) }));
|
|
40
|
+
const first = located.find(word => word.hit);
|
|
41
|
+
const start = first === undefined ? 0 : Math.max(0, first.start - SNIPPET_LEAD);
|
|
42
|
+
const end = Math.min(body.length, start + SNIPPET_LENGTH);
|
|
43
|
+
const highlights = located
|
|
44
|
+
.filter(word => word.hit && word.start >= start && word.end <= end)
|
|
45
|
+
.map(word => ({ start: word.start - start, end: word.end - start }));
|
|
46
|
+
return { snippet: body.slice(start, end), highlights };
|
|
47
|
+
}
|
|
48
|
+
function audienceAllows(document, audiences) {
|
|
49
|
+
const { visibility } = document;
|
|
50
|
+
return visibility.kind === 'public' || visibility.audiences.some(audience => audiences.includes(audience));
|
|
51
|
+
}
|
|
52
|
+
function fieldsMatch(document, filters) {
|
|
53
|
+
return Object.entries(filters).every(([name, expected]) => {
|
|
54
|
+
const actual = document.fields?.[name];
|
|
55
|
+
return Array.isArray(actual) ? actual.includes(expected) : actual === expected;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function scopeMatches(document, query) {
|
|
59
|
+
const collectionOk = query.collections === undefined || query.collections.includes(document.key.collection);
|
|
60
|
+
return collectionOk && (query.locale === undefined || document.locale === query.locale);
|
|
61
|
+
}
|
|
62
|
+
function passesFilters(document, query, tenant) {
|
|
63
|
+
const ownTenant = document.key.siteId === tenant.siteId && document.key.workspaceId === tenant.workspaceId;
|
|
64
|
+
return ownTenant && scopeMatches(document, query) && fieldsMatch(document, query.filters ?? {}) && audienceAllows(document, query.audiences ?? []);
|
|
65
|
+
}
|
|
66
|
+
function pageBounds(query) {
|
|
67
|
+
const limit = query.limit ?? DEFAULT_LIMIT;
|
|
68
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > MAX_LIMIT)
|
|
69
|
+
return `limit must be an integer from 1 to ${MAX_LIMIT}`;
|
|
70
|
+
const cursor = query.cursor ?? '0';
|
|
71
|
+
if (!/^\d+$/.test(cursor))
|
|
72
|
+
return 'cursor is not a cursor of this provider';
|
|
73
|
+
return { offset: Number(cursor), limit };
|
|
74
|
+
}
|
|
75
|
+
/** 0 unless every query term matches some word (AND semantics); title words weigh double. */
|
|
76
|
+
function scoreOf(document, required) {
|
|
77
|
+
const titleWords = words(document.title);
|
|
78
|
+
const bodyWords = words(document.body);
|
|
79
|
+
const all = [...titleWords, ...bodyWords];
|
|
80
|
+
if (!required.termMatchers.every(matcher => all.some(matcher)))
|
|
81
|
+
return 0;
|
|
82
|
+
return titleWords.filter(required.matches).length * 2 + bodyWords.filter(required.matches).length;
|
|
83
|
+
}
|
|
84
|
+
function hitOf(document, score, matches) {
|
|
85
|
+
const { snippet, highlights } = snippetOf({ body: document.body, matches });
|
|
86
|
+
return { key: document.key, revision: document.revision, url: document.url, title: document.title, snippet, highlights, score };
|
|
87
|
+
}
|
|
88
|
+
function runQuery(index, query, typoTolerance, tenant) {
|
|
89
|
+
const terms = words(query.text);
|
|
90
|
+
if (terms.length === 0)
|
|
91
|
+
return providerRejected({ code: 'invalid_request', message: 'query text must not be empty' });
|
|
92
|
+
const bounds = pageBounds(query);
|
|
93
|
+
if (typeof bounds === 'string')
|
|
94
|
+
return providerRejected({ code: 'invalid_request', message: bounds });
|
|
95
|
+
const matches = makeMatcher({ terms, typoTolerance });
|
|
96
|
+
const termMatchers = terms.map(term => makeMatcher({ terms: [term], typoTolerance }));
|
|
97
|
+
const ranked = [...index.entries()]
|
|
98
|
+
.flatMap(([encoded, entry]) => entry.document !== undefined && passesFilters(entry.document, query, tenant) ? [{ encoded, document: entry.document, score: scoreOf(entry.document, { termMatchers, matches }) }] : [])
|
|
99
|
+
.filter(candidate => candidate.score > 0)
|
|
100
|
+
// Score first, then the encoded key: a total order, so cursors over offsets are stable.
|
|
101
|
+
.sort((a, b) => b.score - a.score || (a.encoded < b.encoded ? -1 : 1));
|
|
102
|
+
const end = bounds.offset + bounds.limit;
|
|
103
|
+
const hits = ranked.slice(bounds.offset, end).map(candidate => hitOf(candidate.document, candidate.score, matches));
|
|
104
|
+
return providerOk({ value: end < ranked.length ? { hits, nextCursor: String(end) } : { hits } });
|
|
105
|
+
}
|
|
106
|
+
const isRevision = (revision) => typeof revision === 'number' && Number.isSafeInteger(revision) && revision >= 0;
|
|
107
|
+
function resolveOptions(optional) {
|
|
108
|
+
const { id = 'memory', label = 'In-memory reference provider', acceptsRestricted = true, asyncIndexing = false, typoTolerance = false, locales = 'any', maxBatch = 100, available = () => true, } = optional;
|
|
109
|
+
return { id, label, acceptsRestricted, asyncIndexing, typoTolerance, locales, maxBatch, available };
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The reference provider. Case-insensitive word matching over title + body (every query word must
|
|
113
|
+
* match), plain-text snippet windows with highlight ranges, versioned tombstones, cursor = offset.
|
|
114
|
+
* With `asyncIndexing`, a non-stale write answers `pending` with a task id and becomes visible only
|
|
115
|
+
* when that task (and every earlier one) is settled by the next `awaitTask` call.
|
|
116
|
+
* @complexity Writes O(batch); queries O(documents in the index × words).
|
|
117
|
+
*/
|
|
118
|
+
export function createInMemorySearchProvider(_required = {}, optional = {}) {
|
|
119
|
+
const { id, label, acceptsRestricted, asyncIndexing, typoTolerance, locales, maxBatch, available } = resolveOptions(optional);
|
|
120
|
+
const indexes = new Map();
|
|
121
|
+
const queued = new Map();
|
|
122
|
+
const settled = new Set();
|
|
123
|
+
let taskCounter = 0;
|
|
124
|
+
const capabilities = { acceptsRestricted, typoTolerance, locales, maxBatch, asyncIndexing };
|
|
125
|
+
const unavailable = () => providerUnknown({ code: 'provider_unavailable', message: 'the in-memory provider is unavailable for this context' });
|
|
126
|
+
const missing = (indexName) => providerRejected({ code: 'not_found', message: `index '${indexName}' does not exist` });
|
|
127
|
+
const store = (index, entry) => {
|
|
128
|
+
const encoded = encodeSearchKey({ key: entry.key });
|
|
129
|
+
const current = index.get(encoded);
|
|
130
|
+
if (current !== undefined && current.revision >= entry.revision)
|
|
131
|
+
return false;
|
|
132
|
+
index.set(encoded, entry);
|
|
133
|
+
return true;
|
|
134
|
+
};
|
|
135
|
+
const restrictedRefusal = (entry) => !acceptsRestricted && entry.document?.visibility.kind === 'restricted' ? 'this provider accepts public documents only' : undefined;
|
|
136
|
+
function outcomeOf(index, entry, pending) {
|
|
137
|
+
const base = { key: entry.key, revision: entry.revision };
|
|
138
|
+
const refusal = isRevision(entry.revision) ? restrictedRefusal(entry) : 'revision must be a non-negative safe integer';
|
|
139
|
+
if (refusal !== undefined)
|
|
140
|
+
return { ...base, status: 'rejected', message: refusal };
|
|
141
|
+
const current = index.get(encodeSearchKey({ key: entry.key }));
|
|
142
|
+
if (current !== undefined && current.revision >= entry.revision)
|
|
143
|
+
return { ...base, status: 'stale' };
|
|
144
|
+
if (!asyncIndexing) {
|
|
145
|
+
store(index, entry);
|
|
146
|
+
return { ...base, status: 'applied' };
|
|
147
|
+
}
|
|
148
|
+
pending.push(entry);
|
|
149
|
+
return { ...base, status: 'pending' };
|
|
150
|
+
}
|
|
151
|
+
function write(ctx, entries) {
|
|
152
|
+
if (!available({ ctx }))
|
|
153
|
+
return unavailable();
|
|
154
|
+
if (entries.length > maxBatch)
|
|
155
|
+
return providerRejected({ code: 'invalid_request', message: `at most ${maxBatch} items per write` });
|
|
156
|
+
const index = indexes.get(ctx.indexName);
|
|
157
|
+
if (index === undefined)
|
|
158
|
+
return missing(ctx.indexName);
|
|
159
|
+
const pending = [];
|
|
160
|
+
const outcomes = entries.map(entry => outcomeOf(index, entry, pending));
|
|
161
|
+
if (pending.length === 0)
|
|
162
|
+
return providerOk({ value: { outcomes } });
|
|
163
|
+
taskCounter += 1;
|
|
164
|
+
const taskId = `task_${taskCounter}`;
|
|
165
|
+
queued.set(taskId, { indexName: ctx.indexName, entries: pending });
|
|
166
|
+
return providerOk({ value: { outcomes, taskId } });
|
|
167
|
+
}
|
|
168
|
+
/** Settle every queued task up to and including `taskId`, in write order. */
|
|
169
|
+
function settleThrough(taskId) {
|
|
170
|
+
const ids = [...queued.keys()];
|
|
171
|
+
// awaitTask calls this only when `taskId` is queued, so indexOf is never -1.
|
|
172
|
+
for (const queuedId of ids.slice(0, ids.indexOf(taskId) + 1)) {
|
|
173
|
+
const task = queued.get(queuedId);
|
|
174
|
+
const index = indexes.get(task.indexName);
|
|
175
|
+
// A task whose index was dropped meanwhile has nothing left to write into.
|
|
176
|
+
if (index !== undefined)
|
|
177
|
+
for (const entry of task.entries)
|
|
178
|
+
store(index, entry);
|
|
179
|
+
queued.delete(queuedId);
|
|
180
|
+
settled.add(queuedId);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async function guarded(ctx, run) {
|
|
184
|
+
if (!available({ ctx }))
|
|
185
|
+
return unavailable();
|
|
186
|
+
const index = indexes.get(ctx.indexName);
|
|
187
|
+
return index === undefined ? missing(ctx.indexName) : run(index);
|
|
188
|
+
}
|
|
189
|
+
const provider = {
|
|
190
|
+
id, label, capabilities, credentialKeys: [],
|
|
191
|
+
async ensureIndex(ctx) {
|
|
192
|
+
if (!available({ ctx }))
|
|
193
|
+
return unavailable();
|
|
194
|
+
if (!indexes.has(ctx.indexName))
|
|
195
|
+
indexes.set(ctx.indexName, new Map());
|
|
196
|
+
return providerOk({ value: undefined });
|
|
197
|
+
},
|
|
198
|
+
async dropIndex(ctx) {
|
|
199
|
+
if (!available({ ctx }))
|
|
200
|
+
return unavailable();
|
|
201
|
+
indexes.delete(ctx.indexName);
|
|
202
|
+
return providerOk({ value: undefined });
|
|
203
|
+
},
|
|
204
|
+
async upsert(ctx, { documents }) {
|
|
205
|
+
return write(ctx, documents.map(document => ({ key: document.key, revision: document.revision, document })));
|
|
206
|
+
},
|
|
207
|
+
async remove(ctx, { tombstones }) {
|
|
208
|
+
return write(ctx, tombstones.map((tombstone) => ({ key: tombstone.key, revision: tombstone.revision })));
|
|
209
|
+
},
|
|
210
|
+
async query(ctx, { query }) {
|
|
211
|
+
return guarded(ctx, index => runQuery(index, query, typoTolerance, ctx));
|
|
212
|
+
},
|
|
213
|
+
async revisionOf(ctx, { keys }) {
|
|
214
|
+
return guarded(ctx, index => providerOk({
|
|
215
|
+
value: keys.map((key) => {
|
|
216
|
+
const entry = index.get(encodeSearchKey({ key }));
|
|
217
|
+
return entry === undefined ? { key, revision: null, deleted: false } : { key, revision: entry.revision, deleted: entry.document === undefined };
|
|
218
|
+
}),
|
|
219
|
+
}));
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
if (!asyncIndexing)
|
|
223
|
+
return provider;
|
|
224
|
+
return {
|
|
225
|
+
...provider,
|
|
226
|
+
async awaitTask(ctx, { taskId }) {
|
|
227
|
+
if (!available({ ctx }))
|
|
228
|
+
return unavailable();
|
|
229
|
+
if (queued.has(taskId))
|
|
230
|
+
settleThrough(taskId);
|
|
231
|
+
if (settled.has(taskId))
|
|
232
|
+
return providerOk({ value: 'succeeded' });
|
|
233
|
+
return providerRejected({ code: 'not_found', message: `task '${taskId}' is not known` });
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=memory-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-provider.js","sourceRoot":"","sources":["../../src/testkit/memory-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,UAAU,EAAE,gBAAgB,EAAE,eAAe,GAC9C,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,eAAe,GAIhB,MAAM,gBAAgB,CAAC;AA6BxB,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,YAAY,GAAG,EAAE,CAAC;AACxB,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,sFAAsF;AACtF,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,MAAM,IAAI,GAAG,iBAAiB,CAAC;AAE/B,MAAM,KAAK,GAAG,CAAC,IAAY,EAAY,EAAE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9C,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC;gBAAE,OAAO,UAAU,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;YACnE,OAAO,gBAAgB,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,MAAM,gBAAgB,EAAE,CAAC,CAAC;QAC3F,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/tokens.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SearchIndexer, SearchService } from './api.js';
|
|
2
|
+
import type { SearchDocumentSource } from './ports.js';
|
|
3
|
+
import type { SearchProviderRegistry } from './registry.js';
|
|
4
|
+
export declare const SearchProviderRegistryToken: import("@jini-ai/core").Token<SearchProviderRegistry, string>;
|
|
5
|
+
export declare const SearchServiceToken: import("@jini-ai/core").Token<SearchService, string>;
|
|
6
|
+
export declare const SearchIndexerToken: import("@jini-ai/core").Token<SearchIndexer, string>;
|
|
7
|
+
/** Many-bound: every collection that can be searched contributes its own source. */
|
|
8
|
+
export declare const SearchDocumentSourceToken: import("@jini-ai/core").ManyToken<SearchDocumentSource, string>;
|
|
9
|
+
//# sourceMappingURL=tokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAE5D,eAAO,MAAM,2BAA2B,+DAAoE,CAAC;AAC7G,eAAO,MAAM,kBAAkB,sDAAiD,CAAC;AACjF,eAAO,MAAM,kBAAkB,sDAAiD,CAAC;AACjF,oFAAoF;AACpF,eAAO,MAAM,yBAAyB,iEAAoE,CAAC"}
|
package/dist/tokens.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Composition tokens of the search capability. Consumers (routes, theme blocks, agent tools)
|
|
3
|
+
* resolve only {@link SearchServiceToken}; the composition root alone resolves the indexer and binds
|
|
4
|
+
* one {@link SearchDocumentSourceToken} per collection (CMS posts, pages, a plugin's catalog …).
|
|
5
|
+
*/
|
|
6
|
+
import { manyToken, token } from '@jini-ai/core';
|
|
7
|
+
export const SearchProviderRegistryToken = token({ id: 'search.provider-registry' });
|
|
8
|
+
export const SearchServiceToken = token({ id: 'search.service' });
|
|
9
|
+
export const SearchIndexerToken = token({ id: 'search.indexer' });
|
|
10
|
+
/** Many-bound: every collection that can be searched contributes its own source. */
|
|
11
|
+
export const SearchDocumentSourceToken = manyToken({ id: 'search.document-source' });
|
|
12
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAKjD,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,CAAyB,EAAE,EAAE,EAAE,0BAA0B,EAAE,CAAC,CAAC;AAC7G,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAgB,EAAE,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC;AACjF,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAgB,EAAE,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC;AACjF,oFAAoF;AACpF,MAAM,CAAC,MAAM,yBAAyB,GAAG,SAAS,CAAuB,EAAE,EAAE,EAAE,wBAAwB,EAAE,CAAC,CAAC"}
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Agent tools for site search (lot S6), subpath `@jini-ai/search/tools`.
|
|
3
|
+
*
|
|
4
|
+
* `search_query` and `search_status` are reads. `search_reindex` (bulk vendor writes = cost) and
|
|
5
|
+
* `search_set_provider` (a settings change plus a full backfill into another backend) ask the human
|
|
6
|
+
* first through core's approval lifecycle; only the reindex grant may be remembered, per provider.
|
|
7
|
+
*
|
|
8
|
+
* Agents only ever see PUBLIC results: `search_query` never passes viewer audiences to the service,
|
|
9
|
+
* so a members-only document cannot reach a model context through this tool.
|
|
10
|
+
*
|
|
11
|
+
* Permission is checked through an injected `requirePermission` port (the `@jini-ai/db` transfer
|
|
12
|
+
* tools' shape) rather than `@jini-ai/cms/core`'s helper, so this generic package keeps its single
|
|
13
|
+
* `@jini-ai/core` dependency; the host binds the port to its own permission catalog.
|
|
14
|
+
*/
|
|
15
|
+
import { type AgentToolDefinition, type ApprovalAnswer, type DerivedRiskByToolId, type RememberedApprovalPort, type ToolExecutionContext, type ToolExecutionOptions, type ToolRegistration } from '@jini-ai/core';
|
|
16
|
+
import type { ProviderRegistry } from '@jini-ai/core/provider-registry';
|
|
17
|
+
import type { SearchProvider } from './contract.js';
|
|
18
|
+
import type { SearchIndexer, SearchService } from './api.js';
|
|
19
|
+
export declare const SEARCH_TOOL_DOMAIN = "search";
|
|
20
|
+
/** Reads: the setting and index health are site settings; results are public content only. */
|
|
21
|
+
export declare const SEARCH_READ_PERMISSION = "settings.read";
|
|
22
|
+
/** Writes: choosing and re-filling a search backend is an integration change. */
|
|
23
|
+
export declare const SEARCH_MANAGE_PERMISSION = "admin.integrations.manage";
|
|
24
|
+
/** What the human is asked to approve. */
|
|
25
|
+
export interface SearchApprovalDescription {
|
|
26
|
+
readonly action: 'reindex' | 'set_provider';
|
|
27
|
+
readonly siteId: string;
|
|
28
|
+
readonly providerId: string;
|
|
29
|
+
/** The provider the site uses now (null when search was never configured). */
|
|
30
|
+
readonly fromProviderId: string | null;
|
|
31
|
+
readonly summary: string;
|
|
32
|
+
}
|
|
33
|
+
export interface SearchToolDeps {
|
|
34
|
+
readonly workspaceId: string;
|
|
35
|
+
readonly siteId: string;
|
|
36
|
+
readonly service: SearchService;
|
|
37
|
+
readonly indexer: Pick<SearchIndexer, 'startRebuild'>;
|
|
38
|
+
readonly registry: ProviderRegistry<SearchProvider>;
|
|
39
|
+
/** @throws When the principal lacks the permission (the host's own error). */
|
|
40
|
+
requirePermission(required: {
|
|
41
|
+
readonly principalId: string;
|
|
42
|
+
readonly permission: string;
|
|
43
|
+
}): Promise<void>;
|
|
44
|
+
/** The host's confirmation transport (e.g. an approval card). */
|
|
45
|
+
askHuman(required: {
|
|
46
|
+
readonly ctx: ToolExecutionContext;
|
|
47
|
+
readonly description: SearchApprovalDescription;
|
|
48
|
+
}, optional: ToolExecutionOptions): Promise<ApprovalAnswer>;
|
|
49
|
+
/**
|
|
50
|
+
* Persist the per-site `search.provider` setting. `principalId` is the calling tool principal, so
|
|
51
|
+
* the host's settings ledger records who made the change (added 2026-10-21, additive).
|
|
52
|
+
*/
|
|
53
|
+
setProviderSetting(required: {
|
|
54
|
+
readonly siteId: string;
|
|
55
|
+
readonly providerId: string;
|
|
56
|
+
readonly principalId: string;
|
|
57
|
+
}): Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
export declare const catalog: AgentToolDefinition[];
|
|
60
|
+
/** Independently derived from the calls each handler below makes. */
|
|
61
|
+
export declare const derivedRisk: DerivedRiskByToolId;
|
|
62
|
+
/**
|
|
63
|
+
* Build the four search tool registrations.
|
|
64
|
+
* @param required - Site scope, the service/indexer/registry and the host's permission, approval and
|
|
65
|
+
* setting ports.
|
|
66
|
+
* @param optional.remembered - Persisted approval grants; only `search_reindex:<providerId>` uses it.
|
|
67
|
+
* @returns Registrations through core's `buildDomainRegistrations` (risk corroborated, schemas required).
|
|
68
|
+
* @throws Permission and port failures propagate; malformed input is a `ToolInputError`.
|
|
69
|
+
* @complexity O(1) wiring; each handler is one or two port calls.
|
|
70
|
+
*/
|
|
71
|
+
export declare function buildSearchToolRegistrations(required: SearchToolDeps, optional?: {
|
|
72
|
+
readonly remembered?: RememberedApprovalPort;
|
|
73
|
+
}): ToolRegistration[];
|
|
74
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAEL,KAAK,mBAAmB,EAAE,KAAK,cAAc,EAAE,KAAK,mBAAmB,EAAE,KAAK,sBAAsB,EAAE,KAAK,oBAAoB,EAAE,KAAK,oBAAoB,EAAoB,KAAK,gBAAgB,EACpM,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,eAAe,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE7D,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAC3C,8FAA8F;AAC9F,eAAO,MAAM,sBAAsB,kBAAkB,CAAC;AACtD,iFAAiF;AACjF,eAAO,MAAM,wBAAwB,8BAA8B,CAAC;AAEpE,0CAA0C;AAC1C,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,cAAc,CAAC;IAC5C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,8EAA8E;IAC9E,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,IA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