@mfdaves/okf-mcp 0.3.2-rc.1

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/src/project.js ADDED
@@ -0,0 +1,235 @@
1
+ "use strict";
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const { parseFrontmatterYaml } = require("./parser");
6
+
7
+ const DEFAULT_RELATION_TYPES = [
8
+ "depends_on",
9
+ "produces",
10
+ "consumes",
11
+ "persists_to",
12
+ "materializes_to",
13
+ "configured_by",
14
+ "checked_by",
15
+ "owned_by",
16
+ "supersedes",
17
+ "related_to",
18
+ ];
19
+
20
+ function configId(value, fallback) {
21
+ const raw = String(value || fallback || "").trim();
22
+ return raw.replace(/[^A-Za-z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "") || fallback || "bundle";
23
+ }
24
+
25
+ function isInsidePath(root, target) {
26
+ const relative = path.relative(path.resolve(root), path.resolve(target));
27
+ return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
28
+ }
29
+
30
+ function resolveProjectPath(projectRoot, value, field, errors) {
31
+ if (!value || path.isAbsolute(String(value))) {
32
+ errors.push({
33
+ code: "invalid_project_path",
34
+ field,
35
+ path: value || "",
36
+ message: `${field} must be a relative path inside the project root.`,
37
+ });
38
+ return null;
39
+ }
40
+ const resolved = path.resolve(projectRoot, value);
41
+ if (!isInsidePath(projectRoot, resolved)) {
42
+ errors.push({
43
+ code: "project_path_outside_root",
44
+ field,
45
+ path: value,
46
+ message: `${field} resolves outside the project root.`,
47
+ });
48
+ return null;
49
+ }
50
+ return resolved;
51
+ }
52
+
53
+ function findProjectConfig(startDir) {
54
+ let current = path.resolve(startDir || process.cwd());
55
+ while (true) {
56
+ const yamlPath = path.join(current, "okf.project.yaml");
57
+ const jsonPath = path.join(current, "okf.project.json");
58
+ if (fs.existsSync(yamlPath)) {
59
+ return yamlPath;
60
+ }
61
+ if (fs.existsSync(jsonPath)) {
62
+ return jsonPath;
63
+ }
64
+ const parent = path.dirname(current);
65
+ if (parent === current) {
66
+ return null;
67
+ }
68
+ current = parent;
69
+ }
70
+ }
71
+
72
+ function readConfigFile(configPath) {
73
+ const absolutePath = path.resolve(configPath);
74
+ const text = fs.readFileSync(absolutePath, "utf8");
75
+ if (absolutePath.endsWith(".json")) {
76
+ return JSON.parse(text);
77
+ }
78
+ return parseFrontmatterYaml(text);
79
+ }
80
+
81
+ function normalizeBundles(config, configPath, errors) {
82
+ const rootDir = path.dirname(path.resolve(configPath));
83
+ const bundles = Array.isArray(config.bundles) ? config.bundles : [];
84
+ if (!bundles.length) {
85
+ errors.push({ code: "missing_bundles", message: "Project config must define at least one bundle." });
86
+ }
87
+ const seen = new Set();
88
+ return bundles.map((bundle, index) => {
89
+ if (typeof bundle === "string") {
90
+ const id = configId(path.basename(bundle), `bundle-${index + 1}`);
91
+ if (seen.has(id)) {
92
+ errors.push({ code: "duplicate_bundle_id", bundle: id, message: "Duplicate bundle id." });
93
+ }
94
+ seen.add(id);
95
+ return {
96
+ id,
97
+ root: resolveProjectPath(rootDir, bundle, `bundles[${index}].root`, errors),
98
+ include: [],
99
+ exclude: [],
100
+ };
101
+ }
102
+ const id = configId(bundle && bundle.id, `bundle-${index + 1}`);
103
+ if (seen.has(id)) {
104
+ errors.push({ code: "duplicate_bundle_id", bundle: id, message: "Duplicate bundle id." });
105
+ }
106
+ seen.add(id);
107
+ return {
108
+ id,
109
+ root: resolveProjectPath(rootDir, (bundle && (bundle.root || bundle.path)) || ".", `bundles[${index}].root`, errors),
110
+ include: Array.isArray(bundle.include) ? bundle.include : [],
111
+ exclude: Array.isArray(bundle.exclude) ? bundle.exclude : [],
112
+ };
113
+ }).filter((bundle) => bundle.root);
114
+ }
115
+
116
+ function validateRelationTypes(config, errors) {
117
+ if (config.relationTypes !== undefined && !Array.isArray(config.relationTypes)) {
118
+ errors.push({ code: "invalid_relation_types", message: "relationTypes must be an array." });
119
+ return;
120
+ }
121
+ (config.relationTypes || []).forEach((type) => {
122
+ if (!/^[A-Za-z0-9_.-]+$/.test(String(type))) {
123
+ errors.push({ code: "invalid_relation_type_name", relationType: String(type), message: "Relation type names may contain only letters, numbers, underscores, dots, and hyphens." });
124
+ }
125
+ });
126
+ }
127
+
128
+ function validatePlugins(config, projectRoot, bundleIds, errors) {
129
+ if (config.plugins !== undefined && !Array.isArray(config.plugins)) {
130
+ errors.push({ code: "invalid_plugins", message: "plugins must be an array." });
131
+ return;
132
+ }
133
+ (config.plugins || []).forEach((plugin, index) => {
134
+ const type = plugin && (plugin.type || plugin.name);
135
+ if (!plugin || typeof plugin !== "object" || Array.isArray(plugin)) {
136
+ errors.push({ code: "invalid_plugin", plugin: index, message: "Plugin entries must be objects." });
137
+ return;
138
+ }
139
+ if (!["filesystem", "json-spec"].includes(String(type))) {
140
+ errors.push({ code: "unknown_plugin_type", plugin: plugin.name || index, pluginType: type || "", message: "Unknown generator plugin type." });
141
+ }
142
+ if (!plugin.root) {
143
+ errors.push({ code: "missing_plugin_root", plugin: plugin.name || index, message: "Plugin root is required." });
144
+ } else {
145
+ resolveProjectPath(projectRoot, plugin.root, `plugins[${index}].root`, errors);
146
+ }
147
+ if (!plugin.output) {
148
+ errors.push({ code: "missing_plugin_output", plugin: plugin.name || index, message: "Plugin output is required." });
149
+ } else {
150
+ resolveProjectPath(projectRoot, plugin.output, `plugins[${index}].output`, errors);
151
+ }
152
+ if (plugin.bundle && !bundleIds.has(String(plugin.bundle))) {
153
+ errors.push({ code: "unknown_plugin_bundle", plugin: plugin.name || index, bundle: String(plugin.bundle), message: "Plugin bundle does not exist in project bundles." });
154
+ }
155
+ if (plugin.destinationBundle && !bundleIds.has(String(plugin.destinationBundle))) {
156
+ errors.push({ code: "unknown_plugin_destination_bundle", plugin: plugin.name || index, bundle: String(plugin.destinationBundle), message: "Plugin destinationBundle does not exist in project bundles." });
157
+ }
158
+ });
159
+ }
160
+
161
+ function normalizeRemoteBundles(config, errors) {
162
+ const remotes = Array.isArray(config.remoteBundles) ? config.remoteBundles : [];
163
+ if (config.remoteBundles !== undefined && !Array.isArray(config.remoteBundles)) {
164
+ errors.push({ code: "invalid_remote_bundles", message: "remoteBundles must be an array." });
165
+ return [];
166
+ }
167
+ const seen = new Set();
168
+ return remotes.map((remote, index) => {
169
+ const id = configId(remote && remote.id, `remote-${index + 1}`);
170
+ if (seen.has(id)) {
171
+ errors.push({ code: "duplicate_remote_bundle_id", bundle: id, message: "Duplicate remote bundle id." });
172
+ }
173
+ seen.add(id);
174
+ const provider = String((remote && remote.provider) || "github");
175
+ if (provider !== "github") {
176
+ errors.push({ code: "unsupported_remote_provider", bundle: id, provider, message: "Only github remote bundles are supported." });
177
+ }
178
+ if (!remote || !remote.url) {
179
+ errors.push({ code: "missing_remote_url", bundle: id, message: "Remote bundle url is required." });
180
+ }
181
+ return {
182
+ id,
183
+ provider,
184
+ url: remote && remote.url ? String(remote.url) : "",
185
+ include: Array.isArray(remote && remote.include) ? remote.include : [],
186
+ exclude: Array.isArray(remote && remote.exclude) ? remote.exclude : [],
187
+ };
188
+ });
189
+ }
190
+
191
+ function loadProjectConfig(configPath) {
192
+ const resolvedPath = configPath
193
+ ? path.resolve(configPath)
194
+ : findProjectConfig(process.cwd());
195
+ if (!resolvedPath) {
196
+ throw new Error("No okf.project.yaml or okf.project.json found. Pass --project or --bundle.");
197
+ }
198
+ const rawConfig = readConfigFile(resolvedPath);
199
+ const errors = [];
200
+ if (!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig)) {
201
+ errors.push({ code: "invalid_project_config", message: "Project config must be an object." });
202
+ }
203
+ const config = (!rawConfig || typeof rawConfig !== "object" || Array.isArray(rawConfig)) ? {} : rawConfig;
204
+ validateRelationTypes(config, errors);
205
+ const relationTypes = new Set(DEFAULT_RELATION_TYPES.concat(Array.isArray(config.relationTypes) ? config.relationTypes.map(String) : []));
206
+ const bundles = normalizeBundles(config, resolvedPath, errors);
207
+ const remoteBundles = normalizeRemoteBundles(config, errors);
208
+ const allBundleIds = new Set(bundles.map((bundle) => bundle.id));
209
+ remoteBundles.forEach((bundle) => {
210
+ if (allBundleIds.has(bundle.id)) {
211
+ errors.push({ code: "duplicate_bundle_id", bundle: bundle.id, message: "Remote bundle id duplicates a local bundle id." });
212
+ }
213
+ allBundleIds.add(bundle.id);
214
+ });
215
+ validatePlugins(config, path.dirname(resolvedPath), allBundleIds, errors);
216
+ return {
217
+ path: resolvedPath,
218
+ root: path.dirname(resolvedPath),
219
+ project: config.project || config.name || path.basename(path.dirname(resolvedPath)),
220
+ bundles,
221
+ remoteBundles,
222
+ relationTypes: Array.from(relationTypes),
223
+ plugins: Array.isArray(config.plugins) ? config.plugins : [],
224
+ errors,
225
+ raw: config,
226
+ };
227
+ }
228
+
229
+ module.exports = {
230
+ DEFAULT_RELATION_TYPES,
231
+ findProjectConfig,
232
+ isInsidePath,
233
+ loadProjectConfig,
234
+ resolveProjectPath,
235
+ };
package/src/remote.js ADDED
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+
3
+ const path = require("path");
4
+
5
+ const DEFAULT_REMOTE_LIMITS = {
6
+ maxFiles: 500,
7
+ maxFileBytes: 1024 * 1024,
8
+ maxTotalBytes: 5 * 1024 * 1024,
9
+ };
10
+
11
+ function normalizeSlashes(value) {
12
+ return String(value || "").replace(/\\/g, "/");
13
+ }
14
+
15
+ function encodePath(value) {
16
+ return String(value || "").split("/").filter(Boolean).map(encodeURIComponent).join("/");
17
+ }
18
+
19
+ function sanitizeRemoteId(value, fallback) {
20
+ const raw = String(value || fallback || "remote").trim();
21
+ return raw.replace(/[^A-Za-z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "") || "remote";
22
+ }
23
+
24
+ function parseGitHubBundleUrl(url) {
25
+ let parsed;
26
+ try {
27
+ parsed = new URL(String(url || ""));
28
+ } catch (error) {
29
+ throw new Error(`Invalid GitHub bundle URL: ${url || "<missing>"}`);
30
+ }
31
+ if (parsed.protocol !== "https:" || parsed.hostname !== "github.com") {
32
+ throw new Error("Remote OKF v1 supports only https://github.com URLs.");
33
+ }
34
+ const parts = parsed.pathname.split("/").filter(Boolean);
35
+ if (parts.length < 5 || parts[2] !== "tree") {
36
+ throw new Error("GitHub bundle URL must be a repository tree URL: https://github.com/<owner>/<repo>/tree/<ref>/<path>");
37
+ }
38
+ const owner = parts[0];
39
+ const repo = parts[1];
40
+ const ref = parts[3];
41
+ const bundlePath = normalizeSlashes(parts.slice(4).join("/"));
42
+ if (!owner || !repo || !ref || !bundlePath || bundlePath.split("/").some((part) => part === "." || part === "..")) {
43
+ throw new Error("GitHub bundle URL must include owner, repo, ref, and a safe bundle path.");
44
+ }
45
+ return { owner, repo, ref, path: bundlePath, url: String(parsed) };
46
+ }
47
+
48
+ async function fetchJson(fetchImpl, url) {
49
+ const response = await fetchImpl(url, {
50
+ headers: {
51
+ Accept: "application/vnd.github+json",
52
+ "User-Agent": "okf-mcp",
53
+ },
54
+ });
55
+ if (!response || !response.ok) {
56
+ const status = response ? `${response.status} ${response.statusText || ""}`.trim() : "no response";
57
+ throw new Error(`GitHub request failed: ${status}`);
58
+ }
59
+ return response.json();
60
+ }
61
+
62
+ async function fetchText(fetchImpl, url) {
63
+ const response = await fetchImpl(url, {
64
+ headers: {
65
+ Accept: "text/plain",
66
+ "User-Agent": "okf-mcp",
67
+ },
68
+ });
69
+ if (!response || !response.ok) {
70
+ const status = response ? `${response.status} ${response.statusText || ""}`.trim() : "no response";
71
+ throw new Error(`GitHub raw file request failed: ${status}`);
72
+ }
73
+ return response.text();
74
+ }
75
+
76
+ function relativeRemotePath(rootPath, filePath) {
77
+ const root = normalizeSlashes(rootPath).replace(/\/+$/, "");
78
+ const full = normalizeSlashes(filePath);
79
+ if (full === root) {
80
+ return path.posix.basename(full);
81
+ }
82
+ if (!full.startsWith(`${root}/`)) {
83
+ throw new Error(`Remote file path is outside bundle path: ${filePath}`);
84
+ }
85
+ const relative = full.slice(root.length + 1);
86
+ if (!relative || relative.split("/").some((part) => part === "." || part === "..")) {
87
+ throw new Error(`Remote file path is unsafe: ${filePath}`);
88
+ }
89
+ return relative;
90
+ }
91
+
92
+ async function fetchGitHubBundle(config, options) {
93
+ const source = parseGitHubBundleUrl(config && config.url);
94
+ const fetchImpl = (options && options.fetch) || globalThis.fetch;
95
+ if (typeof fetchImpl !== "function") {
96
+ throw new Error("Remote bundle loading requires fetch support.");
97
+ }
98
+ const limits = Object.assign({}, DEFAULT_REMOTE_LIMITS, (options && options.limits) || {});
99
+ const documents = [];
100
+ let totalBytes = 0;
101
+
102
+ async function walk(apiPath) {
103
+ const apiUrl = `https://api.github.com/repos/${source.owner}/${source.repo}/contents/${encodePath(apiPath)}?ref=${encodeURIComponent(source.ref)}`;
104
+ const entries = await fetchJson(fetchImpl, apiUrl);
105
+ const list = Array.isArray(entries) ? entries : [entries];
106
+ for (const entry of list) {
107
+ if (entry.type === "dir") {
108
+ await walk(entry.path);
109
+ continue;
110
+ }
111
+ if (entry.type !== "file" || !String(entry.name || "").toLowerCase().endsWith(".md")) {
112
+ continue;
113
+ }
114
+ if (documents.length >= limits.maxFiles) {
115
+ throw new Error(`Remote bundle exceeds file limit of ${limits.maxFiles}.`);
116
+ }
117
+ if (Number(entry.size || 0) > limits.maxFileBytes) {
118
+ throw new Error(`Remote file exceeds byte limit: ${entry.path}`);
119
+ }
120
+ if (!entry.download_url) {
121
+ throw new Error(`Remote file has no download URL: ${entry.path}`);
122
+ }
123
+ const text = await fetchText(fetchImpl, entry.download_url);
124
+ const bytes = Buffer.byteLength(text, "utf8");
125
+ if (bytes > limits.maxFileBytes) {
126
+ throw new Error(`Remote file exceeds byte limit after download: ${entry.path}`);
127
+ }
128
+ totalBytes += bytes;
129
+ if (totalBytes > limits.maxTotalBytes) {
130
+ throw new Error(`Remote bundle exceeds total byte limit of ${limits.maxTotalBytes}.`);
131
+ }
132
+ documents.push({
133
+ path: relativeRemotePath(source.path, entry.path),
134
+ text,
135
+ source: `github://${source.owner}/${source.repo}/${source.ref}/${entry.path}`,
136
+ });
137
+ }
138
+ }
139
+
140
+ await walk(source.path);
141
+ return {
142
+ id: sanitizeRemoteId(config.id, path.posix.basename(source.path)),
143
+ remote: true,
144
+ root: "",
145
+ documents,
146
+ include: Array.isArray(config.include) ? config.include : [],
147
+ exclude: Array.isArray(config.exclude) ? config.exclude : [],
148
+ remoteSource: {
149
+ provider: "github",
150
+ url: source.url,
151
+ owner: source.owner,
152
+ repo: source.repo,
153
+ ref: source.ref,
154
+ path: source.path,
155
+ fileCount: documents.length,
156
+ totalBytes,
157
+ },
158
+ };
159
+ }
160
+
161
+ async function fetchRemoteBundles(remoteConfigs, options) {
162
+ const out = [];
163
+ for (const config of remoteConfigs || []) {
164
+ const provider = String((config && config.provider) || "github");
165
+ if (provider !== "github") {
166
+ throw new Error(`Unsupported remote bundle provider: ${provider}`);
167
+ }
168
+ out.push(await fetchGitHubBundle(config, options));
169
+ }
170
+ return out;
171
+ }
172
+
173
+ module.exports = {
174
+ DEFAULT_REMOTE_LIMITS,
175
+ fetchGitHubBundle,
176
+ fetchRemoteBundles,
177
+ parseGitHubBundleUrl,
178
+ sanitizeRemoteId,
179
+ };
package/src/search.js ADDED
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+
3
+ const { conceptSummary } = require("./indexer");
4
+
5
+ function lower(value) {
6
+ return String(value || "").toLowerCase();
7
+ }
8
+
9
+ function asArray(value) {
10
+ if (value === undefined || value === null) {
11
+ return [];
12
+ }
13
+ return Array.isArray(value) ? value : [value];
14
+ }
15
+
16
+ function frontmatterMatches(frontmatter, filters) {
17
+ const entries = Object.entries(filters || {});
18
+ return entries.every(([key, expected]) => {
19
+ const actual = frontmatter[key];
20
+ if (Array.isArray(actual)) {
21
+ return actual.map(String).some((entry) => lower(entry) === lower(expected));
22
+ }
23
+ return lower(actual) === lower(expected);
24
+ });
25
+ }
26
+
27
+ function docText(doc) {
28
+ return [
29
+ doc.title,
30
+ doc.description,
31
+ doc.type,
32
+ doc.path,
33
+ doc.tags.join(" "),
34
+ doc.aliases.join(" "),
35
+ JSON.stringify(doc.frontmatter),
36
+ doc.body,
37
+ ].join("\n");
38
+ }
39
+
40
+ function snippetFor(doc, query) {
41
+ if (!query) {
42
+ return "";
43
+ }
44
+ const text = docText(doc).replace(/\s+/g, " ");
45
+ const idx = lower(text).indexOf(lower(query));
46
+ if (idx === -1) {
47
+ return "";
48
+ }
49
+ const start = Math.max(0, idx - 50);
50
+ return text.slice(start, idx + query.length + 80).trim();
51
+ }
52
+
53
+ function linkedSets(index) {
54
+ const outbound = new Map();
55
+ const inbound = new Map();
56
+ index.edges.filter((edge) => !edge.broken).forEach((edge) => {
57
+ if (!outbound.has(edge.source)) {
58
+ outbound.set(edge.source, new Set());
59
+ }
60
+ if (!inbound.has(edge.target)) {
61
+ inbound.set(edge.target, new Set());
62
+ }
63
+ outbound.get(edge.source).add(edge.target);
64
+ inbound.get(edge.target).add(edge.source);
65
+ });
66
+ return { outbound, inbound };
67
+ }
68
+
69
+ function applyFilters(index, options) {
70
+ const config = options || {};
71
+ const typeFilters = asArray(config.types || config.type).map(lower);
72
+ const tagsAny = asArray(config.tagsAny || config.tag).map(lower);
73
+ const tagsAll = asArray(config.tagsAll).map(lower);
74
+ const { outbound, inbound } = linkedSets(index);
75
+ return index.concepts.filter((doc) => {
76
+ if (config.bundle && doc.bundle !== config.bundle) {
77
+ return false;
78
+ }
79
+ if (config.pathPrefix && !doc.path.startsWith(config.pathPrefix)) {
80
+ return false;
81
+ }
82
+ if (typeFilters.length && !typeFilters.includes(lower(doc.type))) {
83
+ return false;
84
+ }
85
+ const docTags = doc.tags.map(lower);
86
+ if (tagsAny.length && !tagsAny.some((tag) => docTags.includes(tag))) {
87
+ return false;
88
+ }
89
+ if (tagsAll.length && !tagsAll.every((tag) => docTags.includes(tag))) {
90
+ return false;
91
+ }
92
+ if (config.frontmatter && !frontmatterMatches(doc.frontmatter, config.frontmatter)) {
93
+ return false;
94
+ }
95
+ if (config.linkedTo && !(outbound.get(doc.uri) || new Set()).has(config.linkedTo)) {
96
+ return false;
97
+ }
98
+ if (config.linkedFrom && !(inbound.get(doc.uri) || new Set()).has(config.linkedFrom)) {
99
+ return false;
100
+ }
101
+ if (config.orphanOnly && ((outbound.get(doc.uri) || new Set()).size > 0 || (inbound.get(doc.uri) || new Set()).size > 0)) {
102
+ return false;
103
+ }
104
+ if (config.relationType) {
105
+ const hasRelation = index.edges.some((edge) => (
106
+ !edge.broken &&
107
+ edge.source === doc.uri &&
108
+ edge.kind === "relation" &&
109
+ lower(edge.relationType) === lower(config.relationType)
110
+ ));
111
+ if (!hasRelation) {
112
+ return false;
113
+ }
114
+ }
115
+ return true;
116
+ });
117
+ }
118
+
119
+ function scoreDoc(doc, query) {
120
+ if (!query) {
121
+ return 0;
122
+ }
123
+ const q = lower(query);
124
+ let score = 0;
125
+ if (lower(doc.title).includes(q)) {
126
+ score += 8;
127
+ }
128
+ if (lower(doc.type).includes(q)) {
129
+ score += 5;
130
+ }
131
+ if (doc.tags.some((tag) => lower(tag).includes(q))) {
132
+ score += 4;
133
+ }
134
+ if (doc.aliases.some((alias) => lower(alias).includes(q))) {
135
+ score += 4;
136
+ }
137
+ if (lower(doc.description).includes(q)) {
138
+ score += 3;
139
+ }
140
+ if (lower(doc.path).includes(q)) {
141
+ score += 2;
142
+ }
143
+ if (lower(doc.body).includes(q)) {
144
+ score += 1;
145
+ }
146
+ return score;
147
+ }
148
+
149
+ function searchConcepts(index, options) {
150
+ const config = options || {};
151
+ const query = String(config.query || "").trim();
152
+ const limit = Math.max(1, Math.min(Number(config.limit || 25), 250));
153
+ const offset = Math.max(0, Number(config.offset || 0));
154
+ let results = applyFilters(index, config).map((doc) => ({
155
+ doc,
156
+ score: scoreDoc(doc, query),
157
+ }));
158
+ if (query) {
159
+ results = results.filter((entry) => entry.score > 0);
160
+ results.sort((a, b) => b.score - a.score || a.doc.path.localeCompare(b.doc.path));
161
+ } else {
162
+ results.sort((a, b) => a.doc.path.localeCompare(b.doc.path));
163
+ }
164
+ const page = results.slice(offset, offset + limit).map((entry) => Object.assign(conceptSummary(entry.doc), {
165
+ score: entry.score,
166
+ snippet: snippetFor(entry.doc, query),
167
+ }));
168
+ return {
169
+ total: results.length,
170
+ limit,
171
+ offset,
172
+ results: page,
173
+ };
174
+ }
175
+
176
+ module.exports = {
177
+ applyFilters,
178
+ searchConcepts,
179
+ };