@lucern/mcp 0.2.0-alpha.5 → 0.2.0-alpha.7
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/gateway.d.ts +128 -103
- package/dist/gateway.js +851 -364
- package/dist/gateway.js.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +540 -225
- package/dist/index.js.map +1 -1
- package/dist/runtime.js +944 -4274
- package/dist/runtime.js.map +1 -1
- package/package.json +4 -5
package/dist/gateway.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { NextResponse } from 'next/server';
|
|
2
1
|
import { randomUUID } from 'crypto';
|
|
3
2
|
|
|
4
|
-
// ../../lucern/apps/gateway/src/gateway-helpers.ts
|
|
5
|
-
|
|
6
3
|
// ../contracts/src/gateway.contract.ts
|
|
7
4
|
function requireActorPrincipalId(authContext) {
|
|
8
5
|
const principalId = typeof authContext.principalId === "string" ? authContext.principalId.trim() : "";
|
|
@@ -337,7 +334,7 @@ function rankEntityTypeMatches(inputText, entityTypes, options) {
|
|
|
337
334
|
return matches;
|
|
338
335
|
}
|
|
339
336
|
|
|
340
|
-
// ../../
|
|
337
|
+
// ../../apps/gateway/src/gateway-helpers.ts
|
|
341
338
|
function buildHeaders(args) {
|
|
342
339
|
const headers = new Headers();
|
|
343
340
|
headers.set("x-lucern-correlation-id", args.correlationId);
|
|
@@ -461,7 +458,7 @@ function resolveGatewayError(error, fallbackMessage) {
|
|
|
461
458
|
};
|
|
462
459
|
}
|
|
463
460
|
function successResponse(payload, args) {
|
|
464
|
-
return
|
|
461
|
+
return Response.json(
|
|
465
462
|
{
|
|
466
463
|
success: true,
|
|
467
464
|
data: payload,
|
|
@@ -486,19 +483,16 @@ function errorResponse(args) {
|
|
|
486
483
|
})
|
|
487
484
|
);
|
|
488
485
|
if (args.headers) {
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
}
|
|
493
|
-
headers.set(key, String(value));
|
|
494
|
-
}
|
|
486
|
+
new Headers(args.headers).forEach((value, key) => {
|
|
487
|
+
headers.set(key, value);
|
|
488
|
+
});
|
|
495
489
|
}
|
|
496
490
|
const safeMessage = sanitizeErrorMessage({
|
|
497
491
|
message: args.message,
|
|
498
492
|
status: args.status,
|
|
499
493
|
code: args.code
|
|
500
494
|
});
|
|
501
|
-
return
|
|
495
|
+
return Response.json(
|
|
502
496
|
{
|
|
503
497
|
success: false,
|
|
504
498
|
error: safeMessage,
|
|
@@ -533,6 +527,13 @@ var api = makeProxy("api");
|
|
|
533
527
|
var components = makeProxy("components");
|
|
534
528
|
var internal = makeProxy("internal");
|
|
535
529
|
|
|
530
|
+
// ../server-core/src/domain/confidencePolicy.ts
|
|
531
|
+
var allowAlwaysPolicy = {
|
|
532
|
+
async canScore() {
|
|
533
|
+
return { allow: true };
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
|
|
536
537
|
// ../server-core/src/domain/beliefs.ts
|
|
537
538
|
function asRecord(value) {
|
|
538
539
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
@@ -571,6 +572,20 @@ function normalizeRequiredString(value, field) {
|
|
|
571
572
|
}
|
|
572
573
|
return normalized;
|
|
573
574
|
}
|
|
575
|
+
function normalizeRequiredBaseRate(value) {
|
|
576
|
+
const baseRate = readNumber(value);
|
|
577
|
+
if (baseRate === void 0) {
|
|
578
|
+
throwBeliefsError({
|
|
579
|
+
message: "[beliefs] baseRate is required.",
|
|
580
|
+
status: 400,
|
|
581
|
+
code: "INVALID_REQUEST",
|
|
582
|
+
invariantCode: "request.valid_shape",
|
|
583
|
+
suggestion: "Provide baseRate in the request payload."
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
validateOpinionComponent(baseRate, "baseRate");
|
|
587
|
+
return baseRate;
|
|
588
|
+
}
|
|
574
589
|
function clampNumber(value, min, max) {
|
|
575
590
|
return Math.max(min, Math.min(max, value));
|
|
576
591
|
}
|
|
@@ -607,6 +622,15 @@ function decodeExternalId(id, expectedPrefix) {
|
|
|
607
622
|
function encodeId(prefix, rawId) {
|
|
608
623
|
return encodePrefixedId(prefix, normalizeRequiredString(rawId, "rawId"));
|
|
609
624
|
}
|
|
625
|
+
function encodeHistoryReferenceId(prefix, value) {
|
|
626
|
+
const normalized = normalizeRequiredString(value, "historyReferenceId");
|
|
627
|
+
try {
|
|
628
|
+
const decoded = decodePrefixedId(normalized);
|
|
629
|
+
return encodeId(prefix, decoded.value);
|
|
630
|
+
} catch {
|
|
631
|
+
return encodeId(prefix, normalized);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
610
634
|
function normalizeBeliefRecordStatus(value) {
|
|
611
635
|
const normalized = readString(value)?.toLowerCase();
|
|
612
636
|
if (normalized === "active" || normalized === "superseded" || normalized === "archived") {
|
|
@@ -631,11 +655,6 @@ function normalizeForkReason(value) {
|
|
|
631
655
|
function normalizeConfidenceTrigger(value) {
|
|
632
656
|
const normalized = readString(value)?.toLowerCase();
|
|
633
657
|
switch (normalized) {
|
|
634
|
-
case "merge_outcome":
|
|
635
|
-
case "sprint_outcome":
|
|
636
|
-
return "worktree_outcome";
|
|
637
|
-
case "sprint_completed":
|
|
638
|
-
return "worktree_completed";
|
|
639
658
|
case "evidence_added":
|
|
640
659
|
case "evidence_removed":
|
|
641
660
|
case "contradiction_detected":
|
|
@@ -645,6 +664,10 @@ function normalizeConfidenceTrigger(value) {
|
|
|
645
664
|
case "agent_assessment":
|
|
646
665
|
case "worktree_outcome":
|
|
647
666
|
case "worktree_completed":
|
|
667
|
+
case "fusion":
|
|
668
|
+
case "discount":
|
|
669
|
+
case "deduction":
|
|
670
|
+
case "backfill_synthetic":
|
|
648
671
|
return normalized;
|
|
649
672
|
default:
|
|
650
673
|
return "manual";
|
|
@@ -753,6 +776,7 @@ function normalizeBeliefRecord(value) {
|
|
|
753
776
|
);
|
|
754
777
|
const canonicalId = encodeId("bel", rawId);
|
|
755
778
|
const confidence = readNumber(record.confidence);
|
|
779
|
+
const tupleContradicted = typeof record.tupleContradicted === "boolean" ? record.tupleContradicted : typeof metadata.tupleContradicted === "boolean" ? metadata.tupleContradicted : void 0;
|
|
756
780
|
const text = readString(record.canonicalText) ?? readString(record.formulation) ?? readString(record.text) ?? "";
|
|
757
781
|
return {
|
|
758
782
|
id: canonicalId,
|
|
@@ -766,6 +790,7 @@ function normalizeBeliefRecord(value) {
|
|
|
766
790
|
status: normalizeBeliefRecordStatus(record.status ?? metadata.status),
|
|
767
791
|
scoringState: confidence === void 0 ? "unscored" : "scored",
|
|
768
792
|
...confidence !== void 0 ? { confidence } : {},
|
|
793
|
+
...tupleContradicted !== void 0 ? { tupleContradicted } : {},
|
|
769
794
|
...readString(record.beliefStatus) ?? readString(metadata.beliefStatus) ? {
|
|
770
795
|
beliefStatus: readString(record.beliefStatus) ?? readString(metadata.beliefStatus)
|
|
771
796
|
} : {},
|
|
@@ -813,6 +838,9 @@ function normalizeHistoryEntry(value) {
|
|
|
813
838
|
if (baseRate !== void 0) {
|
|
814
839
|
opinion.a = baseRate;
|
|
815
840
|
}
|
|
841
|
+
const triggeringEvidenceRawId = readString(record.triggeringEvidenceId) ?? readStringArray(record.triggeringEvidenceIds)?.[0];
|
|
842
|
+
const triggeringWorktreeRawId = readString(record.triggeringWorktreeId);
|
|
843
|
+
const slOperator = readString(record.slOperator);
|
|
816
844
|
return {
|
|
817
845
|
...readString(record._id) ? { id: readString(record._id) } : {},
|
|
818
846
|
confidence: clampNumber(readNumber(record.confidence) ?? 0, 0, 1),
|
|
@@ -824,6 +852,19 @@ function normalizeHistoryEntry(value) {
|
|
|
824
852
|
...readString(record.assessedBy) ?? readString(record.userId) ? {
|
|
825
853
|
userId: readString(record.assessedBy) ?? readString(record.userId)
|
|
826
854
|
} : {},
|
|
855
|
+
...slOperator ? { slOperator } : {},
|
|
856
|
+
...triggeringEvidenceRawId ? {
|
|
857
|
+
triggeringEvidenceId: encodeHistoryReferenceId(
|
|
858
|
+
"evi",
|
|
859
|
+
triggeringEvidenceRawId
|
|
860
|
+
)
|
|
861
|
+
} : {},
|
|
862
|
+
...triggeringWorktreeRawId ? {
|
|
863
|
+
triggeringWorktreeId: encodeHistoryReferenceId(
|
|
864
|
+
"wt",
|
|
865
|
+
triggeringWorktreeRawId
|
|
866
|
+
)
|
|
867
|
+
} : {},
|
|
827
868
|
...Object.keys(opinion).length > 0 ? { opinion } : {}
|
|
828
869
|
};
|
|
829
870
|
}
|
|
@@ -979,13 +1020,80 @@ function toOpinion(confidence, certainty) {
|
|
|
979
1020
|
a: 0.5
|
|
980
1021
|
};
|
|
981
1022
|
}
|
|
1023
|
+
function validateOpinionComponent(value, field) {
|
|
1024
|
+
if (value < 0 || value > 1) {
|
|
1025
|
+
throwBeliefsError({
|
|
1026
|
+
message: `[beliefs] ${field} must be within [0, 1].`,
|
|
1027
|
+
status: 400,
|
|
1028
|
+
code: "INVALID_REQUEST",
|
|
1029
|
+
invariantCode: "belief.confidence_append_only",
|
|
1030
|
+
suggestion: `Clamp ${field} into the inclusive [0, 1] interval.`
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
function normalizeOpinionTuple(input) {
|
|
1035
|
+
const belief = readNumber(input.belief);
|
|
1036
|
+
const disbelief = readNumber(input.disbelief);
|
|
1037
|
+
const uncertainty = readNumber(input.uncertainty);
|
|
1038
|
+
const baseRate = readNumber(input.baseRate);
|
|
1039
|
+
const tupleValues = [belief, disbelief, uncertainty, baseRate];
|
|
1040
|
+
const providedTupleCount = tupleValues.filter(
|
|
1041
|
+
(value) => value !== void 0
|
|
1042
|
+
).length;
|
|
1043
|
+
if (providedTupleCount > 0) {
|
|
1044
|
+
if (providedTupleCount !== tupleValues.length) {
|
|
1045
|
+
throwBeliefsError({
|
|
1046
|
+
message: "[beliefs] belief, disbelief, uncertainty, and baseRate must all be provided together.",
|
|
1047
|
+
status: 400,
|
|
1048
|
+
code: "INVALID_REQUEST",
|
|
1049
|
+
invariantCode: "belief.confidence_append_only",
|
|
1050
|
+
suggestion: "Provide the full subjective-logic tuple or fall back to scalar confidence + certainty."
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
1053
|
+
validateOpinionComponent(belief, "belief");
|
|
1054
|
+
validateOpinionComponent(disbelief, "disbelief");
|
|
1055
|
+
validateOpinionComponent(uncertainty, "uncertainty");
|
|
1056
|
+
validateOpinionComponent(baseRate, "baseRate");
|
|
1057
|
+
return {
|
|
1058
|
+
b: belief,
|
|
1059
|
+
d: disbelief,
|
|
1060
|
+
u: uncertainty,
|
|
1061
|
+
a: baseRate
|
|
1062
|
+
};
|
|
1063
|
+
}
|
|
1064
|
+
const confidence = readNumber(input.confidence);
|
|
1065
|
+
if (confidence === void 0) {
|
|
1066
|
+
throwBeliefsError({
|
|
1067
|
+
message: "[beliefs] confidence is required when no subjective-logic tuple is provided.",
|
|
1068
|
+
status: 400,
|
|
1069
|
+
code: "INVALID_REQUEST",
|
|
1070
|
+
invariantCode: "belief.confidence_append_only",
|
|
1071
|
+
suggestion: "Provide either confidence in [0, 1] or the full belief/disbelief/uncertainty/baseRate tuple."
|
|
1072
|
+
});
|
|
1073
|
+
}
|
|
1074
|
+
if (confidence < 0 || confidence > 1) {
|
|
1075
|
+
throwBeliefsError({
|
|
1076
|
+
message: "[beliefs] confidence must be within [0, 1].",
|
|
1077
|
+
status: 400,
|
|
1078
|
+
code: "INVALID_REQUEST",
|
|
1079
|
+
invariantCode: "belief.confidence_append_only",
|
|
1080
|
+
suggestion: "Clamp confidence into the inclusive [0, 1] interval."
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
return toOpinion(confidence, readNumber(input.certainty));
|
|
1084
|
+
}
|
|
1085
|
+
function projectOpinion(opinion) {
|
|
1086
|
+
return opinion.b + opinion.a * opinion.u;
|
|
1087
|
+
}
|
|
982
1088
|
async function createBelief(port, input) {
|
|
1089
|
+
const baseRate = normalizeRequiredBaseRate(input.baseRate);
|
|
983
1090
|
const created = await port.createBelief({
|
|
984
1091
|
topicId: normalizeRequiredString(input.topicId, "topicId"),
|
|
985
1092
|
text: normalizeRequiredString(input.text, "text"),
|
|
986
1093
|
rationale: readString(input.rationale),
|
|
987
1094
|
worktreeId: readString(input.worktreeId),
|
|
988
1095
|
pillar: readString(input.pillar),
|
|
1096
|
+
baseRate,
|
|
989
1097
|
sourceBeliefRawIds: readStringArray(input.sourceBeliefIds)?.map(
|
|
990
1098
|
(id) => decodeExternalId(id, "bel")
|
|
991
1099
|
),
|
|
@@ -1086,38 +1194,38 @@ async function forkBelief(port, input) {
|
|
|
1086
1194
|
forkReason
|
|
1087
1195
|
};
|
|
1088
1196
|
}
|
|
1089
|
-
async function updateBeliefConfidence(port, input) {
|
|
1197
|
+
async function updateBeliefConfidence(port, input, options) {
|
|
1090
1198
|
const rawId = decodeExternalId(
|
|
1091
1199
|
normalizeRequiredString(input.id, "beliefId"),
|
|
1092
1200
|
"bel"
|
|
1093
1201
|
);
|
|
1094
|
-
const
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
}
|
|
1104
|
-
if (
|
|
1202
|
+
const opinion = normalizeOpinionTuple(input);
|
|
1203
|
+
const projectedConfidence = projectOpinion(opinion);
|
|
1204
|
+
const existing = await port.fetchBelief(rawId);
|
|
1205
|
+
const policy = allowAlwaysPolicy;
|
|
1206
|
+
const decision = await policy.canScore({
|
|
1207
|
+
beliefId: encodeId("bel", rawId),
|
|
1208
|
+
topicId: readString(asRecord(existing).topicId),
|
|
1209
|
+
tenantId: readString(asRecord(existing).tenantId),
|
|
1210
|
+
metadata: asOptionalRecord(asRecord(existing).metadata)
|
|
1211
|
+
});
|
|
1212
|
+
if (!decision.allow) {
|
|
1105
1213
|
throwBeliefsError({
|
|
1106
|
-
message:
|
|
1107
|
-
status:
|
|
1108
|
-
code: "
|
|
1109
|
-
invariantCode: "belief.
|
|
1110
|
-
suggestion:
|
|
1214
|
+
message: `[beliefs] ${decision.reason}`,
|
|
1215
|
+
status: 409,
|
|
1216
|
+
code: "SCORING_GATED",
|
|
1217
|
+
invariantCode: "belief.scoring.gated",
|
|
1218
|
+
suggestion: decision.suggestion,
|
|
1219
|
+
details: { beliefId: encodeId("bel", rawId) }
|
|
1111
1220
|
});
|
|
1112
1221
|
}
|
|
1113
1222
|
const trigger = normalizeConfidenceTrigger(input.trigger);
|
|
1114
1223
|
const rationale = normalizeRequiredString(input.rationale, "rationale");
|
|
1115
1224
|
const result = await port.modulateConfidence({
|
|
1116
1225
|
beliefRawId: rawId,
|
|
1117
|
-
|
|
1226
|
+
opinion,
|
|
1118
1227
|
trigger,
|
|
1119
|
-
rationale
|
|
1120
|
-
certainty: readNumber(input.certainty)
|
|
1228
|
+
rationale
|
|
1121
1229
|
});
|
|
1122
1230
|
const requestId = createRequestId();
|
|
1123
1231
|
const relationships = normalizeRelationships(await port.getRelationships(rawId));
|
|
@@ -1134,12 +1242,11 @@ async function updateBeliefConfidence(port, input) {
|
|
|
1134
1242
|
await port.getConfidenceHistory(rawId)
|
|
1135
1243
|
).entries;
|
|
1136
1244
|
const latestEntry = historyEntries[0];
|
|
1137
|
-
const opinion = toOpinion(confidence, readNumber(input.certainty));
|
|
1138
1245
|
return {
|
|
1139
1246
|
beliefId: encodeId("bel", rawId),
|
|
1140
1247
|
nodeId: encodeId("bel", rawId),
|
|
1141
1248
|
previousConfidence: readNumber(asRecord(result).previousConfidence) ?? latestEntry?.confidence ?? 0.5,
|
|
1142
|
-
newConfidence: readNumber(asRecord(result).newConfidence) ?? readNumber(asRecord(result).confidence) ??
|
|
1249
|
+
newConfidence: readNumber(asRecord(result).newConfidence) ?? readNumber(asRecord(result).confidence) ?? projectedConfidence,
|
|
1143
1250
|
trigger,
|
|
1144
1251
|
rationale,
|
|
1145
1252
|
requestId,
|
|
@@ -1272,16 +1379,6 @@ async function bisectBeliefConfidence(port, input) {
|
|
|
1272
1379
|
}
|
|
1273
1380
|
|
|
1274
1381
|
// ../server-core/src/beliefs.ts
|
|
1275
|
-
function toSubjectiveLogicOpinion(confidence, certainty) {
|
|
1276
|
-
const boundedConfidence = Math.max(0, Math.min(confidence, 1));
|
|
1277
|
-
const boundedCertainty = typeof certainty === "number" && Number.isFinite(certainty) ? Math.max(0, Math.min(certainty, 1)) : boundedConfidence === 0.5 ? 0.75 : 1;
|
|
1278
|
-
return {
|
|
1279
|
-
belief: boundedConfidence * boundedCertainty,
|
|
1280
|
-
disbelief: (1 - boundedConfidence) * boundedCertainty,
|
|
1281
|
-
uncertainty: Math.max(0, 1 - boundedCertainty),
|
|
1282
|
-
baseRate: 0.5
|
|
1283
|
-
};
|
|
1284
|
-
}
|
|
1285
1382
|
function resolveBeliefNodeId(value) {
|
|
1286
1383
|
const normalized = value.id ?? value.nodeId ?? value.beliefId ?? "";
|
|
1287
1384
|
try {
|
|
@@ -1357,6 +1454,7 @@ function createGatewayBeliefPort(authContext) {
|
|
|
1357
1454
|
rationale: input.rationale,
|
|
1358
1455
|
worktreeId: input.worktreeId,
|
|
1359
1456
|
pillar: input.pillar,
|
|
1457
|
+
baseRate: input.baseRate,
|
|
1360
1458
|
sourceBeliefIds: input.sourceBeliefRawIds,
|
|
1361
1459
|
sourceType: input.sourceType,
|
|
1362
1460
|
beliefType: input.beliefType,
|
|
@@ -1367,15 +1465,12 @@ function createGatewayBeliefPort(authContext) {
|
|
|
1367
1465
|
});
|
|
1368
1466
|
},
|
|
1369
1467
|
refineBelief(input) {
|
|
1370
|
-
return authContext.convex.mutation(
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
userId: authContext.userId
|
|
1377
|
-
}
|
|
1378
|
-
);
|
|
1468
|
+
return authContext.convex.mutation(api.epistemicBeliefs.refineBelief, {
|
|
1469
|
+
nodeId: input.beliefRawId,
|
|
1470
|
+
canonicalText: input.text,
|
|
1471
|
+
rationale: input.rationale,
|
|
1472
|
+
userId: authContext.userId
|
|
1473
|
+
});
|
|
1379
1474
|
},
|
|
1380
1475
|
forkBelief(input) {
|
|
1381
1476
|
return authContext.convex.mutation(api.epistemicBeliefs.forkBelief, {
|
|
@@ -1387,16 +1482,15 @@ function createGatewayBeliefPort(authContext) {
|
|
|
1387
1482
|
});
|
|
1388
1483
|
},
|
|
1389
1484
|
modulateConfidence(input) {
|
|
1390
|
-
const opinion = toSubjectiveLogicOpinion(
|
|
1391
|
-
input.confidence,
|
|
1392
|
-
input.certainty
|
|
1393
|
-
);
|
|
1394
1485
|
return authContext.convex.mutation(api.epistemicBeliefs.modulateConfidence, {
|
|
1395
1486
|
nodeId: input.beliefRawId,
|
|
1396
1487
|
trigger: input.trigger,
|
|
1397
1488
|
rationale: input.rationale,
|
|
1398
1489
|
userId: authContext.userId,
|
|
1399
|
-
|
|
1490
|
+
belief: input.opinion.b,
|
|
1491
|
+
disbelief: input.opinion.d,
|
|
1492
|
+
uncertainty: input.opinion.u,
|
|
1493
|
+
baseRate: input.opinion.a
|
|
1400
1494
|
});
|
|
1401
1495
|
},
|
|
1402
1496
|
archiveBelief(input) {
|
|
@@ -1455,6 +1549,7 @@ async function createBeliefFromGatewayAuth(authContext, input) {
|
|
|
1455
1549
|
rationale: input.rationale,
|
|
1456
1550
|
worktreeId: input.worktreeId,
|
|
1457
1551
|
pillar: input.pillar,
|
|
1552
|
+
baseRate: input.baseRate,
|
|
1458
1553
|
sourceBeliefIds: input.sourceBeliefIds ?? [],
|
|
1459
1554
|
sourceType: input.sourceType,
|
|
1460
1555
|
beliefType: input.beliefType,
|
|
@@ -1659,7 +1754,7 @@ function bisectBeliefConfidenceFromGatewayAuth(authContext, input) {
|
|
|
1659
1754
|
return bisectBeliefConfidence(createGatewayBeliefPort(authContext), input);
|
|
1660
1755
|
}
|
|
1661
1756
|
|
|
1662
|
-
// ../../
|
|
1757
|
+
// ../../apps/gateway/src/routes/beliefs.ts
|
|
1663
1758
|
function asRecord2(value) {
|
|
1664
1759
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
1665
1760
|
}
|
|
@@ -1714,6 +1809,7 @@ async function handleBeliefCreate(args) {
|
|
|
1714
1809
|
rationale: readString2(body.rationale),
|
|
1715
1810
|
worktreeId: readString2(body.worktreeId),
|
|
1716
1811
|
pillar: readString2(body.pillar),
|
|
1812
|
+
baseRate: readNumber2(body.baseRate) ?? Number.NaN,
|
|
1717
1813
|
sourceBeliefIds: readStringArray2(body.sourceBeliefIds),
|
|
1718
1814
|
sourceType: readString2(body.sourceType),
|
|
1719
1815
|
beliefType: readString2(body.beliefType),
|
|
@@ -2413,7 +2509,7 @@ function createContextServerCore(ports) {
|
|
|
2413
2509
|
};
|
|
2414
2510
|
}
|
|
2415
2511
|
|
|
2416
|
-
// ../../
|
|
2512
|
+
// ../../apps/gateway/src/routes/context.ts
|
|
2417
2513
|
function createContextGatewayRoute(deps) {
|
|
2418
2514
|
const core = createContextServerCore(deps);
|
|
2419
2515
|
return {
|
|
@@ -2547,7 +2643,7 @@ function extractBeliefRef(value) {
|
|
|
2547
2643
|
return direct ? normalizeBeliefId(direct) : void 0;
|
|
2548
2644
|
}
|
|
2549
2645
|
function extractBeliefB(record) {
|
|
2550
|
-
const direct = readString3(record.beliefB) ?? readString3(asRecord3(record.metadata).beliefB) ?? readString3(asRecord3(record.aiAnalysis).beliefB);
|
|
2646
|
+
const direct = readString3(record.beliefBId) ?? readString3(record.beliefB) ?? readString3(asRecord3(record.metadata).beliefB) ?? readString3(asRecord3(record.aiAnalysis).beliefB);
|
|
2551
2647
|
if (direct) {
|
|
2552
2648
|
return normalizeBeliefId(direct);
|
|
2553
2649
|
}
|
|
@@ -2575,6 +2671,7 @@ function normalizeContradictionRecord(value) {
|
|
|
2575
2671
|
throw new Error("[contradictions] beliefA is required.");
|
|
2576
2672
|
}
|
|
2577
2673
|
const status = readString3(record.status) ?? readString3(record.resolutionStatus) ?? readString3(metadata.status) ?? "unresolved";
|
|
2674
|
+
const source = readString3(record.source) ?? readString3(metadata.source);
|
|
2578
2675
|
return {
|
|
2579
2676
|
id: encodeId2("con", rawContradictionId),
|
|
2580
2677
|
contradictionId: encodeId2("con", rawContradictionId),
|
|
@@ -2589,6 +2686,7 @@ function normalizeContradictionRecord(value) {
|
|
|
2589
2686
|
defeatType: normalizeDefeatType(
|
|
2590
2687
|
metadata.defeatType ?? aiAnalysis.defeatType ?? record.defeatType
|
|
2591
2688
|
),
|
|
2689
|
+
...source === "evidence_links" || source === "tuple_space" ? { source } : {},
|
|
2592
2690
|
...readNumber3(record.createdAt) !== void 0 ? { createdAt: readNumber3(record.createdAt) } : {},
|
|
2593
2691
|
...readNumber3(record.updatedAt) !== void 0 ? { updatedAt: readNumber3(record.updatedAt) } : {},
|
|
2594
2692
|
...Object.keys(metadata).length > 0 ? { metadata } : {}
|
|
@@ -2808,7 +2906,7 @@ async function getContradictionFromGatewayAuth(authContext, id) {
|
|
|
2808
2906
|
return contradiction;
|
|
2809
2907
|
}
|
|
2810
2908
|
|
|
2811
|
-
// ../../
|
|
2909
|
+
// ../../apps/gateway/src/routes/contradictions.ts
|
|
2812
2910
|
function asRecord5(value) {
|
|
2813
2911
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
2814
2912
|
}
|
|
@@ -3309,7 +3407,7 @@ function deleteEdgesFromGatewayAuth(authContext, input) {
|
|
|
3309
3407
|
});
|
|
3310
3408
|
}
|
|
3311
3409
|
|
|
3312
|
-
// ../../
|
|
3410
|
+
// ../../apps/gateway/src/routes/edges.ts
|
|
3313
3411
|
function asRecord8(value) {
|
|
3314
3412
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
3315
3413
|
}
|
|
@@ -3560,7 +3658,7 @@ async function handleEdgeDelete(args) {
|
|
|
3560
3658
|
}
|
|
3561
3659
|
}
|
|
3562
3660
|
|
|
3563
|
-
// ../../
|
|
3661
|
+
// ../../apps/gateway/src/routes/events.ts
|
|
3564
3662
|
function handleEventsError(error, fallbackMessage, correlationId, policyTraceId) {
|
|
3565
3663
|
const resolved = resolveGatewayError(error, fallbackMessage);
|
|
3566
3664
|
return errorResponse({
|
|
@@ -4124,6 +4222,27 @@ async function linkEvidenceFromGatewayAuth(authContext, input) {
|
|
|
4124
4222
|
function searchEvidenceFromGatewayAuth(authContext, query) {
|
|
4125
4223
|
return searchEvidence(createGatewayEvidencePort(authContext), query);
|
|
4126
4224
|
}
|
|
4225
|
+
function classifyEvidenceFromGatewayAuth(authContext, input) {
|
|
4226
|
+
return authContext.convex.action(api.evidenceClassifier.classifyEvidence, {
|
|
4227
|
+
beliefId: resolveExternalId3(input.beliefId) ?? input.beliefId,
|
|
4228
|
+
evidenceId: resolveExternalId3(input.evidenceId) ?? input.evidenceId,
|
|
4229
|
+
createdBy: authContext.principalId ?? authContext.userId ?? "unknown",
|
|
4230
|
+
config: input.config
|
|
4231
|
+
});
|
|
4232
|
+
}
|
|
4233
|
+
function classifyEvidenceBatchFromGatewayAuth(authContext, input) {
|
|
4234
|
+
return authContext.convex.action(api.evidenceClassifier.classifyEvidenceBatch, {
|
|
4235
|
+
beliefId: resolveExternalId3(input.beliefId) ?? input.beliefId,
|
|
4236
|
+
evidence: input.evidence.map((item) => ({
|
|
4237
|
+
evidenceId: resolveExternalId3(item.evidenceId),
|
|
4238
|
+
insightId: resolveExternalId3(item.insightId),
|
|
4239
|
+
nodeId: resolveExternalId3(item.nodeId),
|
|
4240
|
+
text: item.text
|
|
4241
|
+
})),
|
|
4242
|
+
createdBy: authContext.principalId ?? authContext.userId ?? "unknown",
|
|
4243
|
+
config: input.config
|
|
4244
|
+
});
|
|
4245
|
+
}
|
|
4127
4246
|
async function updateEvidenceStatusFromGatewayAuth(authContext, input) {
|
|
4128
4247
|
const resolvedNodeId = await resolveEvidenceNodeIdWithGatewayAuth(
|
|
4129
4248
|
authContext,
|
|
@@ -4187,7 +4306,7 @@ async function updateEvidenceVerificationStatusFromGatewayAuth(authContext, inpu
|
|
|
4187
4306
|
});
|
|
4188
4307
|
}
|
|
4189
4308
|
|
|
4190
|
-
// ../../
|
|
4309
|
+
// ../../apps/gateway/src/routes/evidence.ts
|
|
4191
4310
|
function asRecord10(value) {
|
|
4192
4311
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
4193
4312
|
}
|
|
@@ -4208,6 +4327,21 @@ function readStringArray4(value) {
|
|
|
4208
4327
|
const items = value.map((entry) => readString11(entry)).filter((entry) => Boolean(entry));
|
|
4209
4328
|
return items.length > 0 ? items : void 0;
|
|
4210
4329
|
}
|
|
4330
|
+
function readEvidenceClassificationConfig(value) {
|
|
4331
|
+
const config = asRecord10(value);
|
|
4332
|
+
return Object.keys(config).length > 0 ? config : void 0;
|
|
4333
|
+
}
|
|
4334
|
+
function readEvidenceClassificationBatch(value) {
|
|
4335
|
+
if (!Array.isArray(value)) {
|
|
4336
|
+
return [];
|
|
4337
|
+
}
|
|
4338
|
+
return value.map((entry) => asRecord10(entry)).map((entry) => ({
|
|
4339
|
+
evidenceId: readString11(entry.evidenceId),
|
|
4340
|
+
insightId: readString11(entry.insightId),
|
|
4341
|
+
nodeId: readString11(entry.nodeId),
|
|
4342
|
+
text: readString11(entry.text)
|
|
4343
|
+
}));
|
|
4344
|
+
}
|
|
4211
4345
|
async function handleEvidenceCreate(args) {
|
|
4212
4346
|
try {
|
|
4213
4347
|
const body = asRecord10(args.body);
|
|
@@ -4344,6 +4478,67 @@ async function handleEvidenceSearch(args) {
|
|
|
4344
4478
|
});
|
|
4345
4479
|
}
|
|
4346
4480
|
}
|
|
4481
|
+
async function handleEvidenceClassify(args) {
|
|
4482
|
+
try {
|
|
4483
|
+
const body = asRecord10(args.body);
|
|
4484
|
+
const payload = await classifyEvidenceFromGatewayAuth(args.authContext, {
|
|
4485
|
+
beliefId: readString11(body.beliefId) ?? "",
|
|
4486
|
+
evidenceId: readString11(body.evidenceId) ?? "",
|
|
4487
|
+
config: readEvidenceClassificationConfig(body.config)
|
|
4488
|
+
});
|
|
4489
|
+
return successResponse(payload, {
|
|
4490
|
+
correlationId: args.correlationId,
|
|
4491
|
+
policyTraceId: args.policyTraceId
|
|
4492
|
+
});
|
|
4493
|
+
} catch (error) {
|
|
4494
|
+
const resolved = resolveGatewayError(
|
|
4495
|
+
error,
|
|
4496
|
+
"Failed to classify evidence."
|
|
4497
|
+
);
|
|
4498
|
+
return errorResponse({
|
|
4499
|
+
code: resolved.code,
|
|
4500
|
+
message: resolved.message,
|
|
4501
|
+
status: resolved.status,
|
|
4502
|
+
correlationId: args.correlationId,
|
|
4503
|
+
policyTraceId: args.policyTraceId,
|
|
4504
|
+
invariant: resolved.invariant,
|
|
4505
|
+
suggestion: resolved.suggestion,
|
|
4506
|
+
details: resolved.details
|
|
4507
|
+
});
|
|
4508
|
+
}
|
|
4509
|
+
}
|
|
4510
|
+
async function handleEvidenceClassifyBatch(args) {
|
|
4511
|
+
try {
|
|
4512
|
+
const body = asRecord10(args.body);
|
|
4513
|
+
const payload = await classifyEvidenceBatchFromGatewayAuth(
|
|
4514
|
+
args.authContext,
|
|
4515
|
+
{
|
|
4516
|
+
beliefId: readString11(body.beliefId) ?? "",
|
|
4517
|
+
evidence: readEvidenceClassificationBatch(body.evidence),
|
|
4518
|
+
config: readEvidenceClassificationConfig(body.config)
|
|
4519
|
+
}
|
|
4520
|
+
);
|
|
4521
|
+
return successResponse(payload, {
|
|
4522
|
+
correlationId: args.correlationId,
|
|
4523
|
+
policyTraceId: args.policyTraceId
|
|
4524
|
+
});
|
|
4525
|
+
} catch (error) {
|
|
4526
|
+
const resolved = resolveGatewayError(
|
|
4527
|
+
error,
|
|
4528
|
+
"Failed to classify evidence batch."
|
|
4529
|
+
);
|
|
4530
|
+
return errorResponse({
|
|
4531
|
+
code: resolved.code,
|
|
4532
|
+
message: resolved.message,
|
|
4533
|
+
status: resolved.status,
|
|
4534
|
+
correlationId: args.correlationId,
|
|
4535
|
+
policyTraceId: args.policyTraceId,
|
|
4536
|
+
invariant: resolved.invariant,
|
|
4537
|
+
suggestion: resolved.suggestion,
|
|
4538
|
+
details: resolved.details
|
|
4539
|
+
});
|
|
4540
|
+
}
|
|
4541
|
+
}
|
|
4347
4542
|
async function handleEvidenceUpdateStatus(args) {
|
|
4348
4543
|
try {
|
|
4349
4544
|
const body = asRecord10(args.body);
|
|
@@ -5578,7 +5773,7 @@ function graphFalsifyFromGatewayAuth(authContext, input) {
|
|
|
5578
5773
|
return graphFalsify(createGatewayGraphPort(authContext), input);
|
|
5579
5774
|
}
|
|
5580
5775
|
|
|
5581
|
-
// ../../
|
|
5776
|
+
// ../../apps/gateway/src/routes/graph.ts
|
|
5582
5777
|
function asRecord14(value) {
|
|
5583
5778
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
5584
5779
|
}
|
|
@@ -5893,7 +6088,7 @@ async function identitySummaryFromGatewayAuth(authContext) {
|
|
|
5893
6088
|
return buildPrincipalContext(claims);
|
|
5894
6089
|
}
|
|
5895
6090
|
|
|
5896
|
-
// ../../
|
|
6091
|
+
// ../../apps/gateway/src/routes/identity.ts
|
|
5897
6092
|
async function handleIdentityWhoami(args) {
|
|
5898
6093
|
try {
|
|
5899
6094
|
const summary = await identitySummaryFromGatewayAuth(args.authContext);
|
|
@@ -6360,7 +6555,7 @@ function matchOntologyFromGatewayAuth(authContext, input) {
|
|
|
6360
6555
|
return matchOntology(createGatewayOntologiesPort(authContext), input);
|
|
6361
6556
|
}
|
|
6362
6557
|
|
|
6363
|
-
// ../../
|
|
6558
|
+
// ../../apps/gateway/src/routes/ontologies.ts
|
|
6364
6559
|
function asRecord16(value) {
|
|
6365
6560
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
6366
6561
|
}
|
|
@@ -6463,7 +6658,7 @@ async function handleOntologyMatch(args) {
|
|
|
6463
6658
|
}
|
|
6464
6659
|
}
|
|
6465
6660
|
|
|
6466
|
-
// ../../
|
|
6661
|
+
// ../../apps/gateway/src/routes/questions.ts
|
|
6467
6662
|
function asRecord17(value) {
|
|
6468
6663
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
6469
6664
|
}
|
|
@@ -7094,7 +7289,7 @@ function searchResourcesFromGatewayAuth(authContext, input) {
|
|
|
7094
7289
|
return searchResources(createGatewaySearchPort(authContext), input);
|
|
7095
7290
|
}
|
|
7096
7291
|
|
|
7097
|
-
// ../../
|
|
7292
|
+
// ../../apps/gateway/src/routes/search.ts
|
|
7098
7293
|
function asRecord18(value) {
|
|
7099
7294
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
7100
7295
|
}
|
|
@@ -7166,10 +7361,14 @@ async function handleSearchResources(args) {
|
|
|
7166
7361
|
}
|
|
7167
7362
|
}
|
|
7168
7363
|
|
|
7169
|
-
// ../server-core/src/domain/
|
|
7364
|
+
// ../server-core/src/domain/sources.ts
|
|
7170
7365
|
function asRecord19(value) {
|
|
7171
7366
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
7172
7367
|
}
|
|
7368
|
+
function asOptionalRecord2(value) {
|
|
7369
|
+
const record = asRecord19(value);
|
|
7370
|
+
return Object.keys(record).length > 0 ? record : void 0;
|
|
7371
|
+
}
|
|
7173
7372
|
function readString22(value) {
|
|
7174
7373
|
if (typeof value !== "string") {
|
|
7175
7374
|
return void 0;
|
|
@@ -7180,8 +7379,296 @@ function readString22(value) {
|
|
|
7180
7379
|
function readNumber16(value) {
|
|
7181
7380
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
7182
7381
|
}
|
|
7382
|
+
function throwSourcesError(args) {
|
|
7383
|
+
const error = new Error(args.message);
|
|
7384
|
+
error.status = args.status;
|
|
7385
|
+
error.code = args.code;
|
|
7386
|
+
error.invariantCode = args.invariantCode;
|
|
7387
|
+
error.suggestion = args.suggestion;
|
|
7388
|
+
error.details = args.details;
|
|
7389
|
+
throw error;
|
|
7390
|
+
}
|
|
7183
7391
|
function normalizeRequiredString8(value, field) {
|
|
7184
7392
|
const normalized = readString22(value);
|
|
7393
|
+
if (!normalized) {
|
|
7394
|
+
throwSourcesError({
|
|
7395
|
+
message: `[sources] ${field} is required.`,
|
|
7396
|
+
status: 400,
|
|
7397
|
+
code: "INVALID_REQUEST",
|
|
7398
|
+
invariantCode: "request.valid_shape",
|
|
7399
|
+
suggestion: `Provide ${field} in the request payload.`
|
|
7400
|
+
});
|
|
7401
|
+
}
|
|
7402
|
+
return normalized;
|
|
7403
|
+
}
|
|
7404
|
+
function decodeExternalId7(id, expectedPrefix) {
|
|
7405
|
+
const normalized = normalizeRequiredString8(id, "id");
|
|
7406
|
+
try {
|
|
7407
|
+
const decoded = decodePrefixedId(normalized);
|
|
7408
|
+
if (expectedPrefix && decoded.prefix !== expectedPrefix) {
|
|
7409
|
+
throwSourcesError({
|
|
7410
|
+
message: `[sources] Expected ${expectedPrefix}_ identifier, received ${normalized}.`,
|
|
7411
|
+
status: 400,
|
|
7412
|
+
code: "INVALID_REQUEST",
|
|
7413
|
+
invariantCode: "request.valid_shape",
|
|
7414
|
+
suggestion: `Use a ${expectedPrefix}_ identifier for this operation.`
|
|
7415
|
+
});
|
|
7416
|
+
}
|
|
7417
|
+
return decoded.value;
|
|
7418
|
+
} catch (error) {
|
|
7419
|
+
if (error instanceof Error && error.message.startsWith("[sources]")) {
|
|
7420
|
+
throw error;
|
|
7421
|
+
}
|
|
7422
|
+
return normalized;
|
|
7423
|
+
}
|
|
7424
|
+
}
|
|
7425
|
+
function encodeId6(prefix, rawId) {
|
|
7426
|
+
return encodePrefixedId(prefix, normalizeRequiredString8(rawId, "rawId"));
|
|
7427
|
+
}
|
|
7428
|
+
function extractCreatedRawId3(value) {
|
|
7429
|
+
const record = asRecord19(value);
|
|
7430
|
+
const rawId = readString22(record.nodeId) ?? readString22(record.sourceId) ?? readString22(record.id) ?? readString22(record._id);
|
|
7431
|
+
return normalizeRequiredString8(rawId, "sourceId");
|
|
7432
|
+
}
|
|
7433
|
+
function normalizeSourceUrl(url) {
|
|
7434
|
+
const trimmed = normalizeRequiredString8(url, "url");
|
|
7435
|
+
let parsed;
|
|
7436
|
+
try {
|
|
7437
|
+
parsed = new URL(trimmed);
|
|
7438
|
+
} catch {
|
|
7439
|
+
throwSourcesError({
|
|
7440
|
+
message: `[sources] Invalid URL: ${trimmed}`,
|
|
7441
|
+
status: 400,
|
|
7442
|
+
code: "INVALID_REQUEST",
|
|
7443
|
+
invariantCode: "source.url.valid",
|
|
7444
|
+
suggestion: "Provide an absolute URL with a valid protocol and host.",
|
|
7445
|
+
details: { url: trimmed }
|
|
7446
|
+
});
|
|
7447
|
+
}
|
|
7448
|
+
const protocol = parsed.protocol.toLowerCase();
|
|
7449
|
+
const hostname = parsed.hostname.toLowerCase();
|
|
7450
|
+
const port = parsed.port ? `:${parsed.port}` : "";
|
|
7451
|
+
const pathname = parsed.pathname === "/" ? "" : parsed.pathname.replace(/\/+$/, "");
|
|
7452
|
+
const sortedEntries = [...parsed.searchParams.entries()].sort(
|
|
7453
|
+
([aKey, aValue], [bKey, bValue]) => aKey === bKey ? aValue.localeCompare(bValue) : aKey.localeCompare(bKey)
|
|
7454
|
+
);
|
|
7455
|
+
const search = new URLSearchParams();
|
|
7456
|
+
for (const [key, value] of sortedEntries) {
|
|
7457
|
+
search.append(key, value);
|
|
7458
|
+
}
|
|
7459
|
+
const searchText = search.toString();
|
|
7460
|
+
return `${protocol}//${hostname}${port}${pathname}${searchText.length > 0 ? `?${searchText}` : ""}`;
|
|
7461
|
+
}
|
|
7462
|
+
function normalizeMetadata(metadata) {
|
|
7463
|
+
const record = asOptionalRecord2(metadata);
|
|
7464
|
+
if (!record) {
|
|
7465
|
+
return void 0;
|
|
7466
|
+
}
|
|
7467
|
+
const { url: _ignoredUrl, contentSha: _ignoredSha, ...rest } = record;
|
|
7468
|
+
return Object.keys(rest).length > 0 ? rest : void 0;
|
|
7469
|
+
}
|
|
7470
|
+
function normalizeSourceRecord(value) {
|
|
7471
|
+
const record = asRecord19(value);
|
|
7472
|
+
const metadata = asRecord19(record.metadata);
|
|
7473
|
+
const rawId = decodeExternalId7(
|
|
7474
|
+
normalizeRequiredString8(
|
|
7475
|
+
readString22(record.nodeId) ?? readString22(record.sourceId) ?? readString22(record.id) ?? readString22(record._id),
|
|
7476
|
+
"sourceId"
|
|
7477
|
+
),
|
|
7478
|
+
"src"
|
|
7479
|
+
);
|
|
7480
|
+
const kind = readString22(record.kind) ?? readString22(metadata.kind) ?? "source";
|
|
7481
|
+
return {
|
|
7482
|
+
id: encodeId6("src", rawId),
|
|
7483
|
+
sourceId: encodeId6("src", rawId),
|
|
7484
|
+
nodeId: encodeId6("src", rawId),
|
|
7485
|
+
...readString22(record.globalId) ? { globalId: readString22(record.globalId) } : {},
|
|
7486
|
+
...readString22(metadata.url) ? { url: readString22(metadata.url) } : {},
|
|
7487
|
+
...readString22(metadata.contentSha) ? { contentSha: readString22(metadata.contentSha) } : {},
|
|
7488
|
+
kind,
|
|
7489
|
+
...readString22(record.title) ? { title: readString22(record.title) } : readString22(metadata.title) ? { title: readString22(metadata.title) } : {},
|
|
7490
|
+
...readNumber16(metadata.capturedAt) !== void 0 ? { capturedAt: readNumber16(metadata.capturedAt) } : {},
|
|
7491
|
+
...readString22(record.topicId) ? { topicId: readString22(record.topicId) } : {},
|
|
7492
|
+
...Object.keys(metadata).length > 0 ? { metadata } : {},
|
|
7493
|
+
...readNumber16(record.createdAt) !== void 0 ? { createdAt: readNumber16(record.createdAt) } : {},
|
|
7494
|
+
...readNumber16(record.updatedAt) !== void 0 ? { updatedAt: readNumber16(record.updatedAt) } : {}
|
|
7495
|
+
};
|
|
7496
|
+
}
|
|
7497
|
+
async function upsertSource(port, input) {
|
|
7498
|
+
const inputUrl = readString22(input.url);
|
|
7499
|
+
const normalizedUrl = inputUrl ? normalizeSourceUrl(inputUrl) : void 0;
|
|
7500
|
+
const normalizedSha = readString22(input.sha);
|
|
7501
|
+
if (!normalizedUrl && !normalizedSha) {
|
|
7502
|
+
throwSourcesError({
|
|
7503
|
+
message: "[sources] url or sha is required.",
|
|
7504
|
+
status: 400,
|
|
7505
|
+
code: "INVALID_REQUEST",
|
|
7506
|
+
invariantCode: "source.identity.required",
|
|
7507
|
+
suggestion: "Provide url or sha."
|
|
7508
|
+
});
|
|
7509
|
+
}
|
|
7510
|
+
const payload = await port.upsertSource({
|
|
7511
|
+
url: normalizedUrl,
|
|
7512
|
+
sha: normalizedSha,
|
|
7513
|
+
kind: normalizeRequiredString8(input.kind, "kind"),
|
|
7514
|
+
...readString22(input.title) ? { title: readString22(input.title) } : {},
|
|
7515
|
+
...readNumber16(input.capturedAt) !== void 0 ? { capturedAt: readNumber16(input.capturedAt) } : {},
|
|
7516
|
+
...readString22(input.topicId) ? { topicId: readString22(input.topicId) } : {},
|
|
7517
|
+
...normalizeMetadata(input.metadata) ? { metadata: normalizeMetadata(input.metadata) } : {},
|
|
7518
|
+
userId: normalizeRequiredString8(input.userId, "userId")
|
|
7519
|
+
});
|
|
7520
|
+
const rawId = extractCreatedRawId3(payload);
|
|
7521
|
+
const persisted = await port.fetchSource(rawId);
|
|
7522
|
+
return normalizeSourceRecord(persisted ?? { ...asRecord19(payload), nodeId: rawId });
|
|
7523
|
+
}
|
|
7524
|
+
async function getSource(port, args) {
|
|
7525
|
+
const rawId = decodeExternalId7(
|
|
7526
|
+
normalizeRequiredString8(args.id, "sourceId"),
|
|
7527
|
+
"src"
|
|
7528
|
+
);
|
|
7529
|
+
const record = await port.fetchSource(rawId);
|
|
7530
|
+
if (!record) {
|
|
7531
|
+
throwSourcesError({
|
|
7532
|
+
message: `Source not found: ${args.id}`,
|
|
7533
|
+
status: 404,
|
|
7534
|
+
code: "NOT_FOUND",
|
|
7535
|
+
invariantCode: "source.exists",
|
|
7536
|
+
suggestion: "Verify the source ID and topic scope, then retry.",
|
|
7537
|
+
details: { sourceId: args.id }
|
|
7538
|
+
});
|
|
7539
|
+
}
|
|
7540
|
+
return normalizeSourceRecord(record);
|
|
7541
|
+
}
|
|
7542
|
+
|
|
7543
|
+
// ../server-core/src/sources.ts
|
|
7544
|
+
function createGatewaySourcePort(authContext) {
|
|
7545
|
+
return {
|
|
7546
|
+
upsertSource(input) {
|
|
7547
|
+
return authContext.convex.mutation(api.epistemicSources.upsertSource, {
|
|
7548
|
+
url: input.url,
|
|
7549
|
+
sha: input.sha,
|
|
7550
|
+
kind: input.kind,
|
|
7551
|
+
title: input.title,
|
|
7552
|
+
capturedAt: input.capturedAt,
|
|
7553
|
+
metadata: input.metadata,
|
|
7554
|
+
topicId: input.topicId,
|
|
7555
|
+
userId: authContext.userId
|
|
7556
|
+
});
|
|
7557
|
+
},
|
|
7558
|
+
fetchSource(rawId) {
|
|
7559
|
+
return authContext.convex.query(api.epistemicSources.getById, {
|
|
7560
|
+
sourceId: rawId,
|
|
7561
|
+
nodeId: rawId
|
|
7562
|
+
});
|
|
7563
|
+
},
|
|
7564
|
+
findByUrl(url) {
|
|
7565
|
+
return authContext.convex.query(api.epistemicSources.findByUrl, {
|
|
7566
|
+
url
|
|
7567
|
+
});
|
|
7568
|
+
},
|
|
7569
|
+
findBySha(sha) {
|
|
7570
|
+
return authContext.convex.query(api.epistemicSources.findBySha, {
|
|
7571
|
+
sha
|
|
7572
|
+
});
|
|
7573
|
+
}
|
|
7574
|
+
};
|
|
7575
|
+
}
|
|
7576
|
+
async function upsertSourceFromGatewayAuth(authContext, input) {
|
|
7577
|
+
return upsertSource(createGatewaySourcePort(authContext), {
|
|
7578
|
+
...input,
|
|
7579
|
+
userId: authContext.userId
|
|
7580
|
+
});
|
|
7581
|
+
}
|
|
7582
|
+
function getSourceFromGatewayAuth(authContext, id) {
|
|
7583
|
+
return getSource(createGatewaySourcePort(authContext), { id });
|
|
7584
|
+
}
|
|
7585
|
+
|
|
7586
|
+
// ../../apps/gateway/src/routes/sources.ts
|
|
7587
|
+
function asRecord20(value) {
|
|
7588
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
7589
|
+
}
|
|
7590
|
+
function readString23(value) {
|
|
7591
|
+
if (typeof value !== "string") {
|
|
7592
|
+
return void 0;
|
|
7593
|
+
}
|
|
7594
|
+
const normalized = value.trim();
|
|
7595
|
+
return normalized.length > 0 ? normalized : void 0;
|
|
7596
|
+
}
|
|
7597
|
+
function readNumber17(value) {
|
|
7598
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
7599
|
+
}
|
|
7600
|
+
function handleSourcesError(error, fallbackMessage, correlationId, policyTraceId) {
|
|
7601
|
+
const resolved = resolveGatewayError(error, fallbackMessage);
|
|
7602
|
+
return errorResponse({
|
|
7603
|
+
code: resolved.code,
|
|
7604
|
+
message: resolved.message,
|
|
7605
|
+
status: resolved.status,
|
|
7606
|
+
correlationId,
|
|
7607
|
+
policyTraceId,
|
|
7608
|
+
invariant: resolved.invariant,
|
|
7609
|
+
suggestion: resolved.suggestion,
|
|
7610
|
+
details: resolved.details
|
|
7611
|
+
});
|
|
7612
|
+
}
|
|
7613
|
+
async function handleSourceUpsert(args) {
|
|
7614
|
+
try {
|
|
7615
|
+
const body = asRecord20(args.body);
|
|
7616
|
+
const payload = await upsertSourceFromGatewayAuth(args.authContext, {
|
|
7617
|
+
url: readString23(body.url),
|
|
7618
|
+
sha: readString23(body.sha),
|
|
7619
|
+
kind: readString23(body.kind) ?? "",
|
|
7620
|
+
title: readString23(body.title),
|
|
7621
|
+
capturedAt: readNumber17(body.capturedAt),
|
|
7622
|
+
topicId: readString23(body.topicId),
|
|
7623
|
+
metadata: asRecord20(body.metadata)
|
|
7624
|
+
});
|
|
7625
|
+
return successResponse(payload, {
|
|
7626
|
+
status: 201,
|
|
7627
|
+
correlationId: args.correlationId,
|
|
7628
|
+
policyTraceId: args.policyTraceId
|
|
7629
|
+
});
|
|
7630
|
+
} catch (error) {
|
|
7631
|
+
return handleSourcesError(
|
|
7632
|
+
error,
|
|
7633
|
+
"Failed to upsert source.",
|
|
7634
|
+
args.correlationId,
|
|
7635
|
+
args.policyTraceId
|
|
7636
|
+
);
|
|
7637
|
+
}
|
|
7638
|
+
}
|
|
7639
|
+
async function handleSourceGet(args) {
|
|
7640
|
+
try {
|
|
7641
|
+
const payload = await getSourceFromGatewayAuth(args.authContext, args.sourceId);
|
|
7642
|
+
return successResponse(payload, {
|
|
7643
|
+
correlationId: args.correlationId,
|
|
7644
|
+
policyTraceId: args.policyTraceId
|
|
7645
|
+
});
|
|
7646
|
+
} catch (error) {
|
|
7647
|
+
return handleSourcesError(
|
|
7648
|
+
error,
|
|
7649
|
+
"Failed to read source.",
|
|
7650
|
+
args.correlationId,
|
|
7651
|
+
args.policyTraceId
|
|
7652
|
+
);
|
|
7653
|
+
}
|
|
7654
|
+
}
|
|
7655
|
+
|
|
7656
|
+
// ../server-core/src/domain/tasks.ts
|
|
7657
|
+
function asRecord21(value) {
|
|
7658
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
7659
|
+
}
|
|
7660
|
+
function readString24(value) {
|
|
7661
|
+
if (typeof value !== "string") {
|
|
7662
|
+
return void 0;
|
|
7663
|
+
}
|
|
7664
|
+
const normalized = value.trim();
|
|
7665
|
+
return normalized.length > 0 ? normalized : void 0;
|
|
7666
|
+
}
|
|
7667
|
+
function readNumber18(value) {
|
|
7668
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
7669
|
+
}
|
|
7670
|
+
function normalizeRequiredString9(value, field) {
|
|
7671
|
+
const normalized = readString24(value);
|
|
7185
7672
|
if (!normalized) {
|
|
7186
7673
|
throwTasksError({
|
|
7187
7674
|
message: `[tasks] ${field} is required.`,
|
|
@@ -7203,7 +7690,7 @@ function throwTasksError(args) {
|
|
|
7203
7690
|
throw error;
|
|
7204
7691
|
}
|
|
7205
7692
|
function normalizeTaskStatus(value) {
|
|
7206
|
-
const normalized =
|
|
7693
|
+
const normalized = readString24(value)?.toLowerCase();
|
|
7207
7694
|
switch (normalized) {
|
|
7208
7695
|
case "in_progress":
|
|
7209
7696
|
return "in_progress";
|
|
@@ -7218,7 +7705,7 @@ function normalizeTaskStatus(value) {
|
|
|
7218
7705
|
}
|
|
7219
7706
|
}
|
|
7220
7707
|
function normalizeTaskPriority(value) {
|
|
7221
|
-
const normalized =
|
|
7708
|
+
const normalized = readString24(value)?.toLowerCase();
|
|
7222
7709
|
switch (normalized) {
|
|
7223
7710
|
case "urgent":
|
|
7224
7711
|
case "critical":
|
|
@@ -7232,7 +7719,7 @@ function normalizeTaskPriority(value) {
|
|
|
7232
7719
|
}
|
|
7233
7720
|
}
|
|
7234
7721
|
function normalizeTaskType(value) {
|
|
7235
|
-
const normalized =
|
|
7722
|
+
const normalized = readString24(value)?.toLowerCase();
|
|
7236
7723
|
switch (normalized) {
|
|
7237
7724
|
case "research":
|
|
7238
7725
|
case "interview":
|
|
@@ -7245,30 +7732,30 @@ function normalizeTaskType(value) {
|
|
|
7245
7732
|
}
|
|
7246
7733
|
}
|
|
7247
7734
|
function extractTaskRawId(value, field = "taskId") {
|
|
7248
|
-
const record =
|
|
7249
|
-
const rawId =
|
|
7250
|
-
return
|
|
7735
|
+
const record = asRecord21(value);
|
|
7736
|
+
const rawId = readString24(record.taskId ?? record._id ?? record.id);
|
|
7737
|
+
return normalizeRequiredString9(rawId, field);
|
|
7251
7738
|
}
|
|
7252
7739
|
function normalizeTaskRecord(value) {
|
|
7253
|
-
const record =
|
|
7254
|
-
const metadata =
|
|
7740
|
+
const record = asRecord21(value);
|
|
7741
|
+
const metadata = asRecord21(record.metadata);
|
|
7255
7742
|
const taskId = extractTaskRawId(record);
|
|
7256
7743
|
return {
|
|
7257
7744
|
id: taskId,
|
|
7258
7745
|
taskId,
|
|
7259
|
-
...
|
|
7260
|
-
title:
|
|
7261
|
-
...
|
|
7746
|
+
...readString24(record.topicId) ? { topicId: readString24(record.topicId) } : {},
|
|
7747
|
+
title: normalizeRequiredString9(record.title, "title"),
|
|
7748
|
+
...readString24(record.description) ? { description: readString24(record.description) } : {},
|
|
7262
7749
|
status: normalizeTaskStatus(record.status ?? metadata.status),
|
|
7263
7750
|
priority: normalizeTaskPriority(record.priority ?? metadata.priority),
|
|
7264
7751
|
taskType: normalizeTaskType(record.taskType ?? metadata.taskType),
|
|
7265
|
-
...
|
|
7266
|
-
...
|
|
7267
|
-
...
|
|
7268
|
-
...
|
|
7269
|
-
...
|
|
7270
|
-
...
|
|
7271
|
-
...
|
|
7752
|
+
...readString24(record.linkedBeliefId) ? { linkedBeliefId: readString24(record.linkedBeliefId) } : {},
|
|
7753
|
+
...readString24(record.linkedQuestionId) ? { linkedQuestionId: readString24(record.linkedQuestionId) } : {},
|
|
7754
|
+
...readString24(record.linkedWorktreeId) ? { linkedWorktreeId: readString24(record.linkedWorktreeId) } : {},
|
|
7755
|
+
...readString24(record.outputSummary) ? { outputSummary: readString24(record.outputSummary) } : {},
|
|
7756
|
+
...readNumber18(record.createdAt) ? { createdAt: readNumber18(record.createdAt) } : {},
|
|
7757
|
+
...readNumber18(record.updatedAt) ? { updatedAt: readNumber18(record.updatedAt) } : {},
|
|
7758
|
+
...readNumber18(record.completedAt) ? { completedAt: readNumber18(record.completedAt) } : {},
|
|
7272
7759
|
...Object.keys(metadata).length > 0 ? { metadata } : {}
|
|
7273
7760
|
};
|
|
7274
7761
|
}
|
|
@@ -7287,47 +7774,47 @@ async function fetchNormalizedTask(deps, rawId) {
|
|
|
7287
7774
|
}
|
|
7288
7775
|
async function createTask(deps, input) {
|
|
7289
7776
|
const created = await deps.createTask({
|
|
7290
|
-
topicId:
|
|
7291
|
-
title:
|
|
7292
|
-
description:
|
|
7777
|
+
topicId: normalizeRequiredString9(input.topicId, "topicId"),
|
|
7778
|
+
title: normalizeRequiredString9(input.title, "title"),
|
|
7779
|
+
description: readString24(input.description),
|
|
7293
7780
|
taskType: normalizeTaskType(input.taskType),
|
|
7294
7781
|
priority: normalizeTaskPriority(input.priority),
|
|
7295
|
-
linkedBeliefId:
|
|
7296
|
-
linkedQuestionId:
|
|
7297
|
-
linkedWorktreeId:
|
|
7782
|
+
linkedBeliefId: readString24(input.linkedBeliefId),
|
|
7783
|
+
linkedQuestionId: readString24(input.linkedQuestionId),
|
|
7784
|
+
linkedWorktreeId: readString24(input.linkedWorktreeId),
|
|
7298
7785
|
metadata: input.metadata && typeof input.metadata === "object" && !Array.isArray(input.metadata) ? input.metadata : void 0
|
|
7299
7786
|
});
|
|
7300
7787
|
return fetchNormalizedTask(deps, extractTaskRawId(created, "created task id"));
|
|
7301
7788
|
}
|
|
7302
7789
|
async function updateTask(deps, input) {
|
|
7303
|
-
const taskRawId =
|
|
7790
|
+
const taskRawId = normalizeRequiredString9(input.id, "id");
|
|
7304
7791
|
const hasPatchField = input.title !== void 0 || input.description !== void 0 || input.priority !== void 0 || input.status !== void 0 || input.linkedBeliefId !== void 0 || input.linkedQuestionId !== void 0 || input.linkedWorktreeId !== void 0 || input.metadata !== void 0;
|
|
7305
7792
|
if (hasPatchField) {
|
|
7306
7793
|
await deps.updateTask({
|
|
7307
7794
|
taskRawId,
|
|
7308
|
-
...input.title !== void 0 ? { title:
|
|
7309
|
-
...input.description !== void 0 ? { description:
|
|
7795
|
+
...input.title !== void 0 ? { title: readString24(input.title) } : {},
|
|
7796
|
+
...input.description !== void 0 ? { description: readString24(input.description) } : {},
|
|
7310
7797
|
...input.priority !== void 0 ? { priority: normalizeTaskPriority(input.priority) } : {},
|
|
7311
7798
|
...input.status !== void 0 ? { status: normalizeTaskStatus(input.status) } : {},
|
|
7312
|
-
...input.linkedBeliefId !== void 0 ? { linkedBeliefId:
|
|
7313
|
-
...input.linkedQuestionId !== void 0 ? { linkedQuestionId:
|
|
7314
|
-
...input.linkedWorktreeId !== void 0 ? { linkedWorktreeId:
|
|
7799
|
+
...input.linkedBeliefId !== void 0 ? { linkedBeliefId: readString24(input.linkedBeliefId) } : {},
|
|
7800
|
+
...input.linkedQuestionId !== void 0 ? { linkedQuestionId: readString24(input.linkedQuestionId) } : {},
|
|
7801
|
+
...input.linkedWorktreeId !== void 0 ? { linkedWorktreeId: readString24(input.linkedWorktreeId) } : {},
|
|
7315
7802
|
...input.metadata && typeof input.metadata === "object" && !Array.isArray(input.metadata) ? { metadata: input.metadata } : {}
|
|
7316
7803
|
});
|
|
7317
7804
|
}
|
|
7318
7805
|
return fetchNormalizedTask(deps, taskRawId);
|
|
7319
7806
|
}
|
|
7320
7807
|
async function completeTask(deps, input) {
|
|
7321
|
-
const taskRawId =
|
|
7808
|
+
const taskRawId = normalizeRequiredString9(input.id, "id");
|
|
7322
7809
|
await deps.completeTask({
|
|
7323
7810
|
taskRawId,
|
|
7324
|
-
outputSummary:
|
|
7811
|
+
outputSummary: readString24(input.outputSummary)
|
|
7325
7812
|
});
|
|
7326
7813
|
return fetchNormalizedTask(deps, taskRawId);
|
|
7327
7814
|
}
|
|
7328
7815
|
async function listTasks(deps, query) {
|
|
7329
|
-
const topicId =
|
|
7330
|
-
const worktreeId =
|
|
7816
|
+
const topicId = readString24(query.topicId);
|
|
7817
|
+
const worktreeId = readString24(query.worktreeId);
|
|
7331
7818
|
if (!topicId && !worktreeId) {
|
|
7332
7819
|
throwTasksError({
|
|
7333
7820
|
message: "[tasks] topicId or worktreeId is required.",
|
|
@@ -7499,11 +7986,11 @@ function listTasksFromGatewayAuth(authContext, query) {
|
|
|
7499
7986
|
return listTasks(createGatewayTasksPort(authContext), query);
|
|
7500
7987
|
}
|
|
7501
7988
|
|
|
7502
|
-
// ../../
|
|
7503
|
-
function
|
|
7989
|
+
// ../../apps/gateway/src/routes/tasks.ts
|
|
7990
|
+
function asRecord22(value) {
|
|
7504
7991
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
7505
7992
|
}
|
|
7506
|
-
function
|
|
7993
|
+
function readString25(value) {
|
|
7507
7994
|
if (typeof value !== "string") {
|
|
7508
7995
|
return void 0;
|
|
7509
7996
|
}
|
|
@@ -7525,16 +8012,16 @@ function handleTasksError(error, fallbackMessage, correlationId, policyTraceId)
|
|
|
7525
8012
|
}
|
|
7526
8013
|
async function handleTaskCreate(args) {
|
|
7527
8014
|
try {
|
|
7528
|
-
const body =
|
|
8015
|
+
const body = asRecord22(args.body);
|
|
7529
8016
|
const payload = await createTaskFromGatewayAuth(args.authContext, {
|
|
7530
|
-
topicId:
|
|
7531
|
-
title:
|
|
7532
|
-
description:
|
|
7533
|
-
taskType:
|
|
7534
|
-
priority:
|
|
7535
|
-
linkedBeliefId:
|
|
7536
|
-
linkedQuestionId:
|
|
7537
|
-
linkedWorktreeId:
|
|
8017
|
+
topicId: readString25(body.topicId) ?? "",
|
|
8018
|
+
title: readString25(body.title) ?? "",
|
|
8019
|
+
description: readString25(body.description),
|
|
8020
|
+
taskType: readString25(body.taskType),
|
|
8021
|
+
priority: readString25(body.priority),
|
|
8022
|
+
linkedBeliefId: readString25(body.linkedBeliefId),
|
|
8023
|
+
linkedQuestionId: readString25(body.linkedQuestionId),
|
|
8024
|
+
linkedWorktreeId: readString25(body.linkedWorktreeId),
|
|
7538
8025
|
metadata: body.metadata && typeof body.metadata === "object" && !Array.isArray(body.metadata) ? body.metadata : void 0
|
|
7539
8026
|
});
|
|
7540
8027
|
return successResponse(payload, {
|
|
@@ -7569,16 +8056,16 @@ async function handleTaskList(args) {
|
|
|
7569
8056
|
}
|
|
7570
8057
|
async function handleTaskUpdate(args) {
|
|
7571
8058
|
try {
|
|
7572
|
-
const body =
|
|
8059
|
+
const body = asRecord22(args.body);
|
|
7573
8060
|
const payload = await updateTaskFromGatewayAuth(args.authContext, {
|
|
7574
8061
|
id: args.taskId,
|
|
7575
|
-
title:
|
|
7576
|
-
description:
|
|
7577
|
-
priority:
|
|
7578
|
-
status:
|
|
7579
|
-
linkedBeliefId:
|
|
7580
|
-
linkedQuestionId:
|
|
7581
|
-
linkedWorktreeId:
|
|
8062
|
+
title: readString25(body.title),
|
|
8063
|
+
description: readString25(body.description),
|
|
8064
|
+
priority: readString25(body.priority),
|
|
8065
|
+
status: readString25(body.status),
|
|
8066
|
+
linkedBeliefId: readString25(body.linkedBeliefId),
|
|
8067
|
+
linkedQuestionId: readString25(body.linkedQuestionId),
|
|
8068
|
+
linkedWorktreeId: readString25(body.linkedWorktreeId),
|
|
7582
8069
|
metadata: body.metadata && typeof body.metadata === "object" && !Array.isArray(body.metadata) ? body.metadata : void 0
|
|
7583
8070
|
});
|
|
7584
8071
|
return successResponse(payload, {
|
|
@@ -7596,10 +8083,10 @@ async function handleTaskUpdate(args) {
|
|
|
7596
8083
|
}
|
|
7597
8084
|
async function handleTaskComplete(args) {
|
|
7598
8085
|
try {
|
|
7599
|
-
const body =
|
|
8086
|
+
const body = asRecord22(args.body);
|
|
7600
8087
|
const payload = await completeTaskFromGatewayAuth(args.authContext, {
|
|
7601
8088
|
id: args.taskId,
|
|
7602
|
-
outputSummary:
|
|
8089
|
+
outputSummary: readString25(body.outputSummary)
|
|
7603
8090
|
});
|
|
7604
8091
|
return successResponse(payload, {
|
|
7605
8092
|
correlationId: args.correlationId,
|
|
@@ -7625,28 +8112,28 @@ function createTopicsError(args) {
|
|
|
7625
8112
|
error.details = args.details;
|
|
7626
8113
|
return error;
|
|
7627
8114
|
}
|
|
7628
|
-
function
|
|
8115
|
+
function asRecord23(value) {
|
|
7629
8116
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
7630
8117
|
}
|
|
7631
|
-
function
|
|
8118
|
+
function readString26(value) {
|
|
7632
8119
|
if (typeof value !== "string") {
|
|
7633
8120
|
return void 0;
|
|
7634
8121
|
}
|
|
7635
8122
|
const normalized = value.trim();
|
|
7636
8123
|
return normalized.length > 0 ? normalized : void 0;
|
|
7637
8124
|
}
|
|
7638
|
-
function
|
|
8125
|
+
function readNumber19(value) {
|
|
7639
8126
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
7640
8127
|
}
|
|
7641
8128
|
function readStringArray8(value) {
|
|
7642
8129
|
if (!Array.isArray(value)) {
|
|
7643
8130
|
return void 0;
|
|
7644
8131
|
}
|
|
7645
|
-
const normalized = value.map((entry) =>
|
|
8132
|
+
const normalized = value.map((entry) => readString26(entry)).filter((entry) => Boolean(entry));
|
|
7646
8133
|
return normalized.length > 0 ? normalized : void 0;
|
|
7647
8134
|
}
|
|
7648
8135
|
function requireString2(value, field) {
|
|
7649
|
-
const normalized =
|
|
8136
|
+
const normalized = readString26(value);
|
|
7650
8137
|
if (!normalized) {
|
|
7651
8138
|
throw createTopicsError({
|
|
7652
8139
|
message: `[topics] ${field} is required.`,
|
|
@@ -7658,7 +8145,7 @@ function requireString2(value, field) {
|
|
|
7658
8145
|
}
|
|
7659
8146
|
return normalized;
|
|
7660
8147
|
}
|
|
7661
|
-
function
|
|
8148
|
+
function decodeExternalId8(id, prefix, field) {
|
|
7662
8149
|
const normalized = requireString2(id, field);
|
|
7663
8150
|
try {
|
|
7664
8151
|
const decoded = decodePrefixedId(normalized);
|
|
@@ -7683,22 +8170,22 @@ function encodeTopicId2(rawId) {
|
|
|
7683
8170
|
return encodePrefixedId("top", requireString2(rawId, "topicId"));
|
|
7684
8171
|
}
|
|
7685
8172
|
function normalizeTopicStatus(value) {
|
|
7686
|
-
const normalized =
|
|
8173
|
+
const normalized = readString26(value)?.toLowerCase();
|
|
7687
8174
|
if (normalized === "active" || normalized === "archived" || normalized === "watching") {
|
|
7688
8175
|
return normalized;
|
|
7689
8176
|
}
|
|
7690
8177
|
return void 0;
|
|
7691
8178
|
}
|
|
7692
8179
|
function normalizeTopicVisibility(value) {
|
|
7693
|
-
const normalized =
|
|
8180
|
+
const normalized = readString26(value)?.toLowerCase();
|
|
7694
8181
|
if (normalized === "private" || normalized === "team" || normalized === "firm" || normalized === "external" || normalized === "public") {
|
|
7695
8182
|
return normalized;
|
|
7696
8183
|
}
|
|
7697
8184
|
return void 0;
|
|
7698
8185
|
}
|
|
7699
8186
|
function normalizeTopicRecord(value) {
|
|
7700
|
-
const record =
|
|
7701
|
-
const rawId =
|
|
8187
|
+
const record = asRecord23(value);
|
|
8188
|
+
const rawId = readString26(record.topicId) ?? readString26(record.id) ?? readString26(record._id) ?? readString26(record.projectId);
|
|
7702
8189
|
if (!rawId) {
|
|
7703
8190
|
throw createTopicsError({
|
|
7704
8191
|
message: "[topics] topicId is required in upstream topic payload.",
|
|
@@ -7708,36 +8195,36 @@ function normalizeTopicRecord(value) {
|
|
|
7708
8195
|
});
|
|
7709
8196
|
}
|
|
7710
8197
|
const topicId = encodeTopicId2(rawId);
|
|
7711
|
-
const parentTopicRawId =
|
|
8198
|
+
const parentTopicRawId = readString26(record.parentTopicId);
|
|
7712
8199
|
return {
|
|
7713
8200
|
id: topicId,
|
|
7714
8201
|
topicId,
|
|
7715
|
-
...
|
|
8202
|
+
...readString26(record.globalId) ? { globalId: readString26(record.globalId) } : {},
|
|
7716
8203
|
name: requireString2(record.name, "name"),
|
|
7717
|
-
type:
|
|
7718
|
-
...
|
|
7719
|
-
...
|
|
8204
|
+
type: readString26(record.type) ?? "theme",
|
|
8205
|
+
...readString26(record.description) ? { description: readString26(record.description) } : {},
|
|
8206
|
+
...readNumber19(record.depth) !== void 0 ? { depth: readNumber19(record.depth) } : {},
|
|
7720
8207
|
...normalizeTopicStatus(record.status) ? { status: normalizeTopicStatus(record.status) } : {},
|
|
7721
8208
|
...parentTopicRawId ? { parentTopicId: encodeTopicId2(parentTopicRawId) } : record.parentTopicId === null ? { parentTopicId: null } : {},
|
|
7722
|
-
...
|
|
7723
|
-
...
|
|
8209
|
+
...readString26(record.tenantId) ? { tenantId: readString26(record.tenantId) } : {},
|
|
8210
|
+
...readString26(record.workspaceId) ? { workspaceId: readString26(record.workspaceId) } : {},
|
|
7724
8211
|
...normalizeTopicVisibility(record.visibility) ? { visibility: normalizeTopicVisibility(record.visibility) } : {},
|
|
7725
|
-
...
|
|
7726
|
-
...
|
|
8212
|
+
...readNumber19(record.createdAt ?? record._creationTime) !== void 0 ? { createdAt: readNumber19(record.createdAt ?? record._creationTime) } : {},
|
|
8213
|
+
...readNumber19(record.updatedAt) !== void 0 ? { updatedAt: readNumber19(record.updatedAt) } : {}
|
|
7727
8214
|
};
|
|
7728
8215
|
}
|
|
7729
8216
|
function normalizeTopicTreeResults(value) {
|
|
7730
8217
|
if (Array.isArray(value)) {
|
|
7731
8218
|
return value;
|
|
7732
8219
|
}
|
|
7733
|
-
const record =
|
|
8220
|
+
const record = asRecord23(value);
|
|
7734
8221
|
if (Array.isArray(record.tree)) {
|
|
7735
8222
|
return record.tree;
|
|
7736
8223
|
}
|
|
7737
8224
|
return [];
|
|
7738
8225
|
}
|
|
7739
8226
|
function normalizeTopicTreeNode(value) {
|
|
7740
|
-
const record =
|
|
8227
|
+
const record = asRecord23(value);
|
|
7741
8228
|
return {
|
|
7742
8229
|
...normalizeTopicRecord(record),
|
|
7743
8230
|
...readStringArray8(record.path) ? { path: readStringArray8(record.path) } : {}
|
|
@@ -7762,24 +8249,24 @@ function classifyCoverage(beliefs, questions, evidence) {
|
|
|
7762
8249
|
async function createTopic(deps, input) {
|
|
7763
8250
|
const created = await deps.createTopic({
|
|
7764
8251
|
name: requireString2(input.name, "name"),
|
|
7765
|
-
description:
|
|
7766
|
-
type:
|
|
7767
|
-
parentTopicRawId: input.parentTopicId ?
|
|
7768
|
-
ontologyId:
|
|
7769
|
-
tenantId:
|
|
7770
|
-
workspaceId:
|
|
8252
|
+
description: readString26(input.description),
|
|
8253
|
+
type: readString26(input.type) ?? "theme",
|
|
8254
|
+
parentTopicRawId: input.parentTopicId ? decodeExternalId8(input.parentTopicId, "top", "parentTopicId") : void 0,
|
|
8255
|
+
ontologyId: readString26(input.ontologyId),
|
|
8256
|
+
tenantId: readString26(input.tenantId),
|
|
8257
|
+
workspaceId: readString26(input.workspaceId),
|
|
7771
8258
|
visibility: normalizeTopicVisibility(input.visibility),
|
|
7772
|
-
createdBy:
|
|
8259
|
+
createdBy: readString26(input.createdBy)
|
|
7773
8260
|
});
|
|
7774
|
-
const createdRecord =
|
|
7775
|
-
const createdRawId =
|
|
7776
|
-
if (createdRawId && !
|
|
8261
|
+
const createdRecord = asRecord23(created);
|
|
8262
|
+
const createdRawId = readString26(createdRecord.topicId) ?? readString26(createdRecord.id) ?? readString26(createdRecord._id) ?? readString26(createdRecord.projectId);
|
|
8263
|
+
if (createdRawId && !readString26(createdRecord.name)) {
|
|
7777
8264
|
const hydrated = await deps.fetchTopic(createdRawId);
|
|
7778
8265
|
if (hydrated) {
|
|
7779
8266
|
return normalizeTopicRecord({
|
|
7780
|
-
...
|
|
8267
|
+
...asRecord23(hydrated),
|
|
7781
8268
|
...createdRecord,
|
|
7782
|
-
topicId:
|
|
8269
|
+
topicId: readString26(asRecord23(hydrated).topicId) ?? readString26(asRecord23(hydrated).id) ?? readString26(asRecord23(hydrated)._id) ?? readString26(asRecord23(hydrated).projectId) ?? createdRawId
|
|
7783
8270
|
});
|
|
7784
8271
|
}
|
|
7785
8272
|
}
|
|
@@ -7795,31 +8282,31 @@ async function updateTopic(deps, input) {
|
|
|
7795
8282
|
});
|
|
7796
8283
|
}
|
|
7797
8284
|
const updated = await deps.updateTopic({
|
|
7798
|
-
topicRawId:
|
|
7799
|
-
name:
|
|
7800
|
-
description:
|
|
7801
|
-
type:
|
|
7802
|
-
ontologyId:
|
|
8285
|
+
topicRawId: decodeExternalId8(input.id, "top", "id"),
|
|
8286
|
+
name: readString26(input.name),
|
|
8287
|
+
description: readString26(input.description),
|
|
8288
|
+
type: readString26(input.type),
|
|
8289
|
+
ontologyId: readString26(input.ontologyId),
|
|
7803
8290
|
clearOntologyId: typeof input.clearOntologyId === "boolean" ? input.clearOntologyId : void 0,
|
|
7804
8291
|
status: normalizeTopicStatus(input.status),
|
|
7805
8292
|
visibility: normalizeTopicVisibility(input.visibility)
|
|
7806
8293
|
});
|
|
7807
|
-
const updatedRecord =
|
|
7808
|
-
const updatedRawId =
|
|
7809
|
-
if (!
|
|
8294
|
+
const updatedRecord = asRecord23(updated);
|
|
8295
|
+
const updatedRawId = readString26(updatedRecord.topicId) ?? readString26(updatedRecord.id) ?? readString26(updatedRecord._id) ?? readString26(updatedRecord.projectId) ?? decodeExternalId8(input.id, "top", "id");
|
|
8296
|
+
if (!readString26(updatedRecord.name) || !readString26(updatedRecord.topicId)) {
|
|
7810
8297
|
const hydrated = await deps.fetchTopic(updatedRawId);
|
|
7811
8298
|
if (hydrated) {
|
|
7812
8299
|
return normalizeTopicRecord({
|
|
7813
|
-
...
|
|
8300
|
+
...asRecord23(hydrated),
|
|
7814
8301
|
...updatedRecord,
|
|
7815
|
-
topicId:
|
|
8302
|
+
topicId: readString26(asRecord23(hydrated).topicId) ?? readString26(asRecord23(hydrated).id) ?? readString26(asRecord23(hydrated)._id) ?? readString26(asRecord23(hydrated).projectId) ?? updatedRawId
|
|
7816
8303
|
});
|
|
7817
8304
|
}
|
|
7818
8305
|
}
|
|
7819
8306
|
return normalizeTopicRecord(updated);
|
|
7820
8307
|
}
|
|
7821
8308
|
async function getTopic(deps, input) {
|
|
7822
|
-
const rawId =
|
|
8309
|
+
const rawId = decodeExternalId8(input.id, "top", "id");
|
|
7823
8310
|
const topic = await deps.fetchTopic(rawId);
|
|
7824
8311
|
if (!topic) {
|
|
7825
8312
|
throw createTopicsError({
|
|
@@ -7834,10 +8321,10 @@ async function getTopic(deps, input) {
|
|
|
7834
8321
|
}
|
|
7835
8322
|
async function listTopics(deps, query = {}) {
|
|
7836
8323
|
const topics = await deps.listTopics({
|
|
7837
|
-
ontologyId:
|
|
7838
|
-
parentTopicRawId: query.parentTopicId ?
|
|
7839
|
-
status:
|
|
7840
|
-
type:
|
|
8324
|
+
ontologyId: readString26(query.ontologyId),
|
|
8325
|
+
parentTopicRawId: query.parentTopicId ? decodeExternalId8(query.parentTopicId, "top", "parentTopicId") : void 0,
|
|
8326
|
+
status: readString26(query.status),
|
|
8327
|
+
type: readString26(query.type)
|
|
7841
8328
|
});
|
|
7842
8329
|
const normalized = dedupeTopics(
|
|
7843
8330
|
(Array.isArray(topics) ? topics : []).map(
|
|
@@ -7852,7 +8339,7 @@ async function listTopics(deps, query = {}) {
|
|
|
7852
8339
|
async function getTopicTree(deps, input) {
|
|
7853
8340
|
const root = await getTopic(deps, { id: input.id });
|
|
7854
8341
|
const tree = await deps.fetchTopicTree({
|
|
7855
|
-
rootRawId:
|
|
8342
|
+
rootRawId: decodeExternalId8(input.id, "top", "id"),
|
|
7856
8343
|
maxDepth: typeof input.maxDepth === "number" && Number.isFinite(input.maxDepth) ? input.maxDepth : void 0
|
|
7857
8344
|
});
|
|
7858
8345
|
const nodes = normalizeTopicTreeResults(tree).map(
|
|
@@ -7873,9 +8360,9 @@ async function getTopicCoverage(deps, input) {
|
|
|
7873
8360
|
const topics = await Promise.all(
|
|
7874
8361
|
scopedTopics.map(async (topic) => {
|
|
7875
8362
|
const [beliefs, questions, evidence] = await Promise.all([
|
|
7876
|
-
deps.listBeliefsByTopic({ topicId:
|
|
7877
|
-
deps.listQuestionsByTopic({ topicId:
|
|
7878
|
-
deps.listEvidenceByTopic({ topicId:
|
|
8363
|
+
deps.listBeliefsByTopic({ topicId: decodeExternalId8(topic.topicId, "top", "topicId"), limit: 500 }),
|
|
8364
|
+
deps.listQuestionsByTopic({ topicId: decodeExternalId8(topic.topicId, "top", "topicId"), limit: 500 }),
|
|
8365
|
+
deps.listEvidenceByTopic({ topicId: decodeExternalId8(topic.topicId, "top", "topicId"), limit: 500 })
|
|
7879
8366
|
]);
|
|
7880
8367
|
const beliefCount = Array.isArray(beliefs) ? beliefs.length : 0;
|
|
7881
8368
|
const questionCount = Array.isArray(questions) ? questions.length : 0;
|
|
@@ -8109,11 +8596,11 @@ function bulkCreateTopicsFromGatewayAuth(authContext, input) {
|
|
|
8109
8596
|
});
|
|
8110
8597
|
}
|
|
8111
8598
|
|
|
8112
|
-
// ../../
|
|
8113
|
-
function
|
|
8599
|
+
// ../../apps/gateway/src/routes/topics.ts
|
|
8600
|
+
function asRecord24(value) {
|
|
8114
8601
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
8115
8602
|
}
|
|
8116
|
-
function
|
|
8603
|
+
function readString27(value) {
|
|
8117
8604
|
if (typeof value !== "string") {
|
|
8118
8605
|
return void 0;
|
|
8119
8606
|
}
|
|
@@ -8123,14 +8610,14 @@ function readString25(value) {
|
|
|
8123
8610
|
function readBoolean(value) {
|
|
8124
8611
|
return typeof value === "boolean" ? value : void 0;
|
|
8125
8612
|
}
|
|
8126
|
-
function
|
|
8613
|
+
function readNumber20(value) {
|
|
8127
8614
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
8128
8615
|
}
|
|
8129
8616
|
function readStringArray9(value) {
|
|
8130
8617
|
if (!Array.isArray(value)) {
|
|
8131
8618
|
return void 0;
|
|
8132
8619
|
}
|
|
8133
|
-
const items = value.map((entry) =>
|
|
8620
|
+
const items = value.map((entry) => readString27(entry)).filter((entry) => Boolean(entry));
|
|
8134
8621
|
return items.length > 0 ? items : void 0;
|
|
8135
8622
|
}
|
|
8136
8623
|
function handleTopicsError(error, fallbackMessage, correlationId, policyTraceId) {
|
|
@@ -8148,17 +8635,17 @@ function handleTopicsError(error, fallbackMessage, correlationId, policyTraceId)
|
|
|
8148
8635
|
}
|
|
8149
8636
|
async function handleTopicCreate(args) {
|
|
8150
8637
|
try {
|
|
8151
|
-
const body =
|
|
8638
|
+
const body = asRecord24(args.body);
|
|
8152
8639
|
const payload = await createTopicFromGatewayAuth(args.authContext, {
|
|
8153
|
-
name:
|
|
8154
|
-
description:
|
|
8155
|
-
type:
|
|
8156
|
-
parentTopicId:
|
|
8157
|
-
ontologyId:
|
|
8158
|
-
tenantId:
|
|
8159
|
-
workspaceId:
|
|
8160
|
-
visibility:
|
|
8161
|
-
createdBy:
|
|
8640
|
+
name: readString27(body.name) ?? "",
|
|
8641
|
+
description: readString27(body.description),
|
|
8642
|
+
type: readString27(body.type),
|
|
8643
|
+
parentTopicId: readString27(body.parentTopicId),
|
|
8644
|
+
ontologyId: readString27(body.ontologyId),
|
|
8645
|
+
tenantId: readString27(body.tenantId),
|
|
8646
|
+
workspaceId: readString27(body.workspaceId),
|
|
8647
|
+
visibility: readString27(body.visibility),
|
|
8648
|
+
createdBy: readString27(body.createdBy)
|
|
8162
8649
|
});
|
|
8163
8650
|
return successResponse(payload, {
|
|
8164
8651
|
status: 201,
|
|
@@ -8176,16 +8663,16 @@ async function handleTopicCreate(args) {
|
|
|
8176
8663
|
}
|
|
8177
8664
|
async function handleTopicUpdate(args) {
|
|
8178
8665
|
try {
|
|
8179
|
-
const body =
|
|
8666
|
+
const body = asRecord24(args.body);
|
|
8180
8667
|
const payload = await updateTopicFromGatewayAuth(args.authContext, {
|
|
8181
8668
|
id: args.topicId,
|
|
8182
|
-
name:
|
|
8183
|
-
description:
|
|
8184
|
-
type:
|
|
8185
|
-
ontologyId:
|
|
8669
|
+
name: readString27(body.name),
|
|
8670
|
+
description: readString27(body.description),
|
|
8671
|
+
type: readString27(body.type),
|
|
8672
|
+
ontologyId: readString27(body.ontologyId),
|
|
8186
8673
|
clearOntologyId: readBoolean(body.clearOntologyId),
|
|
8187
|
-
status:
|
|
8188
|
-
visibility:
|
|
8674
|
+
status: readString27(body.status),
|
|
8675
|
+
visibility: readString27(body.visibility)
|
|
8189
8676
|
});
|
|
8190
8677
|
return successResponse(payload, {
|
|
8191
8678
|
correlationId: args.correlationId,
|
|
@@ -8236,7 +8723,7 @@ async function handleTopicTree(args) {
|
|
|
8236
8723
|
try {
|
|
8237
8724
|
const payload = await getTopicTreeFromGatewayAuth(args.authContext, {
|
|
8238
8725
|
id: args.topicId,
|
|
8239
|
-
maxDepth:
|
|
8726
|
+
maxDepth: readNumber20(args.query.maxDepth)
|
|
8240
8727
|
});
|
|
8241
8728
|
return successResponse(payload, {
|
|
8242
8729
|
correlationId: args.correlationId,
|
|
@@ -8256,7 +8743,7 @@ async function handleTopicCoverage(args) {
|
|
|
8256
8743
|
const payload = await getTopicCoverageFromGatewayAuth(args.authContext, {
|
|
8257
8744
|
id: args.topicId,
|
|
8258
8745
|
includeDescendants: typeof args.query.includeDescendants === "boolean" ? args.query.includeDescendants : void 0,
|
|
8259
|
-
maxDepth:
|
|
8746
|
+
maxDepth: readNumber20(args.query.maxDepth)
|
|
8260
8747
|
});
|
|
8261
8748
|
return successResponse(payload, {
|
|
8262
8749
|
correlationId: args.correlationId,
|
|
@@ -8273,9 +8760,9 @@ async function handleTopicCoverage(args) {
|
|
|
8273
8760
|
}
|
|
8274
8761
|
async function handleTopicRemove(args) {
|
|
8275
8762
|
try {
|
|
8276
|
-
const body =
|
|
8763
|
+
const body = asRecord24(args.body);
|
|
8277
8764
|
const payload = await removeTopicFromGatewayAuth(args.authContext, {
|
|
8278
|
-
id:
|
|
8765
|
+
id: readString27(body.id) ?? readString27(body.topicId) ?? ""
|
|
8279
8766
|
});
|
|
8280
8767
|
return successResponse(payload, {
|
|
8281
8768
|
correlationId: args.correlationId,
|
|
@@ -8292,22 +8779,22 @@ async function handleTopicRemove(args) {
|
|
|
8292
8779
|
}
|
|
8293
8780
|
async function handleTopicBulkCreate(args) {
|
|
8294
8781
|
try {
|
|
8295
|
-
const body =
|
|
8296
|
-
const topics = Array.isArray(body.topics) ? body.topics.map((entry) =>
|
|
8297
|
-
globalId:
|
|
8298
|
-
name:
|
|
8299
|
-
description:
|
|
8300
|
-
type:
|
|
8301
|
-
parentTopicId:
|
|
8302
|
-
depth:
|
|
8782
|
+
const body = asRecord24(args.body);
|
|
8783
|
+
const topics = Array.isArray(body.topics) ? body.topics.map((entry) => asRecord24(entry)).map((entry) => ({
|
|
8784
|
+
globalId: readString27(entry.globalId) ?? "",
|
|
8785
|
+
name: readString27(entry.name) ?? "",
|
|
8786
|
+
description: readString27(entry.description),
|
|
8787
|
+
type: readString27(entry.type) ?? "theme",
|
|
8788
|
+
parentTopicId: readString27(entry.parentTopicId),
|
|
8789
|
+
depth: readNumber20(entry.depth) ?? 0,
|
|
8303
8790
|
path: readStringArray9(entry.path) ?? [],
|
|
8304
|
-
tenantId:
|
|
8305
|
-
workspaceId:
|
|
8306
|
-
graphScopeProjectId:
|
|
8307
|
-
status:
|
|
8308
|
-
visibility:
|
|
8309
|
-
metadata:
|
|
8310
|
-
createdBy:
|
|
8791
|
+
tenantId: readString27(entry.tenantId),
|
|
8792
|
+
workspaceId: readString27(entry.workspaceId),
|
|
8793
|
+
graphScopeProjectId: readString27(entry.graphScopeProjectId),
|
|
8794
|
+
status: readString27(entry.status) ?? "active",
|
|
8795
|
+
visibility: readString27(entry.visibility),
|
|
8796
|
+
metadata: asRecord24(entry.metadata),
|
|
8797
|
+
createdBy: readString27(entry.createdBy)
|
|
8311
8798
|
})) : [];
|
|
8312
8799
|
const payload = await bulkCreateTopicsFromGatewayAuth(args.authContext, {
|
|
8313
8800
|
topics
|
|
@@ -8327,11 +8814,11 @@ async function handleTopicBulkCreate(args) {
|
|
|
8327
8814
|
}
|
|
8328
8815
|
}
|
|
8329
8816
|
|
|
8330
|
-
// ../../
|
|
8331
|
-
function
|
|
8817
|
+
// ../../apps/gateway/src/routes/webhooks.ts
|
|
8818
|
+
function asRecord25(value) {
|
|
8332
8819
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
8333
8820
|
}
|
|
8334
|
-
function
|
|
8821
|
+
function readString28(value) {
|
|
8335
8822
|
if (typeof value !== "string") {
|
|
8336
8823
|
return void 0;
|
|
8337
8824
|
}
|
|
@@ -8345,7 +8832,7 @@ function readStringArray10(value) {
|
|
|
8345
8832
|
if (!Array.isArray(value)) {
|
|
8346
8833
|
return void 0;
|
|
8347
8834
|
}
|
|
8348
|
-
const normalized = value.map((entry) =>
|
|
8835
|
+
const normalized = value.map((entry) => readString28(entry)).filter((entry) => Boolean(entry));
|
|
8349
8836
|
return normalized.length > 0 ? normalized : void 0;
|
|
8350
8837
|
}
|
|
8351
8838
|
function handleWebhooksError(error, fallbackMessage, correlationId, policyTraceId) {
|
|
@@ -8363,16 +8850,16 @@ function handleWebhooksError(error, fallbackMessage, correlationId, policyTraceI
|
|
|
8363
8850
|
}
|
|
8364
8851
|
async function handleWebhookCreate(args) {
|
|
8365
8852
|
try {
|
|
8366
|
-
const body =
|
|
8853
|
+
const body = asRecord25(args.body);
|
|
8367
8854
|
const payload = await args.authContext.convex.mutation(
|
|
8368
8855
|
"events:createWebhook",
|
|
8369
8856
|
{
|
|
8370
8857
|
tenantId: args.authContext.tenantId,
|
|
8371
8858
|
workspaceId: args.authContext.workspaceId,
|
|
8372
|
-
topicId:
|
|
8373
|
-
url:
|
|
8859
|
+
topicId: readString28(body.topicId),
|
|
8860
|
+
url: readString28(body.url) ?? "",
|
|
8374
8861
|
events: readStringArray10(body.events) ?? [],
|
|
8375
|
-
secret:
|
|
8862
|
+
secret: readString28(body.secret) ?? "",
|
|
8376
8863
|
active: readBoolean2(body.active),
|
|
8377
8864
|
createdBy: args.authContext.principalId ?? args.authContext.userId
|
|
8378
8865
|
}
|
|
@@ -8433,17 +8920,17 @@ async function handleWebhookGet(args) {
|
|
|
8433
8920
|
}
|
|
8434
8921
|
async function handleWebhookUpdate(args) {
|
|
8435
8922
|
try {
|
|
8436
|
-
const body =
|
|
8923
|
+
const body = asRecord25(args.body);
|
|
8437
8924
|
const payload = await args.authContext.convex.mutation(
|
|
8438
8925
|
"events:updateWebhook",
|
|
8439
8926
|
{
|
|
8440
8927
|
webhookId: args.webhookId,
|
|
8441
8928
|
tenantId: args.authContext.tenantId,
|
|
8442
8929
|
workspaceId: args.authContext.workspaceId,
|
|
8443
|
-
url:
|
|
8930
|
+
url: readString28(body.url),
|
|
8444
8931
|
events: readStringArray10(body.events),
|
|
8445
|
-
secret:
|
|
8446
|
-
topicId:
|
|
8932
|
+
secret: readString28(body.secret),
|
|
8933
|
+
topicId: readString28(body.topicId),
|
|
8447
8934
|
clearTopicId: body.topicId === null ? true : readBoolean2(body.clearTopicId),
|
|
8448
8935
|
active: readBoolean2(body.active),
|
|
8449
8936
|
updatedBy: args.authContext.principalId ?? args.authContext.userId
|
|
@@ -8487,12 +8974,12 @@ async function handleWebhookDelete(args) {
|
|
|
8487
8974
|
}
|
|
8488
8975
|
async function handleWebhookTest(args) {
|
|
8489
8976
|
try {
|
|
8490
|
-
const body =
|
|
8977
|
+
const body = asRecord25(args.body);
|
|
8491
8978
|
const payload = await args.authContext.convex.action("events:testWebhook", {
|
|
8492
8979
|
webhookId: args.webhookId,
|
|
8493
8980
|
tenantId: args.authContext.tenantId,
|
|
8494
8981
|
workspaceId: args.authContext.workspaceId,
|
|
8495
|
-
topicId:
|
|
8982
|
+
topicId: readString28(body.topicId),
|
|
8496
8983
|
actorId: args.authContext.principalId ?? args.authContext.userId,
|
|
8497
8984
|
actorType: inferActorType({
|
|
8498
8985
|
authMode: args.authContext.authMode,
|
|
@@ -8571,28 +9058,28 @@ function createWorktreesError(args) {
|
|
|
8571
9058
|
error.details = args.details;
|
|
8572
9059
|
return error;
|
|
8573
9060
|
}
|
|
8574
|
-
function
|
|
9061
|
+
function asRecord26(value) {
|
|
8575
9062
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
8576
9063
|
}
|
|
8577
|
-
function
|
|
9064
|
+
function readString29(value) {
|
|
8578
9065
|
if (typeof value !== "string") {
|
|
8579
9066
|
return void 0;
|
|
8580
9067
|
}
|
|
8581
9068
|
const normalized = value.trim();
|
|
8582
9069
|
return normalized.length > 0 ? normalized : void 0;
|
|
8583
9070
|
}
|
|
8584
|
-
function
|
|
9071
|
+
function readNumber21(value) {
|
|
8585
9072
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
8586
9073
|
}
|
|
8587
9074
|
function readStringArray11(value) {
|
|
8588
9075
|
if (!Array.isArray(value)) {
|
|
8589
9076
|
return void 0;
|
|
8590
9077
|
}
|
|
8591
|
-
const normalized = value.map((entry) =>
|
|
9078
|
+
const normalized = value.map((entry) => readString29(entry)).filter((entry) => Boolean(entry));
|
|
8592
9079
|
return normalized.length > 0 ? normalized : void 0;
|
|
8593
9080
|
}
|
|
8594
9081
|
function requireString3(value, field) {
|
|
8595
|
-
const normalized =
|
|
9082
|
+
const normalized = readString29(value);
|
|
8596
9083
|
if (!normalized) {
|
|
8597
9084
|
throw createWorktreesError({
|
|
8598
9085
|
message: `[worktrees] ${field} is required.`,
|
|
@@ -8604,7 +9091,7 @@ function requireString3(value, field) {
|
|
|
8604
9091
|
}
|
|
8605
9092
|
return normalized;
|
|
8606
9093
|
}
|
|
8607
|
-
function
|
|
9094
|
+
function decodeExternalId9(id, prefix, field) {
|
|
8608
9095
|
const normalized = requireString3(id, field);
|
|
8609
9096
|
try {
|
|
8610
9097
|
const decoded = decodePrefixedId(normalized);
|
|
@@ -8638,8 +9125,8 @@ function encodeQuestionId(rawId) {
|
|
|
8638
9125
|
return encodePrefixedId("que", requireString3(rawId, "questionId"));
|
|
8639
9126
|
}
|
|
8640
9127
|
function normalizeWorktreeRecord(value) {
|
|
8641
|
-
const record =
|
|
8642
|
-
const rawId =
|
|
9128
|
+
const record = asRecord26(value);
|
|
9129
|
+
const rawId = readString29(record.worktreeId) ?? readString29(record.id) ?? readString29(record._id);
|
|
8643
9130
|
if (!rawId) {
|
|
8644
9131
|
throw createWorktreesError({
|
|
8645
9132
|
message: "[worktrees] worktreeId is required in upstream worktree payload.",
|
|
@@ -8649,22 +9136,22 @@ function normalizeWorktreeRecord(value) {
|
|
|
8649
9136
|
});
|
|
8650
9137
|
}
|
|
8651
9138
|
const worktreeId = encodeWorktreeId(rawId);
|
|
8652
|
-
const topicRawId =
|
|
9139
|
+
const topicRawId = readString29(record.topicId);
|
|
8653
9140
|
return {
|
|
8654
9141
|
worktreeId,
|
|
8655
9142
|
id: worktreeId,
|
|
8656
9143
|
...topicRawId ? { topicId: encodeTopicId3(topicRawId) } : {},
|
|
8657
|
-
title:
|
|
8658
|
-
...
|
|
8659
|
-
...
|
|
8660
|
-
...
|
|
8661
|
-
...
|
|
8662
|
-
...
|
|
8663
|
-
...
|
|
8664
|
-
...
|
|
8665
|
-
...
|
|
8666
|
-
...
|
|
8667
|
-
...
|
|
9144
|
+
title: readString29(record.title) ?? readString29(record.name) ?? "Untitled",
|
|
9145
|
+
...readString29(record.status) ? { status: readString29(record.status) } : {},
|
|
9146
|
+
...readString29(record.phase) ? { phase: readString29(record.phase) } : {},
|
|
9147
|
+
...readString29(record.branchId) !== void 0 ? { branchId: readString29(record.branchId) ?? null } : {},
|
|
9148
|
+
...readString29(record.objective) ? { objective: readString29(record.objective) } : {},
|
|
9149
|
+
...readString29(record.hypothesis) ? { hypothesis: readString29(record.hypothesis) } : {},
|
|
9150
|
+
...readString29(record.gate) ? { gate: readString29(record.gate) } : {},
|
|
9151
|
+
...readString29(record.track) ? { track: readString29(record.track) } : {},
|
|
9152
|
+
...readNumber21(record.trackPosition) !== void 0 ? { trackPosition: readNumber21(record.trackPosition) } : {},
|
|
9153
|
+
...readNumber21(record.executionBand) !== void 0 ? { executionBand: readNumber21(record.executionBand) } : {},
|
|
9154
|
+
...readNumber21(record.executionOrder) !== void 0 ? { executionOrder: readNumber21(record.executionOrder) } : {},
|
|
8668
9155
|
...readStringArray11(record.dependsOn) ? {
|
|
8669
9156
|
dependsOn: readStringArray11(record.dependsOn).map(
|
|
8670
9157
|
(id) => encodeWorktreeId(id)
|
|
@@ -8685,20 +9172,20 @@ function normalizeWorktreeRecord(value) {
|
|
|
8685
9172
|
(id) => encodeQuestionId(id)
|
|
8686
9173
|
)
|
|
8687
9174
|
} : {},
|
|
8688
|
-
...
|
|
8689
|
-
...
|
|
9175
|
+
...readNumber21(record.questionCount) !== void 0 ? { questionCount: readNumber21(record.questionCount) } : {},
|
|
9176
|
+
...readNumber21(record.taskCount) !== void 0 ? { taskCount: readNumber21(record.taskCount) } : {},
|
|
8690
9177
|
...Array.isArray(record.frameworkSuggestions) ? { frameworkSuggestions: record.frameworkSuggestions } : {},
|
|
8691
9178
|
...Array.isArray(record.dependencySuggestions) ? { dependencySuggestions: record.dependencySuggestions } : {},
|
|
8692
9179
|
...typeof record.autoShapeApplied === "boolean" ? { autoShapeApplied: record.autoShapeApplied } : {},
|
|
8693
9180
|
...Array.isArray(record.proofArtifacts) ? { proofArtifacts: record.proofArtifacts } : record.proofArtifacts === null ? { proofArtifacts: null } : {},
|
|
8694
|
-
...
|
|
8695
|
-
...
|
|
9181
|
+
...readString29(record.staffingHint) !== void 0 ? { staffingHint: readString29(record.staffingHint) ?? null } : {},
|
|
9182
|
+
...readNumber21(record.lastReconciledAt) !== void 0 ? { lastReconciledAt: readNumber21(record.lastReconciledAt) } : record.lastReconciledAt === null ? { lastReconciledAt: null } : {},
|
|
8696
9183
|
...record.autoFixPolicy && typeof record.autoFixPolicy === "object" ? {
|
|
8697
9184
|
autoFixPolicy: record.autoFixPolicy
|
|
8698
9185
|
} : record.autoFixPolicy === null ? { autoFixPolicy: null } : {},
|
|
8699
|
-
...
|
|
8700
|
-
...
|
|
8701
|
-
...
|
|
9186
|
+
...readString29(record.lensId) !== void 0 ? { lensId: readString29(record.lensId) ?? null } : {},
|
|
9187
|
+
...readNumber21(record.createdAt ?? record._creationTime) !== void 0 ? { createdAt: readNumber21(record.createdAt ?? record._creationTime) } : {},
|
|
9188
|
+
...readNumber21(record.updatedAt) !== void 0 ? { updatedAt: readNumber21(record.updatedAt) } : {}
|
|
8702
9189
|
};
|
|
8703
9190
|
}
|
|
8704
9191
|
function dedupeWorktrees(records) {
|
|
@@ -8709,30 +9196,30 @@ function dedupeWorktrees(records) {
|
|
|
8709
9196
|
return [...byId.values()];
|
|
8710
9197
|
}
|
|
8711
9198
|
async function createWorktree(deps, input) {
|
|
8712
|
-
const topicRawId =
|
|
9199
|
+
const topicRawId = decodeExternalId9(input.topicId, "top", "topicId");
|
|
8713
9200
|
const created = await deps.createWorktree({
|
|
8714
9201
|
title: requireString3(input.title, "title"),
|
|
8715
9202
|
topicRawId,
|
|
8716
|
-
objective:
|
|
8717
|
-
hypothesis:
|
|
9203
|
+
objective: readString29(input.objective),
|
|
9204
|
+
hypothesis: readString29(input.hypothesis),
|
|
8718
9205
|
beliefRawIds: input.beliefIds?.map(
|
|
8719
|
-
(id) =>
|
|
9206
|
+
(id) => decodeExternalId9(id, "bel", "beliefIds")
|
|
8720
9207
|
),
|
|
8721
9208
|
autoShape: typeof input.autoShape === "boolean" ? input.autoShape : void 0,
|
|
8722
|
-
domainPackId:
|
|
9209
|
+
domainPackId: readString29(input.domainPackId),
|
|
8723
9210
|
executionOrder: typeof input.executionOrder === "number" && Number.isFinite(input.executionOrder) ? input.executionOrder : void 0,
|
|
8724
9211
|
dependsOn: input.dependsOn?.map(
|
|
8725
|
-
(id) =>
|
|
9212
|
+
(id) => decodeExternalId9(id, "wt", "dependsOn")
|
|
8726
9213
|
),
|
|
8727
|
-
blocks: input.blocks?.map((id) =>
|
|
8728
|
-
gate:
|
|
9214
|
+
blocks: input.blocks?.map((id) => decodeExternalId9(id, "wt", "blocks")),
|
|
9215
|
+
gate: readString29(input.gate),
|
|
8729
9216
|
proofArtifacts: Array.isArray(input.proofArtifacts) ? input.proofArtifacts : void 0,
|
|
8730
|
-
staffingHint:
|
|
9217
|
+
staffingHint: readString29(input.staffingHint),
|
|
8731
9218
|
lastReconciledAt: typeof input.lastReconciledAt === "number" && Number.isFinite(input.lastReconciledAt) ? input.lastReconciledAt : void 0,
|
|
8732
9219
|
autoFixPolicy: input.autoFixPolicy && typeof input.autoFixPolicy === "object" ? input.autoFixPolicy : void 0,
|
|
8733
|
-
lensId:
|
|
9220
|
+
lensId: readString29(input.lensId)
|
|
8734
9221
|
});
|
|
8735
|
-
const createdRecord = typeof created === "string" ? { worktreeId: created } :
|
|
9222
|
+
const createdRecord = typeof created === "string" ? { worktreeId: created } : asRecord26(created);
|
|
8736
9223
|
return normalizeWorktreeRecord({
|
|
8737
9224
|
topicId: topicRawId,
|
|
8738
9225
|
title: input.title,
|
|
@@ -8741,10 +9228,10 @@ async function createWorktree(deps, input) {
|
|
|
8741
9228
|
}
|
|
8742
9229
|
async function listWorktrees(deps, query) {
|
|
8743
9230
|
const worktrees = await deps.listWorktreesByTopic({
|
|
8744
|
-
topicId:
|
|
9231
|
+
topicId: decodeExternalId9(query.topicId, "top", "topicId"),
|
|
8745
9232
|
limit: typeof query.limit === "number" && Number.isFinite(query.limit) ? query.limit : void 0
|
|
8746
9233
|
});
|
|
8747
|
-
const statusFilter =
|
|
9234
|
+
const statusFilter = readString29(query.status)?.toLowerCase();
|
|
8748
9235
|
const normalized = dedupeWorktrees(
|
|
8749
9236
|
(Array.isArray(worktrees) ? worktrees : []).map((worktree) => normalizeWorktreeRecord(worktree)).filter(
|
|
8750
9237
|
(worktree) => statusFilter ? String(worktree.status ?? "").toLowerCase() === statusFilter : true
|
|
@@ -8756,76 +9243,76 @@ async function listWorktrees(deps, query) {
|
|
|
8756
9243
|
};
|
|
8757
9244
|
}
|
|
8758
9245
|
async function activateWorktree(deps, input) {
|
|
8759
|
-
const rawId =
|
|
9246
|
+
const rawId = decodeExternalId9(input.id, "wt", "id");
|
|
8760
9247
|
const activated = await deps.activateWorktree({ worktreeRawId: rawId });
|
|
8761
9248
|
return normalizeWorktreeRecord({
|
|
8762
9249
|
worktreeId: rawId,
|
|
8763
9250
|
status: "active",
|
|
8764
|
-
...
|
|
9251
|
+
...asRecord26(activated)
|
|
8765
9252
|
});
|
|
8766
9253
|
}
|
|
8767
9254
|
async function updateWorktree(deps, input) {
|
|
8768
|
-
const rawId =
|
|
9255
|
+
const rawId = decodeExternalId9(input.id, "wt", "id");
|
|
8769
9256
|
const updated = await deps.updateWorktreeMetadata({
|
|
8770
9257
|
worktreeRawId: rawId,
|
|
8771
|
-
objective:
|
|
8772
|
-
hypothesis:
|
|
8773
|
-
rationale:
|
|
8774
|
-
track:
|
|
9258
|
+
objective: readString29(input.objective),
|
|
9259
|
+
hypothesis: readString29(input.hypothesis),
|
|
9260
|
+
rationale: readString29(input.rationale),
|
|
9261
|
+
track: readString29(input.track),
|
|
8775
9262
|
trackPosition: typeof input.trackPosition === "number" && Number.isFinite(input.trackPosition) ? input.trackPosition : void 0,
|
|
8776
9263
|
executionBand: typeof input.executionBand === "number" && Number.isFinite(input.executionBand) ? input.executionBand : void 0,
|
|
8777
9264
|
executionOrder: typeof input.executionOrder === "number" && Number.isFinite(input.executionOrder) ? input.executionOrder : void 0,
|
|
8778
9265
|
dependsOn: input.dependsOn?.map(
|
|
8779
|
-
(id) =>
|
|
9266
|
+
(id) => decodeExternalId9(id, "wt", "dependsOn")
|
|
8780
9267
|
),
|
|
8781
|
-
blocks: input.blocks?.map((id) =>
|
|
8782
|
-
gate:
|
|
8783
|
-
status:
|
|
8784
|
-
topicId:
|
|
9268
|
+
blocks: input.blocks?.map((id) => decodeExternalId9(id, "wt", "blocks")),
|
|
9269
|
+
gate: readString29(input.gate),
|
|
9270
|
+
status: readString29(input.status),
|
|
9271
|
+
topicId: readString29(input.topicId),
|
|
8785
9272
|
additionalTopicIds: input.additionalTopicIds,
|
|
8786
9273
|
proofArtifacts: input.proofArtifacts,
|
|
8787
|
-
staffingHint:
|
|
9274
|
+
staffingHint: readString29(input.staffingHint),
|
|
8788
9275
|
lastReconciledAt: typeof input.lastReconciledAt === "number" && Number.isFinite(input.lastReconciledAt) ? input.lastReconciledAt : void 0,
|
|
8789
9276
|
autoFixPolicy: input.autoFixPolicy,
|
|
8790
|
-
lensId:
|
|
9277
|
+
lensId: readString29(input.lensId)
|
|
8791
9278
|
});
|
|
8792
9279
|
return normalizeWorktreeRecord({
|
|
8793
9280
|
worktreeId: rawId,
|
|
8794
|
-
...
|
|
9281
|
+
...asRecord26(updated)
|
|
8795
9282
|
});
|
|
8796
9283
|
}
|
|
8797
9284
|
async function updateWorktreeTargets(deps, input) {
|
|
8798
|
-
const rawId =
|
|
9285
|
+
const rawId = decodeExternalId9(input.id, "wt", "id");
|
|
8799
9286
|
const updated = await deps.updateWorktreeTargets({
|
|
8800
9287
|
worktreeRawId: rawId,
|
|
8801
9288
|
addBeliefRawIds: input.addBeliefIds?.map(
|
|
8802
|
-
(id) =>
|
|
9289
|
+
(id) => decodeExternalId9(id, "bel", "addBeliefIds")
|
|
8803
9290
|
),
|
|
8804
9291
|
addQuestionRawIds: input.addQuestionIds?.map(
|
|
8805
|
-
(id) =>
|
|
9292
|
+
(id) => decodeExternalId9(id, "que", "addQuestionIds")
|
|
8806
9293
|
),
|
|
8807
9294
|
removeBeliefRawIds: input.removeBeliefIds?.map(
|
|
8808
|
-
(id) =>
|
|
9295
|
+
(id) => decodeExternalId9(id, "bel", "removeBeliefIds")
|
|
8809
9296
|
),
|
|
8810
9297
|
removeQuestionRawIds: input.removeQuestionIds?.map(
|
|
8811
|
-
(id) =>
|
|
9298
|
+
(id) => decodeExternalId9(id, "que", "removeQuestionIds")
|
|
8812
9299
|
)
|
|
8813
9300
|
});
|
|
8814
9301
|
return normalizeWorktreeRecord({
|
|
8815
9302
|
worktreeId: rawId,
|
|
8816
|
-
...
|
|
9303
|
+
...asRecord26(updated)
|
|
8817
9304
|
});
|
|
8818
9305
|
}
|
|
8819
9306
|
async function mergeWorktree(deps, input) {
|
|
8820
|
-
const rawId =
|
|
8821
|
-
const summary =
|
|
9307
|
+
const rawId = decodeExternalId9(input.id, "wt", "id");
|
|
9308
|
+
const summary = readString29(input.summary) ?? "Worktree merged.";
|
|
8822
9309
|
await deps.completeWorktree({ worktreeRawId: rawId, summary });
|
|
8823
9310
|
const failedBeliefs = [];
|
|
8824
9311
|
let beliefsScored = 0;
|
|
8825
9312
|
for (const outcome of input.outcomes) {
|
|
8826
9313
|
try {
|
|
8827
9314
|
await deps.scoreBeliefOutcome({
|
|
8828
|
-
beliefRawId:
|
|
9315
|
+
beliefRawId: decodeExternalId9(outcome.beliefId, "bel", "beliefId"),
|
|
8829
9316
|
confidence: outcome.confidence,
|
|
8830
9317
|
rationale: requireString3(outcome.rationale, "rationale")
|
|
8831
9318
|
});
|
|
@@ -8833,7 +9320,7 @@ async function mergeWorktree(deps, input) {
|
|
|
8833
9320
|
} catch (error) {
|
|
8834
9321
|
failedBeliefs.push({
|
|
8835
9322
|
beliefId: encodeBeliefId(
|
|
8836
|
-
|
|
9323
|
+
decodeExternalId9(outcome.beliefId, "bel", "beliefId")
|
|
8837
9324
|
),
|
|
8838
9325
|
reason: error instanceof Error ? error.message : "Scoring failed"
|
|
8839
9326
|
});
|
|
@@ -8850,7 +9337,7 @@ async function mergeWorktree(deps, input) {
|
|
|
8850
9337
|
}
|
|
8851
9338
|
|
|
8852
9339
|
// ../server-core/src/worktrees.ts
|
|
8853
|
-
function
|
|
9340
|
+
function toSubjectiveLogicOpinion(confidence) {
|
|
8854
9341
|
const boundedConfidence = Math.max(0, Math.min(confidence, 1));
|
|
8855
9342
|
return {
|
|
8856
9343
|
belief: boundedConfidence,
|
|
@@ -8914,7 +9401,7 @@ function buildCreateMutationArgs(input, userId) {
|
|
|
8914
9401
|
...Array.isArray(input.beliefIds) && input.beliefIds.length > 0 ? { targetBeliefIds: input.beliefIds.map((id) => id) } : {}
|
|
8915
9402
|
};
|
|
8916
9403
|
}
|
|
8917
|
-
function
|
|
9404
|
+
function readString30(value) {
|
|
8918
9405
|
if (typeof value !== "string") {
|
|
8919
9406
|
return void 0;
|
|
8920
9407
|
}
|
|
@@ -8934,7 +9421,7 @@ async function resolveWorktreeTopicIdWithGatewayAuth(authContext, worktreeId) {
|
|
|
8934
9421
|
const worktree = await authContext.convex.query(api.worktrees.get, {
|
|
8935
9422
|
worktreeId
|
|
8936
9423
|
});
|
|
8937
|
-
return
|
|
9424
|
+
return readString30(worktree?.topicId);
|
|
8938
9425
|
}
|
|
8939
9426
|
async function emitWorktreeEventFromGatewayAuth(authContext, args) {
|
|
8940
9427
|
return emitDomainEvent(
|
|
@@ -9026,7 +9513,7 @@ function createGatewayWorktreesPort(authContext) {
|
|
|
9026
9513
|
});
|
|
9027
9514
|
},
|
|
9028
9515
|
scoreBeliefOutcome(args) {
|
|
9029
|
-
const opinion =
|
|
9516
|
+
const opinion = toSubjectiveLogicOpinion(args.confidence);
|
|
9030
9517
|
return authContext.convex.mutation(api.epistemicBeliefs.modulateConfidence, {
|
|
9031
9518
|
nodeId: args.beliefRawId,
|
|
9032
9519
|
trigger: "worktree_outcome",
|
|
@@ -9214,25 +9701,25 @@ function bulkCreateWorktreesFromGatewayAuth(authContext, input) {
|
|
|
9214
9701
|
});
|
|
9215
9702
|
}
|
|
9216
9703
|
|
|
9217
|
-
// ../../
|
|
9218
|
-
function
|
|
9704
|
+
// ../../apps/gateway/src/routes/worktrees.ts
|
|
9705
|
+
function asRecord27(value) {
|
|
9219
9706
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
9220
9707
|
}
|
|
9221
|
-
function
|
|
9708
|
+
function readString31(value) {
|
|
9222
9709
|
if (typeof value !== "string") {
|
|
9223
9710
|
return void 0;
|
|
9224
9711
|
}
|
|
9225
9712
|
const normalized = value.trim();
|
|
9226
9713
|
return normalized.length > 0 ? normalized : void 0;
|
|
9227
9714
|
}
|
|
9228
|
-
function
|
|
9715
|
+
function readNumber22(value) {
|
|
9229
9716
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
9230
9717
|
}
|
|
9231
9718
|
function readStringArray12(value) {
|
|
9232
9719
|
if (!Array.isArray(value)) {
|
|
9233
9720
|
return void 0;
|
|
9234
9721
|
}
|
|
9235
|
-
const normalized = value.map((entry) =>
|
|
9722
|
+
const normalized = value.map((entry) => readString31(entry)).filter((entry) => Boolean(entry));
|
|
9236
9723
|
return normalized.length > 0 ? normalized : void 0;
|
|
9237
9724
|
}
|
|
9238
9725
|
function handleWorktreesError(error, fallbackMessage, correlationId, policyTraceId) {
|
|
@@ -9250,24 +9737,24 @@ function handleWorktreesError(error, fallbackMessage, correlationId, policyTrace
|
|
|
9250
9737
|
}
|
|
9251
9738
|
async function handleWorktreeCreate(args) {
|
|
9252
9739
|
try {
|
|
9253
|
-
const body =
|
|
9740
|
+
const body = asRecord27(args.body);
|
|
9254
9741
|
const payload = await createWorktreeFromGatewayAuth(args.authContext, {
|
|
9255
|
-
title:
|
|
9256
|
-
topicId:
|
|
9257
|
-
objective:
|
|
9258
|
-
hypothesis:
|
|
9742
|
+
title: readString31(body.title) ?? "",
|
|
9743
|
+
topicId: readString31(body.topicId ?? body.projectId) ?? "",
|
|
9744
|
+
objective: readString31(body.objective),
|
|
9745
|
+
hypothesis: readString31(body.hypothesis),
|
|
9259
9746
|
beliefIds: readStringArray12(body.beliefIds) ?? readStringArray12(body.beliefs),
|
|
9260
9747
|
autoShape: typeof body.autoShape === "boolean" ? body.autoShape : void 0,
|
|
9261
|
-
domainPackId:
|
|
9262
|
-
executionOrder:
|
|
9748
|
+
domainPackId: readString31(body.domainPackId),
|
|
9749
|
+
executionOrder: readNumber22(body.executionOrder),
|
|
9263
9750
|
dependsOn: readStringArray12(body.dependsOn),
|
|
9264
9751
|
blocks: readStringArray12(body.blocks),
|
|
9265
|
-
gate:
|
|
9752
|
+
gate: readString31(body.gate),
|
|
9266
9753
|
proofArtifacts: Array.isArray(body.proofArtifacts) ? body.proofArtifacts : void 0,
|
|
9267
|
-
staffingHint:
|
|
9268
|
-
lastReconciledAt:
|
|
9754
|
+
staffingHint: readString31(body.staffingHint),
|
|
9755
|
+
lastReconciledAt: readNumber22(body.lastReconciledAt),
|
|
9269
9756
|
autoFixPolicy: body.autoFixPolicy && typeof body.autoFixPolicy === "object" && !Array.isArray(body.autoFixPolicy) ? body.autoFixPolicy : void 0,
|
|
9270
|
-
lensId:
|
|
9757
|
+
lensId: readString31(body.lensId)
|
|
9271
9758
|
});
|
|
9272
9759
|
return successResponse(payload, {
|
|
9273
9760
|
status: 201,
|
|
@@ -9286,9 +9773,9 @@ async function handleWorktreeCreate(args) {
|
|
|
9286
9773
|
async function handleWorktreeList(args) {
|
|
9287
9774
|
try {
|
|
9288
9775
|
const payload = await listWorktreesFromGatewayAuth(args.authContext, {
|
|
9289
|
-
topicId:
|
|
9290
|
-
status:
|
|
9291
|
-
limit:
|
|
9776
|
+
topicId: readString31(args.query.topicId) ?? "",
|
|
9777
|
+
status: readString31(args.query.status),
|
|
9778
|
+
limit: readNumber22(args.query.limit)
|
|
9292
9779
|
});
|
|
9293
9780
|
return successResponse(payload, {
|
|
9294
9781
|
correlationId: args.correlationId,
|
|
@@ -9306,10 +9793,10 @@ async function handleWorktreeList(args) {
|
|
|
9306
9793
|
async function handleWorktreeListAll(args) {
|
|
9307
9794
|
try {
|
|
9308
9795
|
const payload = await listAllWorktreesFromGatewayAuth(args.authContext, {
|
|
9309
|
-
status:
|
|
9310
|
-
track:
|
|
9311
|
-
executionBand:
|
|
9312
|
-
limit:
|
|
9796
|
+
status: readString31(args.query.status),
|
|
9797
|
+
track: readString31(args.query.track),
|
|
9798
|
+
executionBand: readNumber22(args.query.executionBand),
|
|
9799
|
+
limit: readNumber22(args.query.limit)
|
|
9313
9800
|
});
|
|
9314
9801
|
return successResponse(payload, {
|
|
9315
9802
|
correlationId: args.correlationId,
|
|
@@ -9344,27 +9831,27 @@ async function handleWorktreeActivate(args) {
|
|
|
9344
9831
|
}
|
|
9345
9832
|
async function handleWorktreeUpdate(args) {
|
|
9346
9833
|
try {
|
|
9347
|
-
const body =
|
|
9834
|
+
const body = asRecord27(args.body);
|
|
9348
9835
|
const payload = await updateWorktreeFromGatewayAuth(args.authContext, {
|
|
9349
9836
|
id: args.worktreeId,
|
|
9350
|
-
objective:
|
|
9351
|
-
hypothesis:
|
|
9352
|
-
rationale:
|
|
9353
|
-
track:
|
|
9354
|
-
trackPosition:
|
|
9355
|
-
executionBand:
|
|
9356
|
-
executionOrder:
|
|
9837
|
+
objective: readString31(body.objective),
|
|
9838
|
+
hypothesis: readString31(body.hypothesis),
|
|
9839
|
+
rationale: readString31(body.rationale),
|
|
9840
|
+
track: readString31(body.track),
|
|
9841
|
+
trackPosition: readNumber22(body.trackPosition),
|
|
9842
|
+
executionBand: readNumber22(body.executionBand),
|
|
9843
|
+
executionOrder: readNumber22(body.executionOrder),
|
|
9357
9844
|
dependsOn: readStringArray12(body.dependsOn),
|
|
9358
9845
|
blocks: readStringArray12(body.blocks),
|
|
9359
|
-
gate:
|
|
9360
|
-
status:
|
|
9361
|
-
topicId:
|
|
9846
|
+
gate: readString31(body.gate),
|
|
9847
|
+
status: readString31(body.status),
|
|
9848
|
+
topicId: readString31(body.topicId),
|
|
9362
9849
|
additionalTopicIds: readStringArray12(body.additionalTopicIds),
|
|
9363
9850
|
proofArtifacts: Array.isArray(body.proofArtifacts) ? body.proofArtifacts : void 0,
|
|
9364
|
-
staffingHint:
|
|
9365
|
-
lastReconciledAt:
|
|
9851
|
+
staffingHint: readString31(body.staffingHint),
|
|
9852
|
+
lastReconciledAt: readNumber22(body.lastReconciledAt),
|
|
9366
9853
|
autoFixPolicy: body.autoFixPolicy && typeof body.autoFixPolicy === "object" ? body.autoFixPolicy : void 0,
|
|
9367
|
-
lensId:
|
|
9854
|
+
lensId: readString31(body.lensId)
|
|
9368
9855
|
});
|
|
9369
9856
|
return successResponse(payload, {
|
|
9370
9857
|
correlationId: args.correlationId,
|
|
@@ -9381,16 +9868,16 @@ async function handleWorktreeUpdate(args) {
|
|
|
9381
9868
|
}
|
|
9382
9869
|
async function handleWorktreeMerge(args) {
|
|
9383
9870
|
try {
|
|
9384
|
-
const body =
|
|
9871
|
+
const body = asRecord27(args.body);
|
|
9385
9872
|
const rawOutcomes = Array.isArray(body.outcomes) ? body.outcomes : [];
|
|
9386
|
-
const outcomes = rawOutcomes.map((entry) =>
|
|
9387
|
-
beliefId:
|
|
9388
|
-
confidence:
|
|
9389
|
-
rationale:
|
|
9873
|
+
const outcomes = rawOutcomes.map((entry) => asRecord27(entry)).map((entry) => ({
|
|
9874
|
+
beliefId: readString31(entry.beliefId) ?? "",
|
|
9875
|
+
confidence: readNumber22(entry.confidence) ?? Number.NaN,
|
|
9876
|
+
rationale: readString31(entry.rationale) ?? ""
|
|
9390
9877
|
}));
|
|
9391
9878
|
const payload = await mergeWorktreeFromGatewayAuth(args.authContext, {
|
|
9392
9879
|
id: args.worktreeId,
|
|
9393
|
-
summary:
|
|
9880
|
+
summary: readString31(body.summary),
|
|
9394
9881
|
outcomes
|
|
9395
9882
|
});
|
|
9396
9883
|
return successResponse(payload, {
|
|
@@ -9408,7 +9895,7 @@ async function handleWorktreeMerge(args) {
|
|
|
9408
9895
|
}
|
|
9409
9896
|
async function handleWorktreeUpdateTargets(args) {
|
|
9410
9897
|
try {
|
|
9411
|
-
const body =
|
|
9898
|
+
const body = asRecord27(args.body);
|
|
9412
9899
|
const payload = await updateWorktreeTargetsFromGatewayAuth(
|
|
9413
9900
|
args.authContext,
|
|
9414
9901
|
{
|
|
@@ -9434,11 +9921,11 @@ async function handleWorktreeUpdateTargets(args) {
|
|
|
9434
9921
|
}
|
|
9435
9922
|
async function handleWorktreeComplete(args) {
|
|
9436
9923
|
try {
|
|
9437
|
-
const body =
|
|
9924
|
+
const body = asRecord27(args.body);
|
|
9438
9925
|
const payload = await completeWorktreeRecordFromGatewayAuth(
|
|
9439
9926
|
args.authContext,
|
|
9440
9927
|
{
|
|
9441
|
-
worktreeId:
|
|
9928
|
+
worktreeId: readString31(body.worktreeId) ?? "",
|
|
9442
9929
|
keyFindings: readStringArray12(body.keyFindings),
|
|
9443
9930
|
decisionsReached: readStringArray12(body.decisionsReached),
|
|
9444
9931
|
nextSteps: readStringArray12(body.nextSteps)
|
|
@@ -9459,9 +9946,9 @@ async function handleWorktreeComplete(args) {
|
|
|
9459
9946
|
}
|
|
9460
9947
|
async function handleWorktreeAdvancePhase(args) {
|
|
9461
9948
|
try {
|
|
9462
|
-
const body =
|
|
9949
|
+
const body = asRecord27(args.body);
|
|
9463
9950
|
const payload = await advanceWorktreePhaseFromGatewayAuth(args.authContext, {
|
|
9464
|
-
worktreeId:
|
|
9951
|
+
worktreeId: readString31(body.worktreeId) ?? ""
|
|
9465
9952
|
});
|
|
9466
9953
|
return successResponse(payload, {
|
|
9467
9954
|
correlationId: args.correlationId,
|
|
@@ -9478,10 +9965,10 @@ async function handleWorktreeAdvancePhase(args) {
|
|
|
9478
9965
|
}
|
|
9479
9966
|
async function handleWorktreeSetPhase(args) {
|
|
9480
9967
|
try {
|
|
9481
|
-
const body =
|
|
9968
|
+
const body = asRecord27(args.body);
|
|
9482
9969
|
const payload = await setWorktreePhaseFromGatewayAuth(args.authContext, {
|
|
9483
|
-
worktreeId:
|
|
9484
|
-
phase:
|
|
9970
|
+
worktreeId: readString31(body.worktreeId) ?? "",
|
|
9971
|
+
phase: readString31(body.phase) ?? ""
|
|
9485
9972
|
});
|
|
9486
9973
|
return successResponse(payload, {
|
|
9487
9974
|
correlationId: args.correlationId,
|
|
@@ -9498,12 +9985,12 @@ async function handleWorktreeSetPhase(args) {
|
|
|
9498
9985
|
}
|
|
9499
9986
|
async function handleWorktreePatchState(args) {
|
|
9500
9987
|
try {
|
|
9501
|
-
const body =
|
|
9988
|
+
const body = asRecord27(args.body);
|
|
9502
9989
|
const payload = await patchWorktreeStateFromGatewayAuth(
|
|
9503
9990
|
args.authContext,
|
|
9504
9991
|
{
|
|
9505
|
-
worktreeId:
|
|
9506
|
-
patch:
|
|
9992
|
+
worktreeId: readString31(body.worktreeId) ?? "",
|
|
9993
|
+
patch: asRecord27(body.patch)
|
|
9507
9994
|
}
|
|
9508
9995
|
);
|
|
9509
9996
|
return successResponse(payload, {
|
|
@@ -9521,7 +10008,7 @@ async function handleWorktreePatchState(args) {
|
|
|
9521
10008
|
}
|
|
9522
10009
|
async function handleWorktreeBulkCreate(args) {
|
|
9523
10010
|
try {
|
|
9524
|
-
const body =
|
|
10011
|
+
const body = asRecord27(args.body);
|
|
9525
10012
|
const payload = await bulkCreateWorktreesFromGatewayAuth(args.authContext, {
|
|
9526
10013
|
worktrees: Array.isArray(body.worktrees) ? body.worktrees : []
|
|
9527
10014
|
});
|
|
@@ -9540,6 +10027,6 @@ async function handleWorktreeBulkCreate(args) {
|
|
|
9540
10027
|
}
|
|
9541
10028
|
}
|
|
9542
10029
|
|
|
9543
|
-
export { createContextGatewayRoute, handleBeliefArchive, handleBeliefBatchUpdateCriticality, handleBeliefBisect, handleBeliefConfidenceHistory, handleBeliefCreate, handleBeliefCreateContract, handleBeliefFork, handleBeliefGet, handleBeliefLineage, handleBeliefLink, handleBeliefList, handleBeliefReassignTopic, handleBeliefRefine, handleBeliefRelationships, handleBeliefUnlinkEvidence, handleBeliefUpdateConfidence, handleBeliefUpdateCriticality, handleBeliefUpdateRationale, handleBeliefUpdateStatus, handleContradictionFlag, handleContradictionGet, handleContradictionList, handleEdgeBatchCreate, handleEdgeCreate, handleEdgeDelete, handleEdgeList, handleEdgeRemove, handleEdgeTraverse, handleEdgeUpdate, handleEdgesRemoveBetween, handleEventsList, handleEventsReplay, handleEvidenceCreate, handleEvidenceFlagIncorrect, handleEvidenceGet, handleEvidenceLink, handleEvidenceList, handleEvidenceRemove, handleEvidenceSearch, handleEvidenceUpdate, handleEvidenceUpdateStatus, handleEvidenceUpdateVerificationStatus, handleGraphAnalyze, handleGraphBias, handleGraphFalsify, handleGraphGaps, handleGraphNeighborhood, handleGraphTraverse, handleIdentityWhoami, handleOntologyBind, handleOntologyGet, handleOntologyList, handleOntologyMatch, handleQuestionAdd, handleQuestionAdvanceToConviction, handleQuestionAnswer, handleQuestionArchive, handleQuestionBatchCreate, handleQuestionCreate, handleQuestionDelete, handleQuestionFinalizeConviction, handleQuestionGet, handleQuestionGetAnswer, handleQuestionList, handleQuestionRefine, handleQuestionUpdate, handleQuestionUpdateConviction, handleQuestionUpdatePriority, handleQuestionUpdateStatus, handleSearchResources, handleTaskComplete, handleTaskCreate, handleTaskList, handleTaskUpdate, handleTopicBulkCreate, handleTopicCoverage, handleTopicCreate, handleTopicGet, handleTopicList, handleTopicRemove, handleTopicTree, handleTopicUpdate, handleWebhookCreate, handleWebhookDelete, handleWebhookDeliveries, handleWebhookGet, handleWebhookHealth, handleWebhookList, handleWebhookTest, handleWebhookUpdate, handleWorktreeActivate, handleWorktreeAdvancePhase, handleWorktreeBulkCreate, handleWorktreeComplete, handleWorktreeCreate, handleWorktreeList, handleWorktreeListAll, handleWorktreeMerge, handleWorktreePatchState, handleWorktreeSetPhase, handleWorktreeUpdate, handleWorktreeUpdateTargets };
|
|
10030
|
+
export { createContextGatewayRoute, handleBeliefArchive, handleBeliefBatchUpdateCriticality, handleBeliefBisect, handleBeliefConfidenceHistory, handleBeliefCreate, handleBeliefCreateContract, handleBeliefFork, handleBeliefGet, handleBeliefLineage, handleBeliefLink, handleBeliefList, handleBeliefReassignTopic, handleBeliefRefine, handleBeliefRelationships, handleBeliefUnlinkEvidence, handleBeliefUpdateConfidence, handleBeliefUpdateCriticality, handleBeliefUpdateRationale, handleBeliefUpdateStatus, handleContradictionFlag, handleContradictionGet, handleContradictionList, handleEdgeBatchCreate, handleEdgeCreate, handleEdgeDelete, handleEdgeList, handleEdgeRemove, handleEdgeTraverse, handleEdgeUpdate, handleEdgesRemoveBetween, handleEventsList, handleEventsReplay, handleEvidenceClassify, handleEvidenceClassifyBatch, handleEvidenceCreate, handleEvidenceFlagIncorrect, handleEvidenceGet, handleEvidenceLink, handleEvidenceList, handleEvidenceRemove, handleEvidenceSearch, handleEvidenceUpdate, handleEvidenceUpdateStatus, handleEvidenceUpdateVerificationStatus, handleGraphAnalyze, handleGraphBias, handleGraphFalsify, handleGraphGaps, handleGraphNeighborhood, handleGraphTraverse, handleIdentityWhoami, handleOntologyBind, handleOntologyGet, handleOntologyList, handleOntologyMatch, handleQuestionAdd, handleQuestionAdvanceToConviction, handleQuestionAnswer, handleQuestionArchive, handleQuestionBatchCreate, handleQuestionCreate, handleQuestionDelete, handleQuestionFinalizeConviction, handleQuestionGet, handleQuestionGetAnswer, handleQuestionList, handleQuestionRefine, handleQuestionUpdate, handleQuestionUpdateConviction, handleQuestionUpdatePriority, handleQuestionUpdateStatus, handleSearchResources, handleSourceGet, handleSourceUpsert, handleTaskComplete, handleTaskCreate, handleTaskList, handleTaskUpdate, handleTopicBulkCreate, handleTopicCoverage, handleTopicCreate, handleTopicGet, handleTopicList, handleTopicRemove, handleTopicTree, handleTopicUpdate, handleWebhookCreate, handleWebhookDelete, handleWebhookDeliveries, handleWebhookGet, handleWebhookHealth, handleWebhookList, handleWebhookTest, handleWebhookUpdate, handleWorktreeActivate, handleWorktreeAdvancePhase, handleWorktreeBulkCreate, handleWorktreeComplete, handleWorktreeCreate, handleWorktreeList, handleWorktreeListAll, handleWorktreeMerge, handleWorktreePatchState, handleWorktreeSetPhase, handleWorktreeUpdate, handleWorktreeUpdateTargets };
|
|
9544
10031
|
//# sourceMappingURL=gateway.js.map
|
|
9545
10032
|
//# sourceMappingURL=gateway.js.map
|