@lucern/graph-primitives 0.1.0-alpha.4 → 0.3.0-alpha.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/dist/beliefDecay.js +229 -1115
- package/dist/beliefDecay.js.map +1 -1
- package/dist/beliefEvidenceLinks.js +53 -834
- package/dist/beliefEvidenceLinks.js.map +1 -1
- package/dist/confidencePropagationDispatch.d.ts +3 -3
- package/dist/confidencePropagationDispatch.js +30 -308
- package/dist/confidencePropagationDispatch.js.map +1 -1
- package/dist/contradictions.js +5 -797
- package/dist/contradictions.js.map +1 -1
- package/dist/edges/contradicts.js +1 -122
- package/dist/edges/contradicts.js.map +1 -1
- package/dist/edges/dependsOn.js +14 -172
- package/dist/edges/dependsOn.js.map +1 -1
- package/dist/edges/elaborates.js +1 -49
- package/dist/edges/elaborates.js.map +1 -1
- package/dist/edges/index.js +14 -277
- package/dist/edges/index.js.map +1 -1
- package/dist/edges/informs.js +1 -62
- package/dist/edges/informs.js.map +1 -1
- package/dist/edges/propagationTypes.d.ts +2 -2
- package/dist/edges/propagationTypes.js.map +1 -1
- package/dist/edges/refutes.js +1 -62
- package/dist/edges/refutes.js.map +1 -1
- package/dist/edges/supports.js +1 -122
- package/dist/edges/supports.js.map +1 -1
- package/dist/edges/utils.d.ts +6 -6
- package/dist/edges/utils.js +1 -130
- package/dist/edges/utils.js.map +1 -1
- package/dist/entityBridge.js +2 -17
- package/dist/entityBridge.js.map +1 -1
- package/dist/entityLifecycle.js +62 -848
- package/dist/entityLifecycle.js.map +1 -1
- package/dist/epistemicAnswers.js +27 -838
- package/dist/epistemicAnswers.js.map +1 -1
- package/dist/epistemicBeliefs.js +186 -2214
- package/dist/epistemicBeliefs.js.map +1 -1
- package/dist/epistemicContractHelpers.js +1 -318
- package/dist/epistemicContractHelpers.js.map +1 -1
- package/dist/epistemicContracts.js +163 -2467
- package/dist/epistemicContracts.js.map +1 -1
- package/dist/epistemicEdges.js +60 -863
- package/dist/epistemicEdges.js.map +1 -1
- package/dist/epistemicEvidence.js +116 -1647
- package/dist/epistemicEvidence.js.map +1 -1
- package/dist/epistemicHelpers.js +3 -2
- package/dist/epistemicHelpers.js.map +1 -1
- package/dist/epistemicLinking.js +2 -785
- package/dist/epistemicLinking.js.map +1 -1
- package/dist/epistemicNodes.js +34 -1427
- package/dist/epistemicNodes.js.map +1 -1
- package/dist/epistemicQuestions.js +88 -1637
- package/dist/epistemicQuestions.js.map +1 -1
- package/dist/epistemicSources.js +28 -1421
- package/dist/epistemicSources.js.map +1 -1
- package/dist/evaluators/index.js +163 -2467
- package/dist/evaluators/index.js.map +1 -1
- package/dist/index.js +486 -3649
- package/dist/index.js.map +1 -1
- package/dist/ontology-matching.js +1 -344
- package/dist/ontology-matching.js.map +1 -1
- package/dist/ontologyApproval.js +1 -13
- package/dist/ontologyApproval.js.map +1 -1
- package/dist/ontologyDefinitions.js +2 -17
- package/dist/ontologyDefinitions.js.map +1 -1
- package/dist/ontologyRegistry.js +2 -17
- package/dist/ontologyRegistry.js.map +1 -1
- package/dist/projectionReconciliation.js +2 -17
- package/dist/projectionReconciliation.js.map +1 -1
- package/dist/questionEvidenceLinks.js +242 -837
- package/dist/questionEvidenceLinks.js.map +1 -1
- package/dist/text-matching.js +1 -244
- package/dist/text-matching.js.map +1 -1
- package/dist/workflowBridge.d.ts +27 -0
- package/dist/workflowBridge.js +303 -0
- package/dist/workflowBridge.js.map +1 -0
- package/dist/workspaceIsolation.js +8 -609
- package/dist/workspaceIsolation.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,934 +1,15 @@
|
|
|
1
1
|
import { v } from 'convex/values';
|
|
2
|
-
import {
|
|
2
|
+
import { checkProjectAccess, checkScopeAccess } from '@lucern/access-control/access';
|
|
3
|
+
import { normalizeAudienceKey, canAudienceClassAccess, classFromAudienceKey } from '@lucern/access-control/audience';
|
|
4
|
+
import { listAudienceRegistryRows } from '@lucern/access-control/audienceRegistry';
|
|
5
|
+
import { getCurrentUserId } from '@lucern/access-control/auth';
|
|
6
|
+
import { permissiveReturn } from '@lucern/contracts/schema-helpers/validators';
|
|
7
|
+
import { componentsGeneric, mutationGeneric, anyApi, queryGeneric, internalQueryGeneric, internalMutationGeneric } from 'convex/server';
|
|
8
|
+
import { isNodeType, getLayerForNodeType } from '@lucern/contracts/schema-helpers/spine/tables/epistemicNodes';
|
|
3
9
|
|
|
4
10
|
// src/epistemicQuestions.ts
|
|
5
11
|
var api = anyApi;
|
|
6
12
|
componentsGeneric();
|
|
7
|
-
|
|
8
|
-
// ../access-control/src/topicProjectOverlay.ts
|
|
9
|
-
var LEGACY_SCOPE_FIELD = "graphScopeProjectId";
|
|
10
|
-
function readNonEmptyString(value) {
|
|
11
|
-
if (typeof value !== "string") {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
const normalized = value.trim();
|
|
15
|
-
return normalized.length > 0 ? normalized : void 0;
|
|
16
|
-
}
|
|
17
|
-
function readStringArray(value) {
|
|
18
|
-
if (!Array.isArray(value)) {
|
|
19
|
-
return [];
|
|
20
|
-
}
|
|
21
|
-
return value.map((entry) => readNonEmptyString(entry)).filter((entry) => Boolean(entry));
|
|
22
|
-
}
|
|
23
|
-
function readMetadata(topic) {
|
|
24
|
-
return topic.metadata && typeof topic.metadata === "object" ? topic.metadata : {};
|
|
25
|
-
}
|
|
26
|
-
function readLegacyProjectId(value) {
|
|
27
|
-
if (!value) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
return readNonEmptyString(value[LEGACY_SCOPE_FIELD]);
|
|
31
|
-
}
|
|
32
|
-
function coerceVisibility(value) {
|
|
33
|
-
return value === "private" || value === "team" || value === "firm" || value === "external" || value === "public" ? value : void 0;
|
|
34
|
-
}
|
|
35
|
-
function coerceStatus(value) {
|
|
36
|
-
return value === "active" || value === "archived" || value === "watching" ? value : void 0;
|
|
37
|
-
}
|
|
38
|
-
function mapProjectType(topic, metadata) {
|
|
39
|
-
const explicit = readNonEmptyString(metadata.projectType);
|
|
40
|
-
if (explicit) {
|
|
41
|
-
return explicit;
|
|
42
|
-
}
|
|
43
|
-
if (topic.type === "theme") {
|
|
44
|
-
return "thematic";
|
|
45
|
-
}
|
|
46
|
-
return readNonEmptyString(topic.type) || "general";
|
|
47
|
-
}
|
|
48
|
-
function isProjectLikeTopic(topic) {
|
|
49
|
-
const metadata = readMetadata(topic);
|
|
50
|
-
return topic.type === "theme" || topic.type === "thematic" || topic.type === "deal" || topic.type === "monitoring" || readLegacyProjectId(topic) !== void 0 || readNonEmptyString(metadata.projectType) !== void 0;
|
|
51
|
-
}
|
|
52
|
-
async function resolveTopicDoc(ctx, scopeId) {
|
|
53
|
-
if (ctx?.db && typeof ctx.db.get === "function") {
|
|
54
|
-
try {
|
|
55
|
-
const directTopic = await ctx.db.get(scopeId);
|
|
56
|
-
if (directTopic) {
|
|
57
|
-
return directTopic;
|
|
58
|
-
}
|
|
59
|
-
} catch {
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (typeof ctx.runQuery !== "function") {
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
try {
|
|
66
|
-
const topic = await ctx.runQuery(api.topics.get, {
|
|
67
|
-
id: String(scopeId)
|
|
68
|
-
});
|
|
69
|
-
if (topic?.name !== void 0 && topic?.type !== void 0) {
|
|
70
|
-
return topic;
|
|
71
|
-
}
|
|
72
|
-
} catch {
|
|
73
|
-
}
|
|
74
|
-
try {
|
|
75
|
-
const topic = await ctx.runQuery(api.topics.getByLegacyScopeId, {
|
|
76
|
-
projectId: String(scopeId)
|
|
77
|
-
});
|
|
78
|
-
if (topic?.name !== void 0 && topic?.type !== void 0) {
|
|
79
|
-
return topic;
|
|
80
|
-
}
|
|
81
|
-
} catch {
|
|
82
|
-
}
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
function materializeTopicProjectOverlay(topic, idMode = "legacy") {
|
|
86
|
-
const metadata = readMetadata(topic);
|
|
87
|
-
const topicId = String(topic._id);
|
|
88
|
-
const legacyProjectId = readLegacyProjectId(topic) || readLegacyProjectId(metadata) || readNonEmptyString(metadata.legacyProjectId);
|
|
89
|
-
const storageProjectId = legacyProjectId || topicId;
|
|
90
|
-
const outwardId = idMode === "topic" ? topicId : storageProjectId;
|
|
91
|
-
const visibility = coerceVisibility(topic.visibility) || coerceVisibility(metadata.visibility) || "private";
|
|
92
|
-
const status = coerceStatus(topic.status) || coerceStatus(metadata.status) || "active";
|
|
93
|
-
const createdAt = typeof topic.createdAt === "number" ? topic.createdAt : typeof topic._creationTime === "number" ? topic._creationTime : 0;
|
|
94
|
-
const updatedAt = typeof topic.updatedAt === "number" ? topic.updatedAt : typeof metadata.updatedAt === "number" ? metadata.updatedAt : createdAt;
|
|
95
|
-
return {
|
|
96
|
-
...metadata,
|
|
97
|
-
_id: outwardId,
|
|
98
|
-
projectId: outwardId,
|
|
99
|
-
topicId,
|
|
100
|
-
storageProjectId,
|
|
101
|
-
legacyProjectId,
|
|
102
|
-
name: readNonEmptyString(topic.name) || "Untitled Theme",
|
|
103
|
-
type: mapProjectType(topic, metadata),
|
|
104
|
-
description: readNonEmptyString(topic.description),
|
|
105
|
-
ownerId: readNonEmptyString(metadata.ownerId) || readNonEmptyString(topic.createdBy) || "system",
|
|
106
|
-
sharedWith: readStringArray(metadata.sharedWith),
|
|
107
|
-
visibility,
|
|
108
|
-
tenantId: readNonEmptyString(topic.tenantId) || readNonEmptyString(metadata.tenantId),
|
|
109
|
-
workspaceId: readNonEmptyString(topic.workspaceId) || readNonEmptyString(metadata.workspaceId),
|
|
110
|
-
status,
|
|
111
|
-
tags: readStringArray(metadata.tags),
|
|
112
|
-
chatCount: typeof metadata.chatCount === "number" ? metadata.chatCount : 0,
|
|
113
|
-
artifactCount: typeof metadata.artifactCount === "number" ? metadata.artifactCount : 0,
|
|
114
|
-
lastActivityAt: typeof metadata.lastActivityAt === "number" ? metadata.lastActivityAt : updatedAt,
|
|
115
|
-
_creationTime: typeof topic._creationTime === "number" ? topic._creationTime : createdAt,
|
|
116
|
-
createdAt,
|
|
117
|
-
updatedAt
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
async function resolveTopicProjectOverlay(ctx, scopeId, options = {}) {
|
|
121
|
-
const topic = await resolveTopicDoc(ctx, scopeId);
|
|
122
|
-
if (!topic) {
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
if (options.projectLikeOnly !== false && !isProjectLikeTopic(topic)) {
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
return materializeTopicProjectOverlay(topic, options.idMode);
|
|
129
|
-
}
|
|
130
|
-
async function listTopicProjectOverlays(ctx, options = {}) {
|
|
131
|
-
let allTopics = [];
|
|
132
|
-
if (ctx?.db?.query && typeof ctx.db.query === "function") {
|
|
133
|
-
try {
|
|
134
|
-
allTopics = await ctx.db.query("topics").collect();
|
|
135
|
-
} catch {
|
|
136
|
-
allTopics = [];
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
if (allTopics.length === 0 && typeof ctx.runQuery === "function") {
|
|
140
|
-
allTopics = (await ctx.runQuery(api.topics.list, {}) ?? []) || [];
|
|
141
|
-
}
|
|
142
|
-
return allTopics.filter(
|
|
143
|
-
(topic) => options.projectLikeOnly === false || isProjectLikeTopic(topic)
|
|
144
|
-
).map((topic) => materializeTopicProjectOverlay(topic, options.idMode));
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// ../access-control/src/projectGrantsBridge.ts
|
|
148
|
-
var PROJECT_GRANT_STATUSES = ["active", "revoked", "expired"];
|
|
149
|
-
function normalizeString(value) {
|
|
150
|
-
if (typeof value !== "string") {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
const trimmed = value.trim();
|
|
154
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
155
|
-
}
|
|
156
|
-
async function resolveGrantScopeIds(ctx, args) {
|
|
157
|
-
const topicId = normalizeString(args.topicId);
|
|
158
|
-
const projectId = normalizeString(args.projectId);
|
|
159
|
-
for (const scopeId of [topicId, projectId]) {
|
|
160
|
-
if (!scopeId) {
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
try {
|
|
164
|
-
const overlay = await resolveTopicProjectOverlay(ctx, scopeId, {
|
|
165
|
-
idMode: "legacy",
|
|
166
|
-
projectLikeOnly: false
|
|
167
|
-
});
|
|
168
|
-
if (overlay) {
|
|
169
|
-
return {
|
|
170
|
-
topicId: normalizeString(overlay.topicId) ?? topicId,
|
|
171
|
-
projectId: normalizeString(overlay.projectId) ?? projectId ?? scopeId
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
} catch {
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return { topicId, projectId };
|
|
178
|
-
}
|
|
179
|
-
async function normalizeProjectGrantRow(ctx, row) {
|
|
180
|
-
const scope = await resolveGrantScopeIds(ctx, {
|
|
181
|
-
topicId: row.topicId,
|
|
182
|
-
projectId: row.projectId
|
|
183
|
-
});
|
|
184
|
-
return {
|
|
185
|
-
...row,
|
|
186
|
-
...scope.topicId ? { topicId: scope.topicId } : {},
|
|
187
|
-
...scope.projectId ?? scope.topicId ? { projectId: scope.projectId ?? scope.topicId } : {}
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
async function normalizeProjectGrantRows(ctx, rows) {
|
|
191
|
-
return await Promise.all(rows.map((row) => normalizeProjectGrantRow(ctx, row)));
|
|
192
|
-
}
|
|
193
|
-
async function listProjectGrantsByPrincipal(ctx, principalId) {
|
|
194
|
-
const rows = await Promise.all(
|
|
195
|
-
PROJECT_GRANT_STATUSES.map(
|
|
196
|
-
(status) => ctx.db.query("projectGrants").withIndex(
|
|
197
|
-
"by_principal_status",
|
|
198
|
-
(q) => q.eq("principalId", principalId).eq("status", status)
|
|
199
|
-
).collect()
|
|
200
|
-
)
|
|
201
|
-
);
|
|
202
|
-
return await normalizeProjectGrantRows(ctx, rows.flat());
|
|
203
|
-
}
|
|
204
|
-
async function listProjectGrantsByGroup(ctx, groupId) {
|
|
205
|
-
const rows = await Promise.all(
|
|
206
|
-
PROJECT_GRANT_STATUSES.map(
|
|
207
|
-
(status) => ctx.db.query("projectGrants").withIndex(
|
|
208
|
-
"by_group_status",
|
|
209
|
-
(q) => q.eq("groupId", groupId).eq("status", status)
|
|
210
|
-
).collect()
|
|
211
|
-
)
|
|
212
|
-
);
|
|
213
|
-
return await normalizeProjectGrantRows(ctx, rows.flat());
|
|
214
|
-
}
|
|
215
|
-
function buildScopeMatchers(inputScopeId, resolved) {
|
|
216
|
-
return new Set(
|
|
217
|
-
[inputScopeId, resolved.topicId, resolved.projectId].map((value) => normalizeString(value)).filter((value) => Boolean(value))
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
function matchesResolvedScope(row, scopeIds) {
|
|
221
|
-
const rowTopicId = normalizeString(row.topicId);
|
|
222
|
-
const rowProjectId = normalizeString(row.projectId);
|
|
223
|
-
return rowTopicId !== void 0 && scopeIds.has(rowTopicId) || rowProjectId !== void 0 && scopeIds.has(rowProjectId);
|
|
224
|
-
}
|
|
225
|
-
async function bridgeListProjectGrantsByTopicAndPrincipal(ctx, topicId, principalId) {
|
|
226
|
-
const resolved = await resolveGrantScopeIds(ctx, { topicId });
|
|
227
|
-
const scopeIds = buildScopeMatchers(topicId, resolved);
|
|
228
|
-
const rows = await listProjectGrantsByPrincipal(ctx, principalId);
|
|
229
|
-
return rows.filter((row) => matchesResolvedScope(row, scopeIds));
|
|
230
|
-
}
|
|
231
|
-
async function bridgeListProjectGrantsByTopicAndGroup(ctx, topicId, groupId) {
|
|
232
|
-
const resolved = await resolveGrantScopeIds(ctx, { topicId });
|
|
233
|
-
const scopeIds = buildScopeMatchers(topicId, resolved);
|
|
234
|
-
const rows = await listProjectGrantsByGroup(ctx, groupId);
|
|
235
|
-
return rows.filter((row) => matchesResolvedScope(row, scopeIds));
|
|
236
|
-
}
|
|
237
|
-
async function bridgeListProjectGrantsByPrincipalStatus(ctx, principalId, status) {
|
|
238
|
-
const rows = await listProjectGrantsByPrincipal(ctx, principalId);
|
|
239
|
-
return rows.filter((row) => row.status === status);
|
|
240
|
-
}
|
|
241
|
-
async function bridgeListProjectGrantsByGroupStatus(ctx, groupId, status) {
|
|
242
|
-
const rows = await listProjectGrantsByGroup(ctx, groupId);
|
|
243
|
-
return rows.filter((row) => row.status === status);
|
|
244
|
-
}
|
|
245
|
-
async function bridgeInsertProjectGrant(ctx, value) {
|
|
246
|
-
const resolved = await resolveGrantScopeIds(ctx, value);
|
|
247
|
-
return await ctx.db.insert("projectGrants", {
|
|
248
|
-
...value,
|
|
249
|
-
...resolved.topicId ? { topicId: resolved.topicId } : {},
|
|
250
|
-
...resolved.projectId ?? resolved.topicId ? { projectId: resolved.projectId ?? resolved.topicId } : {}
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// ../access-control/src/resolvers.ts
|
|
255
|
-
async function findUserByClerkId(ctx, clerkId) {
|
|
256
|
-
const normalizedClerkId = clerkId.trim();
|
|
257
|
-
if (!normalizedClerkId) {
|
|
258
|
-
return null;
|
|
259
|
-
}
|
|
260
|
-
if (typeof ctx.runQuery === "function") {
|
|
261
|
-
try {
|
|
262
|
-
const bridgedUser = await ctx.runQuery(api.users.getUserByClerkId, {
|
|
263
|
-
clerkId: normalizedClerkId
|
|
264
|
-
});
|
|
265
|
-
if (bridgedUser) {
|
|
266
|
-
return bridgedUser;
|
|
267
|
-
}
|
|
268
|
-
} catch {
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
try {
|
|
272
|
-
const users = await ctx.db.query("users").collect();
|
|
273
|
-
return users.find((user) => String(user.clerkId ?? "") === normalizedClerkId) ?? null;
|
|
274
|
-
} catch {
|
|
275
|
-
return null;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
async function findUserByPrincipalId(ctx, principalId) {
|
|
279
|
-
const normalizedPrincipalId = principalId.trim();
|
|
280
|
-
if (!normalizedPrincipalId) {
|
|
281
|
-
return null;
|
|
282
|
-
}
|
|
283
|
-
try {
|
|
284
|
-
const users = await ctx.db.query("users").collect();
|
|
285
|
-
return users.find(
|
|
286
|
-
(user) => String(user.defaultPrincipalId ?? "") === normalizedPrincipalId
|
|
287
|
-
) ?? null;
|
|
288
|
-
} catch {
|
|
289
|
-
return null;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
async function findAgentByPrincipalId(ctx, principalId) {
|
|
293
|
-
const normalizedPrincipalId = principalId.trim();
|
|
294
|
-
if (!normalizedPrincipalId) {
|
|
295
|
-
return null;
|
|
296
|
-
}
|
|
297
|
-
if (typeof ctx.runQuery === "function") {
|
|
298
|
-
try {
|
|
299
|
-
const bridgedAgent = await ctx.runQuery(
|
|
300
|
-
api.agents.getAgentByPrincipalId,
|
|
301
|
-
{
|
|
302
|
-
principalId: normalizedPrincipalId
|
|
303
|
-
}
|
|
304
|
-
);
|
|
305
|
-
if (bridgedAgent) {
|
|
306
|
-
return bridgedAgent;
|
|
307
|
-
}
|
|
308
|
-
} catch {
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
try {
|
|
312
|
-
const agents = await ctx.db.query("agents").collect();
|
|
313
|
-
return agents.find(
|
|
314
|
-
(agent) => String(agent.principalId ?? "") === normalizedPrincipalId
|
|
315
|
-
) ?? null;
|
|
316
|
-
} catch {
|
|
317
|
-
return null;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
function defaultResolvers() {
|
|
321
|
-
return {
|
|
322
|
-
async getProject(ctx, topicId) {
|
|
323
|
-
return await resolveTopicProjectOverlay(ctx, topicId, {
|
|
324
|
-
idMode: "legacy",
|
|
325
|
-
projectLikeOnly: false
|
|
326
|
-
});
|
|
327
|
-
},
|
|
328
|
-
async listTopics(ctx) {
|
|
329
|
-
return await listTopicProjectOverlays(ctx, { idMode: "legacy" });
|
|
330
|
-
},
|
|
331
|
-
async listTopicsByOwner(ctx, ownerId) {
|
|
332
|
-
const topics = await listTopicProjectOverlays(ctx, { idMode: "legacy" });
|
|
333
|
-
return topics.filter((topic) => topic.ownerId === ownerId);
|
|
334
|
-
},
|
|
335
|
-
async listTopicsByVisibility(ctx, visibility) {
|
|
336
|
-
const topics = await listTopicProjectOverlays(ctx, { idMode: "legacy" });
|
|
337
|
-
return topics.filter((topic) => topic.visibility === visibility);
|
|
338
|
-
},
|
|
339
|
-
async listProjectGrantsByProjectAndPrincipal(ctx, topicId, principalId) {
|
|
340
|
-
return await bridgeListProjectGrantsByTopicAndPrincipal(
|
|
341
|
-
ctx,
|
|
342
|
-
topicId,
|
|
343
|
-
principalId
|
|
344
|
-
);
|
|
345
|
-
},
|
|
346
|
-
async listProjectGrantsByProjectAndGroup(ctx, topicId, groupId) {
|
|
347
|
-
return await bridgeListProjectGrantsByTopicAndGroup(ctx, topicId, groupId);
|
|
348
|
-
},
|
|
349
|
-
async listProjectGrantsByPrincipalStatus(ctx, principalId, status) {
|
|
350
|
-
return await bridgeListProjectGrantsByPrincipalStatus(
|
|
351
|
-
ctx,
|
|
352
|
-
principalId,
|
|
353
|
-
status
|
|
354
|
-
);
|
|
355
|
-
},
|
|
356
|
-
async listProjectGrantsByGroupStatus(ctx, groupId, status) {
|
|
357
|
-
return await bridgeListProjectGrantsByGroupStatus(ctx, groupId, status);
|
|
358
|
-
},
|
|
359
|
-
async insertProjectGrant(ctx, value) {
|
|
360
|
-
return await bridgeInsertProjectGrant(ctx, value);
|
|
361
|
-
},
|
|
362
|
-
async getAgentByPrincipalId(ctx, principalId) {
|
|
363
|
-
return await findAgentByPrincipalId(ctx, principalId);
|
|
364
|
-
},
|
|
365
|
-
async getUserByClerkId(ctx, clerkId) {
|
|
366
|
-
return await findUserByClerkId(ctx, clerkId);
|
|
367
|
-
},
|
|
368
|
-
async getUserByPrincipalId(ctx, principalId) {
|
|
369
|
-
return await findUserByPrincipalId(ctx, principalId);
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
var resolverOverrides = {};
|
|
374
|
-
function resolveAccessControlAppResolvers(_ctx) {
|
|
375
|
-
return {
|
|
376
|
-
...defaultResolvers(),
|
|
377
|
-
...resolverOverrides
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
// ../access-control/src/principalContext.ts
|
|
382
|
-
function requireCanonicalResolvedUser(user, clerkId) {
|
|
383
|
-
const resolved = user;
|
|
384
|
-
if (!resolved) {
|
|
385
|
-
throw new Error(
|
|
386
|
-
`[AccessControl] Canonical user identity required for ${clerkId}. Sync users.upsertUser before user-bound access checks.`
|
|
387
|
-
);
|
|
388
|
-
}
|
|
389
|
-
const { mcRole, defaultTenantId, defaultWorkspaceId, defaultPrincipalId } = resolved;
|
|
390
|
-
if (mcRole !== "platform_admin" && mcRole !== "tenant_admin" && mcRole !== "workspace_admin" && mcRole !== "editor" && mcRole !== "viewer" && mcRole !== "auditor" && mcRole !== "service_agent") {
|
|
391
|
-
throw new Error(
|
|
392
|
-
`[AccessControl] Canonical MC role required for ${clerkId}. Re-sync Master Control identity before user-bound access checks.`
|
|
393
|
-
);
|
|
394
|
-
}
|
|
395
|
-
if (typeof defaultTenantId !== "string" || defaultTenantId.trim().length === 0) {
|
|
396
|
-
throw new Error(
|
|
397
|
-
`[AccessControl] Canonical home tenant required for ${clerkId}. Re-sync Master Control identity before user-bound access checks.`
|
|
398
|
-
);
|
|
399
|
-
}
|
|
400
|
-
if (typeof defaultWorkspaceId !== "string" || defaultWorkspaceId.trim().length === 0) {
|
|
401
|
-
throw new Error(
|
|
402
|
-
`[AccessControl] Canonical home workspace required for ${clerkId}. Re-sync Master Control identity before user-bound access checks.`
|
|
403
|
-
);
|
|
404
|
-
}
|
|
405
|
-
if (typeof defaultPrincipalId !== "string" || defaultPrincipalId.trim().length === 0) {
|
|
406
|
-
throw new Error(
|
|
407
|
-
`[AccessControl] Canonical federated principal required for ${clerkId}. Re-sync Master Control identity before user-bound access checks.`
|
|
408
|
-
);
|
|
409
|
-
}
|
|
410
|
-
return {
|
|
411
|
-
mcRole,
|
|
412
|
-
defaultTenantId: defaultTenantId.trim(),
|
|
413
|
-
defaultWorkspaceId: defaultWorkspaceId.trim(),
|
|
414
|
-
defaultPrincipalId: defaultPrincipalId.trim()
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
function isPrincipalIdInput(value) {
|
|
418
|
-
return value.startsWith("user:") || value.startsWith("group:") || value.startsWith("service:") || value.startsWith("agent:") || value.startsWith("external_viewer:");
|
|
419
|
-
}
|
|
420
|
-
async function resolveCanonicalUserRecord(ctx, actorId) {
|
|
421
|
-
const normalizedActorId = actorId.trim();
|
|
422
|
-
const clerkId = isPrincipalIdInput(normalizedActorId) && normalizedActorId.startsWith("user:") ? normalizedActorId.slice("user:".length) : normalizedActorId;
|
|
423
|
-
const resolvers = resolveAccessControlAppResolvers();
|
|
424
|
-
const resolvedByClerkId = await resolvers.getUserByClerkId(ctx, clerkId);
|
|
425
|
-
if (resolvedByClerkId) {
|
|
426
|
-
return {
|
|
427
|
-
resolvedUser: resolvedByClerkId,
|
|
428
|
-
clerkId,
|
|
429
|
-
contextClerkId: clerkId
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
const resolvedByPrincipalId = await resolvers.getUserByPrincipalId(
|
|
433
|
-
ctx,
|
|
434
|
-
normalizedActorId
|
|
435
|
-
);
|
|
436
|
-
return {
|
|
437
|
-
resolvedUser: resolvedByPrincipalId ?? null,
|
|
438
|
-
clerkId,
|
|
439
|
-
contextClerkId: normalizedActorId.startsWith("user:") && clerkId.length > 0 ? clerkId : normalizedActorId
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
function uniqRoles(roles) {
|
|
443
|
-
const roleSet = /* @__PURE__ */ new Set();
|
|
444
|
-
for (const role of roles) {
|
|
445
|
-
if (role === "platform_admin" || role === "tenant_admin" || role === "workspace_admin" || role === "editor" || role === "viewer" || role === "auditor" || role === "service_agent") {
|
|
446
|
-
roleSet.add(role);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
return [...roleSet];
|
|
450
|
-
}
|
|
451
|
-
function normalizeGroupIds(value) {
|
|
452
|
-
if (!Array.isArray(value)) {
|
|
453
|
-
return [];
|
|
454
|
-
}
|
|
455
|
-
return [...new Set(
|
|
456
|
-
value.filter((entry) => typeof entry === "string").map((entry) => entry.trim()).filter(Boolean)
|
|
457
|
-
)];
|
|
458
|
-
}
|
|
459
|
-
function requireServiceAgentUser(user, actorId) {
|
|
460
|
-
const canonicalUser = requireCanonicalResolvedUser(user, actorId);
|
|
461
|
-
if (canonicalUser.mcRole !== "service_agent") {
|
|
462
|
-
throw new Error(
|
|
463
|
-
`[AccessControl] Canonical service_agent identity required for ${actorId}. Sync users.upsertUser before agent-bound access checks.`
|
|
464
|
-
);
|
|
465
|
-
}
|
|
466
|
-
return canonicalUser;
|
|
467
|
-
}
|
|
468
|
-
function requireCanonicalResolvedAgent(agent, actorId) {
|
|
469
|
-
const resolved = agent;
|
|
470
|
-
if (!resolved) {
|
|
471
|
-
throw new Error(
|
|
472
|
-
`[AccessControl] Agent "${actorId}" not found in agents or users table.`
|
|
473
|
-
);
|
|
474
|
-
}
|
|
475
|
-
if (typeof resolved.principalId !== "string" || resolved.principalId.trim().length === 0) {
|
|
476
|
-
throw new Error(
|
|
477
|
-
`[AccessControl] Canonical agent principalId required for ${actorId}.`
|
|
478
|
-
);
|
|
479
|
-
}
|
|
480
|
-
if (typeof resolved.tenantId !== "string" || resolved.tenantId.trim().length === 0) {
|
|
481
|
-
throw new Error(
|
|
482
|
-
`[AccessControl] Canonical home tenant required for ${actorId}.`
|
|
483
|
-
);
|
|
484
|
-
}
|
|
485
|
-
if (typeof resolved.workspaceId !== "string" || resolved.workspaceId.trim().length === 0) {
|
|
486
|
-
throw new Error(
|
|
487
|
-
`[AccessControl] Canonical home workspace required for ${actorId}.`
|
|
488
|
-
);
|
|
489
|
-
}
|
|
490
|
-
return {
|
|
491
|
-
principalId: resolved.principalId.trim(),
|
|
492
|
-
tenantId: resolved.tenantId.trim(),
|
|
493
|
-
workspaceId: resolved.workspaceId.trim(),
|
|
494
|
-
roles: uniqRoles(Array.isArray(resolved.roles) ? resolved.roles : []) ?? ["service_agent"],
|
|
495
|
-
groupIds: normalizeGroupIds(resolved.groupIds)
|
|
496
|
-
};
|
|
497
|
-
}
|
|
498
|
-
async function resolvePrincipalContext(ctx, actorId) {
|
|
499
|
-
if (actorId.startsWith("agent:")) {
|
|
500
|
-
const resolvers = resolveAccessControlAppResolvers();
|
|
501
|
-
const resolvedAgent = await resolvers.getAgentByPrincipalId(ctx, actorId);
|
|
502
|
-
if (resolvedAgent) {
|
|
503
|
-
const agent = requireCanonicalResolvedAgent(
|
|
504
|
-
resolvedAgent,
|
|
505
|
-
actorId
|
|
506
|
-
);
|
|
507
|
-
return {
|
|
508
|
-
principalId: agent.principalId,
|
|
509
|
-
principalType: "service",
|
|
510
|
-
clerkId: actorId,
|
|
511
|
-
tenantId: agent.tenantId,
|
|
512
|
-
workspaceId: agent.workspaceId,
|
|
513
|
-
roles: agent.roles.length > 0 ? agent.roles : ["service_agent"],
|
|
514
|
-
groupIds: agent.groupIds,
|
|
515
|
-
isPlatformAdmin: false,
|
|
516
|
-
isTenantAdmin: false,
|
|
517
|
-
isWorkspaceAdmin: false,
|
|
518
|
-
isSystemFallback: false
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
const resolvedUser2 = await resolvers.getUserByClerkId(
|
|
522
|
-
ctx,
|
|
523
|
-
actorId
|
|
524
|
-
);
|
|
525
|
-
if (!resolvedUser2) {
|
|
526
|
-
throw new Error(
|
|
527
|
-
`[AccessControl] Agent "${actorId}" not found in agents or users table.`
|
|
528
|
-
);
|
|
529
|
-
}
|
|
530
|
-
const user2 = requireServiceAgentUser(
|
|
531
|
-
resolvedUser2,
|
|
532
|
-
actorId
|
|
533
|
-
);
|
|
534
|
-
console.warn(
|
|
535
|
-
`[AccessControl] Deprecated legacy service-agent fallback for ${actorId}; migrate this principal into identity.agents.`
|
|
536
|
-
);
|
|
537
|
-
return {
|
|
538
|
-
principalId: user2.defaultPrincipalId,
|
|
539
|
-
principalType: "service",
|
|
540
|
-
clerkId: actorId,
|
|
541
|
-
tenantId: user2.defaultTenantId,
|
|
542
|
-
workspaceId: user2.defaultWorkspaceId,
|
|
543
|
-
roles: ["service_agent"],
|
|
544
|
-
groupIds: normalizeGroupIds(resolvedUser2?.principalGroupIds),
|
|
545
|
-
isPlatformAdmin: false,
|
|
546
|
-
isTenantAdmin: false,
|
|
547
|
-
isWorkspaceAdmin: false,
|
|
548
|
-
isSystemFallback: false
|
|
549
|
-
};
|
|
550
|
-
}
|
|
551
|
-
const {
|
|
552
|
-
resolvedUser,
|
|
553
|
-
contextClerkId
|
|
554
|
-
} = await resolveCanonicalUserRecord(ctx, actorId);
|
|
555
|
-
const user = requireCanonicalResolvedUser(
|
|
556
|
-
resolvedUser,
|
|
557
|
-
contextClerkId
|
|
558
|
-
);
|
|
559
|
-
if (!user.defaultPrincipalId) {
|
|
560
|
-
throw new Error(
|
|
561
|
-
`[AccessControl] Canonical federated principal required for ${contextClerkId}. Re-sync Master Control identity before user-bound access checks.`
|
|
562
|
-
);
|
|
563
|
-
}
|
|
564
|
-
if (user.mcRole === "service_agent") {
|
|
565
|
-
return {
|
|
566
|
-
principalId: user.defaultPrincipalId,
|
|
567
|
-
principalType: "service",
|
|
568
|
-
clerkId: contextClerkId,
|
|
569
|
-
tenantId: user.defaultTenantId,
|
|
570
|
-
workspaceId: user.defaultWorkspaceId,
|
|
571
|
-
roles: ["service_agent"],
|
|
572
|
-
groupIds: normalizeGroupIds(resolvedUser?.principalGroupIds),
|
|
573
|
-
isPlatformAdmin: false,
|
|
574
|
-
isTenantAdmin: false,
|
|
575
|
-
isWorkspaceAdmin: false,
|
|
576
|
-
isSystemFallback: false
|
|
577
|
-
};
|
|
578
|
-
}
|
|
579
|
-
const principalId = user.defaultPrincipalId;
|
|
580
|
-
const effectiveRole = user.mcRole;
|
|
581
|
-
const roles = effectiveRole === "platform_admin" ? ["platform_admin", "tenant_admin"] : effectiveRole === "tenant_admin" ? ["tenant_admin"] : [effectiveRole];
|
|
582
|
-
const tenantId = user.defaultTenantId;
|
|
583
|
-
const workspaceId = user.defaultWorkspaceId;
|
|
584
|
-
const isPlatformAdmin = effectiveRole === "platform_admin";
|
|
585
|
-
return {
|
|
586
|
-
principalId,
|
|
587
|
-
principalType: "user",
|
|
588
|
-
clerkId: contextClerkId,
|
|
589
|
-
tenantId,
|
|
590
|
-
workspaceId,
|
|
591
|
-
roles: uniqRoles(roles),
|
|
592
|
-
groupIds: normalizeGroupIds(resolvedUser?.principalGroupIds),
|
|
593
|
-
isPlatformAdmin,
|
|
594
|
-
isTenantAdmin: isPlatformAdmin || effectiveRole === "tenant_admin",
|
|
595
|
-
isWorkspaceAdmin: isPlatformAdmin || effectiveRole === "tenant_admin" || effectiveRole === "workspace_admin",
|
|
596
|
-
isSystemFallback: false
|
|
597
|
-
};
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
// ../access-control/src/access.ts
|
|
601
|
-
function isTopicInPrincipalTenant(topic, principalTenantId) {
|
|
602
|
-
if (!topic.tenantId) {
|
|
603
|
-
return false;
|
|
604
|
-
}
|
|
605
|
-
if (!principalTenantId) {
|
|
606
|
-
return false;
|
|
607
|
-
}
|
|
608
|
-
return String(topic.tenantId) === String(principalTenantId);
|
|
609
|
-
}
|
|
610
|
-
function isTopicInPrincipalWorkspace(topic, principalWorkspaceId) {
|
|
611
|
-
if (!topic.workspaceId) {
|
|
612
|
-
return false;
|
|
613
|
-
}
|
|
614
|
-
if (!principalWorkspaceId) {
|
|
615
|
-
return false;
|
|
616
|
-
}
|
|
617
|
-
return String(topic.workspaceId) === String(principalWorkspaceId);
|
|
618
|
-
}
|
|
619
|
-
function isLegacyUnscopedTopic(topic) {
|
|
620
|
-
return !topic.tenantId || !topic.workspaceId;
|
|
621
|
-
}
|
|
622
|
-
function isGrantScopeAlignedToTopic(topic, grant) {
|
|
623
|
-
if (topic.tenantId && grant.tenantId && String(topic.tenantId) !== String(grant.tenantId)) {
|
|
624
|
-
return false;
|
|
625
|
-
}
|
|
626
|
-
if (topic.workspaceId && grant.workspaceId && String(topic.workspaceId) !== String(grant.workspaceId)) {
|
|
627
|
-
return false;
|
|
628
|
-
}
|
|
629
|
-
return true;
|
|
630
|
-
}
|
|
631
|
-
function isGrantSourceAllowedForVisibility(visibility, source) {
|
|
632
|
-
if (source !== "external_share") {
|
|
633
|
-
return true;
|
|
634
|
-
}
|
|
635
|
-
return visibility === "external" || visibility === "public";
|
|
636
|
-
}
|
|
637
|
-
function isGrantActive(grant) {
|
|
638
|
-
if (grant.status !== "active") {
|
|
639
|
-
return false;
|
|
640
|
-
}
|
|
641
|
-
if (grant.expiresAt !== void 0 && grant.expiresAt <= Date.now()) {
|
|
642
|
-
return false;
|
|
643
|
-
}
|
|
644
|
-
return true;
|
|
645
|
-
}
|
|
646
|
-
async function hasPrincipalGrant(ctx, args) {
|
|
647
|
-
const grants = await resolveAccessControlAppResolvers().listProjectGrantsByProjectAndPrincipal(
|
|
648
|
-
ctx,
|
|
649
|
-
args.topic._id,
|
|
650
|
-
args.principalId
|
|
651
|
-
);
|
|
652
|
-
if (grants.some(
|
|
653
|
-
(grant) => isGrantActive(grant) && isGrantScopeAlignedToTopic(args.topic, grant) && isGrantSourceAllowedForVisibility(
|
|
654
|
-
args.topic.visibility,
|
|
655
|
-
grant.source
|
|
656
|
-
) && (!args.principalIsExternal || args.topic.visibility === "public" || grant.source === "external_share")
|
|
657
|
-
)) {
|
|
658
|
-
return true;
|
|
659
|
-
}
|
|
660
|
-
return false;
|
|
661
|
-
}
|
|
662
|
-
async function hasGroupGrant(ctx, args) {
|
|
663
|
-
if (args.groupIds.length === 0) {
|
|
664
|
-
return false;
|
|
665
|
-
}
|
|
666
|
-
for (const groupId of args.groupIds) {
|
|
667
|
-
const grants = await resolveAccessControlAppResolvers().listProjectGrantsByProjectAndGroup(ctx, args.topic._id, groupId);
|
|
668
|
-
if (grants.some(
|
|
669
|
-
(grant) => isGrantActive(grant) && isGrantScopeAlignedToTopic(args.topic, grant) && isGrantSourceAllowedForVisibility(
|
|
670
|
-
args.topic.visibility,
|
|
671
|
-
grant.source
|
|
672
|
-
)
|
|
673
|
-
)) {
|
|
674
|
-
return true;
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
return false;
|
|
678
|
-
}
|
|
679
|
-
function isExternalPrincipal(_ctx, _args) {
|
|
680
|
-
return false;
|
|
681
|
-
}
|
|
682
|
-
async function evaluateTopicAccessDetailed(ctx, args) {
|
|
683
|
-
if (args.legacyUserId) {
|
|
684
|
-
return {
|
|
685
|
-
hasAccess: true,
|
|
686
|
-
isAdmin: false,
|
|
687
|
-
isOwner: false,
|
|
688
|
-
isShared: false,
|
|
689
|
-
hasGrant: true,
|
|
690
|
-
isFirmVisible: true,
|
|
691
|
-
isExternalVisible: false,
|
|
692
|
-
isPublicVisible: false,
|
|
693
|
-
isTenantScopeMatch: true,
|
|
694
|
-
isWorkspaceScopeMatch: true,
|
|
695
|
-
isPrincipalExternal: false
|
|
696
|
-
};
|
|
697
|
-
}
|
|
698
|
-
const topic = await resolveAccessControlAppResolvers().getProject(
|
|
699
|
-
ctx,
|
|
700
|
-
args.topicId
|
|
701
|
-
);
|
|
702
|
-
if (!topic) {
|
|
703
|
-
return {
|
|
704
|
-
hasAccess: false,
|
|
705
|
-
isAdmin: false,
|
|
706
|
-
isOwner: false,
|
|
707
|
-
isShared: false,
|
|
708
|
-
hasGrant: false,
|
|
709
|
-
isFirmVisible: false,
|
|
710
|
-
isExternalVisible: false,
|
|
711
|
-
isPublicVisible: false,
|
|
712
|
-
isTenantScopeMatch: false,
|
|
713
|
-
isWorkspaceScopeMatch: false,
|
|
714
|
-
isPrincipalExternal: false
|
|
715
|
-
};
|
|
716
|
-
}
|
|
717
|
-
const { principalContext, legacyUserId } = args;
|
|
718
|
-
const userIsAdmin = principalContext.isPlatformAdmin;
|
|
719
|
-
const isOwner = topic.ownerId === legacyUserId;
|
|
720
|
-
const isShared = (topic.sharedWith ?? []).includes(legacyUserId);
|
|
721
|
-
const principalIsExternal = await isExternalPrincipal(ctx, {
|
|
722
|
-
groupIds: principalContext.groupIds,
|
|
723
|
-
topicTenantId: topic.tenantId,
|
|
724
|
-
topicWorkspaceId: topic.workspaceId
|
|
725
|
-
});
|
|
726
|
-
const hasPrincipalGrantResult = await hasPrincipalGrant(ctx, {
|
|
727
|
-
topic,
|
|
728
|
-
principalId: principalContext.principalId,
|
|
729
|
-
principalIsExternal
|
|
730
|
-
});
|
|
731
|
-
const hasGroupGrantResult = await hasGroupGrant(ctx, {
|
|
732
|
-
topic,
|
|
733
|
-
groupIds: principalContext.groupIds
|
|
734
|
-
});
|
|
735
|
-
const hasGrant = isShared || hasPrincipalGrantResult || hasGroupGrantResult;
|
|
736
|
-
const legacyUnscoped = isLegacyUnscopedTopic(topic);
|
|
737
|
-
const tenantScopeMatch = isTopicInPrincipalTenant(
|
|
738
|
-
topic,
|
|
739
|
-
principalContext.tenantId
|
|
740
|
-
);
|
|
741
|
-
const workspaceScopeMatch = isTopicInPrincipalWorkspace(
|
|
742
|
-
topic,
|
|
743
|
-
principalContext.workspaceId
|
|
744
|
-
);
|
|
745
|
-
const isPublicVisible = topic.visibility === "public";
|
|
746
|
-
const isFirmVisible = topic.visibility === "firm" && !legacyUnscoped && tenantScopeMatch && workspaceScopeMatch && !principalIsExternal;
|
|
747
|
-
const hasScopedGrant = hasGrant && (legacyUnscoped || tenantScopeMatch && workspaceScopeMatch);
|
|
748
|
-
const isExternalVisible = topic.visibility === "external" && hasScopedGrant;
|
|
749
|
-
const hasAccess = userIsAdmin || isOwner || hasScopedGrant || isPublicVisible || isFirmVisible;
|
|
750
|
-
return {
|
|
751
|
-
hasAccess,
|
|
752
|
-
isAdmin: userIsAdmin,
|
|
753
|
-
isOwner,
|
|
754
|
-
isShared,
|
|
755
|
-
hasGrant,
|
|
756
|
-
isFirmVisible,
|
|
757
|
-
isExternalVisible,
|
|
758
|
-
isPublicVisible,
|
|
759
|
-
isTenantScopeMatch: tenantScopeMatch,
|
|
760
|
-
isWorkspaceScopeMatch: workspaceScopeMatch,
|
|
761
|
-
isPrincipalExternal: principalIsExternal
|
|
762
|
-
};
|
|
763
|
-
}
|
|
764
|
-
async function checkTopicAccessDetailed(ctx, topicId, userId) {
|
|
765
|
-
const principalContext = await resolvePrincipalContext(ctx, userId);
|
|
766
|
-
return evaluateTopicAccessDetailed(ctx, {
|
|
767
|
-
topicId,
|
|
768
|
-
legacyUserId: userId,
|
|
769
|
-
principalContext
|
|
770
|
-
});
|
|
771
|
-
}
|
|
772
|
-
async function checkTopicAccess(ctx, topicId, userId) {
|
|
773
|
-
const result = await checkTopicAccessDetailed(ctx, topicId, userId);
|
|
774
|
-
return result.hasAccess;
|
|
775
|
-
}
|
|
776
|
-
async function checkScopeAccess(ctx, scopeId, userId) {
|
|
777
|
-
try {
|
|
778
|
-
const topic = await ctx.db.get(scopeId);
|
|
779
|
-
if (topic && topic.name !== void 0 && topic.type !== void 0) {
|
|
780
|
-
return true;
|
|
781
|
-
}
|
|
782
|
-
} catch {
|
|
783
|
-
}
|
|
784
|
-
try {
|
|
785
|
-
return await checkTopicAccess(ctx, scopeId, userId);
|
|
786
|
-
} catch {
|
|
787
|
-
return false;
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
var checkProjectAccess = checkTopicAccess;
|
|
791
|
-
|
|
792
|
-
// ../access-control/src/audience.ts
|
|
793
|
-
var AUDIENCE_CLASS_RANK = {
|
|
794
|
-
public: 0,
|
|
795
|
-
restricted_external: 1,
|
|
796
|
-
internal: 2
|
|
797
|
-
};
|
|
798
|
-
function normalizeKey(key) {
|
|
799
|
-
return (key ?? "").trim().toLowerCase().replace(/[^a-z0-9:_-]+/g, "_").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
|
|
800
|
-
}
|
|
801
|
-
function normalizeAudienceKey(key) {
|
|
802
|
-
return normalizeKey(key);
|
|
803
|
-
}
|
|
804
|
-
function classFromAudienceKey(audienceKey, fallback = "internal") {
|
|
805
|
-
const key = normalizeKey(audienceKey);
|
|
806
|
-
if (!key) {
|
|
807
|
-
return fallback;
|
|
808
|
-
}
|
|
809
|
-
if (key === "internal") {
|
|
810
|
-
return "internal";
|
|
811
|
-
}
|
|
812
|
-
if (key === "public") {
|
|
813
|
-
return "public";
|
|
814
|
-
}
|
|
815
|
-
if (key === "lp" || key === "external" || key === "client" || key === "partner" || key === "portfolio" || key === "network" || key === "restricted_external") {
|
|
816
|
-
return "restricted_external";
|
|
817
|
-
}
|
|
818
|
-
return fallback;
|
|
819
|
-
}
|
|
820
|
-
function canAudienceClassAccess(viewerClass, resourceClass) {
|
|
821
|
-
return AUDIENCE_CLASS_RANK[viewerClass] >= AUDIENCE_CLASS_RANK[resourceClass];
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
// ../access-control/src/audienceRegistry.ts
|
|
825
|
-
var DEFAULT_AUDIENCES = [
|
|
826
|
-
{
|
|
827
|
-
audienceKey: "internal",
|
|
828
|
-
audienceLabel: "Internal",
|
|
829
|
-
audienceClass: "internal"
|
|
830
|
-
},
|
|
831
|
-
{
|
|
832
|
-
audienceKey: "lp",
|
|
833
|
-
audienceLabel: "Limited Partners",
|
|
834
|
-
audienceClass: "restricted_external"
|
|
835
|
-
},
|
|
836
|
-
{
|
|
837
|
-
audienceKey: "public",
|
|
838
|
-
audienceLabel: "Public",
|
|
839
|
-
audienceClass: "public"
|
|
840
|
-
}
|
|
841
|
-
];
|
|
842
|
-
var AUDIENCE_CLASS_PRIORITY = {
|
|
843
|
-
internal: 0,
|
|
844
|
-
restricted_external: 1,
|
|
845
|
-
public: 2
|
|
846
|
-
};
|
|
847
|
-
function normalizeRegistryRow(row) {
|
|
848
|
-
return {
|
|
849
|
-
audienceKey: normalizeAudienceKey(row.audienceKey),
|
|
850
|
-
audienceLabel: row.audienceLabel,
|
|
851
|
-
audienceClass: row.audienceClass,
|
|
852
|
-
workspaceId: row.workspaceId
|
|
853
|
-
};
|
|
854
|
-
}
|
|
855
|
-
function dedupeRegistryRows(rows) {
|
|
856
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
857
|
-
for (const row of rows) {
|
|
858
|
-
const key = normalizeAudienceKey(row.audienceKey);
|
|
859
|
-
if (!key) {
|
|
860
|
-
continue;
|
|
861
|
-
}
|
|
862
|
-
const existing = byKey.get(key);
|
|
863
|
-
const isWorkspaceScoped = row.workspaceId !== void 0;
|
|
864
|
-
const existingWorkspaceScoped = existing?.workspaceId !== void 0;
|
|
865
|
-
if (!existing || isWorkspaceScoped && !existingWorkspaceScoped) {
|
|
866
|
-
byKey.set(key, {
|
|
867
|
-
...row,
|
|
868
|
-
audienceKey: key
|
|
869
|
-
});
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
const normalized = [...byKey.values()];
|
|
873
|
-
normalized.sort((a, b) => {
|
|
874
|
-
const classDelta = AUDIENCE_CLASS_PRIORITY[a.audienceClass] - AUDIENCE_CLASS_PRIORITY[b.audienceClass];
|
|
875
|
-
if (classDelta !== 0) {
|
|
876
|
-
return classDelta;
|
|
877
|
-
}
|
|
878
|
-
return a.audienceKey.localeCompare(b.audienceKey);
|
|
879
|
-
});
|
|
880
|
-
return normalized;
|
|
881
|
-
}
|
|
882
|
-
async function queryRegistryRows(ctx, args) {
|
|
883
|
-
if (!args.tenantId) {
|
|
884
|
-
return [...DEFAULT_AUDIENCES];
|
|
885
|
-
}
|
|
886
|
-
const rows = await ctx.db.query("platformAudiences").withIndex("by_tenantId", (q) => q.eq("tenantId", args.tenantId)).collect();
|
|
887
|
-
const workspaceIdString = args.workspaceId ? String(args.workspaceId) : null;
|
|
888
|
-
const tenantScoped = rows.filter((row) => row.status === "active");
|
|
889
|
-
const applicable = tenantScoped.filter((row) => {
|
|
890
|
-
if (!row.workspaceId) {
|
|
891
|
-
return true;
|
|
892
|
-
}
|
|
893
|
-
if (!workspaceIdString) {
|
|
894
|
-
return false;
|
|
895
|
-
}
|
|
896
|
-
return String(row.workspaceId) === workspaceIdString;
|
|
897
|
-
});
|
|
898
|
-
return dedupeRegistryRows([
|
|
899
|
-
...DEFAULT_AUDIENCES,
|
|
900
|
-
...applicable.map(
|
|
901
|
-
(row) => normalizeRegistryRow({
|
|
902
|
-
audienceKey: row.audienceKey,
|
|
903
|
-
audienceLabel: row.audienceLabel,
|
|
904
|
-
audienceClass: row.audienceClass,
|
|
905
|
-
workspaceId: row.workspaceId
|
|
906
|
-
})
|
|
907
|
-
)
|
|
908
|
-
]);
|
|
909
|
-
}
|
|
910
|
-
async function listAudienceRegistryRows(ctx, args) {
|
|
911
|
-
return queryRegistryRows(ctx, args);
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
// ../access-control/src/auth.ts
|
|
915
|
-
async function getCurrentUserId(ctx) {
|
|
916
|
-
const identity = await ctx.auth.getUserIdentity();
|
|
917
|
-
return identity?.subject ?? null;
|
|
918
|
-
}
|
|
919
|
-
var permissiveReturn = v.optional(v.any());
|
|
920
|
-
var looseJsonObject = v.record(v.string(), v.any());
|
|
921
|
-
var looseJsonArray = v.array(v.any());
|
|
922
|
-
v.union(
|
|
923
|
-
v.string(),
|
|
924
|
-
v.number(),
|
|
925
|
-
v.boolean(),
|
|
926
|
-
v.null(),
|
|
927
|
-
looseJsonObject,
|
|
928
|
-
looseJsonArray
|
|
929
|
-
);
|
|
930
|
-
var api2 = anyApi;
|
|
931
|
-
componentsGeneric();
|
|
932
13
|
var internal = anyApi;
|
|
933
14
|
var internalMutation = internalMutationGeneric;
|
|
934
15
|
var internalQuery = internalQueryGeneric;
|
|
@@ -969,48 +50,48 @@ function generateGlobalId() {
|
|
|
969
50
|
}
|
|
970
51
|
|
|
971
52
|
// src/topicProjectOverlay.ts
|
|
972
|
-
var
|
|
973
|
-
function
|
|
53
|
+
var LEGACY_SCOPE_FIELD = "graphScopeProjectId";
|
|
54
|
+
function readNonEmptyString(value) {
|
|
974
55
|
if (typeof value !== "string") {
|
|
975
56
|
return;
|
|
976
57
|
}
|
|
977
58
|
const normalized = value.trim();
|
|
978
59
|
return normalized.length > 0 ? normalized : void 0;
|
|
979
60
|
}
|
|
980
|
-
function
|
|
61
|
+
function readStringArray(value) {
|
|
981
62
|
if (!Array.isArray(value)) {
|
|
982
63
|
return [];
|
|
983
64
|
}
|
|
984
|
-
return value.map((entry) =>
|
|
65
|
+
return value.map((entry) => readNonEmptyString(entry)).filter((entry) => Boolean(entry));
|
|
985
66
|
}
|
|
986
|
-
function
|
|
67
|
+
function readMetadata(topic) {
|
|
987
68
|
return topic.metadata && typeof topic.metadata === "object" ? topic.metadata : {};
|
|
988
69
|
}
|
|
989
|
-
function
|
|
70
|
+
function readLegacyProjectId(value) {
|
|
990
71
|
if (!value) {
|
|
991
72
|
return;
|
|
992
73
|
}
|
|
993
|
-
return
|
|
74
|
+
return readNonEmptyString(value[LEGACY_SCOPE_FIELD]);
|
|
994
75
|
}
|
|
995
|
-
function
|
|
76
|
+
function coerceVisibility(value) {
|
|
996
77
|
return value === "private" || value === "team" || value === "firm" || value === "external" || value === "public" ? value : void 0;
|
|
997
78
|
}
|
|
998
|
-
function
|
|
79
|
+
function coerceStatus(value) {
|
|
999
80
|
return value === "active" || value === "archived" || value === "watching" ? value : void 0;
|
|
1000
81
|
}
|
|
1001
|
-
function
|
|
1002
|
-
const explicit =
|
|
82
|
+
function mapProjectType(topic, metadata) {
|
|
83
|
+
const explicit = readNonEmptyString(metadata.projectType);
|
|
1003
84
|
if (explicit) {
|
|
1004
85
|
return explicit;
|
|
1005
86
|
}
|
|
1006
87
|
if (topic.type === "theme") {
|
|
1007
88
|
return "thematic";
|
|
1008
89
|
}
|
|
1009
|
-
return
|
|
90
|
+
return readNonEmptyString(topic.type) || "general";
|
|
1010
91
|
}
|
|
1011
|
-
function
|
|
1012
|
-
const metadata =
|
|
1013
|
-
return topic.type === "theme" || topic.type === "thematic" || topic.type === "deal" || topic.type === "monitoring" ||
|
|
92
|
+
function isProjectLikeTopic(topic) {
|
|
93
|
+
const metadata = readMetadata(topic);
|
|
94
|
+
return topic.type === "theme" || topic.type === "thematic" || topic.type === "deal" || topic.type === "monitoring" || readLegacyProjectId(topic) !== void 0 || readNonEmptyString(metadata.projectType) !== void 0;
|
|
1014
95
|
}
|
|
1015
96
|
function isMissingLucernChildComponentError(error) {
|
|
1016
97
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -1018,7 +99,7 @@ function isMissingLucernChildComponentError(error) {
|
|
|
1018
99
|
'Child component ComponentName(Identifier("lucern")) not found'
|
|
1019
100
|
) || message.includes("Child component") && message.includes("lucern") && message.includes("not found");
|
|
1020
101
|
}
|
|
1021
|
-
async function
|
|
102
|
+
async function resolveTopicDoc(ctx, scopeId) {
|
|
1022
103
|
if (ctx?.db && typeof ctx.db.get === "function") {
|
|
1023
104
|
try {
|
|
1024
105
|
const directTopic = await ctx.db.get(scopeId);
|
|
@@ -1032,7 +113,7 @@ async function resolveTopicDoc2(ctx, scopeId) {
|
|
|
1032
113
|
return null;
|
|
1033
114
|
}
|
|
1034
115
|
try {
|
|
1035
|
-
const topic = await ctx.runQuery(
|
|
116
|
+
const topic = await ctx.runQuery(api.topics.get, {
|
|
1036
117
|
id: String(scopeId)
|
|
1037
118
|
});
|
|
1038
119
|
if (topic?.name !== void 0 && topic?.type !== void 0) {
|
|
@@ -1041,7 +122,7 @@ async function resolveTopicDoc2(ctx, scopeId) {
|
|
|
1041
122
|
} catch {
|
|
1042
123
|
}
|
|
1043
124
|
try {
|
|
1044
|
-
const topic = await ctx.runQuery(
|
|
125
|
+
const topic = await ctx.runQuery(api.topics.getByLegacyScopeId, {
|
|
1045
126
|
projectId: String(scopeId)
|
|
1046
127
|
});
|
|
1047
128
|
if (topic?.name !== void 0 && topic?.type !== void 0) {
|
|
@@ -1051,14 +132,14 @@ async function resolveTopicDoc2(ctx, scopeId) {
|
|
|
1051
132
|
}
|
|
1052
133
|
return null;
|
|
1053
134
|
}
|
|
1054
|
-
function
|
|
1055
|
-
const metadata =
|
|
135
|
+
function materializeTopicProjectOverlay(topic, idMode = "legacy") {
|
|
136
|
+
const metadata = readMetadata(topic);
|
|
1056
137
|
const topicId = String(topic._id);
|
|
1057
|
-
const legacyProjectId =
|
|
138
|
+
const legacyProjectId = readLegacyProjectId(topic) || readLegacyProjectId(metadata) || readNonEmptyString(metadata.legacyProjectId);
|
|
1058
139
|
const storageProjectId = legacyProjectId || topicId;
|
|
1059
140
|
const outwardId = idMode === "topic" ? topicId : storageProjectId;
|
|
1060
|
-
const visibility =
|
|
1061
|
-
const status =
|
|
141
|
+
const visibility = coerceVisibility(topic.visibility) || coerceVisibility(metadata.visibility) || "private";
|
|
142
|
+
const status = coerceStatus(topic.status) || coerceStatus(metadata.status) || "active";
|
|
1062
143
|
const createdAt = typeof topic.createdAt === "number" ? topic.createdAt : typeof topic._creationTime === "number" ? topic._creationTime : 0;
|
|
1063
144
|
const updatedAt = typeof topic.updatedAt === "number" ? topic.updatedAt : typeof metadata.updatedAt === "number" ? metadata.updatedAt : createdAt;
|
|
1064
145
|
return {
|
|
@@ -1068,16 +149,16 @@ function materializeTopicProjectOverlay2(topic, idMode = "legacy") {
|
|
|
1068
149
|
topicId,
|
|
1069
150
|
storageProjectId,
|
|
1070
151
|
legacyProjectId,
|
|
1071
|
-
name:
|
|
1072
|
-
type:
|
|
1073
|
-
description:
|
|
1074
|
-
ownerId:
|
|
1075
|
-
sharedWith:
|
|
152
|
+
name: readNonEmptyString(topic.name) || "Untitled Theme",
|
|
153
|
+
type: mapProjectType(topic, metadata),
|
|
154
|
+
description: readNonEmptyString(topic.description),
|
|
155
|
+
ownerId: readNonEmptyString(metadata.ownerId) || readNonEmptyString(topic.createdBy) || "system",
|
|
156
|
+
sharedWith: readStringArray(metadata.sharedWith),
|
|
1076
157
|
visibility,
|
|
1077
|
-
tenantId:
|
|
1078
|
-
workspaceId:
|
|
158
|
+
tenantId: readNonEmptyString(topic.tenantId) || readNonEmptyString(metadata.tenantId),
|
|
159
|
+
workspaceId: readNonEmptyString(topic.workspaceId) || readNonEmptyString(metadata.workspaceId),
|
|
1079
160
|
status,
|
|
1080
|
-
tags:
|
|
161
|
+
tags: readStringArray(metadata.tags),
|
|
1081
162
|
chatCount: typeof metadata.chatCount === "number" ? metadata.chatCount : 0,
|
|
1082
163
|
artifactCount: typeof metadata.artifactCount === "number" ? metadata.artifactCount : 0,
|
|
1083
164
|
lastActivityAt: typeof metadata.lastActivityAt === "number" ? metadata.lastActivityAt : updatedAt,
|
|
@@ -1086,17 +167,17 @@ function materializeTopicProjectOverlay2(topic, idMode = "legacy") {
|
|
|
1086
167
|
updatedAt
|
|
1087
168
|
};
|
|
1088
169
|
}
|
|
1089
|
-
async function
|
|
1090
|
-
const topic = await
|
|
170
|
+
async function resolveTopicProjectOverlay(ctx, scopeId, options = {}) {
|
|
171
|
+
const topic = await resolveTopicDoc(ctx, scopeId);
|
|
1091
172
|
if (!topic) {
|
|
1092
173
|
return null;
|
|
1093
174
|
}
|
|
1094
|
-
if (options.projectLikeOnly !== false && !
|
|
175
|
+
if (options.projectLikeOnly !== false && !isProjectLikeTopic(topic)) {
|
|
1095
176
|
return null;
|
|
1096
177
|
}
|
|
1097
|
-
return
|
|
178
|
+
return materializeTopicProjectOverlay(topic, options.idMode);
|
|
1098
179
|
}
|
|
1099
|
-
async function
|
|
180
|
+
async function listTopicProjectOverlays(ctx, options = {}) {
|
|
1100
181
|
let allTopics = [];
|
|
1101
182
|
if (ctx?.db?.query && typeof ctx.db.query === "function") {
|
|
1102
183
|
try {
|
|
@@ -1106,18 +187,18 @@ async function listTopicProjectOverlays2(ctx, options = {}) {
|
|
|
1106
187
|
}
|
|
1107
188
|
}
|
|
1108
189
|
if (allTopics.length === 0 && typeof ctx.runQuery === "function") {
|
|
1109
|
-
allTopics = (await ctx.runQuery(
|
|
190
|
+
allTopics = (await ctx.runQuery(api.topics.list, {}) ?? []) || [];
|
|
1110
191
|
}
|
|
1111
192
|
return allTopics.filter(
|
|
1112
|
-
(topic) => options.projectLikeOnly === false ||
|
|
1113
|
-
).map((topic) =>
|
|
193
|
+
(topic) => options.projectLikeOnly === false || isProjectLikeTopic(topic)
|
|
194
|
+
).map((topic) => materializeTopicProjectOverlay(topic, options.idMode));
|
|
1114
195
|
}
|
|
1115
196
|
async function patchTopicProjectOverlay(ctx, scopeId, value) {
|
|
1116
|
-
const topic = await
|
|
197
|
+
const topic = await resolveTopicDoc(ctx, scopeId);
|
|
1117
198
|
if (!topic) {
|
|
1118
199
|
return null;
|
|
1119
200
|
}
|
|
1120
|
-
const nextMetadata = { ...
|
|
201
|
+
const nextMetadata = { ...readMetadata(topic) };
|
|
1121
202
|
const patch = {};
|
|
1122
203
|
const topicUpdateArgs = {
|
|
1123
204
|
id: String(topic._id)
|
|
@@ -1142,7 +223,7 @@ async function patchTopicProjectOverlay(ctx, scopeId, value) {
|
|
|
1142
223
|
`patchTopicProjectOverlay cannot mutate ${key} via component-owned topics`
|
|
1143
224
|
);
|
|
1144
225
|
case "status": {
|
|
1145
|
-
const status =
|
|
226
|
+
const status = coerceStatus(rawValue);
|
|
1146
227
|
if (status) {
|
|
1147
228
|
patch.status = status;
|
|
1148
229
|
topicUpdateArgs.status = status;
|
|
@@ -1150,7 +231,7 @@ async function patchTopicProjectOverlay(ctx, scopeId, value) {
|
|
|
1150
231
|
break;
|
|
1151
232
|
}
|
|
1152
233
|
case "visibility": {
|
|
1153
|
-
const visibility =
|
|
234
|
+
const visibility = coerceVisibility(rawValue);
|
|
1154
235
|
if (visibility) {
|
|
1155
236
|
patch.visibility = visibility;
|
|
1156
237
|
topicUpdateArgs.visibility = visibility;
|
|
@@ -1158,7 +239,7 @@ async function patchTopicProjectOverlay(ctx, scopeId, value) {
|
|
|
1158
239
|
break;
|
|
1159
240
|
}
|
|
1160
241
|
case "type": {
|
|
1161
|
-
const projectType =
|
|
242
|
+
const projectType = readNonEmptyString(rawValue);
|
|
1162
243
|
if (projectType) {
|
|
1163
244
|
nextMetadata.projectType = projectType;
|
|
1164
245
|
} else {
|
|
@@ -1182,7 +263,7 @@ async function patchTopicProjectOverlay(ctx, scopeId, value) {
|
|
|
1182
263
|
topicUpdateArgs.metadata = nextMetadata;
|
|
1183
264
|
if (typeof ctx.runMutation === "function") {
|
|
1184
265
|
try {
|
|
1185
|
-
await ctx.runMutation(
|
|
266
|
+
await ctx.runMutation(api.topics.update, topicUpdateArgs);
|
|
1186
267
|
} catch (error) {
|
|
1187
268
|
if (!isMissingLucernChildComponentError(error) || !ctx?.db || typeof ctx.db.patch !== "function") {
|
|
1188
269
|
throw error;
|
|
@@ -1196,7 +277,7 @@ async function patchTopicProjectOverlay(ctx, scopeId, value) {
|
|
|
1196
277
|
"Cannot patch topic without component adapter (ctx.runMutation unavailable)"
|
|
1197
278
|
);
|
|
1198
279
|
}
|
|
1199
|
-
return
|
|
280
|
+
return materializeTopicProjectOverlay(
|
|
1200
281
|
{
|
|
1201
282
|
...topic,
|
|
1202
283
|
...patch,
|
|
@@ -1229,10 +310,10 @@ async function patchProjectWithTolerance(ctx, projectId, value) {
|
|
|
1229
310
|
});
|
|
1230
311
|
}
|
|
1231
312
|
}
|
|
1232
|
-
function
|
|
313
|
+
function defaultResolvers() {
|
|
1233
314
|
return {
|
|
1234
315
|
async getProject(ctx, projectId) {
|
|
1235
|
-
return await
|
|
316
|
+
return await resolveTopicProjectOverlay(ctx, projectId, {
|
|
1236
317
|
idMode: "legacy",
|
|
1237
318
|
projectLikeOnly: false
|
|
1238
319
|
});
|
|
@@ -1241,7 +322,7 @@ function defaultResolvers2() {
|
|
|
1241
322
|
await patchProjectWithTolerance(ctx, projectId, value);
|
|
1242
323
|
},
|
|
1243
324
|
async listTopics(ctx) {
|
|
1244
|
-
return await
|
|
325
|
+
return await listTopicProjectOverlays(ctx, {
|
|
1245
326
|
idMode: "legacy"
|
|
1246
327
|
});
|
|
1247
328
|
},
|
|
@@ -1250,24 +331,24 @@ function defaultResolvers2() {
|
|
|
1250
331
|
}
|
|
1251
332
|
};
|
|
1252
333
|
}
|
|
1253
|
-
var
|
|
334
|
+
var resolverOverrides = {};
|
|
1254
335
|
function resolveGraphPrimitivesAppResolvers(_ctx) {
|
|
1255
336
|
return {
|
|
1256
|
-
...
|
|
1257
|
-
...
|
|
337
|
+
...defaultResolvers(),
|
|
338
|
+
...resolverOverrides
|
|
1258
339
|
};
|
|
1259
340
|
}
|
|
1260
|
-
var
|
|
341
|
+
var LEGACY_SCOPE_FIELD2 = "graphScopeProjectId";
|
|
1261
342
|
function asMappedProjectId(topic) {
|
|
1262
343
|
if (!topic) {
|
|
1263
344
|
return;
|
|
1264
345
|
}
|
|
1265
|
-
const directLegacyProjectId = normalizeScopeValue(topic[
|
|
346
|
+
const directLegacyProjectId = normalizeScopeValue(topic[LEGACY_SCOPE_FIELD2]);
|
|
1266
347
|
if (directLegacyProjectId) {
|
|
1267
348
|
return directLegacyProjectId;
|
|
1268
349
|
}
|
|
1269
350
|
const metadata = topic.metadata || {};
|
|
1270
|
-
const candidate = metadata[
|
|
351
|
+
const candidate = metadata[LEGACY_SCOPE_FIELD2] || metadata.legacyProjectId || metadata.projectId || metadata.scopeProjectId;
|
|
1271
352
|
return candidate ? candidate : void 0;
|
|
1272
353
|
}
|
|
1273
354
|
function normalizeScopeValue(value) {
|
|
@@ -1296,7 +377,7 @@ async function findTopicsByScopeAlias(ctx, scopeId) {
|
|
|
1296
377
|
try {
|
|
1297
378
|
return await ctx.db.query("topics").withIndex(
|
|
1298
379
|
"by_graph_scope_project",
|
|
1299
|
-
(q) => q.eq(
|
|
380
|
+
(q) => q.eq(LEGACY_SCOPE_FIELD2, scopeId)
|
|
1300
381
|
).collect();
|
|
1301
382
|
} catch {
|
|
1302
383
|
const topics = await ctx.db.query("topics").collect();
|
|
@@ -1312,7 +393,7 @@ async function tryResolveHostTopicById(ctx, topicId) {
|
|
|
1312
393
|
return null;
|
|
1313
394
|
}
|
|
1314
395
|
try {
|
|
1315
|
-
return await ctx.runQuery(
|
|
396
|
+
return await ctx.runQuery(api.topics.get, {
|
|
1316
397
|
id: topicId
|
|
1317
398
|
}) ?? null;
|
|
1318
399
|
} catch {
|
|
@@ -1324,7 +405,7 @@ async function tryResolveHostTopicByLegacyScope(ctx, legacyScopeId) {
|
|
|
1324
405
|
return null;
|
|
1325
406
|
}
|
|
1326
407
|
try {
|
|
1327
|
-
return await ctx.runQuery(
|
|
408
|
+
return await ctx.runQuery(api.topics.getByLegacyScopeId, {
|
|
1328
409
|
projectId: legacyScopeId
|
|
1329
410
|
}) ?? null;
|
|
1330
411
|
} catch {
|
|
@@ -1443,597 +524,6 @@ var optionalScopeArgs = {
|
|
|
1443
524
|
projectId: v.optional(v.string()),
|
|
1444
525
|
topicId: v.optional(v.string())
|
|
1445
526
|
};
|
|
1446
|
-
v.number();
|
|
1447
|
-
v.union(
|
|
1448
|
-
v.literal("very_high"),
|
|
1449
|
-
// 0.9+
|
|
1450
|
-
v.literal("high"),
|
|
1451
|
-
// 0.7-0.9
|
|
1452
|
-
v.literal("medium"),
|
|
1453
|
-
// 0.4-0.7
|
|
1454
|
-
v.literal("low"),
|
|
1455
|
-
// 0.2-0.4
|
|
1456
|
-
v.literal("very_low")
|
|
1457
|
-
// 0-0.2
|
|
1458
|
-
);
|
|
1459
|
-
v.union(
|
|
1460
|
-
v.literal(1),
|
|
1461
|
-
// Critical
|
|
1462
|
-
v.literal(2),
|
|
1463
|
-
// High
|
|
1464
|
-
v.literal(3),
|
|
1465
|
-
// Medium
|
|
1466
|
-
v.literal(4),
|
|
1467
|
-
// Low
|
|
1468
|
-
v.literal(5)
|
|
1469
|
-
// Backlog
|
|
1470
|
-
);
|
|
1471
|
-
v.union(
|
|
1472
|
-
v.literal("critical"),
|
|
1473
|
-
v.literal("high"),
|
|
1474
|
-
v.literal("medium"),
|
|
1475
|
-
v.literal("low"),
|
|
1476
|
-
v.literal("backlog")
|
|
1477
|
-
);
|
|
1478
|
-
v.union(
|
|
1479
|
-
v.literal("active"),
|
|
1480
|
-
v.literal("paused"),
|
|
1481
|
-
v.literal("completed"),
|
|
1482
|
-
v.literal("archived")
|
|
1483
|
-
);
|
|
1484
|
-
v.union(
|
|
1485
|
-
v.literal("pending"),
|
|
1486
|
-
v.literal("processing"),
|
|
1487
|
-
v.literal("completed"),
|
|
1488
|
-
v.literal("failed")
|
|
1489
|
-
);
|
|
1490
|
-
v.object({
|
|
1491
|
-
crunchbaseId: v.optional(v.string()),
|
|
1492
|
-
linkedinUrl: v.optional(v.string()),
|
|
1493
|
-
pitchbookId: v.optional(v.string()),
|
|
1494
|
-
twitterUrl: v.optional(v.string()),
|
|
1495
|
-
domain: v.optional(v.string())
|
|
1496
|
-
});
|
|
1497
|
-
var sourceType = v.union(
|
|
1498
|
-
v.literal("proprietary"),
|
|
1499
|
-
// Internal Stack research
|
|
1500
|
-
v.literal("primary"),
|
|
1501
|
-
// Direct interviews, calls
|
|
1502
|
-
v.literal("secondary"),
|
|
1503
|
-
// Published sources
|
|
1504
|
-
v.literal("ai_generated"),
|
|
1505
|
-
// AI-synthesized
|
|
1506
|
-
v.literal("user_input"),
|
|
1507
|
-
// Manual user entry
|
|
1508
|
-
v.literal("inferred")
|
|
1509
|
-
// System inference
|
|
1510
|
-
);
|
|
1511
|
-
v.object({
|
|
1512
|
-
sourceType: v.optional(sourceType),
|
|
1513
|
-
sourceId: v.optional(v.string()),
|
|
1514
|
-
// Reference to source entity
|
|
1515
|
-
sourceUrl: v.optional(v.string()),
|
|
1516
|
-
sourceDate: v.optional(v.number()),
|
|
1517
|
-
sourceName: v.optional(v.string())
|
|
1518
|
-
});
|
|
1519
|
-
v.object({
|
|
1520
|
-
cursor: v.optional(v.string()),
|
|
1521
|
-
limit: v.optional(v.number())
|
|
1522
|
-
});
|
|
1523
|
-
v.object({
|
|
1524
|
-
hasMore: v.boolean(),
|
|
1525
|
-
nextCursor: v.optional(v.string()),
|
|
1526
|
-
totalCount: v.optional(v.number())
|
|
1527
|
-
});
|
|
1528
|
-
var richTextContent = v.object({
|
|
1529
|
-
type: v.literal("doc"),
|
|
1530
|
-
content: looseJsonArray
|
|
1531
|
-
});
|
|
1532
|
-
v.union(v.string(), richTextContent);
|
|
1533
|
-
v.object({
|
|
1534
|
-
promptTokens: v.optional(v.number()),
|
|
1535
|
-
completionTokens: v.optional(v.number()),
|
|
1536
|
-
totalTokens: v.optional(v.number())
|
|
1537
|
-
});
|
|
1538
|
-
v.object({
|
|
1539
|
-
fileName: v.optional(v.string()),
|
|
1540
|
-
fileSize: v.optional(v.number()),
|
|
1541
|
-
mimeType: v.optional(v.string()),
|
|
1542
|
-
storageId: v.optional(v.id("_storage")),
|
|
1543
|
-
externalUrl: v.optional(v.string())
|
|
1544
|
-
});
|
|
1545
|
-
|
|
1546
|
-
// ../schema-management/src/spine/tables/epistemicNodes.ts
|
|
1547
|
-
var nodeType = v.union(
|
|
1548
|
-
// --- L4: Audit Targets (decisions, outcomes) ---
|
|
1549
|
-
v.literal("decision"),
|
|
1550
|
-
// Investment decision with knowledge horizon snapshot
|
|
1551
|
-
// --- L3: Traversal Anchors (epistemic structure) ---
|
|
1552
|
-
v.literal("belief"),
|
|
1553
|
-
// Structured conviction (immutable formulation)
|
|
1554
|
-
v.literal("question"),
|
|
1555
|
-
// Unit of uncertainty
|
|
1556
|
-
v.literal("theme"),
|
|
1557
|
-
// Investment thesis / conviction cluster
|
|
1558
|
-
v.literal("deal"),
|
|
1559
|
-
// Investment evaluation process
|
|
1560
|
-
v.literal("topic"),
|
|
1561
|
-
// Hierarchical knowledge container
|
|
1562
|
-
// --- L2: Compression Boundary (minimum reasoning unit) ---
|
|
1563
|
-
v.literal("claim"),
|
|
1564
|
-
// Atomic assertion that can be true/false
|
|
1565
|
-
v.literal("evidence"),
|
|
1566
|
-
// Interpreted signal linked to beliefs
|
|
1567
|
-
v.literal("synthesis"),
|
|
1568
|
-
// Primers, deep research
|
|
1569
|
-
v.literal("answer"),
|
|
1570
|
-
// Immutable answer snapshot for a question
|
|
1571
|
-
// --- L1: Terminal Leaves (non-traversable, grounding) ---
|
|
1572
|
-
v.literal("atomic_fact"),
|
|
1573
|
-
// Raw fact from source (not interpreted)
|
|
1574
|
-
v.literal("excerpt"),
|
|
1575
|
-
// Direct quote from source document
|
|
1576
|
-
v.literal("source"),
|
|
1577
|
-
// News, documents, transcripts
|
|
1578
|
-
// --- Ontological Entities (things in the world) ---
|
|
1579
|
-
v.literal("company"),
|
|
1580
|
-
// Organization (subtype: private, corporate, portfolio)
|
|
1581
|
-
v.literal("person"),
|
|
1582
|
-
// Individual (founder, expert, LP, contact)
|
|
1583
|
-
v.literal("investor"),
|
|
1584
|
-
// Investment entity (subtype: vc, lp, cvc, pe, family_office, angel)
|
|
1585
|
-
v.literal("function"),
|
|
1586
|
-
// What a company does (from classifier)
|
|
1587
|
-
v.literal("value_chain")
|
|
1588
|
-
// Market structure / value flow
|
|
1589
|
-
);
|
|
1590
|
-
var epistemicLayer = v.union(
|
|
1591
|
-
v.literal("L4"),
|
|
1592
|
-
// Decisions, outcomes - audit targets
|
|
1593
|
-
v.literal("L3"),
|
|
1594
|
-
// Beliefs, questions, themes - traversal anchors
|
|
1595
|
-
v.literal("L2"),
|
|
1596
|
-
// Claims, evidence, synthesis - compression boundary
|
|
1597
|
-
v.literal("L1"),
|
|
1598
|
-
// Atomic facts, excerpts, sources - terminal leaves
|
|
1599
|
-
v.literal("ontological"),
|
|
1600
|
-
// Companies, people, etc - not epistemic
|
|
1601
|
-
v.literal("organizational")
|
|
1602
|
-
// Topics, lenses, worktrees — structural containers
|
|
1603
|
-
);
|
|
1604
|
-
var nodeStatus = v.union(
|
|
1605
|
-
v.literal("active"),
|
|
1606
|
-
v.literal("superseded"),
|
|
1607
|
-
// Replaced by newer version
|
|
1608
|
-
v.literal("archived"),
|
|
1609
|
-
v.literal("deleted")
|
|
1610
|
-
);
|
|
1611
|
-
var sourceType2 = v.union(
|
|
1612
|
-
v.literal("human"),
|
|
1613
|
-
// User created directly
|
|
1614
|
-
v.literal("ai_extracted"),
|
|
1615
|
-
// LLM extracted from a source
|
|
1616
|
-
v.literal("ai_generated"),
|
|
1617
|
-
// LLM synthesized/created
|
|
1618
|
-
v.literal("imported"),
|
|
1619
|
-
// External system import
|
|
1620
|
-
v.literal("system"),
|
|
1621
|
-
// System-generated (migrations, classifiers)
|
|
1622
|
-
v.literal("verified"),
|
|
1623
|
-
// Human-verified source
|
|
1624
|
-
v.literal("proprietary")
|
|
1625
|
-
// Proprietary/internal data
|
|
1626
|
-
);
|
|
1627
|
-
var verificationStatus = v.union(
|
|
1628
|
-
v.literal("unverified"),
|
|
1629
|
-
v.literal("human_verified"),
|
|
1630
|
-
v.literal("ai_verified"),
|
|
1631
|
-
v.literal("contradicted"),
|
|
1632
|
-
v.literal("outdated")
|
|
1633
|
-
);
|
|
1634
|
-
var syncStatus = v.union(
|
|
1635
|
-
v.literal("synced"),
|
|
1636
|
-
// Node and edges fully synced to Neo4j
|
|
1637
|
-
v.literal("pending_edges"),
|
|
1638
|
-
// Node created, edges being created
|
|
1639
|
-
v.literal("edge_creation_failed")
|
|
1640
|
-
// Edge creation failed, needs retry
|
|
1641
|
-
);
|
|
1642
|
-
var audienceLabel = v.string();
|
|
1643
|
-
var sensitivityTier = v.union(
|
|
1644
|
-
v.literal("low"),
|
|
1645
|
-
v.literal("medium"),
|
|
1646
|
-
v.literal("high"),
|
|
1647
|
-
v.literal("restricted")
|
|
1648
|
-
);
|
|
1649
|
-
var exportClass = v.union(
|
|
1650
|
-
v.literal("internal_only"),
|
|
1651
|
-
v.literal("client_safe"),
|
|
1652
|
-
v.literal("public_safe"),
|
|
1653
|
-
v.literal("restricted")
|
|
1654
|
-
);
|
|
1655
|
-
var anonymizationClass = v.union(
|
|
1656
|
-
v.literal("none"),
|
|
1657
|
-
v.literal("standard"),
|
|
1658
|
-
v.literal("strict")
|
|
1659
|
-
);
|
|
1660
|
-
var epistemicStatus = v.union(
|
|
1661
|
-
v.literal("hypothesis"),
|
|
1662
|
-
// Initial conjecture, low evidence
|
|
1663
|
-
v.literal("emerging"),
|
|
1664
|
-
// Building evidence, gaining traction
|
|
1665
|
-
v.literal("established"),
|
|
1666
|
-
// Well-evidenced, core to thesis
|
|
1667
|
-
v.literal("challenged"),
|
|
1668
|
-
// Contradicting evidence appeared
|
|
1669
|
-
v.literal("assumption"),
|
|
1670
|
-
// Taken as given, not actively tested
|
|
1671
|
-
v.literal("deprecated")
|
|
1672
|
-
// Superseded or abandoned
|
|
1673
|
-
);
|
|
1674
|
-
var beliefStatus = v.union(
|
|
1675
|
-
v.literal("assumption"),
|
|
1676
|
-
v.literal("hypothesis"),
|
|
1677
|
-
v.literal("belief"),
|
|
1678
|
-
v.literal("fact")
|
|
1679
|
-
);
|
|
1680
|
-
var reversibility = v.union(
|
|
1681
|
-
v.literal("irreversible"),
|
|
1682
|
-
// One-way door decision
|
|
1683
|
-
v.literal("hard_to_reverse"),
|
|
1684
|
-
// Significant cost to undo
|
|
1685
|
-
v.literal("reversible"),
|
|
1686
|
-
// Can change course with moderate effort
|
|
1687
|
-
v.literal("trivial")
|
|
1688
|
-
// Easy to adjust
|
|
1689
|
-
);
|
|
1690
|
-
var predictionOutcome = v.union(
|
|
1691
|
-
v.literal("pending"),
|
|
1692
|
-
v.literal("confirmed"),
|
|
1693
|
-
v.literal("disconfirmed"),
|
|
1694
|
-
v.literal("partial"),
|
|
1695
|
-
v.literal("expired")
|
|
1696
|
-
);
|
|
1697
|
-
var predictionMeta = v.object({
|
|
1698
|
-
isPrediction: v.boolean(),
|
|
1699
|
-
registeredAt: v.number(),
|
|
1700
|
-
// When prediction was made
|
|
1701
|
-
expectedBy: v.optional(v.number()),
|
|
1702
|
-
// When we expect resolution
|
|
1703
|
-
outcome: v.optional(predictionOutcome),
|
|
1704
|
-
outcomeRecordedAt: v.optional(v.number()),
|
|
1705
|
-
outcomeEvidenceId: v.optional(v.string()),
|
|
1706
|
-
// globalId of confirming evidence
|
|
1707
|
-
confidenceAtPrediction: v.optional(v.number()),
|
|
1708
|
-
// 0-1
|
|
1709
|
-
actualVsPredicted: v.optional(v.string())
|
|
1710
|
-
// Notes on how outcome compared
|
|
1711
|
-
});
|
|
1712
|
-
var methodology = v.union(
|
|
1713
|
-
// Primary Research (high value)
|
|
1714
|
-
v.literal("primary_research"),
|
|
1715
|
-
// Direct investigation
|
|
1716
|
-
v.literal("expert_interview"),
|
|
1717
|
-
// Expert call/interview
|
|
1718
|
-
v.literal("customer_interview"),
|
|
1719
|
-
// Customer research
|
|
1720
|
-
v.literal("field_observation"),
|
|
1721
|
-
// On-site observation
|
|
1722
|
-
v.literal("proprietary_data"),
|
|
1723
|
-
// Internal data analysis
|
|
1724
|
-
// Secondary Research
|
|
1725
|
-
v.literal("desk_research"),
|
|
1726
|
-
// Public sources
|
|
1727
|
-
v.literal("regulatory_filing"),
|
|
1728
|
-
// SEC, regulatory docs
|
|
1729
|
-
v.literal("news_article"),
|
|
1730
|
-
// News/press
|
|
1731
|
-
v.literal("academic_paper"),
|
|
1732
|
-
// Academic research
|
|
1733
|
-
// AI-Assisted
|
|
1734
|
-
v.literal("ai_synthesis"),
|
|
1735
|
-
// AI-generated synthesis
|
|
1736
|
-
v.literal("ai_extraction")
|
|
1737
|
-
// AI-extracted from source
|
|
1738
|
-
);
|
|
1739
|
-
var informationAsymmetry = v.union(
|
|
1740
|
-
v.literal("proprietary"),
|
|
1741
|
-
// Only we have this
|
|
1742
|
-
v.literal("early"),
|
|
1743
|
-
// We're early but others will get it
|
|
1744
|
-
v.literal("common")
|
|
1745
|
-
// Everyone has access
|
|
1746
|
-
);
|
|
1747
|
-
var temporalNature = v.union(
|
|
1748
|
-
v.literal("factual"),
|
|
1749
|
-
// Resolved outcome. Grounded in reality.
|
|
1750
|
-
v.literal("forecast"),
|
|
1751
|
-
// Prediction. Will resolve. Discounted weight.
|
|
1752
|
-
v.literal("unknown")
|
|
1753
|
-
// Not yet classified.
|
|
1754
|
-
);
|
|
1755
|
-
var questionType = v.union(
|
|
1756
|
-
v.literal("validation"),
|
|
1757
|
-
// Does evidence support this belief?
|
|
1758
|
-
v.literal("falsification"),
|
|
1759
|
-
// What would prove this belief wrong?
|
|
1760
|
-
v.literal("assumption_probe"),
|
|
1761
|
-
// Is this unstated assumption true?
|
|
1762
|
-
v.literal("prediction_test"),
|
|
1763
|
-
// Will this predicted outcome occur?
|
|
1764
|
-
v.literal("counterfactual"),
|
|
1765
|
-
// What would we expect if X were false?
|
|
1766
|
-
v.literal("discovery"),
|
|
1767
|
-
// What don't we know yet?
|
|
1768
|
-
v.literal("clarification"),
|
|
1769
|
-
// What does X actually mean?
|
|
1770
|
-
v.literal("comparison"),
|
|
1771
|
-
// How does X compare to Y?
|
|
1772
|
-
v.literal("causal"),
|
|
1773
|
-
// What caused X?
|
|
1774
|
-
v.literal("mechanism"),
|
|
1775
|
-
// How does X work?
|
|
1776
|
-
v.literal("general")
|
|
1777
|
-
// Unclassified
|
|
1778
|
-
);
|
|
1779
|
-
var questionPriority = v.union(
|
|
1780
|
-
v.literal("critical"),
|
|
1781
|
-
// Blocks decision-making
|
|
1782
|
-
v.literal("high"),
|
|
1783
|
-
// Important for thesis
|
|
1784
|
-
v.literal("medium"),
|
|
1785
|
-
// Would be nice to know
|
|
1786
|
-
v.literal("low")
|
|
1787
|
-
// Background/curiosity
|
|
1788
|
-
);
|
|
1789
|
-
var answerQuality = v.union(
|
|
1790
|
-
v.literal("definitive"),
|
|
1791
|
-
// Clear, well-supported
|
|
1792
|
-
v.literal("strong"),
|
|
1793
|
-
// Good evidence, high confidence
|
|
1794
|
-
v.literal("moderate"),
|
|
1795
|
-
// Some evidence
|
|
1796
|
-
v.literal("weak"),
|
|
1797
|
-
// Limited evidence
|
|
1798
|
-
v.literal("speculative"),
|
|
1799
|
-
// Mostly conjecture
|
|
1800
|
-
v.literal("unanswered")
|
|
1801
|
-
// No answer yet
|
|
1802
|
-
);
|
|
1803
|
-
var consensusView = v.union(
|
|
1804
|
-
v.literal("aligned"),
|
|
1805
|
-
// We agree with market consensus
|
|
1806
|
-
v.literal("ahead_of"),
|
|
1807
|
-
// We see this before consensus does
|
|
1808
|
-
v.literal("contrarian"),
|
|
1809
|
-
// We actively disagree with consensus
|
|
1810
|
-
v.literal("orthogonal"),
|
|
1811
|
-
// We're looking at something consensus isn't discussing
|
|
1812
|
-
v.literal("unknown")
|
|
1813
|
-
// We don't know what consensus thinks
|
|
1814
|
-
);
|
|
1815
|
-
var themeConviction = v.union(
|
|
1816
|
-
v.literal("high"),
|
|
1817
|
-
// Strong conviction, actively deploying
|
|
1818
|
-
v.literal("medium"),
|
|
1819
|
-
// Building conviction
|
|
1820
|
-
v.literal("low"),
|
|
1821
|
-
// Exploring, not convicted
|
|
1822
|
-
v.literal("negative")
|
|
1823
|
-
// Actively avoiding
|
|
1824
|
-
);
|
|
1825
|
-
var decisionType = v.union(
|
|
1826
|
-
v.literal("invest"),
|
|
1827
|
-
v.literal("pass"),
|
|
1828
|
-
v.literal("follow_on"),
|
|
1829
|
-
v.literal("exit"),
|
|
1830
|
-
v.literal("deep_dive"),
|
|
1831
|
-
v.literal("monitor"),
|
|
1832
|
-
v.literal("deprioritize"),
|
|
1833
|
-
v.literal("thesis_adopt"),
|
|
1834
|
-
v.literal("thesis_revise"),
|
|
1835
|
-
v.literal("thesis_abandon")
|
|
1836
|
-
);
|
|
1837
|
-
var decisionOutcome = v.union(
|
|
1838
|
-
v.literal("pending"),
|
|
1839
|
-
v.literal("successful"),
|
|
1840
|
-
v.literal("unsuccessful"),
|
|
1841
|
-
v.literal("mixed"),
|
|
1842
|
-
v.literal("unknown")
|
|
1843
|
-
);
|
|
1844
|
-
var externalIds2 = v.object({
|
|
1845
|
-
crunchbase: v.optional(v.string()),
|
|
1846
|
-
linkedin: v.optional(v.string()),
|
|
1847
|
-
pitchbook: v.optional(v.string()),
|
|
1848
|
-
twitter: v.optional(v.string()),
|
|
1849
|
-
website: v.optional(v.string())
|
|
1850
|
-
});
|
|
1851
|
-
defineTable({
|
|
1852
|
-
// === IDENTITY ===
|
|
1853
|
-
globalId: v.string(),
|
|
1854
|
-
// UUID - survives migration to Neo4j
|
|
1855
|
-
// === TYPE ===
|
|
1856
|
-
nodeType,
|
|
1857
|
-
// === EPISTEMIC LAYER ===
|
|
1858
|
-
epistemicLayer: v.optional(epistemicLayer),
|
|
1859
|
-
// === SUBTYPE (for typed entities) ===
|
|
1860
|
-
subtype: v.optional(v.string()),
|
|
1861
|
-
// company: private|corporate|portfolio, investor: vc|lp|cvc|pe|family_office|angel
|
|
1862
|
-
// === CONTENT ===
|
|
1863
|
-
canonicalText: v.string(),
|
|
1864
|
-
// The core content (belief statement, company name, etc.)
|
|
1865
|
-
contentHash: v.string(),
|
|
1866
|
-
// SHA256(nodeType + canonicalText) for deduplication
|
|
1867
|
-
// Extended content (for sources/syntheses)
|
|
1868
|
-
content: v.optional(v.string()),
|
|
1869
|
-
// Full text for documents/articles
|
|
1870
|
-
contentType: v.optional(v.string()),
|
|
1871
|
-
// "markdown", "html", "pdf", "text"
|
|
1872
|
-
// === METADATA ===
|
|
1873
|
-
title: v.optional(v.string()),
|
|
1874
|
-
// Display title
|
|
1875
|
-
tags: v.optional(v.array(v.string())),
|
|
1876
|
-
domain: v.optional(v.string()),
|
|
1877
|
-
// For companies: website domain
|
|
1878
|
-
// Type-specific metadata (flexible object - LEGACY)
|
|
1879
|
-
// New code should use the typed fields below when available
|
|
1880
|
-
metadata: v.optional(looseJsonObject),
|
|
1881
|
-
// === POLICY / ENTITLEMENT ===
|
|
1882
|
-
tenantId: v.optional(v.string()),
|
|
1883
|
-
workspaceId: v.optional(v.string()),
|
|
1884
|
-
ownerPrincipalId: v.optional(v.string()),
|
|
1885
|
-
audienceLabel: v.optional(audienceLabel),
|
|
1886
|
-
policyTags: v.optional(v.array(v.string())),
|
|
1887
|
-
sensitivityTier: v.optional(sensitivityTier),
|
|
1888
|
-
exportClass: v.optional(exportClass),
|
|
1889
|
-
anonymizationClass: v.optional(anonymizationClass),
|
|
1890
|
-
// === PUBLICATION (visibility-based, not copy-based) ===
|
|
1891
|
-
// Publication expands who can see a workspace-local node — the node stays
|
|
1892
|
-
// in its workspace, like a microservice exposing part of its API surface.
|
|
1893
|
-
// Rules-based: pack/tenant-level publicationRules auto-evaluate on
|
|
1894
|
-
// confidence changes and node creation. No manual click-by-click.
|
|
1895
|
-
publicationStatus: v.optional(
|
|
1896
|
-
v.union(
|
|
1897
|
-
v.literal("unpublished"),
|
|
1898
|
-
// Default: workspace-local only
|
|
1899
|
-
v.literal("published"),
|
|
1900
|
-
// Visible at tenant scope (rules matched)
|
|
1901
|
-
v.literal("suppressed")
|
|
1902
|
-
// Manually blocked even if rules match
|
|
1903
|
-
)
|
|
1904
|
-
),
|
|
1905
|
-
publishedAt: v.optional(v.number()),
|
|
1906
|
-
// When publication status last changed to published
|
|
1907
|
-
publishedBy: v.optional(v.string()),
|
|
1908
|
-
// userId or "system:publication_rules" for auto-publish
|
|
1909
|
-
// === TYPED METADATA FIELDS ===
|
|
1910
|
-
// --- Belief ---
|
|
1911
|
-
// Belief type — validated against schemaEnumConfig category "belief_type"
|
|
1912
|
-
// Platform core: hypothesis, belief, principle, invariant, assumption,
|
|
1913
|
-
// tenet, prior, preference, goal, forecast
|
|
1914
|
-
beliefType: v.optional(v.string()),
|
|
1915
|
-
beliefStatus: v.optional(beliefStatus),
|
|
1916
|
-
epistemicStatus: v.optional(epistemicStatus),
|
|
1917
|
-
reversibility: v.optional(reversibility),
|
|
1918
|
-
predictionMeta: v.optional(predictionMeta),
|
|
1919
|
-
// Consensus tracking (for non-consensus detection)
|
|
1920
|
-
consensusView: v.optional(consensusView),
|
|
1921
|
-
consensusConfidence: v.optional(v.number()),
|
|
1922
|
-
// 0-1: What we think consensus confidence is
|
|
1923
|
-
consensusSource: v.optional(v.string()),
|
|
1924
|
-
// Where we got the consensus view (twitter, reports, etc.)
|
|
1925
|
-
// --- Evidence ---
|
|
1926
|
-
methodology: v.optional(methodology),
|
|
1927
|
-
informationAsymmetry: v.optional(informationAsymmetry),
|
|
1928
|
-
temporalNature: v.optional(temporalNature),
|
|
1929
|
-
// --- Question ---
|
|
1930
|
-
questionType: v.optional(questionType),
|
|
1931
|
-
questionPriority: v.optional(questionPriority),
|
|
1932
|
-
answerQuality: v.optional(answerQuality),
|
|
1933
|
-
// --- Theme ---
|
|
1934
|
-
themeConviction: v.optional(themeConviction),
|
|
1935
|
-
// Market timing (for "early on theme" detection)
|
|
1936
|
-
marketAwarenessDate: v.optional(v.number()),
|
|
1937
|
-
// When this theme became broadly discussed
|
|
1938
|
-
marketAwarenessSource: v.optional(v.string()),
|
|
1939
|
-
// How we know (first major report, twitter volume spike, etc.)
|
|
1940
|
-
earlySignalIds: v.optional(v.array(v.string())),
|
|
1941
|
-
// globalIds of evidence we had before market awareness
|
|
1942
|
-
// --- Decision ---
|
|
1943
|
-
decisionType: v.optional(decisionType),
|
|
1944
|
-
decisionOutcome: v.optional(decisionOutcome),
|
|
1945
|
-
// === EXTERNAL IDS (for ontological entities) ===
|
|
1946
|
-
externalIds: v.optional(externalIds2),
|
|
1947
|
-
// === PROVENANCE ===
|
|
1948
|
-
sourceType: sourceType2,
|
|
1949
|
-
aiProvider: v.optional(v.string()),
|
|
1950
|
-
// "claude", "gemini", "gpt-4", etc.
|
|
1951
|
-
extractedFromNodeId: v.optional(v.id("epistemicNodes")),
|
|
1952
|
-
// Quick reference to source
|
|
1953
|
-
// === EXTRACTION CONTEXT ===
|
|
1954
|
-
extractionModel: v.optional(v.string()),
|
|
1955
|
-
// "claude-sonnet-4-20250514"
|
|
1956
|
-
extractionPromptName: v.optional(v.string()),
|
|
1957
|
-
// "lucern/extract-evidence"
|
|
1958
|
-
extractionPromptVersion: v.optional(v.number()),
|
|
1959
|
-
extractionTemperature: v.optional(v.number()),
|
|
1960
|
-
extractionLangfuseTraceId: v.optional(v.string()),
|
|
1961
|
-
// === GROUNDING VERIFICATION ===
|
|
1962
|
-
groundingVerified: v.optional(v.boolean()),
|
|
1963
|
-
groundingConfidence: v.optional(v.number()),
|
|
1964
|
-
// 0-1 match quality
|
|
1965
|
-
groundingMatchedText: v.optional(v.string()),
|
|
1966
|
-
// Actual text from source
|
|
1967
|
-
groundingStartOffset: v.optional(v.number()),
|
|
1968
|
-
groundingEndOffset: v.optional(v.number()),
|
|
1969
|
-
groundingRejectionReason: v.optional(v.string()),
|
|
1970
|
-
// === CONFIDENCE & VERIFICATION ===
|
|
1971
|
-
confidence: v.optional(v.number()),
|
|
1972
|
-
// 0-1 projected probability P(x) = b + a*u
|
|
1973
|
-
verificationStatus: v.optional(verificationStatus),
|
|
1974
|
-
// === SL OPINION (Subjective Logic — Kernel v2) ===
|
|
1975
|
-
// Replaces scalar confidence with rich epistemic state.
|
|
1976
|
-
// b + d + u = 1. P(x) = b + a*u is stored in `confidence` for backward compat.
|
|
1977
|
-
opinion_b: v.optional(v.number()),
|
|
1978
|
-
// Belief: evidence FOR (0-1)
|
|
1979
|
-
opinion_d: v.optional(v.number()),
|
|
1980
|
-
// Disbelief: evidence AGAINST (0-1)
|
|
1981
|
-
opinion_u: v.optional(v.number()),
|
|
1982
|
-
// Uncertainty: absence of evidence (0-1)
|
|
1983
|
-
opinion_a: v.optional(v.number()),
|
|
1984
|
-
// Base rate / prior probability (0-1)
|
|
1985
|
-
tupleContradicted: v.optional(v.boolean()),
|
|
1986
|
-
// Single-belief tuple-space contradiction flag
|
|
1987
|
-
// === LIFECYCLE ===
|
|
1988
|
-
status: nodeStatus,
|
|
1989
|
-
supersededBy: v.optional(v.id("epistemicNodes")),
|
|
1990
|
-
// === OWNERSHIP ===
|
|
1991
|
-
topicId: v.optional(v.string()),
|
|
1992
|
-
// Canonical scope container (topic-first model)
|
|
1993
|
-
projectId: v.optional(v.string()),
|
|
1994
|
-
// DEPRECATED: Use belongs_to edges
|
|
1995
|
-
createdBy: v.string(),
|
|
1996
|
-
// Clerk user ID
|
|
1997
|
-
createdAt: v.number(),
|
|
1998
|
-
updatedAt: v.number(),
|
|
1999
|
-
// === NEO4J SYNC STATUS ===
|
|
2000
|
-
syncStatus: v.optional(syncStatus),
|
|
2001
|
-
syncError: v.optional(v.string())
|
|
2002
|
-
// Error message if sync failed
|
|
2003
|
-
}).index("by_globalId", ["globalId"]).index("by_contentHash", ["contentHash"]).index("by_nodeType", ["nodeType"]).index("by_subtype", ["nodeType", "subtype"]).index("by_domain", ["domain"]).index("by_project", ["projectId"]).index("by_project_type", ["projectId", "nodeType"]).index("by_topic", ["topicId"]).index("by_topic_type", ["topicId", "nodeType"]).index("by_tenantId", ["tenantId"]).index("by_workspaceId", ["workspaceId"]).index("by_tenant_workspace", ["tenantId", "workspaceId"]).index("by_audienceLabel", ["audienceLabel"]).index("by_sensitivityTier", ["sensitivityTier"]).index("by_exportClass", ["exportClass"]).index("by_status", ["status"]).index("by_sourceType", ["sourceType"]).index("by_verification", ["verificationStatus"]).index("by_layer", ["epistemicLayer"]).index("by_layer_type", ["epistemicLayer", "nodeType"]).index("by_syncStatus", ["syncStatus"]).index("by_publicationStatus", ["publicationStatus"]).index("by_tenant_publicationStatus", ["tenantId", "publicationStatus"]).index("by_belief_status", ["nodeType", "beliefStatus"]).index("by_epistemic_status", ["nodeType", "epistemicStatus"]).index("by_temporal_nature", ["nodeType", "temporalNature"]).index("by_methodology", ["nodeType", "methodology"]).index("by_reversibility", ["nodeType", "reversibility"]).index("by_questionType", ["nodeType", "questionType"]).index("by_questionPriority", ["nodeType", "questionPriority"]).searchIndex("search_canonicalText", {
|
|
2004
|
-
searchField: "canonicalText",
|
|
2005
|
-
filterFields: ["nodeType", "projectId", "topicId", "status"]
|
|
2006
|
-
});
|
|
2007
|
-
function getLayerForNodeType(type) {
|
|
2008
|
-
switch (type) {
|
|
2009
|
-
case "decision":
|
|
2010
|
-
return "L4";
|
|
2011
|
-
case "belief":
|
|
2012
|
-
case "question":
|
|
2013
|
-
case "theme":
|
|
2014
|
-
case "deal":
|
|
2015
|
-
return "L3";
|
|
2016
|
-
case "claim":
|
|
2017
|
-
case "evidence":
|
|
2018
|
-
case "synthesis":
|
|
2019
|
-
case "answer":
|
|
2020
|
-
return "L2";
|
|
2021
|
-
case "atomic_fact":
|
|
2022
|
-
case "excerpt":
|
|
2023
|
-
case "source":
|
|
2024
|
-
return "L1";
|
|
2025
|
-
case "topic":
|
|
2026
|
-
return "organizational";
|
|
2027
|
-
case "company":
|
|
2028
|
-
case "person":
|
|
2029
|
-
case "investor":
|
|
2030
|
-
case "function":
|
|
2031
|
-
case "value_chain":
|
|
2032
|
-
return "ontological";
|
|
2033
|
-
}
|
|
2034
|
-
}
|
|
2035
|
-
|
|
2036
|
-
// src/workspaceIsolation.ts
|
|
2037
527
|
function normalizeScopeValue2(value) {
|
|
2038
528
|
if (typeof value !== "string") {
|
|
2039
529
|
return;
|
|
@@ -2051,7 +541,7 @@ function throwWorkspaceIsolationError(args) {
|
|
|
2051
541
|
throw error;
|
|
2052
542
|
}
|
|
2053
543
|
function assertWorkspaceScopedEpistemicNodeScope(args) {
|
|
2054
|
-
const layer = getLayerForNodeType(args.nodeType);
|
|
544
|
+
const layer = isNodeType(args.nodeType) ? getLayerForNodeType(args.nodeType) : void 0;
|
|
2055
545
|
if (layer === "ontological") {
|
|
2056
546
|
return;
|
|
2057
547
|
}
|
|
@@ -2079,11 +569,11 @@ function nodeMatchesWorkspaceReasoningScope(node, scope) {
|
|
|
2079
569
|
const scopeWorkspaceId = normalizeScopeValue2(scope.workspaceId);
|
|
2080
570
|
const nodeTenantId = normalizeScopeValue2(node.tenantId);
|
|
2081
571
|
const nodeWorkspaceId = normalizeScopeValue2(node.workspaceId);
|
|
2082
|
-
const
|
|
572
|
+
const epistemicLayer = typeof node.epistemicLayer === "string" ? node.epistemicLayer : void 0;
|
|
2083
573
|
if (scopeTenantId && nodeTenantId && scopeTenantId !== nodeTenantId) {
|
|
2084
574
|
return false;
|
|
2085
575
|
}
|
|
2086
|
-
if (
|
|
576
|
+
if (epistemicLayer === "ontological" && nodeWorkspaceId === void 0) {
|
|
2087
577
|
return true;
|
|
2088
578
|
}
|
|
2089
579
|
if (!scopeWorkspaceId && node.publicationStatus === "published") {
|
|
@@ -2095,11 +585,11 @@ function nodeMatchesWorkspaceReasoningScope(node, scope) {
|
|
|
2095
585
|
return scopeWorkspaceId === nodeWorkspaceId;
|
|
2096
586
|
}
|
|
2097
587
|
async function resolveNodeScopeForWorkspaceIsolation(ctx, node) {
|
|
2098
|
-
const
|
|
588
|
+
const epistemicLayer = typeof node?.epistemicLayer === "string" ? node.epistemicLayer : void 0;
|
|
2099
589
|
const resolved = {
|
|
2100
590
|
tenantId: normalizeScopeValue2(node?.tenantId),
|
|
2101
591
|
workspaceId: normalizeScopeValue2(node?.workspaceId),
|
|
2102
|
-
epistemicLayer
|
|
592
|
+
epistemicLayer,
|
|
2103
593
|
nodeType: typeof node?.nodeType === "string" ? node.nodeType : void 0
|
|
2104
594
|
};
|
|
2105
595
|
if (!node) {
|
|
@@ -2167,38 +657,7 @@ function assertTenantPackWorkspaceMutationAllowed(args) {
|
|
|
2167
657
|
});
|
|
2168
658
|
}
|
|
2169
659
|
|
|
2170
|
-
//
|
|
2171
|
-
function normalizeString2(value) {
|
|
2172
|
-
if (typeof value !== "string") {
|
|
2173
|
-
return void 0;
|
|
2174
|
-
}
|
|
2175
|
-
const trimmed = value.trim();
|
|
2176
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
2177
|
-
}
|
|
2178
|
-
function requireScopeId(...ids) {
|
|
2179
|
-
for (const id of ids) {
|
|
2180
|
-
const normalized = normalizeString2(id);
|
|
2181
|
-
if (normalized) {
|
|
2182
|
-
return normalized;
|
|
2183
|
-
}
|
|
2184
|
-
}
|
|
2185
|
-
throw new Error("No scope identifier provided (topicId or projectId required)");
|
|
2186
|
-
}
|
|
2187
|
-
async function resolveTopicProjectScope2(ctx, args) {
|
|
2188
|
-
const resolved = await resolveTopicProjectScope(ctx, {
|
|
2189
|
-
topicId: normalizeString2(args.topicId),
|
|
2190
|
-
projectId: normalizeString2(args.projectId)
|
|
2191
|
-
});
|
|
2192
|
-
const topicId = normalizeString2(resolved.topicId);
|
|
2193
|
-
const projectId = requireScopeId(
|
|
2194
|
-
resolved.projectId,
|
|
2195
|
-
args.projectId,
|
|
2196
|
-
topicId
|
|
2197
|
-
);
|
|
2198
|
-
return { projectId, ...topicId ? { topicId } : {} };
|
|
2199
|
-
}
|
|
2200
|
-
|
|
2201
|
-
// ../worktrees/src/v1/engine/worktreeWorkflowBridge.ts
|
|
660
|
+
// src/workflowBridge.ts
|
|
2202
661
|
function isLegacySprintDoc(doc) {
|
|
2203
662
|
if (!doc || typeof doc !== "object") {
|
|
2204
663
|
return false;
|
|
@@ -2224,7 +683,7 @@ async function findPairedWorktreeForSprint(ctx, sprint) {
|
|
|
2224
683
|
let topicId = getStringField(sprint, "topicId");
|
|
2225
684
|
if (!topicId) {
|
|
2226
685
|
try {
|
|
2227
|
-
const scope = await
|
|
686
|
+
const scope = await resolveTopicProjectScope(ctx, {
|
|
2228
687
|
topicId: getStringField(sprint, "topicId"),
|
|
2229
688
|
projectId: getStringField(sprint, "projectId")
|
|
2230
689
|
});
|
|
@@ -2299,10 +758,10 @@ async function resolveWorkflowBridgeDoc(ctx, workflowId) {
|
|
|
2299
758
|
|
|
2300
759
|
// src/epistemicQuestions.ts
|
|
2301
760
|
function generateContentHash(text) {
|
|
2302
|
-
const
|
|
761
|
+
const content = `question:${text.trim().toLowerCase().replace(/\s+/g, " ")}`;
|
|
2303
762
|
let hash = 5381;
|
|
2304
|
-
for (let i = 0; i <
|
|
2305
|
-
hash = (hash << 5) + hash +
|
|
763
|
+
for (let i = 0; i < content.length; i++) {
|
|
764
|
+
hash = (hash << 5) + hash + content.charCodeAt(i);
|
|
2306
765
|
hash &= hash;
|
|
2307
766
|
}
|
|
2308
767
|
return Math.abs(hash).toString(16).padStart(8, "0");
|
|
@@ -2406,21 +865,13 @@ async function resolveQuestionScopeOrNull(ctx, args) {
|
|
|
2406
865
|
}
|
|
2407
866
|
async function getQuestionNodesForScope(ctx, scope, args) {
|
|
2408
867
|
const fetchNodes = (query2) => typeof args?.scanLimit === "number" ? query2.order("desc").take(args.scanLimit) : query2.collect();
|
|
2409
|
-
const
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
scope.projectId ? fetchNodes(
|
|
2417
|
-
ctx.db.query("epistemicNodes").withIndex(
|
|
2418
|
-
"by_project_type",
|
|
2419
|
-
(q) => q.eq("projectId", scope.projectId).eq("nodeType", "question")
|
|
2420
|
-
)
|
|
2421
|
-
) : Promise.resolve([])
|
|
2422
|
-
]);
|
|
2423
|
-
return dedupeQuestionNodes([...topicNodes, ...projectNodes]).filter(
|
|
868
|
+
const topicNodes = await fetchNodes(
|
|
869
|
+
ctx.db.query("epistemicNodes").withIndex(
|
|
870
|
+
"by_topic_type",
|
|
871
|
+
(q) => q.eq("topicId", scope.topicId).eq("nodeType", "question")
|
|
872
|
+
)
|
|
873
|
+
);
|
|
874
|
+
return dedupeQuestionNodes(topicNodes).filter(
|
|
2424
875
|
(node) => questionMatchesScope(node, scope)
|
|
2425
876
|
);
|
|
2426
877
|
}
|
|
@@ -4586,8 +3037,8 @@ var getByPillar = query({
|
|
|
4586
3037
|
return { questions: [], beliefs: [] };
|
|
4587
3038
|
}
|
|
4588
3039
|
const allBeliefNodes = await ctx.db.query("epistemicNodes").withIndex(
|
|
4589
|
-
|
|
4590
|
-
(q) =>
|
|
3040
|
+
"by_topic_type",
|
|
3041
|
+
(q) => q.eq("topicId", scope.topicId).eq("nodeType", "belief")
|
|
4591
3042
|
).collect();
|
|
4592
3043
|
const beliefs = allBeliefNodes.filter((n) => {
|
|
4593
3044
|
const meta = n.metadata || {};
|
|
@@ -4953,8 +3404,8 @@ var getQuestionClusterPositions = query({
|
|
|
4953
3404
|
};
|
|
4954
3405
|
}
|
|
4955
3406
|
const questionNodes = await ctx.db.query("epistemicNodes").withIndex(
|
|
4956
|
-
|
|
4957
|
-
(q) =>
|
|
3407
|
+
"by_topic_type",
|
|
3408
|
+
(q) => q.eq("topicId", scope.topicId).eq("nodeType", "question")
|
|
4958
3409
|
).collect();
|
|
4959
3410
|
const activeQuestionNodes = questionNodes.filter(isActiveQuestionNode);
|
|
4960
3411
|
const positions = {};
|
|
@@ -4964,8 +3415,8 @@ var getQuestionClusterPositions = query({
|
|
|
4964
3415
|
for (const question of activeQuestionNodes) {
|
|
4965
3416
|
const id = question._id.toString();
|
|
4966
3417
|
const meta = question.metadata || {};
|
|
4967
|
-
const
|
|
4968
|
-
if (
|
|
3418
|
+
const questionType = typeof question.questionType === "string" ? question.questionType : typeof meta.questionType === "string" ? meta.questionType : void 0;
|
|
3419
|
+
if (questionType === "belief_test" || meta.testType) {
|
|
4969
3420
|
positions[id] = "cluster";
|
|
4970
3421
|
clusterCount++;
|
|
4971
3422
|
} else if (resolveLinkedWorktreeId(meta)) {
|