@digital-science-dsl/dimensions-analytics-mcp 0.5.3 → 1.0.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/CHANGELOG.md +4 -56
- package/README.md +1 -5
- package/dist/client/deployment-config.d.ts +20 -2
- package/dist/client/deployment-config.d.ts.map +1 -1
- package/dist/client/deployment-config.js +26 -2
- package/dist/client/deployment-config.js.map +1 -1
- package/dist/client/internal-dsl-client.d.ts +1 -1
- package/dist/client/internal-dsl-client.d.ts.map +1 -1
- package/dist/client/internal-dsl-client.js +2 -5
- package/dist/client/internal-dsl-client.js.map +1 -1
- package/dist/dsl/create-client.d.ts +1 -1
- package/dist/dsl/create-client.js +1 -1
- package/dist/dsl/fluent-query-builder.d.ts +1 -1
- package/dist/dsl/fluent-query-builder.js +1 -1
- package/dist/dsl/schema/cache.d.ts +2 -2
- package/dist/dsl/schema/cache.d.ts.map +1 -1
- package/dist/dsl/schema/cache.js +8 -14
- package/dist/dsl/schema/cache.js.map +1 -1
- package/dist/dsl/schema/load.d.ts +0 -1
- package/dist/dsl/schema/load.d.ts.map +1 -1
- package/dist/dsl/schema/load.js +1 -3
- package/dist/dsl/schema/load.js.map +1 -1
- package/dist/mcp/tools/schema.d.ts +0 -2
- package/dist/mcp/tools/schema.d.ts.map +1 -1
- package/dist/mcp/tools/schema.js.map +1 -1
- package/dist/mcp/utils.d.ts +0 -4
- package/dist/mcp/utils.d.ts.map +1 -1
- package/dist/mcp/utils.js +0 -7
- package/dist/mcp/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/client/deployment-config.ts +39 -2
- package/src/client/internal-dsl-client.ts +2 -6
- package/src/dsl/create-client.ts +1 -1
- package/src/dsl/fluent-query-builder.ts +1 -1
- package/src/dsl/schema/cache.ts +8 -13
- package/src/dsl/schema/load.ts +1 -4
- package/src/mcp/tools/schema.ts +0 -3
- package/src/mcp/utils.ts +0 -12
- package/test/client/deployment-config.test.ts +25 -1
- package/test/client/http-client.test.ts +2 -2
- package/test/client/internal-dsl-client.test.ts +3 -0
- package/test/dsl/schema/cache.test.ts +2 -4
- package/test/helpers/tool-test-harness.ts +2 -19
- package/test/middleware/field-aliases.test.ts +1 -1
- package/test/tools/analytics.test.ts +2 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/examples/dsl-examples.d.ts +0 -11
- package/dist/examples/dsl-examples.d.ts.map +0 -1
- package/dist/examples/dsl-examples.js +0 -49
- package/dist/examples/dsl-examples.js.map +0 -1
- package/dist/examples/usage-scenarios.d.ts +0 -22
- package/dist/examples/usage-scenarios.d.ts.map +0 -1
- package/dist/examples/usage-scenarios.js +0 -173
- package/dist/examples/usage-scenarios.js.map +0 -1
- package/dist/funder-org-names.d.ts +0 -12
- package/dist/funder-org-names.d.ts.map +0 -1
- package/dist/funder-org-names.js +0 -30
- package/dist/funder-org-names.js.map +0 -1
- package/dist/http.d.ts +0 -29
- package/dist/http.d.ts.map +0 -1
- package/dist/http.js +0 -173
- package/dist/http.js.map +0 -1
- package/dist/kwq/build-query.d.ts +0 -26
- package/dist/kwq/build-query.d.ts.map +0 -1
- package/dist/kwq/build-query.js +0 -37
- package/dist/kwq/build-query.js.map +0 -1
- package/dist/kwq/concept-groups.d.ts +0 -49
- package/dist/kwq/concept-groups.d.ts.map +0 -1
- package/dist/kwq/concept-groups.js +0 -55
- package/dist/kwq/concept-groups.js.map +0 -1
- package/dist/kwq/dsl-assembler.d.ts +0 -28
- package/dist/kwq/dsl-assembler.d.ts.map +0 -1
- package/dist/kwq/dsl-assembler.js +0 -124
- package/dist/kwq/dsl-assembler.js.map +0 -1
- package/dist/kwq/ensemble.d.ts +0 -38
- package/dist/kwq/ensemble.d.ts.map +0 -1
- package/dist/kwq/ensemble.js +0 -107
- package/dist/kwq/ensemble.js.map +0 -1
- package/dist/kwq/index.d.ts +0 -16
- package/dist/kwq/index.d.ts.map +0 -1
- package/dist/kwq/index.js +0 -14
- package/dist/kwq/index.js.map +0 -1
- package/dist/kwq/types.d.ts +0 -120
- package/dist/kwq/types.d.ts.map +0 -1
- package/dist/kwq/types.js +0 -11
- package/dist/kwq/types.js.map +0 -1
- package/dist/lambda.d.ts +0 -10
- package/dist/lambda.d.ts.map +0 -1
- package/dist/lambda.js +0 -4
- package/dist/lambda.js.map +0 -1
- package/dist/mcp/tools/concept-profile.d.ts +0 -14
- package/dist/mcp/tools/concept-profile.d.ts.map +0 -1
- package/dist/mcp/tools/concept-profile.js +0 -130
- package/dist/mcp/tools/concept-profile.js.map +0 -1
- package/dist/mcp/tools/dataset-profile.d.ts +0 -15
- package/dist/mcp/tools/dataset-profile.d.ts.map +0 -1
- package/dist/mcp/tools/dataset-profile.js +0 -194
- package/dist/mcp/tools/dataset-profile.js.map +0 -1
- package/dist/mcp/tools/impact-chain.d.ts +0 -15
- package/dist/mcp/tools/impact-chain.d.ts.map +0 -1
- package/dist/mcp/tools/impact-chain.js +0 -96
- package/dist/mcp/tools/impact-chain.js.map +0 -1
- package/dist/mcp/tools/kwq.d.ts +0 -19
- package/dist/mcp/tools/kwq.d.ts.map +0 -1
- package/dist/mcp/tools/kwq.js +0 -156
- package/dist/mcp/tools/kwq.js.map +0 -1
- package/dist/mcp/tools/policy-profile.d.ts +0 -15
- package/dist/mcp/tools/policy-profile.d.ts.map +0 -1
- package/dist/mcp/tools/policy-profile.js +0 -174
- package/dist/mcp/tools/policy-profile.js.map +0 -1
- package/dist/mcp/tools/profile.d.ts +0 -14
- package/dist/mcp/tools/profile.d.ts.map +0 -1
- package/dist/mcp/tools/profile.js +0 -349
- package/dist/mcp/tools/profile.js.map +0 -1
- package/dist/middleware/field-aliases.d.ts +0 -97
- package/dist/middleware/field-aliases.d.ts.map +0 -1
- package/dist/middleware/field-aliases.js +0 -208
- package/dist/middleware/field-aliases.js.map +0 -1
- package/dist/resources/schema.d.ts +0 -13
- package/dist/resources/schema.d.ts.map +0 -1
- package/dist/resources/schema.js +0 -204
- package/dist/resources/schema.js.map +0 -1
- package/dist/schema/context.d.ts +0 -10
- package/dist/schema/context.d.ts.map +0 -1
- package/dist/schema/context.js +0 -6
- package/dist/schema/context.js.map +0 -1
- package/dist/schema/index.d.ts +0 -9
- package/dist/schema/index.d.ts.map +0 -1
- package/dist/schema/index.js +0 -6
- package/dist/schema/index.js.map +0 -1
- package/dist/schema/load.d.ts +0 -43
- package/dist/schema/load.d.ts.map +0 -1
- package/dist/schema/load.js +0 -139
- package/dist/schema/load.js.map +0 -1
- package/dist/schema/store.d.ts +0 -112
- package/dist/schema/store.d.ts.map +0 -1
- package/dist/schema/store.js +0 -173
- package/dist/schema/store.js.map +0 -1
- package/dist/schema/structured-entities.d.ts +0 -21
- package/dist/schema/structured-entities.d.ts.map +0 -1
- package/dist/schema/structured-entities.js +0 -39
- package/dist/schema/structured-entities.js.map +0 -1
- package/dist/schema/types.d.ts +0 -36
- package/dist/schema/types.d.ts.map +0 -1
- package/dist/schema/types.js +0 -6
- package/dist/schema/types.js.map +0 -1
- package/dist/server.d.ts +0 -57
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js +0 -144
- package/dist/server.js.map +0 -1
- package/dist/telemetry.d.ts +0 -172
- package/dist/telemetry.d.ts.map +0 -1
- package/dist/telemetry.js +0 -233
- package/dist/telemetry.js.map +0 -1
- package/dist/tools/analytics-filters.d.ts +0 -18
- package/dist/tools/analytics-filters.d.ts.map +0 -1
- package/dist/tools/analytics-filters.js +0 -35
- package/dist/tools/analytics-filters.js.map +0 -1
- package/dist/tools/analytics.d.ts +0 -16
- package/dist/tools/analytics.d.ts.map +0 -1
- package/dist/tools/analytics.js +0 -381
- package/dist/tools/analytics.js.map +0 -1
- package/dist/tools/concept-profile.d.ts +0 -14
- package/dist/tools/concept-profile.d.ts.map +0 -1
- package/dist/tools/concept-profile.js +0 -130
- package/dist/tools/concept-profile.js.map +0 -1
- package/dist/tools/dataset-profile.d.ts +0 -15
- package/dist/tools/dataset-profile.d.ts.map +0 -1
- package/dist/tools/dataset-profile.js +0 -194
- package/dist/tools/dataset-profile.js.map +0 -1
- package/dist/tools/functions.d.ts +0 -14
- package/dist/tools/functions.d.ts.map +0 -1
- package/dist/tools/functions.js +0 -294
- package/dist/tools/functions.js.map +0 -1
- package/dist/tools/impact-chain.d.ts +0 -15
- package/dist/tools/impact-chain.d.ts.map +0 -1
- package/dist/tools/impact-chain.js +0 -96
- package/dist/tools/impact-chain.js.map +0 -1
- package/dist/tools/kwq.d.ts +0 -19
- package/dist/tools/kwq.d.ts.map +0 -1
- package/dist/tools/kwq.js +0 -156
- package/dist/tools/kwq.js.map +0 -1
- package/dist/tools/lookup.d.ts +0 -14
- package/dist/tools/lookup.d.ts.map +0 -1
- package/dist/tools/lookup.js +0 -213
- package/dist/tools/lookup.js.map +0 -1
- package/dist/tools/policy-profile.d.ts +0 -15
- package/dist/tools/policy-profile.d.ts.map +0 -1
- package/dist/tools/policy-profile.js +0 -174
- package/dist/tools/policy-profile.js.map +0 -1
- package/dist/tools/profile.d.ts +0 -14
- package/dist/tools/profile.d.ts.map +0 -1
- package/dist/tools/profile.js +0 -349
- package/dist/tools/profile.js.map +0 -1
- package/dist/tools/query.d.ts +0 -16
- package/dist/tools/query.d.ts.map +0 -1
- package/dist/tools/query.js +0 -53
- package/dist/tools/query.js.map +0 -1
- package/dist/tools/schema.d.ts +0 -23
- package/dist/tools/schema.d.ts.map +0 -1
- package/dist/tools/schema.js +0 -124
- package/dist/tools/schema.js.map +0 -1
- package/dist/tools/search-entity-metadata.d.ts +0 -18
- package/dist/tools/search-entity-metadata.d.ts.map +0 -1
- package/dist/tools/search-entity-metadata.js +0 -221
- package/dist/tools/search-entity-metadata.js.map +0 -1
- package/dist/tools/search.d.ts +0 -23
- package/dist/tools/search.d.ts.map +0 -1
- package/dist/tools/search.js +0 -110
- package/dist/tools/search.js.map +0 -1
- package/dist/tools/solr-fields.d.ts +0 -39
- package/dist/tools/solr-fields.d.ts.map +0 -1
- package/dist/tools/solr-fields.js +0 -40
- package/dist/tools/solr-fields.js.map +0 -1
- package/dist/utils.d.ts +0 -70
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -104
- package/dist/utils.js.map +0 -1
package/dist/kwq/ensemble.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ring 4: RRF (Reciprocal Rank Fusion) ensemble.
|
|
3
|
-
*
|
|
4
|
-
* Executes multiple QuerySpecs in parallel, merges results using RRF scoring,
|
|
5
|
-
* and returns a fused ranking. Pure function — no LLM dependency.
|
|
6
|
-
*
|
|
7
|
-
* @module ensemble
|
|
8
|
-
*/
|
|
9
|
-
import { buildQuery } from "./build-query.js";
|
|
10
|
-
const DEFAULT_K = 60;
|
|
11
|
-
const DEFAULT_LIMIT = 100;
|
|
12
|
-
/**
|
|
13
|
-
* Execute multiple query specs and fuse results using Reciprocal Rank Fusion.
|
|
14
|
-
*
|
|
15
|
-
* RRF score for a document `d` across N ranked lists:
|
|
16
|
-
* score(d) = Σ 1/(k + rank_i(d))
|
|
17
|
-
* where rank_i is the 0-based position in list i.
|
|
18
|
-
*
|
|
19
|
-
* @param execute - Executes a DSL string and returns the raw API response.
|
|
20
|
-
* In MCP context: `(dsl) => client.rawQuery(dsl)`.
|
|
21
|
-
* @param specs - Query specifications to build, execute, and fuse.
|
|
22
|
-
* @param options - Optional k (default 60) and limit (default 100).
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```typescript
|
|
26
|
-
* const result = await ensembleQueries(
|
|
27
|
-
* (dsl) => client.rawQuery(dsl),
|
|
28
|
-
* [
|
|
29
|
-
* { entity: "publications", search: "quantum networking" },
|
|
30
|
-
* { entity: "publications", search: "quantum key distribution" },
|
|
31
|
-
* ],
|
|
32
|
-
* );
|
|
33
|
-
* // result.items: [{ id: "pub.123", rrfScore: 0.033, ... }, ...]
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export async function ensembleQueries(execute, specs, options) {
|
|
37
|
-
const startMs = Date.now();
|
|
38
|
-
const k = options?.k ?? DEFAULT_K;
|
|
39
|
-
const limit = options?.limit ?? DEFAULT_LIMIT;
|
|
40
|
-
// Phase 1: Build DSL for each spec, skip invalid ones
|
|
41
|
-
const built = specs.map((spec, originalIndex) => {
|
|
42
|
-
const result = buildQuery(spec);
|
|
43
|
-
return { spec, result, valid: result.validation._tag === "valid", originalIndex };
|
|
44
|
-
});
|
|
45
|
-
// Phase 2: Execute valid queries in parallel
|
|
46
|
-
const validEntries = built.filter((b) => b.valid);
|
|
47
|
-
const settled = await Promise.allSettled(validEntries.map((entry) => execute(entry.result.dsl)));
|
|
48
|
-
const rankedLists = [];
|
|
49
|
-
for (let i = 0; i < settled.length; i++) {
|
|
50
|
-
const outcome = settled[i];
|
|
51
|
-
if (outcome.status !== "fulfilled")
|
|
52
|
-
continue;
|
|
53
|
-
const response = outcome.value;
|
|
54
|
-
const entity = validEntries[i].spec.entity;
|
|
55
|
-
// Dimensions API returns entity array under the entity name key
|
|
56
|
-
const entityArray = response[entity];
|
|
57
|
-
if (!Array.isArray(entityArray))
|
|
58
|
-
continue;
|
|
59
|
-
rankedLists.push({
|
|
60
|
-
specIndex: validEntries[i].originalIndex,
|
|
61
|
-
items: entityArray,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
// Phase 4: RRF merge
|
|
65
|
-
const scoreMap = new Map();
|
|
66
|
-
for (const list of rankedLists) {
|
|
67
|
-
for (let rank = 0; rank < list.items.length; rank++) {
|
|
68
|
-
const item = list.items[rank];
|
|
69
|
-
const id = String(item.id ?? "");
|
|
70
|
-
if (!id)
|
|
71
|
-
continue;
|
|
72
|
-
const existing = scoreMap.get(id);
|
|
73
|
-
const contribution = 1 / (k + rank);
|
|
74
|
-
if (existing) {
|
|
75
|
-
existing.rrfScore += contribution;
|
|
76
|
-
existing.sourceIndices.push(list.specIndex);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
scoreMap.set(id, {
|
|
80
|
-
rrfScore: contribution,
|
|
81
|
-
sourceIndices: [list.specIndex],
|
|
82
|
-
data: item,
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
// Phase 5: Sort by rrfScore descending, truncate to limit
|
|
88
|
-
const items = [...scoreMap.entries()]
|
|
89
|
-
.map(([id, entry]) => ({
|
|
90
|
-
id,
|
|
91
|
-
rrfScore: entry.rrfScore,
|
|
92
|
-
sourceIndices: entry.sourceIndices,
|
|
93
|
-
data: entry.data,
|
|
94
|
-
}))
|
|
95
|
-
.sort((a, b) => b.rrfScore - a.rrfScore)
|
|
96
|
-
.slice(0, limit);
|
|
97
|
-
return {
|
|
98
|
-
items,
|
|
99
|
-
metadata: {
|
|
100
|
-
specsProvided: specs.length,
|
|
101
|
-
specsExecuted: rankedLists.length,
|
|
102
|
-
k,
|
|
103
|
-
durationMs: Date.now() - startMs,
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=ensemble.js.map
|
package/dist/kwq/ensemble.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ensemble.js","sourceRoot":"","sources":["../../src/kwq/ensemble.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAA0D,EAC1D,KAA2B,EAC3B,OAAwC;IAExC,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC3B,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC,IAAI,SAAS,CAAC;IAClC,MAAM,KAAK,GAAG,OAAO,EAAE,KAAK,IAAI,aAAa,CAAC;IAE9C,sDAAsD;IACtD,MAAM,KAAK,GAAG,KAAK,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AAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC;SACvC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAEnB,OAAO;QACL,KAAK;QACL,QAAQ,EAAE;YACR,aAAa,EAAE,KAAK,CAAC,MAAM;YAC3B,aAAa,EAAE,WAAW,CAAC,MAAM;YACjC,CAAC;YACD,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO;SACjC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/kwq/index.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @digital-science/dimensions-kwq
|
|
3
|
-
*
|
|
4
|
-
* Keyword query construction for Dimensions DSL.
|
|
5
|
-
*
|
|
6
|
-
* Ring 1: buildQuery() — structured spec → DSL string
|
|
7
|
-
* Ring 4: ensembleQueries() — multi-query RRF fusion
|
|
8
|
-
*
|
|
9
|
-
* @module index
|
|
10
|
-
*/
|
|
11
|
-
export { buildQuery, buildSearchNode } from "./build-query.js";
|
|
12
|
-
export type { ConceptGroup, ConceptGroupsInput } from "./concept-groups.js";
|
|
13
|
-
export { conceptGroupsToQuerySpec } from "./concept-groups.js";
|
|
14
|
-
export { ensembleQueries } from "./ensemble.js";
|
|
15
|
-
export type { BuildResult, EnsembleItem, EnsembleResult, FilterSpec, QuerySpec, SearchExpr, } from "./types.js";
|
|
16
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/kwq/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/kwq/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC/D,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,YAAY,EACV,WAAW,EACX,YAAY,EACZ,cAAc,EACd,UAAU,EACV,SAAS,EACT,UAAU,GACX,MAAM,YAAY,CAAC"}
|
package/dist/kwq/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @digital-science/dimensions-kwq
|
|
3
|
-
*
|
|
4
|
-
* Keyword query construction for Dimensions DSL.
|
|
5
|
-
*
|
|
6
|
-
* Ring 1: buildQuery() — structured spec → DSL string
|
|
7
|
-
* Ring 4: ensembleQueries() — multi-query RRF fusion
|
|
8
|
-
*
|
|
9
|
-
* @module index
|
|
10
|
-
*/
|
|
11
|
-
export { buildQuery, buildSearchNode } from "./build-query.js";
|
|
12
|
-
export { conceptGroupsToQuerySpec } from "./concept-groups.js";
|
|
13
|
-
export { ensembleQueries } from "./ensemble.js";
|
|
14
|
-
//# sourceMappingURL=index.js.map
|
package/dist/kwq/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/kwq/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/kwq/types.d.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Types for the KWQ (Keyword Query) package.
|
|
3
|
-
*
|
|
4
|
-
* Ring 1: QuerySpec → buildQuery() → BuildResult (DSL string)
|
|
5
|
-
* Ring 4: ensembleQueries() → EnsembleResult
|
|
6
|
-
*
|
|
7
|
-
* @module types
|
|
8
|
-
*/
|
|
9
|
-
/** Result of structural query validation (API validates on execute). */
|
|
10
|
-
export type ValidationResult = {
|
|
11
|
-
readonly _tag: "valid";
|
|
12
|
-
readonly warnings: readonly [];
|
|
13
|
-
} | {
|
|
14
|
-
readonly _tag: "invalid";
|
|
15
|
-
readonly errors: readonly {
|
|
16
|
-
readonly message: string;
|
|
17
|
-
}[];
|
|
18
|
-
readonly warnings: readonly [];
|
|
19
|
-
};
|
|
20
|
-
/** Dimensions search index names (see describe schema `search_fields`). */
|
|
21
|
-
export type SearchIndex = "full_data" | "full_data_exact" | "title_abstract_only" | "title_only" | "authors" | "inventors" | "investigators" | "concepts" | "funding" | "abstract_only" | "title_abstract" | "title_abstract_concepts";
|
|
22
|
-
/**
|
|
23
|
-
* A search expression tree.
|
|
24
|
-
*
|
|
25
|
-
* - `string` shorthand becomes a single phrase with default index
|
|
26
|
-
* - `{ term, index? }` for explicit per-clause index control
|
|
27
|
-
* - `{ and: [...] }` / `{ or: [...] }` for boolean composition
|
|
28
|
-
*/
|
|
29
|
-
export type SearchExpr = string | {
|
|
30
|
-
readonly term: string;
|
|
31
|
-
readonly index?: SearchIndex;
|
|
32
|
-
} | {
|
|
33
|
-
readonly and: readonly SearchExpr[];
|
|
34
|
-
} | {
|
|
35
|
-
readonly or: readonly SearchExpr[];
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* A WHERE-clause filter.
|
|
39
|
-
*/
|
|
40
|
-
export interface FilterSpec {
|
|
41
|
-
readonly field: string;
|
|
42
|
-
readonly op: "=" | "!=" | ">" | "<" | ">=" | "<=" | "in" | "~";
|
|
43
|
-
readonly value: string | number | readonly string[] | readonly number[];
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Full query specification — the input to `buildQuery()`.
|
|
47
|
-
*/
|
|
48
|
-
export interface QuerySpec {
|
|
49
|
-
/** Target entity type */
|
|
50
|
-
readonly entity: "publications" | "grants" | "researchers" | "patents" | "clinical_trials" | "datasets" | "policy_documents" | "organizations";
|
|
51
|
-
/** Search expression (the `for "..."` clause) */
|
|
52
|
-
readonly search?: SearchExpr;
|
|
53
|
-
/** Exclusion expression — combined as `search NOT exclude` */
|
|
54
|
-
readonly exclude?: SearchExpr;
|
|
55
|
-
/** Default search index for terms without explicit index */
|
|
56
|
-
readonly index?: SearchIndex;
|
|
57
|
-
/** WHERE-clause filters */
|
|
58
|
-
readonly filters?: readonly FilterSpec[];
|
|
59
|
-
/** Fields to return */
|
|
60
|
-
readonly fields?: readonly string[];
|
|
61
|
-
/** Sort field */
|
|
62
|
-
readonly sortBy?: string;
|
|
63
|
-
/** Sort order (default: "desc") */
|
|
64
|
-
readonly sortOrder?: "asc" | "desc";
|
|
65
|
-
/** Result limit (default: 20) */
|
|
66
|
-
readonly limit?: number;
|
|
67
|
-
/** Result offset */
|
|
68
|
-
readonly skip?: number;
|
|
69
|
-
}
|
|
70
|
-
/** Lightweight complexity summary for a built query. */
|
|
71
|
-
export interface QueryComplexity {
|
|
72
|
-
readonly filterCount: number;
|
|
73
|
-
readonly hasExclusion: boolean;
|
|
74
|
-
readonly hasSearch: boolean;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Result of `buildQuery()`.
|
|
78
|
-
*/
|
|
79
|
-
export interface BuildResult {
|
|
80
|
-
/** Emitted DSL string */
|
|
81
|
-
readonly dsl: string;
|
|
82
|
-
/** Validation result (may be valid with warnings, or invalid with errors) */
|
|
83
|
-
readonly validation: ValidationResult;
|
|
84
|
-
/** Human-readable query explanation */
|
|
85
|
-
readonly description: string;
|
|
86
|
-
/** Query complexity metrics */
|
|
87
|
-
readonly complexity: QueryComplexity;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* A single item in the fused RRF ranking.
|
|
91
|
-
*/
|
|
92
|
-
export interface EnsembleItem {
|
|
93
|
-
/** Entity ID (e.g. publication id, grant id) */
|
|
94
|
-
readonly id: string;
|
|
95
|
-
/** Reciprocal Rank Fusion score: Σ 1/(k + rank_i) */
|
|
96
|
-
readonly rrfScore: number;
|
|
97
|
-
/** Indices of the source specs that contributed this item (0-based) */
|
|
98
|
-
readonly sourceIndices: readonly number[];
|
|
99
|
-
/** Raw entity data from the first source that contained this item */
|
|
100
|
-
readonly data: Record<string, unknown>;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Result of `ensembleQueries()`.
|
|
104
|
-
*/
|
|
105
|
-
export interface EnsembleResult {
|
|
106
|
-
/** Fused items sorted by rrfScore descending */
|
|
107
|
-
readonly items: readonly EnsembleItem[];
|
|
108
|
-
/** Ensemble metadata */
|
|
109
|
-
readonly metadata: {
|
|
110
|
-
/** Number of specs provided */
|
|
111
|
-
readonly specsProvided: number;
|
|
112
|
-
/** Number of specs that produced valid DSL and executed successfully */
|
|
113
|
-
readonly specsExecuted: number;
|
|
114
|
-
/** RRF k parameter used */
|
|
115
|
-
readonly k: number;
|
|
116
|
-
/** Total duration in milliseconds */
|
|
117
|
-
readonly durationMs: number;
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/kwq/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/kwq/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,wEAAwE;AACxE,MAAM,MAAM,gBAAgB,GACxB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,EAAE,CAAA;CAAE,GAC1D;IACE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,SAAS;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACzD,QAAQ,CAAC,QAAQ,EAAE,SAAS,EAAE,CAAC;CAChC,CAAC;AAEN,2EAA2E;AAC3E,MAAM,MAAM,WAAW,GACnB,WAAW,GACX,iBAAiB,GACjB,qBAAqB,GAC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QACjB,+BAA+B;QAC/B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;QAC/B,wEAAwE;QACxE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;QAC/B,2BAA2B;QAC3B,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;QACnB,qCAAqC;QACrC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;KAC7B,CAAC;CACH"}
|
package/dist/kwq/types.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Types for the KWQ (Keyword Query) package.
|
|
3
|
-
*
|
|
4
|
-
* Ring 1: QuerySpec → buildQuery() → BuildResult (DSL string)
|
|
5
|
-
* Ring 4: ensembleQueries() → EnsembleResult
|
|
6
|
-
*
|
|
7
|
-
* @module types
|
|
8
|
-
*/
|
|
9
|
-
export {};
|
|
10
|
-
// #endregion
|
|
11
|
-
//# sourceMappingURL=types.js.map
|
package/dist/kwq/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/kwq/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;;AA8JH,aAAa"}
|
package/dist/lambda.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare const handler: <L extends import("hono/aws-lambda").LambdaEvent>(event: L, lambdaContext?: import("hono/aws-lambda").LambdaContext) => Promise<import("hono/aws-lambda").APIGatewayProxyResult & (L extends {
|
|
2
|
-
multiValueHeaders: Record<string, string[]>;
|
|
3
|
-
} ? {
|
|
4
|
-
headers?: undefined;
|
|
5
|
-
multiValueHeaders: Record<string, string[]>;
|
|
6
|
-
} : {
|
|
7
|
-
headers: Record<string, string>;
|
|
8
|
-
multiValueHeaders?: undefined;
|
|
9
|
-
})>;
|
|
10
|
-
//# sourceMappingURL=lambda.d.ts.map
|
package/dist/lambda.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lambda.d.ts","sourceRoot":"","sources":["../src/lambda.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO;;;;;;;;GAAc,CAAC"}
|
package/dist/lambda.js
DELETED
package/dist/lambda.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lambda.js","sourceRoot":"","sources":["../src/lambda.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEhC,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Concept profile tool for the MCP server.
|
|
3
|
-
* Provides multi-dimensional concept profiling across entity types via the Dimensions DSL.
|
|
4
|
-
* @module mcp/tools/concept-profile
|
|
5
|
-
*/
|
|
6
|
-
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
7
|
-
import type { DimensionsClient } from "../../dsl/index.js";
|
|
8
|
-
/**
|
|
9
|
-
* Registers the concept_profile tool with the MCP server.
|
|
10
|
-
* @param server - MCP server instance
|
|
11
|
-
* @param client - Dimensions client instance
|
|
12
|
-
*/
|
|
13
|
-
export declare function registerConceptProfileTools(server: McpServer, client: DimensionsClient): void;
|
|
14
|
-
//# sourceMappingURL=concept-profile.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"concept-profile.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/concept-profile.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAkB3D;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAkI7F"}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Concept profile tool for the MCP server.
|
|
3
|
-
* Provides multi-dimensional concept profiling across entity types via the Dimensions DSL.
|
|
4
|
-
* @module mcp/tools/concept-profile
|
|
5
|
-
*/
|
|
6
|
-
import { z } from "zod";
|
|
7
|
-
import { asArray, formatErrorResult, formatToolResult, READ_ONLY_API_ANNOTATIONS, } from "../utils.js";
|
|
8
|
-
/** Entity types used for entity footprint counts. */
|
|
9
|
-
const FOOTPRINT_ENTITIES = [
|
|
10
|
-
"publications",
|
|
11
|
-
"grants",
|
|
12
|
-
"patents",
|
|
13
|
-
"clinical_trials",
|
|
14
|
-
"datasets",
|
|
15
|
-
"policy_documents",
|
|
16
|
-
];
|
|
17
|
-
/**
|
|
18
|
-
* Registers the concept_profile tool with the MCP server.
|
|
19
|
-
* @param server - MCP server instance
|
|
20
|
-
* @param client - Dimensions client instance
|
|
21
|
-
*/
|
|
22
|
-
export function registerConceptProfileTools(server, client) {
|
|
23
|
-
server.registerTool("concept_profile", {
|
|
24
|
-
description: "Build a multi-dimensional profile for a research concept. Returns publication analytics (year trends, top orgs, journals, funders, field classification) and entity footprint across 6 entity types.",
|
|
25
|
-
inputSchema: {
|
|
26
|
-
concept: z.string().describe("The concept to profile (e.g., 'CRISPR', 'machine learning')"),
|
|
27
|
-
includeAnalytics: z
|
|
28
|
-
.boolean()
|
|
29
|
-
.default(true)
|
|
30
|
-
.describe("Include DSL facet analytics (year trends, top orgs, journals, funders, fields)"),
|
|
31
|
-
includeEntityFootprint: z
|
|
32
|
-
.boolean()
|
|
33
|
-
.default(true)
|
|
34
|
-
.describe("Include cross-entity type record counts"),
|
|
35
|
-
facetLimit: z
|
|
36
|
-
.number()
|
|
37
|
-
.int()
|
|
38
|
-
.min(1)
|
|
39
|
-
.max(50)
|
|
40
|
-
.default(10)
|
|
41
|
-
.describe("Max buckets per facet in analytics"),
|
|
42
|
-
},
|
|
43
|
-
outputSchema: {
|
|
44
|
-
found: z.boolean().describe("Whether results were found for the concept"),
|
|
45
|
-
concept: z.string().optional().describe("The profiled concept"),
|
|
46
|
-
profile: z
|
|
47
|
-
.record(z.string(), z.unknown())
|
|
48
|
-
.optional()
|
|
49
|
-
.describe("Multi-dimensional concept profile"),
|
|
50
|
-
},
|
|
51
|
-
annotations: READ_ONLY_API_ANNOTATIONS,
|
|
52
|
-
}, async (args) => {
|
|
53
|
-
try {
|
|
54
|
-
const profile = {};
|
|
55
|
-
const phases = [];
|
|
56
|
-
// Phase 1: DSL facet analytics
|
|
57
|
-
if (args.includeAnalytics !== false) {
|
|
58
|
-
phases.push((async () => {
|
|
59
|
-
const facetFields = ["year", "research_orgs", "journal", "funders", "category_for"];
|
|
60
|
-
const facetResults = await Promise.all(facetFields.map(async (field) => {
|
|
61
|
-
const dsl = client
|
|
62
|
-
.createQueryBuilder()
|
|
63
|
-
.search("publications")
|
|
64
|
-
.for(args.concept)
|
|
65
|
-
.returnFacet(field, { limit: field === "year" ? 50 : args.facetLimit })
|
|
66
|
-
.limit(0)
|
|
67
|
-
.build();
|
|
68
|
-
const response = await client.rawQuery(dsl);
|
|
69
|
-
return { field, data: response };
|
|
70
|
-
}));
|
|
71
|
-
const analytics = {};
|
|
72
|
-
for (const { field, data } of facetResults) {
|
|
73
|
-
const buckets = asArray(data[field]);
|
|
74
|
-
switch (field) {
|
|
75
|
-
case "year":
|
|
76
|
-
analytics.yearTrend = buckets;
|
|
77
|
-
break;
|
|
78
|
-
case "research_orgs":
|
|
79
|
-
analytics.topOrgs = buckets;
|
|
80
|
-
break;
|
|
81
|
-
case "journal":
|
|
82
|
-
analytics.topJournals = buckets;
|
|
83
|
-
break;
|
|
84
|
-
case "funders":
|
|
85
|
-
analytics.topFunders = buckets;
|
|
86
|
-
break;
|
|
87
|
-
case "category_for":
|
|
88
|
-
analytics.fieldClassification = buckets;
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
profile.analytics = analytics;
|
|
93
|
-
})());
|
|
94
|
-
}
|
|
95
|
-
// Phase 2: DSL entity footprint
|
|
96
|
-
if (args.includeEntityFootprint !== false) {
|
|
97
|
-
phases.push((async () => {
|
|
98
|
-
const counts = await Promise.all(FOOTPRINT_ENTITIES.map(async (entityType) => {
|
|
99
|
-
const dsl = client
|
|
100
|
-
.createQueryBuilder()
|
|
101
|
-
.search(entityType)
|
|
102
|
-
.for(args.concept)
|
|
103
|
-
.limit(1)
|
|
104
|
-
.build();
|
|
105
|
-
const response = await client.rawQuery(dsl);
|
|
106
|
-
const total = typeof response._stats?.total_count === "number"
|
|
107
|
-
? response._stats.total_count
|
|
108
|
-
: 0;
|
|
109
|
-
return { entityType, count: total };
|
|
110
|
-
}));
|
|
111
|
-
const entityFootprint = {};
|
|
112
|
-
for (const { entityType, count } of counts) {
|
|
113
|
-
entityFootprint[entityType] = count;
|
|
114
|
-
}
|
|
115
|
-
profile.entityFootprint = entityFootprint;
|
|
116
|
-
})());
|
|
117
|
-
}
|
|
118
|
-
await Promise.all(phases);
|
|
119
|
-
return formatToolResult({
|
|
120
|
-
found: true,
|
|
121
|
-
concept: args.concept,
|
|
122
|
-
profile,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
catch (error) {
|
|
126
|
-
return formatErrorResult(error);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
//# sourceMappingURL=concept-profile.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"concept-profile.js","sourceRoot":"","sources":["../../../src/mcp/tools/concept-profile.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,gBAAgB,EAChB,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AAErB,qDAAqD;AACrD,MAAM,kBAAkB,GAAG;IACzB,cAAc;IACd,QAA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,eAAe,CAAC;gBAC5C,CAAC,CAAC,EAAE,CACL,CAAC;YACJ,CAAC;YAED,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAE1B,OAAO,gBAAgB,CAAC;gBACtB,KAAK,EAAE,IAAI;gBACX,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,OAAO;aACR,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Dataset profile tool for the MCP server.
|
|
3
|
-
* Provides deep profiling of Dimensions datasets including structural links
|
|
4
|
-
* to associated publications and grants.
|
|
5
|
-
* @module mcp/tools/dataset-profile
|
|
6
|
-
*/
|
|
7
|
-
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
8
|
-
import type { DimensionsClient } from "../../dsl/index.js";
|
|
9
|
-
/**
|
|
10
|
-
* Registers the dataset_profile tool with the MCP server.
|
|
11
|
-
* @param server - MCP server instance
|
|
12
|
-
* @param client - Dimensions client instance
|
|
13
|
-
*/
|
|
14
|
-
export declare function registerDatasetProfileTools(server: McpServer, client: DimensionsClient): void;
|
|
15
|
-
//# sourceMappingURL=dataset-profile.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dataset-profile.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/dataset-profile.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAQ3D;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,GAAG,IAAI,CA6M7F"}
|