@lucern/contracts 0.1.1-alpha.1 → 0.1.2-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/README.md +3 -0
- package/dist/agents/v1.d.ts +2 -0
- package/dist/agents/v1.js +3 -0
- package/dist/agents/v1.js.map +1 -0
- package/dist/api-enums.contract.d.ts +60 -0
- package/dist/api-enums.contract.js +174 -0
- package/dist/api-enums.contract.js.map +1 -0
- package/dist/auth-context.contract.d.ts +2 -0
- package/dist/auth-context.contract.js +48 -0
- package/dist/auth-context.contract.js.map +1 -0
- package/dist/auth-session.contract.d.ts +2 -0
- package/dist/auth-session.contract.js +48 -0
- package/dist/auth-session.contract.js.map +1 -0
- package/dist/auth.contract.d.ts +92 -0
- package/dist/auth.contract.js +48 -0
- package/dist/auth.contract.js.map +1 -0
- package/dist/beliefs/v1.d.ts +2 -0
- package/dist/beliefs/v1.js +3 -0
- package/dist/beliefs/v1.js.map +1 -0
- package/dist/context-pack.contract.d.ts +496 -0
- package/dist/context-pack.contract.js +98 -0
- package/dist/context-pack.contract.js.map +1 -0
- package/dist/convex-admin.contract.d.ts +7 -0
- package/dist/convex-admin.contract.js +3 -0
- package/dist/convex-admin.contract.js.map +1 -0
- package/dist/events-types.contract.d.ts +1 -0
- package/dist/events-types.contract.js +136 -0
- package/dist/events-types.contract.js.map +1 -0
- package/dist/events.contract.d.ts +178 -0
- package/dist/events.contract.js +136 -0
- package/dist/events.contract.js.map +1 -0
- package/dist/evidence/v1.d.ts +2 -0
- package/dist/evidence/v1.js +3 -0
- package/dist/evidence/v1.js.map +1 -0
- package/dist/gateway.contract.d.ts +79 -0
- package/dist/gateway.contract.js +12 -0
- package/dist/gateway.contract.js.map +1 -0
- package/dist/graph/v1.d.ts +2 -0
- package/dist/graph/v1.js +3 -0
- package/dist/graph/v1.js.map +1 -0
- package/dist/ids.contract.d.ts +9 -0
- package/{src/ids.contract.ts → dist/ids.contract.js} +10 -17
- package/dist/ids.contract.js.map +1 -0
- package/dist/index.d.ts +15 -2004
- package/dist/index.js +61 -118
- package/dist/index.js.map +1 -0
- package/dist/lens-filter.contract.d.ts +72 -0
- package/dist/lens-filter.contract.js +71 -0
- package/dist/lens-filter.contract.js.map +1 -0
- package/dist/lens-workflow.contract.d.ts +87 -0
- package/dist/lens-workflow.contract.js +123 -0
- package/dist/lens-workflow.contract.js.map +1 -0
- package/dist/mcp-tools.contract-D8kXcP6d.d.ts +254 -0
- package/dist/mcp-tools.contract.d.ts +1 -0
- package/dist/mcp-tools.contract.js +3016 -0
- package/dist/mcp-tools.contract.js.map +1 -0
- package/dist/ontologies/v1.d.ts +2 -0
- package/dist/ontologies/v1.js +3 -0
- package/dist/ontologies/v1.js.map +1 -0
- package/dist/ontology-matching.contract.d.ts +1 -0
- package/dist/ontology-matching.contract.js +346 -0
- package/dist/ontology-matching.contract.js.map +1 -0
- package/dist/prompt.contract.d.ts +26 -0
- package/dist/prompt.contract.js +12 -0
- package/dist/prompt.contract.js.map +1 -0
- package/dist/questions/v1.d.ts +2 -0
- package/dist/questions/v1.js +3 -0
- package/dist/questions/v1.js.map +1 -0
- package/dist/sdk-methods.contract.d.ts +376 -0
- package/dist/sdk-methods.contract.js +3 -0
- package/dist/sdk-methods.contract.js.map +1 -0
- package/dist/sdk-tools.contract-BnV0hKLp.d.ts +150 -0
- package/dist/sdk-tools.contract.d.ts +2 -0
- package/dist/sdk-tools.contract.js +4252 -0
- package/dist/sdk-tools.contract.js.map +1 -0
- package/dist/text-matching.contract.d.ts +55 -0
- package/{src/text-matching.contract.ts → dist/text-matching.contract.js} +36 -137
- package/dist/text-matching.contract.js.map +1 -0
- package/dist/topic-scope.contract.d.ts +1 -0
- package/{src/v1/topics/v1.ts → dist/topic-scope.contract.js} +13 -38
- package/dist/topic-scope.contract.js.map +1 -0
- package/dist/topics/v1.d.ts +2 -0
- package/dist/topics/v1.js +3 -0
- package/dist/topics/v1.js.map +1 -0
- package/dist/v1/agents/v1.d.ts +2 -0
- package/dist/v1/agents/v1.js +3 -0
- package/dist/v1/agents/v1.js.map +1 -0
- package/dist/v1/beliefs/v1.d.ts +2 -0
- package/dist/v1/beliefs/v1.js +3 -0
- package/dist/v1/beliefs/v1.js.map +1 -0
- package/dist/v1/evidence/v1.d.ts +2 -0
- package/dist/v1/evidence/v1.js +3 -0
- package/dist/v1/evidence/v1.js.map +1 -0
- package/dist/v1/graph/v1.d.ts +2 -0
- package/dist/v1/graph/v1.js +3 -0
- package/dist/v1/graph/v1.js.map +1 -0
- package/dist/v1/ontologies/v1.d.ts +78 -0
- package/dist/v1/ontologies/v1.js +346 -0
- package/dist/v1/ontologies/v1.js.map +1 -0
- package/dist/v1/questions/v1.d.ts +2 -0
- package/dist/v1/questions/v1.js +3 -0
- package/dist/v1/questions/v1.js.map +1 -0
- package/dist/v1/topics/v1.d.ts +21 -0
- package/dist/v1/topics/v1.js +54 -0
- package/dist/v1/topics/v1.js.map +1 -0
- package/dist/v1/worktrees/v1.d.ts +2 -0
- package/dist/v1/worktrees/v1.js +3 -0
- package/dist/v1/worktrees/v1.js.map +1 -0
- package/dist/workflow-runtime.contract.d.ts +163 -0
- package/dist/workflow-runtime.contract.js +245 -0
- package/dist/workflow-runtime.contract.js.map +1 -0
- package/dist/worktrees/v1.d.ts +2 -0
- package/dist/worktrees/v1.js +3 -0
- package/dist/worktrees/v1.js.map +1 -0
- package/package.json +23 -7
- package/src/agents/v1.ts +0 -8
- package/src/api-enums.contract.ts +0 -183
- package/src/auth-context.contract.ts +0 -9
- package/src/auth-session.contract.ts +0 -9
- package/src/auth.contract.ts +0 -162
- package/src/beliefs/v1.ts +0 -8
- package/src/context-pack.contract.ts +0 -704
- package/src/convex-admin.contract.ts +0 -14
- package/src/events-types.contract.ts +0 -9
- package/src/events.contract.ts +0 -376
- package/src/evidence/v1.ts +0 -8
- package/src/gateway.contract.ts +0 -151
- package/src/graph/v1.ts +0 -8
- package/src/index.ts +0 -30
- package/src/lens-filter.contract.ts +0 -183
- package/src/lens-workflow.contract.ts +0 -162
- package/src/mcp-tools.contract.ts +0 -3636
- package/src/ontologies/v1.ts +0 -8
- package/src/ontology-matching.contract.ts +0 -9
- package/src/prompt.contract.ts +0 -50
- package/src/questions/v1.ts +0 -8
- package/src/sdk-methods.contract.ts +0 -522
- package/src/sdk-tools.contract.ts +0 -1545
- package/src/topic-scope.contract.ts +0 -9
- package/src/topics/v1.ts +0 -8
- package/src/v1/agents/v1.ts +0 -8
- package/src/v1/beliefs/v1.ts +0 -8
- package/src/v1/evidence/v1.ts +0 -8
- package/src/v1/graph/v1.ts +0 -8
- package/src/v1/ontologies/v1.ts +0 -276
- package/src/v1/questions/v1.ts +0 -8
- package/src/v1/worktrees/v1.ts +0 -8
- package/src/workflow-runtime.contract.ts +0 -440
- package/src/worktrees/v1.ts +0 -8
- package/tsconfig.json +0 -9
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @lucern/contracts — topic-scope compat shim
|
|
3
|
-
*
|
|
4
|
-
* This file moved to ./v1/topics/v1.ts during EK-16 T1 PR 2.
|
|
5
|
-
* Retained here until the Lucern 1.0.0 barrel-sunset cut (D12).
|
|
6
|
-
* New code should import from "@lucern/contracts/v1/topics" directly.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export * from "./v1/topics/v1";
|
package/src/topics/v1.ts
DELETED
package/src/v1/agents/v1.ts
DELETED
package/src/v1/beliefs/v1.ts
DELETED
package/src/v1/evidence/v1.ts
DELETED
package/src/v1/graph/v1.ts
DELETED
package/src/v1/ontologies/v1.ts
DELETED
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @lucern/contracts — OntologiesV1 namespace (resource contracts)
|
|
3
|
-
*
|
|
4
|
-
* Ontology Matching Engine — L0 entity type classification and similarity scoring.
|
|
5
|
-
* Provides bigram-based text similarity for matching free text against
|
|
6
|
-
* ontology entity types. Domain-agnostic: works identically for companies,
|
|
7
|
-
* molecules, code modules, or any tenant-defined entity vocabulary.
|
|
8
|
-
*
|
|
9
|
-
* Moved from src/ontology-matching.contract.ts in EK-16 T1 PR 2.
|
|
10
|
-
* Compat shim remains at the old path until the Lucern 1.0.0 cut.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
bigramTokenize,
|
|
15
|
-
jaccardSimilarity,
|
|
16
|
-
prepareLexicalQuery,
|
|
17
|
-
scoreLexicalSignals,
|
|
18
|
-
wordOverlapScore,
|
|
19
|
-
wordTokenize,
|
|
20
|
-
} from "../../text-matching.contract";
|
|
21
|
-
|
|
22
|
-
// =============================================================================
|
|
23
|
-
// TYPES
|
|
24
|
-
// =============================================================================
|
|
25
|
-
|
|
26
|
-
/** An entity type definition from a resolved ontology version. */
|
|
27
|
-
export type OntologyEntityType = {
|
|
28
|
-
value: string;
|
|
29
|
-
label: string;
|
|
30
|
-
description?: string;
|
|
31
|
-
subtypes?: Array<{ value: string; label: string; description?: string }>;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/** A scored match between input text and an entity type. */
|
|
35
|
-
export type EntityTypeMatch = {
|
|
36
|
-
entityType: string;
|
|
37
|
-
label: string;
|
|
38
|
-
score: number;
|
|
39
|
-
reason: string;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/** A candidate entity node that can be matched against a target node. */
|
|
43
|
-
export type EntityMatchCandidate = {
|
|
44
|
-
nodeId: string;
|
|
45
|
-
entityType: string;
|
|
46
|
-
title: string;
|
|
47
|
-
canonicalText: string;
|
|
48
|
-
connectedBeliefCount: number;
|
|
49
|
-
connectedEvidenceCount: number;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/** A scored entity match with suggested bridge edge type. */
|
|
53
|
-
export type EntityConnectionMatch = {
|
|
54
|
-
entityNodeId: string;
|
|
55
|
-
entityType: string;
|
|
56
|
-
title: string;
|
|
57
|
-
score: number;
|
|
58
|
-
suggestedEdgeType: string;
|
|
59
|
-
reason: string;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// =============================================================================
|
|
63
|
-
// ENTITY TYPE SCORING
|
|
64
|
-
// =============================================================================
|
|
65
|
-
|
|
66
|
-
/** Weights for combining scoring signals. */
|
|
67
|
-
const MATCH_WEIGHTS = {
|
|
68
|
-
tokenOverlap: 0.35,
|
|
69
|
-
bigramSimilarity: 0.25,
|
|
70
|
-
wordOverlap: 0.2,
|
|
71
|
-
descriptionBonus: 0.2,
|
|
72
|
-
} as const;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Score how well input text matches a single entity type definition.
|
|
76
|
-
* Combines bigram Jaccard similarity, word overlap, and description matching.
|
|
77
|
-
*/
|
|
78
|
-
export function scoreEntityTypeMatch(
|
|
79
|
-
inputText: string,
|
|
80
|
-
entityType: OntologyEntityType
|
|
81
|
-
): EntityTypeMatch {
|
|
82
|
-
const preparedQuery = prepareLexicalQuery(inputText);
|
|
83
|
-
const labelText = `${entityType.label} ${entityType.value}`;
|
|
84
|
-
|
|
85
|
-
const tokenScore = scoreLexicalSignals(preparedQuery, [
|
|
86
|
-
{ text: labelText, weight: 1, strategy: "tokenOverlap" },
|
|
87
|
-
]);
|
|
88
|
-
|
|
89
|
-
// Score against the type label (primary signal)
|
|
90
|
-
const labelBigrams = bigramTokenize(entityType.label);
|
|
91
|
-
const bigramScore = jaccardSimilarity(preparedQuery.bigrams, labelBigrams);
|
|
92
|
-
|
|
93
|
-
// Word overlap with label + value
|
|
94
|
-
const labelWords = wordTokenize(labelText);
|
|
95
|
-
const wordScore = wordOverlapScore(preparedQuery.words, labelWords);
|
|
96
|
-
|
|
97
|
-
// Description matching bonus (if description exists)
|
|
98
|
-
let descScore = 0;
|
|
99
|
-
if (entityType.description) {
|
|
100
|
-
descScore = scoreLexicalSignals(preparedQuery, [
|
|
101
|
-
{ text: entityType.description, weight: 1, strategy: "tokenOverlap" },
|
|
102
|
-
]);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Check subtypes for additional matches
|
|
106
|
-
let subtypeBonus = 0;
|
|
107
|
-
if (entityType.subtypes && entityType.subtypes.length > 0) {
|
|
108
|
-
for (const subtype of entityType.subtypes) {
|
|
109
|
-
const subtypeScore = scoreLexicalSignals(preparedQuery, [
|
|
110
|
-
{
|
|
111
|
-
text: `${subtype.label} ${subtype.value} ${subtype.description || ""}`,
|
|
112
|
-
weight: 1,
|
|
113
|
-
strategy: "tokenOverlap",
|
|
114
|
-
},
|
|
115
|
-
]);
|
|
116
|
-
subtypeBonus = Math.max(subtypeBonus, subtypeScore * 0.3); // up to 30% subtype bonus
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const score = Math.min(
|
|
121
|
-
1.0,
|
|
122
|
-
tokenScore * MATCH_WEIGHTS.tokenOverlap +
|
|
123
|
-
bigramScore * MATCH_WEIGHTS.bigramSimilarity +
|
|
124
|
-
wordScore * MATCH_WEIGHTS.wordOverlap +
|
|
125
|
-
descScore * MATCH_WEIGHTS.descriptionBonus +
|
|
126
|
-
subtypeBonus
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
// Generate human-readable reason
|
|
130
|
-
const reasons: string[] = [];
|
|
131
|
-
if (tokenScore > 0.3) {
|
|
132
|
-
reasons.push(`stem match: ${(tokenScore * 100).toFixed(0)}%`);
|
|
133
|
-
}
|
|
134
|
-
if (bigramScore > 0.3) {
|
|
135
|
-
reasons.push(`text similarity: ${(bigramScore * 100).toFixed(0)}%`);
|
|
136
|
-
}
|
|
137
|
-
if (wordScore > 0.3) {
|
|
138
|
-
reasons.push(`word match: ${(wordScore * 100).toFixed(0)}%`);
|
|
139
|
-
}
|
|
140
|
-
if (descScore > 0.2) {
|
|
141
|
-
reasons.push("description match");
|
|
142
|
-
}
|
|
143
|
-
if (subtypeBonus > 0.05) {
|
|
144
|
-
reasons.push("subtype match");
|
|
145
|
-
}
|
|
146
|
-
const reason = reasons.length > 0 ? reasons.join(", ") : "low similarity";
|
|
147
|
-
|
|
148
|
-
return {
|
|
149
|
-
entityType: entityType.value,
|
|
150
|
-
label: entityType.label,
|
|
151
|
-
score,
|
|
152
|
-
reason,
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Rank all entity types in an ontology against input text.
|
|
158
|
-
* Returns matches sorted by score (descending), filtered to score > minScore.
|
|
159
|
-
*/
|
|
160
|
-
export function rankEntityTypeMatches(
|
|
161
|
-
inputText: string,
|
|
162
|
-
entityTypes: OntologyEntityType[],
|
|
163
|
-
options?: { minScore?: number; limit?: number }
|
|
164
|
-
): EntityTypeMatch[] {
|
|
165
|
-
const minScore = options?.minScore ?? 0.05;
|
|
166
|
-
const limit = options?.limit ?? 10;
|
|
167
|
-
|
|
168
|
-
const matches = entityTypes
|
|
169
|
-
.map((et) => scoreEntityTypeMatch(inputText, et))
|
|
170
|
-
.filter((m) => m.score >= minScore)
|
|
171
|
-
.sort((a, b) => b.score - a.score)
|
|
172
|
-
.slice(0, limit);
|
|
173
|
-
|
|
174
|
-
return matches;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// =============================================================================
|
|
178
|
-
// ENTITY DISCOVERY SCORING
|
|
179
|
-
// =============================================================================
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Score how well a node's text matches an entity candidate.
|
|
183
|
-
* Used by discover_entity_connections to suggest missing bridge edges.
|
|
184
|
-
*/
|
|
185
|
-
export function scoreEntityConnection(
|
|
186
|
-
nodeText: string,
|
|
187
|
-
candidate: EntityMatchCandidate,
|
|
188
|
-
options?: { connectivityWeight?: number }
|
|
189
|
-
): EntityConnectionMatch {
|
|
190
|
-
const preparedQuery = prepareLexicalQuery(nodeText);
|
|
191
|
-
const connectivityWeight = options?.connectivityWeight ?? 0.3;
|
|
192
|
-
const textWeight = 1.0 - connectivityWeight;
|
|
193
|
-
const candidateText = `${candidate.title} ${candidate.canonicalText}`;
|
|
194
|
-
const tokenScore = scoreLexicalSignals(preparedQuery, [
|
|
195
|
-
{ text: candidateText, weight: 1, strategy: "tokenOverlap" },
|
|
196
|
-
]);
|
|
197
|
-
const textScore = scoreLexicalSignals(preparedQuery, [
|
|
198
|
-
{ text: candidateText, weight: 1, strategy: "bigramJaccard" },
|
|
199
|
-
]);
|
|
200
|
-
const wordScore = scoreLexicalSignals(preparedQuery, [
|
|
201
|
-
{ text: candidateText, weight: 1, strategy: "wordOverlap" },
|
|
202
|
-
]);
|
|
203
|
-
|
|
204
|
-
// Connectivity signal (normalized externally by caller)
|
|
205
|
-
const maxConnections = Math.max(
|
|
206
|
-
1,
|
|
207
|
-
candidate.connectedBeliefCount + candidate.connectedEvidenceCount
|
|
208
|
-
);
|
|
209
|
-
const connectivityScore = Math.min(1.0, maxConnections / 10); // soft-cap at 10
|
|
210
|
-
|
|
211
|
-
const combinedTextScore =
|
|
212
|
-
tokenScore * 0.45 + textScore * 0.35 + wordScore * 0.2;
|
|
213
|
-
const score =
|
|
214
|
-
combinedTextScore * textWeight + connectivityScore * connectivityWeight;
|
|
215
|
-
|
|
216
|
-
// Suggest edge type based on entity type
|
|
217
|
-
const suggestedEdgeType = suggestEdgeType(candidate.entityType);
|
|
218
|
-
|
|
219
|
-
const reason =
|
|
220
|
-
tokenScore > 0.3
|
|
221
|
-
? `stem match: ${(tokenScore * 100).toFixed(0)}%`
|
|
222
|
-
: textScore > 0.2
|
|
223
|
-
? `name similarity: ${(textScore * 100).toFixed(0)}%`
|
|
224
|
-
: wordScore > 0.2
|
|
225
|
-
? `keyword match: ${(wordScore * 100).toFixed(0)}%`
|
|
226
|
-
: `connectivity: ${candidate.connectedBeliefCount} beliefs`;
|
|
227
|
-
|
|
228
|
-
return {
|
|
229
|
-
entityNodeId: candidate.nodeId,
|
|
230
|
-
entityType: candidate.entityType,
|
|
231
|
-
title: candidate.title,
|
|
232
|
-
score,
|
|
233
|
-
suggestedEdgeType,
|
|
234
|
-
reason,
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Suggest the most appropriate bridge edge type for an entity type.
|
|
240
|
-
*/
|
|
241
|
-
function suggestEdgeType(entityType: string): string {
|
|
242
|
-
switch (entityType) {
|
|
243
|
-
case "company":
|
|
244
|
-
case "person":
|
|
245
|
-
case "investor":
|
|
246
|
-
return "contains";
|
|
247
|
-
case "function":
|
|
248
|
-
case "value_chain":
|
|
249
|
-
return "impacts";
|
|
250
|
-
default:
|
|
251
|
-
return "contains";
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Rank entity candidates against a node's text.
|
|
257
|
-
* Returns sorted matches above the minimum score threshold.
|
|
258
|
-
*/
|
|
259
|
-
export function rankEntityConnections(
|
|
260
|
-
nodeText: string,
|
|
261
|
-
candidates: EntityMatchCandidate[],
|
|
262
|
-
options?: { minScore?: number; limit?: number; connectivityWeight?: number }
|
|
263
|
-
): EntityConnectionMatch[] {
|
|
264
|
-
const minScore = options?.minScore ?? 0.05;
|
|
265
|
-
const limit = options?.limit ?? 10;
|
|
266
|
-
|
|
267
|
-
return candidates
|
|
268
|
-
.map((c) =>
|
|
269
|
-
scoreEntityConnection(nodeText, c, {
|
|
270
|
-
connectivityWeight: options?.connectivityWeight,
|
|
271
|
-
})
|
|
272
|
-
)
|
|
273
|
-
.filter((m) => m.score >= minScore)
|
|
274
|
-
.sort((a, b) => b.score - a.score)
|
|
275
|
-
.slice(0, limit);
|
|
276
|
-
}
|
package/src/v1/questions/v1.ts
DELETED
package/src/v1/worktrees/v1.ts
DELETED