@semiont/make-meaning 0.5.11 → 0.5.13
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/README.md +10 -10
- package/dist/index.d.ts +140 -107
- package/dist/index.js +532 -618
- package/dist/index.js.map +1 -1
- package/dist/smelter-main.js +144 -30
- package/dist/smelter-main.js.map +1 -1
- package/dist/weaver-main.js +10746 -0
- package/dist/weaver-main.js.map +1 -0
- package/package.json +17 -13
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FsJobQueue } from '@semiont/jobs';
|
|
2
2
|
import { FilesystemViewStorage, resolveStorageUri, EventQuery, createEventStore } from '@semiont/event-sourcing';
|
|
3
|
-
import { getPrimaryRepresentation, decodeRepresentation, getResourceEntityTypes, getResourceId, getTargetSource, resourceId, getBodySource, getTargetSelector, deriveViews, getTextPositionSelector, annotationId, errField, userId, generateUuid, getExactText, busRequest, cloneToken, baseMediaType, isSupportedMediaType, capabilitiesOf, didToAgent, assembleAnnotation, jobId, entityType, baseUrl, busLog, BRIDGED_CHANNELS, burstBuffer, textExtractionOf, getPrimaryMediaType, extensionForMediaType, applyBodyOperations,
|
|
3
|
+
import { getPrimaryRepresentation, decodeRepresentation, getResourceEntityTypes, getResourceId, getTargetSource, resourceId, getBodySource, getTargetSelector, deriveViews, getTextPositionSelector, annotationId, errField, userId, generateUuid, getExactText, busRequest, cloneToken, baseMediaType, isSupportedMediaType, capabilitiesOf, didToAgent, assembleAnnotation, jobId, entityType, baseUrl, busLog, BRIDGED_CHANNELS, burstBuffer, textExtractionOf, getPrimaryMediaType, extensionForMediaType, applyBodyOperations, softwareToAgent } from '@semiont/core';
|
|
4
4
|
import { withActorSpan, recordBusEmit, withSpan, SpanKind, registerJobQueueProvider, registerVectorIndexSizeProvider } from '@semiont/observability';
|
|
5
5
|
import { createInferenceClient } from '@semiont/inference';
|
|
6
6
|
import { getGraphDatabase } from '@semiont/graph';
|
|
@@ -26,11 +26,11 @@ var __commonJS = (cb, mod) => function __require() {
|
|
|
26
26
|
throw mod = 0, e;
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
|
-
var __copyProps = (to,
|
|
30
|
-
if (
|
|
31
|
-
for (let key of __getOwnPropNames(
|
|
29
|
+
var __copyProps = (to, from8, except, desc) => {
|
|
30
|
+
if (from8 && typeof from8 === "object" || typeof from8 === "function") {
|
|
31
|
+
for (let key of __getOwnPropNames(from8))
|
|
32
32
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
33
|
-
__defProp(to, key, { get: () =>
|
|
33
|
+
__defProp(to, key, { get: () => from8[key], enumerable: !(desc = __getOwnPropDesc(from8, key)) || desc.enumerable });
|
|
34
34
|
}
|
|
35
35
|
return to;
|
|
36
36
|
};
|
|
@@ -139,9 +139,9 @@ var require_Subscription = __commonJS({
|
|
|
139
139
|
}
|
|
140
140
|
return ar;
|
|
141
141
|
};
|
|
142
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
143
|
-
for (var i = 0, il =
|
|
144
|
-
to[j] =
|
|
142
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
143
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
144
|
+
to[j] = from8[i];
|
|
145
145
|
return to;
|
|
146
146
|
};
|
|
147
147
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -149,14 +149,14 @@ var require_Subscription = __commonJS({
|
|
|
149
149
|
var isFunction_1 = require_isFunction();
|
|
150
150
|
var UnsubscriptionError_1 = require_UnsubscriptionError();
|
|
151
151
|
var arrRemove_1 = require_arrRemove();
|
|
152
|
-
var
|
|
153
|
-
function
|
|
152
|
+
var Subscription7 = (function() {
|
|
153
|
+
function Subscription8(initialTeardown) {
|
|
154
154
|
this.initialTeardown = initialTeardown;
|
|
155
155
|
this.closed = false;
|
|
156
156
|
this._parentage = null;
|
|
157
157
|
this._finalizers = null;
|
|
158
158
|
}
|
|
159
|
-
|
|
159
|
+
Subscription8.prototype.unsubscribe = function() {
|
|
160
160
|
var e_1, _a, e_2, _b;
|
|
161
161
|
var errors;
|
|
162
162
|
if (!this.closed) {
|
|
@@ -223,13 +223,13 @@ var require_Subscription = __commonJS({
|
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
};
|
|
226
|
-
|
|
226
|
+
Subscription8.prototype.add = function(teardown) {
|
|
227
227
|
var _a;
|
|
228
228
|
if (teardown && teardown !== this) {
|
|
229
229
|
if (this.closed) {
|
|
230
230
|
execFinalizer(teardown);
|
|
231
231
|
} else {
|
|
232
|
-
if (teardown instanceof
|
|
232
|
+
if (teardown instanceof Subscription8) {
|
|
233
233
|
if (teardown.closed || teardown._hasParent(this)) {
|
|
234
234
|
return;
|
|
235
235
|
}
|
|
@@ -239,15 +239,15 @@ var require_Subscription = __commonJS({
|
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
241
|
};
|
|
242
|
-
|
|
242
|
+
Subscription8.prototype._hasParent = function(parent) {
|
|
243
243
|
var _parentage = this._parentage;
|
|
244
244
|
return _parentage === parent || Array.isArray(_parentage) && _parentage.includes(parent);
|
|
245
245
|
};
|
|
246
|
-
|
|
246
|
+
Subscription8.prototype._addParent = function(parent) {
|
|
247
247
|
var _parentage = this._parentage;
|
|
248
248
|
this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
|
|
249
249
|
};
|
|
250
|
-
|
|
250
|
+
Subscription8.prototype._removeParent = function(parent) {
|
|
251
251
|
var _parentage = this._parentage;
|
|
252
252
|
if (_parentage === parent) {
|
|
253
253
|
this._parentage = null;
|
|
@@ -255,24 +255,24 @@ var require_Subscription = __commonJS({
|
|
|
255
255
|
arrRemove_1.arrRemove(_parentage, parent);
|
|
256
256
|
}
|
|
257
257
|
};
|
|
258
|
-
|
|
258
|
+
Subscription8.prototype.remove = function(teardown) {
|
|
259
259
|
var _finalizers = this._finalizers;
|
|
260
260
|
_finalizers && arrRemove_1.arrRemove(_finalizers, teardown);
|
|
261
|
-
if (teardown instanceof
|
|
261
|
+
if (teardown instanceof Subscription8) {
|
|
262
262
|
teardown._removeParent(this);
|
|
263
263
|
}
|
|
264
264
|
};
|
|
265
|
-
|
|
266
|
-
var empty = new
|
|
265
|
+
Subscription8.EMPTY = (function() {
|
|
266
|
+
var empty = new Subscription8();
|
|
267
267
|
empty.closed = true;
|
|
268
268
|
return empty;
|
|
269
269
|
})();
|
|
270
|
-
return
|
|
270
|
+
return Subscription8;
|
|
271
271
|
})();
|
|
272
|
-
exports.Subscription =
|
|
273
|
-
exports.EMPTY_SUBSCRIPTION =
|
|
272
|
+
exports.Subscription = Subscription7;
|
|
273
|
+
exports.EMPTY_SUBSCRIPTION = Subscription7.EMPTY;
|
|
274
274
|
function isSubscription(value) {
|
|
275
|
-
return value instanceof
|
|
275
|
+
return value instanceof Subscription7 || value && "closed" in value && isFunction_1.isFunction(value.remove) && isFunction_1.isFunction(value.add) && isFunction_1.isFunction(value.unsubscribe);
|
|
276
276
|
}
|
|
277
277
|
exports.isSubscription = isSubscription;
|
|
278
278
|
function execFinalizer(finalizer) {
|
|
@@ -320,9 +320,9 @@ var require_timeoutProvider = __commonJS({
|
|
|
320
320
|
}
|
|
321
321
|
return ar;
|
|
322
322
|
};
|
|
323
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
324
|
-
for (var i = 0, il =
|
|
325
|
-
to[j] =
|
|
323
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
324
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
325
|
+
to[j] = from8[i];
|
|
326
326
|
return to;
|
|
327
327
|
};
|
|
328
328
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1065,9 +1065,9 @@ var require_animationFrameProvider = __commonJS({
|
|
|
1065
1065
|
}
|
|
1066
1066
|
return ar;
|
|
1067
1067
|
};
|
|
1068
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
1069
|
-
for (var i = 0, il =
|
|
1070
|
-
to[j] =
|
|
1068
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
1069
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
1070
|
+
to[j] = from8[i];
|
|
1071
1071
|
return to;
|
|
1072
1072
|
};
|
|
1073
1073
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1209,9 +1209,9 @@ var require_Subject = __commonJS({
|
|
|
1209
1209
|
var ObjectUnsubscribedError_1 = require_ObjectUnsubscribedError();
|
|
1210
1210
|
var arrRemove_1 = require_arrRemove();
|
|
1211
1211
|
var errorContext_1 = require_errorContext();
|
|
1212
|
-
var
|
|
1213
|
-
__extends(
|
|
1214
|
-
function
|
|
1212
|
+
var Subject3 = (function(_super) {
|
|
1213
|
+
__extends(Subject4, _super);
|
|
1214
|
+
function Subject4() {
|
|
1215
1215
|
var _this = _super.call(this) || this;
|
|
1216
1216
|
_this.closed = false;
|
|
1217
1217
|
_this.currentObservers = null;
|
|
@@ -1221,17 +1221,17 @@ var require_Subject = __commonJS({
|
|
|
1221
1221
|
_this.thrownError = null;
|
|
1222
1222
|
return _this;
|
|
1223
1223
|
}
|
|
1224
|
-
|
|
1224
|
+
Subject4.prototype.lift = function(operator) {
|
|
1225
1225
|
var subject = new AnonymousSubject(this, this);
|
|
1226
1226
|
subject.operator = operator;
|
|
1227
1227
|
return subject;
|
|
1228
1228
|
};
|
|
1229
|
-
|
|
1229
|
+
Subject4.prototype._throwIfClosed = function() {
|
|
1230
1230
|
if (this.closed) {
|
|
1231
1231
|
throw new ObjectUnsubscribedError_1.ObjectUnsubscribedError();
|
|
1232
1232
|
}
|
|
1233
1233
|
};
|
|
1234
|
-
|
|
1234
|
+
Subject4.prototype.next = function(value) {
|
|
1235
1235
|
var _this = this;
|
|
1236
1236
|
errorContext_1.errorContext(function() {
|
|
1237
1237
|
var e_1, _a;
|
|
@@ -1257,7 +1257,7 @@ var require_Subject = __commonJS({
|
|
|
1257
1257
|
}
|
|
1258
1258
|
});
|
|
1259
1259
|
};
|
|
1260
|
-
|
|
1260
|
+
Subject4.prototype.error = function(err) {
|
|
1261
1261
|
var _this = this;
|
|
1262
1262
|
errorContext_1.errorContext(function() {
|
|
1263
1263
|
_this._throwIfClosed();
|
|
@@ -1271,7 +1271,7 @@ var require_Subject = __commonJS({
|
|
|
1271
1271
|
}
|
|
1272
1272
|
});
|
|
1273
1273
|
};
|
|
1274
|
-
|
|
1274
|
+
Subject4.prototype.complete = function() {
|
|
1275
1275
|
var _this = this;
|
|
1276
1276
|
errorContext_1.errorContext(function() {
|
|
1277
1277
|
_this._throwIfClosed();
|
|
@@ -1284,11 +1284,11 @@ var require_Subject = __commonJS({
|
|
|
1284
1284
|
}
|
|
1285
1285
|
});
|
|
1286
1286
|
};
|
|
1287
|
-
|
|
1287
|
+
Subject4.prototype.unsubscribe = function() {
|
|
1288
1288
|
this.isStopped = this.closed = true;
|
|
1289
1289
|
this.observers = this.currentObservers = null;
|
|
1290
1290
|
};
|
|
1291
|
-
Object.defineProperty(
|
|
1291
|
+
Object.defineProperty(Subject4.prototype, "observed", {
|
|
1292
1292
|
get: function() {
|
|
1293
1293
|
var _a;
|
|
1294
1294
|
return ((_a = this.observers) === null || _a === void 0 ? void 0 : _a.length) > 0;
|
|
@@ -1296,16 +1296,16 @@ var require_Subject = __commonJS({
|
|
|
1296
1296
|
enumerable: false,
|
|
1297
1297
|
configurable: true
|
|
1298
1298
|
});
|
|
1299
|
-
|
|
1299
|
+
Subject4.prototype._trySubscribe = function(subscriber) {
|
|
1300
1300
|
this._throwIfClosed();
|
|
1301
1301
|
return _super.prototype._trySubscribe.call(this, subscriber);
|
|
1302
1302
|
};
|
|
1303
|
-
|
|
1303
|
+
Subject4.prototype._subscribe = function(subscriber) {
|
|
1304
1304
|
this._throwIfClosed();
|
|
1305
1305
|
this._checkFinalizedStatuses(subscriber);
|
|
1306
1306
|
return this._innerSubscribe(subscriber);
|
|
1307
1307
|
};
|
|
1308
|
-
|
|
1308
|
+
Subject4.prototype._innerSubscribe = function(subscriber) {
|
|
1309
1309
|
var _this = this;
|
|
1310
1310
|
var _a = this, hasError = _a.hasError, isStopped = _a.isStopped, observers = _a.observers;
|
|
1311
1311
|
if (hasError || isStopped) {
|
|
@@ -1318,7 +1318,7 @@ var require_Subject = __commonJS({
|
|
|
1318
1318
|
arrRemove_1.arrRemove(observers, subscriber);
|
|
1319
1319
|
});
|
|
1320
1320
|
};
|
|
1321
|
-
|
|
1321
|
+
Subject4.prototype._checkFinalizedStatuses = function(subscriber) {
|
|
1322
1322
|
var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, isStopped = _a.isStopped;
|
|
1323
1323
|
if (hasError) {
|
|
1324
1324
|
subscriber.error(thrownError);
|
|
@@ -1326,17 +1326,17 @@ var require_Subject = __commonJS({
|
|
|
1326
1326
|
subscriber.complete();
|
|
1327
1327
|
}
|
|
1328
1328
|
};
|
|
1329
|
-
|
|
1329
|
+
Subject4.prototype.asObservable = function() {
|
|
1330
1330
|
var observable = new Observable_1.Observable();
|
|
1331
1331
|
observable.source = this;
|
|
1332
1332
|
return observable;
|
|
1333
1333
|
};
|
|
1334
|
-
|
|
1334
|
+
Subject4.create = function(destination, source) {
|
|
1335
1335
|
return new AnonymousSubject(destination, source);
|
|
1336
1336
|
};
|
|
1337
|
-
return
|
|
1337
|
+
return Subject4;
|
|
1338
1338
|
})(Observable_1.Observable);
|
|
1339
|
-
exports.Subject =
|
|
1339
|
+
exports.Subject = Subject3;
|
|
1340
1340
|
var AnonymousSubject = (function(_super) {
|
|
1341
1341
|
__extends(AnonymousSubject2, _super);
|
|
1342
1342
|
function AnonymousSubject2(destination, source) {
|
|
@@ -1362,7 +1362,7 @@ var require_Subject = __commonJS({
|
|
|
1362
1362
|
return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : Subscription_1.EMPTY_SUBSCRIPTION;
|
|
1363
1363
|
};
|
|
1364
1364
|
return AnonymousSubject2;
|
|
1365
|
-
})(
|
|
1365
|
+
})(Subject3);
|
|
1366
1366
|
exports.AnonymousSubject = AnonymousSubject;
|
|
1367
1367
|
}
|
|
1368
1368
|
});
|
|
@@ -1653,9 +1653,9 @@ var require_intervalProvider = __commonJS({
|
|
|
1653
1653
|
}
|
|
1654
1654
|
return ar;
|
|
1655
1655
|
};
|
|
1656
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
1657
|
-
for (var i = 0, il =
|
|
1658
|
-
to[j] =
|
|
1656
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
1657
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
1658
|
+
to[j] = from8[i];
|
|
1659
1659
|
return to;
|
|
1660
1660
|
};
|
|
1661
1661
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1859,9 +1859,9 @@ var require_immediateProvider = __commonJS({
|
|
|
1859
1859
|
}
|
|
1860
1860
|
return ar;
|
|
1861
1861
|
};
|
|
1862
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
1863
|
-
for (var i = 0, il =
|
|
1864
|
-
to[j] =
|
|
1862
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
1863
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
1864
|
+
to[j] = from8[i];
|
|
1865
1865
|
return to;
|
|
1866
1866
|
};
|
|
1867
1867
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -3383,10 +3383,10 @@ var require_from = __commonJS({
|
|
|
3383
3383
|
exports.from = void 0;
|
|
3384
3384
|
var scheduled_1 = require_scheduled();
|
|
3385
3385
|
var innerFrom_1 = require_innerFrom();
|
|
3386
|
-
function
|
|
3386
|
+
function from8(input, scheduler) {
|
|
3387
3387
|
return scheduler ? scheduled_1.scheduled(input, scheduler) : innerFrom_1.innerFrom(input);
|
|
3388
3388
|
}
|
|
3389
|
-
exports.from =
|
|
3389
|
+
exports.from = from8;
|
|
3390
3390
|
}
|
|
3391
3391
|
});
|
|
3392
3392
|
|
|
@@ -3759,9 +3759,9 @@ var require_mapOneOrManyArgs = __commonJS({
|
|
|
3759
3759
|
}
|
|
3760
3760
|
return ar;
|
|
3761
3761
|
};
|
|
3762
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
3763
|
-
for (var i = 0, il =
|
|
3764
|
-
to[j] =
|
|
3762
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
3763
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
3764
|
+
to[j] = from8[i];
|
|
3765
3765
|
return to;
|
|
3766
3766
|
};
|
|
3767
3767
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -3800,9 +3800,9 @@ var require_bindCallbackInternals = __commonJS({
|
|
|
3800
3800
|
}
|
|
3801
3801
|
return ar;
|
|
3802
3802
|
};
|
|
3803
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
3804
|
-
for (var i = 0, il =
|
|
3805
|
-
to[j] =
|
|
3803
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
3804
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
3805
|
+
to[j] = from8[i];
|
|
3806
3806
|
return to;
|
|
3807
3807
|
};
|
|
3808
3808
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -4115,12 +4115,12 @@ var require_mergeMap = __commonJS({
|
|
|
4115
4115
|
var lift_1 = require_lift();
|
|
4116
4116
|
var mergeInternals_1 = require_mergeInternals();
|
|
4117
4117
|
var isFunction_1 = require_isFunction();
|
|
4118
|
-
function
|
|
4118
|
+
function mergeMap6(project, resultSelector, concurrent) {
|
|
4119
4119
|
if (concurrent === void 0) {
|
|
4120
4120
|
concurrent = Infinity;
|
|
4121
4121
|
}
|
|
4122
4122
|
if (isFunction_1.isFunction(resultSelector)) {
|
|
4123
|
-
return
|
|
4123
|
+
return mergeMap6(function(a, i) {
|
|
4124
4124
|
return map_1.map(function(b, ii) {
|
|
4125
4125
|
return resultSelector(a, b, i, ii);
|
|
4126
4126
|
})(innerFrom_1.innerFrom(project(a, i)));
|
|
@@ -4132,7 +4132,7 @@ var require_mergeMap = __commonJS({
|
|
|
4132
4132
|
return mergeInternals_1.mergeInternals(source, subscriber, project, concurrent);
|
|
4133
4133
|
});
|
|
4134
4134
|
}
|
|
4135
|
-
exports.mergeMap =
|
|
4135
|
+
exports.mergeMap = mergeMap6;
|
|
4136
4136
|
}
|
|
4137
4137
|
});
|
|
4138
4138
|
|
|
@@ -4903,9 +4903,9 @@ var require_zip = __commonJS({
|
|
|
4903
4903
|
}
|
|
4904
4904
|
return ar;
|
|
4905
4905
|
};
|
|
4906
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
4907
|
-
for (var i = 0, il =
|
|
4908
|
-
to[j] =
|
|
4906
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
4907
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
4908
|
+
to[j] = from8[i];
|
|
4909
4909
|
return to;
|
|
4910
4910
|
};
|
|
4911
4911
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -5517,9 +5517,9 @@ var require_combineLatest2 = __commonJS({
|
|
|
5517
5517
|
}
|
|
5518
5518
|
return ar;
|
|
5519
5519
|
};
|
|
5520
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
5521
|
-
for (var i = 0, il =
|
|
5522
|
-
to[j] =
|
|
5520
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
5521
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
5522
|
+
to[j] = from8[i];
|
|
5523
5523
|
return to;
|
|
5524
5524
|
};
|
|
5525
5525
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -5564,9 +5564,9 @@ var require_combineLatestWith = __commonJS({
|
|
|
5564
5564
|
}
|
|
5565
5565
|
return ar;
|
|
5566
5566
|
};
|
|
5567
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
5568
|
-
for (var i = 0, il =
|
|
5569
|
-
to[j] =
|
|
5567
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
5568
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
5569
|
+
to[j] = from8[i];
|
|
5570
5570
|
return to;
|
|
5571
5571
|
};
|
|
5572
5572
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -5590,10 +5590,10 @@ var require_concatMap = __commonJS({
|
|
|
5590
5590
|
exports.concatMap = void 0;
|
|
5591
5591
|
var mergeMap_1 = require_mergeMap();
|
|
5592
5592
|
var isFunction_1 = require_isFunction();
|
|
5593
|
-
function
|
|
5593
|
+
function concatMap5(project, resultSelector) {
|
|
5594
5594
|
return isFunction_1.isFunction(resultSelector) ? mergeMap_1.mergeMap(project, resultSelector, 1) : mergeMap_1.mergeMap(project, 1);
|
|
5595
5595
|
}
|
|
5596
|
-
exports.concatMap =
|
|
5596
|
+
exports.concatMap = concatMap5;
|
|
5597
5597
|
}
|
|
5598
5598
|
});
|
|
5599
5599
|
|
|
@@ -5635,9 +5635,9 @@ var require_concat2 = __commonJS({
|
|
|
5635
5635
|
}
|
|
5636
5636
|
return ar;
|
|
5637
5637
|
};
|
|
5638
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
5639
|
-
for (var i = 0, il =
|
|
5640
|
-
to[j] =
|
|
5638
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
5639
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
5640
|
+
to[j] = from8[i];
|
|
5641
5641
|
return to;
|
|
5642
5642
|
};
|
|
5643
5643
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -5680,9 +5680,9 @@ var require_concatWith = __commonJS({
|
|
|
5680
5680
|
}
|
|
5681
5681
|
return ar;
|
|
5682
5682
|
};
|
|
5683
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
5684
|
-
for (var i = 0, il =
|
|
5685
|
-
to[j] =
|
|
5683
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
5684
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
5685
|
+
to[j] = from8[i];
|
|
5686
5686
|
return to;
|
|
5687
5687
|
};
|
|
5688
5688
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -6155,9 +6155,9 @@ var require_endWith = __commonJS({
|
|
|
6155
6155
|
}
|
|
6156
6156
|
return ar;
|
|
6157
6157
|
};
|
|
6158
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
6159
|
-
for (var i = 0, il =
|
|
6160
|
-
to[j] =
|
|
6158
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
6159
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
6160
|
+
to[j] = from8[i];
|
|
6161
6161
|
return to;
|
|
6162
6162
|
};
|
|
6163
6163
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -6386,7 +6386,7 @@ var require_groupBy = __commonJS({
|
|
|
6386
6386
|
var Subject_1 = require_Subject();
|
|
6387
6387
|
var lift_1 = require_lift();
|
|
6388
6388
|
var OperatorSubscriber_1 = require_OperatorSubscriber();
|
|
6389
|
-
function
|
|
6389
|
+
function groupBy3(keySelector, elementOrOptions, duration, connector) {
|
|
6390
6390
|
return lift_1.operate(function(source, subscriber) {
|
|
6391
6391
|
var element;
|
|
6392
6392
|
if (!elementOrOptions || typeof elementOrOptions === "function") {
|
|
@@ -6453,7 +6453,7 @@ var require_groupBy = __commonJS({
|
|
|
6453
6453
|
}
|
|
6454
6454
|
});
|
|
6455
6455
|
}
|
|
6456
|
-
exports.groupBy =
|
|
6456
|
+
exports.groupBy = groupBy3;
|
|
6457
6457
|
}
|
|
6458
6458
|
});
|
|
6459
6459
|
|
|
@@ -6683,9 +6683,9 @@ var require_merge2 = __commonJS({
|
|
|
6683
6683
|
}
|
|
6684
6684
|
return ar;
|
|
6685
6685
|
};
|
|
6686
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
6687
|
-
for (var i = 0, il =
|
|
6688
|
-
to[j] =
|
|
6686
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
6687
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
6688
|
+
to[j] = from8[i];
|
|
6689
6689
|
return to;
|
|
6690
6690
|
};
|
|
6691
6691
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -6729,9 +6729,9 @@ var require_mergeWith = __commonJS({
|
|
|
6729
6729
|
}
|
|
6730
6730
|
return ar;
|
|
6731
6731
|
};
|
|
6732
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
6733
|
-
for (var i = 0, il =
|
|
6734
|
-
to[j] =
|
|
6732
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
6733
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
6734
|
+
to[j] = from8[i];
|
|
6735
6735
|
return to;
|
|
6736
6736
|
};
|
|
6737
6737
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -6811,9 +6811,9 @@ var require_onErrorResumeNextWith = __commonJS({
|
|
|
6811
6811
|
}
|
|
6812
6812
|
return ar;
|
|
6813
6813
|
};
|
|
6814
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
6815
|
-
for (var i = 0, il =
|
|
6816
|
-
to[j] =
|
|
6814
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
6815
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
6816
|
+
to[j] = from8[i];
|
|
6817
6817
|
return to;
|
|
6818
6818
|
};
|
|
6819
6819
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -6988,9 +6988,9 @@ var require_raceWith = __commonJS({
|
|
|
6988
6988
|
}
|
|
6989
6989
|
return ar;
|
|
6990
6990
|
};
|
|
6991
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
6992
|
-
for (var i = 0, il =
|
|
6993
|
-
to[j] =
|
|
6991
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
6992
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
6993
|
+
to[j] = from8[i];
|
|
6994
6994
|
return to;
|
|
6995
6995
|
};
|
|
6996
6996
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -7377,9 +7377,9 @@ var require_share = __commonJS({
|
|
|
7377
7377
|
}
|
|
7378
7378
|
return ar;
|
|
7379
7379
|
};
|
|
7380
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
7381
|
-
for (var i = 0, il =
|
|
7382
|
-
to[j] =
|
|
7380
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
7381
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
7382
|
+
to[j] = from8[i];
|
|
7383
7383
|
return to;
|
|
7384
7384
|
};
|
|
7385
7385
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -8352,9 +8352,9 @@ var require_withLatestFrom = __commonJS({
|
|
|
8352
8352
|
}
|
|
8353
8353
|
return ar;
|
|
8354
8354
|
};
|
|
8355
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
8356
|
-
for (var i = 0, il =
|
|
8357
|
-
to[j] =
|
|
8355
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
8356
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
8357
|
+
to[j] = from8[i];
|
|
8358
8358
|
return to;
|
|
8359
8359
|
};
|
|
8360
8360
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -8436,9 +8436,9 @@ var require_zip2 = __commonJS({
|
|
|
8436
8436
|
}
|
|
8437
8437
|
return ar;
|
|
8438
8438
|
};
|
|
8439
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
8440
|
-
for (var i = 0, il =
|
|
8441
|
-
to[j] =
|
|
8439
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
8440
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
8441
|
+
to[j] = from8[i];
|
|
8442
8442
|
return to;
|
|
8443
8443
|
};
|
|
8444
8444
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -8478,9 +8478,9 @@ var require_zipWith = __commonJS({
|
|
|
8478
8478
|
}
|
|
8479
8479
|
return ar;
|
|
8480
8480
|
};
|
|
8481
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
8482
|
-
for (var i = 0, il =
|
|
8483
|
-
to[j] =
|
|
8481
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
8482
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
8483
|
+
to[j] = from8[i];
|
|
8484
8484
|
return to;
|
|
8485
8485
|
};
|
|
8486
8486
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -9243,9 +9243,9 @@ var require_race2 = __commonJS({
|
|
|
9243
9243
|
}
|
|
9244
9244
|
return ar;
|
|
9245
9245
|
};
|
|
9246
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
9247
|
-
for (var i = 0, il =
|
|
9248
|
-
to[j] =
|
|
9246
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
9247
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
9248
|
+
to[j] = from8[i];
|
|
9249
9249
|
return to;
|
|
9250
9250
|
};
|
|
9251
9251
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -9744,425 +9744,143 @@ function resolveWorkerInference(config, workerType) {
|
|
|
9744
9744
|
}
|
|
9745
9745
|
|
|
9746
9746
|
// src/service.ts
|
|
9747
|
-
var
|
|
9748
|
-
var
|
|
9749
|
-
|
|
9750
|
-
// src/graph/consumer.ts
|
|
9751
|
-
var import_rxjs = __toESM(require_cjs());
|
|
9752
|
-
var import_operators = __toESM(require_operators());
|
|
9753
|
-
|
|
9754
|
-
// src/batch-utils.ts
|
|
9755
|
-
function partitionByType(events) {
|
|
9756
|
-
const runs = [];
|
|
9757
|
-
let currentRun = [];
|
|
9758
|
-
for (const event of events) {
|
|
9759
|
-
if (currentRun.length > 0 && currentRun[0].type !== event.type) {
|
|
9760
|
-
runs.push(currentRun);
|
|
9761
|
-
currentRun = [];
|
|
9762
|
-
}
|
|
9763
|
-
currentRun.push(event);
|
|
9764
|
-
}
|
|
9765
|
-
if (currentRun.length > 0) runs.push(currentRun);
|
|
9766
|
-
return runs;
|
|
9767
|
-
}
|
|
9747
|
+
var import_rxjs6 = __toESM(require_cjs());
|
|
9748
|
+
var import_operators6 = __toESM(require_operators());
|
|
9768
9749
|
|
|
9769
|
-
// src/
|
|
9770
|
-
var
|
|
9771
|
-
constructor(
|
|
9772
|
-
|
|
9773
|
-
this.
|
|
9774
|
-
this.coreEventBus = coreEventBus;
|
|
9775
|
-
this.logger = logger;
|
|
9776
|
-
}
|
|
9777
|
-
eventStore;
|
|
9778
|
-
graphDb;
|
|
9779
|
-
coreEventBus;
|
|
9780
|
-
// Event types that produce GraphDB mutations — filter everything else
|
|
9781
|
-
static GRAPH_RELEVANT_EVENTS = /* @__PURE__ */ new Set([
|
|
9782
|
-
"yield:created",
|
|
9783
|
-
"mark:archived",
|
|
9784
|
-
"mark:unarchived",
|
|
9785
|
-
"mark:added",
|
|
9786
|
-
"mark:removed",
|
|
9787
|
-
"mark:body-updated",
|
|
9788
|
-
"mark:entity-tag-added",
|
|
9789
|
-
"mark:entity-tag-removed",
|
|
9790
|
-
"frame:entity-type-added"
|
|
9791
|
-
]);
|
|
9792
|
-
// Burst buffer thresholds — see class doc and BATCH-GRAPH-CONSUMER-RX.md
|
|
9793
|
-
static BURST_WINDOW_MS = 50;
|
|
9794
|
-
static MAX_BATCH_SIZE = 500;
|
|
9795
|
-
static IDLE_TIMEOUT_MS = 200;
|
|
9796
|
-
_globalSubscriptions = [];
|
|
9797
|
-
eventSubject = new import_rxjs.Subject();
|
|
9798
|
-
pipelineSubscription = null;
|
|
9799
|
-
lastProcessed = /* @__PURE__ */ new Map();
|
|
9800
|
-
logger;
|
|
9801
|
-
async initialize() {
|
|
9802
|
-
this.logger.info("GraphDB consumer initialized");
|
|
9803
|
-
await this.subscribeToGlobalEvents();
|
|
9804
|
-
}
|
|
9805
|
-
/**
|
|
9806
|
-
* Subscribe globally to ALL events, pre-filter to graph-relevant types,
|
|
9807
|
-
* and wire through the RxJS burst-buffered pipeline.
|
|
9808
|
-
*/
|
|
9809
|
-
async subscribeToGlobalEvents() {
|
|
9810
|
-
for (const eventType of _GraphDBConsumer.GRAPH_RELEVANT_EVENTS) {
|
|
9811
|
-
this._globalSubscriptions.push(
|
|
9812
|
-
this.coreEventBus.getDomainEvent(eventType).subscribe(
|
|
9813
|
-
(storedEvent) => this.eventSubject.next(storedEvent)
|
|
9814
|
-
)
|
|
9815
|
-
);
|
|
9816
|
-
}
|
|
9817
|
-
this.pipelineSubscription = this.eventSubject.pipe(
|
|
9818
|
-
// Split into one inner Observable per resource (system events grouped under '__system__')
|
|
9819
|
-
(0, import_operators.groupBy)((se) => se.resourceId ?? "__system__"),
|
|
9820
|
-
(0, import_operators.mergeMap)((group) => {
|
|
9821
|
-
if (group.key === "__system__") {
|
|
9822
|
-
return group.pipe(
|
|
9823
|
-
(0, import_operators.concatMap)((se) => (0, import_rxjs.from)(this.safeApplyEvent(se)))
|
|
9824
|
-
);
|
|
9825
|
-
}
|
|
9826
|
-
return group.pipe(
|
|
9827
|
-
burstBuffer({
|
|
9828
|
-
burstWindowMs: _GraphDBConsumer.BURST_WINDOW_MS,
|
|
9829
|
-
maxBatchSize: _GraphDBConsumer.MAX_BATCH_SIZE,
|
|
9830
|
-
idleTimeoutMs: _GraphDBConsumer.IDLE_TIMEOUT_MS
|
|
9831
|
-
}),
|
|
9832
|
-
(0, import_operators.concatMap)((eventOrBatch) => {
|
|
9833
|
-
if (Array.isArray(eventOrBatch)) {
|
|
9834
|
-
return (0, import_rxjs.from)(this.processBatch(eventOrBatch));
|
|
9835
|
-
}
|
|
9836
|
-
return (0, import_rxjs.from)(this.safeApplyEvent(eventOrBatch).then(() => {
|
|
9837
|
-
this.lastProcessed.set(
|
|
9838
|
-
eventOrBatch.resourceId,
|
|
9839
|
-
eventOrBatch.metadata.sequenceNumber
|
|
9840
|
-
);
|
|
9841
|
-
}));
|
|
9842
|
-
})
|
|
9843
|
-
);
|
|
9844
|
-
})
|
|
9845
|
-
).subscribe({
|
|
9846
|
-
error: (err) => {
|
|
9847
|
-
this.logger.error("GraphDB consumer pipeline error", { error: err });
|
|
9848
|
-
}
|
|
9849
|
-
});
|
|
9850
|
-
this.logger.info("Subscribed to global events with burst-buffered pipeline");
|
|
9851
|
-
}
|
|
9852
|
-
/**
|
|
9853
|
-
* Wrap applyEventToGraph in try/catch so one failed event doesn't kill the pipeline.
|
|
9854
|
-
*/
|
|
9855
|
-
async safeApplyEvent(storedEvent) {
|
|
9856
|
-
await new Promise((resolve2) => setTimeout(resolve2, 0));
|
|
9857
|
-
try {
|
|
9858
|
-
await this.applyEventToGraph(storedEvent);
|
|
9859
|
-
} catch (error) {
|
|
9860
|
-
this.logger.error("Failed to apply event to graph", {
|
|
9861
|
-
eventType: storedEvent.type,
|
|
9862
|
-
resourceId: storedEvent.resourceId,
|
|
9863
|
-
error: errField(error)
|
|
9864
|
-
});
|
|
9865
|
-
}
|
|
9866
|
-
}
|
|
9867
|
-
ensureInitialized() {
|
|
9868
|
-
return this.graphDb;
|
|
9869
|
-
}
|
|
9870
|
-
/**
|
|
9871
|
-
* Stop the consumer, flush remaining buffered events, and unsubscribe.
|
|
9872
|
-
*/
|
|
9873
|
-
async stop() {
|
|
9874
|
-
this.logger.info("Stopping GraphDB consumer");
|
|
9875
|
-
for (const sub of this._globalSubscriptions) sub.unsubscribe();
|
|
9876
|
-
this._globalSubscriptions = [];
|
|
9877
|
-
this.eventSubject.complete();
|
|
9878
|
-
if (this.pipelineSubscription) {
|
|
9879
|
-
this.pipelineSubscription.unsubscribe();
|
|
9880
|
-
this.pipelineSubscription = null;
|
|
9881
|
-
}
|
|
9882
|
-
this.eventSubject = new import_rxjs.Subject();
|
|
9883
|
-
this.logger.info("GraphDB consumer stopped");
|
|
9884
|
-
}
|
|
9885
|
-
/**
|
|
9886
|
-
* Process a batch of events for the same resource.
|
|
9887
|
-
* Partitions into consecutive same-type runs for batch optimization.
|
|
9888
|
-
*/
|
|
9889
|
-
async processBatch(events) {
|
|
9890
|
-
const runs = partitionByType(events);
|
|
9891
|
-
for (const run of runs) {
|
|
9892
|
-
try {
|
|
9893
|
-
if (run.length === 1) {
|
|
9894
|
-
await this.applyEventToGraph(run[0]);
|
|
9895
|
-
} else {
|
|
9896
|
-
await this.applyBatchByType(run);
|
|
9897
|
-
}
|
|
9898
|
-
} catch (error) {
|
|
9899
|
-
this.logger.error("Failed to process batch run", {
|
|
9900
|
-
eventType: run[0].type,
|
|
9901
|
-
runSize: run.length,
|
|
9902
|
-
error: errField(error)
|
|
9903
|
-
});
|
|
9904
|
-
}
|
|
9905
|
-
const last = run[run.length - 1];
|
|
9906
|
-
if (last.resourceId) {
|
|
9907
|
-
this.lastProcessed.set(last.resourceId, last.metadata.sequenceNumber);
|
|
9908
|
-
}
|
|
9909
|
-
}
|
|
9910
|
-
this.logger.debug("Processed batch", {
|
|
9911
|
-
resourceId: events[0]?.resourceId,
|
|
9912
|
-
batchSize: events.length
|
|
9913
|
-
});
|
|
9750
|
+
// src/weave-progress.ts
|
|
9751
|
+
var WeaveProgressTimeout = class extends Error {
|
|
9752
|
+
constructor(resourceId10, sequenceNumber, timeoutMs) {
|
|
9753
|
+
super(`weave:applied parity not reached for ${resourceId10} (seq ${sequenceNumber}) within ${timeoutMs}ms`);
|
|
9754
|
+
this.name = "WeaveProgressTimeout";
|
|
9914
9755
|
}
|
|
9915
|
-
|
|
9916
|
-
|
|
9917
|
-
|
|
9918
|
-
|
|
9919
|
-
|
|
9920
|
-
|
|
9921
|
-
|
|
9922
|
-
|
|
9923
|
-
|
|
9924
|
-
|
|
9925
|
-
|
|
9926
|
-
|
|
9927
|
-
|
|
9928
|
-
|
|
9929
|
-
|
|
9930
|
-
|
|
9931
|
-
|
|
9932
|
-
|
|
9933
|
-
|
|
9934
|
-
|
|
9935
|
-
|
|
9936
|
-
|
|
9937
|
-
|
|
9938
|
-
|
|
9939
|
-
break;
|
|
9756
|
+
};
|
|
9757
|
+
var APPLIED_TTL_MS = 5 * 6e4;
|
|
9758
|
+
var SWEEP_INTERVAL_MS = 6e4;
|
|
9759
|
+
function createWeaveProgress(eventBus) {
|
|
9760
|
+
const applied = /* @__PURE__ */ new Map();
|
|
9761
|
+
const waiters = /* @__PURE__ */ new Set();
|
|
9762
|
+
let disposed = false;
|
|
9763
|
+
let lastSweep = Date.now();
|
|
9764
|
+
const subscription = eventBus.get("weave:applied").subscribe(({ resourceId: resourceId10, sequenceNumber }) => {
|
|
9765
|
+
const now = Date.now();
|
|
9766
|
+
if (now - lastSweep >= SWEEP_INTERVAL_MS) {
|
|
9767
|
+
lastSweep = now;
|
|
9768
|
+
for (const [rid, entry] of applied) {
|
|
9769
|
+
if (now - entry.at >= APPLIED_TTL_MS) applied.delete(rid);
|
|
9770
|
+
}
|
|
9771
|
+
}
|
|
9772
|
+
const current = applied.get(resourceId10);
|
|
9773
|
+
if (current !== void 0 && current.seq >= sequenceNumber) return;
|
|
9774
|
+
applied.set(resourceId10, { seq: sequenceNumber, at: now });
|
|
9775
|
+
for (const waiter of waiters) {
|
|
9776
|
+
if (waiter.resourceId === resourceId10 && sequenceNumber >= waiter.sequenceNumber) {
|
|
9777
|
+
clearTimeout(waiter.timer);
|
|
9778
|
+
waiters.delete(waiter);
|
|
9779
|
+
waiter.resolve();
|
|
9940
9780
|
}
|
|
9941
|
-
default:
|
|
9942
|
-
for (const event of events) {
|
|
9943
|
-
await this.applyEventToGraph(event);
|
|
9944
|
-
}
|
|
9945
9781
|
}
|
|
9946
|
-
}
|
|
9947
|
-
|
|
9948
|
-
|
|
9949
|
-
|
|
9950
|
-
|
|
9951
|
-
|
|
9952
|
-
|
|
9953
|
-
|
|
9954
|
-
|
|
9955
|
-
|
|
9956
|
-
|
|
9957
|
-
|
|
9958
|
-
|
|
9959
|
-
|
|
9960
|
-
|
|
9961
|
-
|
|
9962
|
-
|
|
9963
|
-
|
|
9964
|
-
|
|
9965
|
-
|
|
9966
|
-
|
|
9967
|
-
|
|
9968
|
-
|
|
9969
|
-
|
|
9970
|
-
|
|
9971
|
-
|
|
9972
|
-
|
|
9973
|
-
};
|
|
9974
|
-
}
|
|
9975
|
-
/**
|
|
9976
|
-
* Apply a single event to GraphDB.
|
|
9977
|
-
*/
|
|
9978
|
-
async applyEventToGraph(storedEvent) {
|
|
9979
|
-
const graphDb = this.ensureInitialized();
|
|
9980
|
-
const event = storedEvent;
|
|
9981
|
-
this.logger.debug("Applying event to GraphDB", {
|
|
9982
|
-
eventType: event.type,
|
|
9983
|
-
sequenceNumber: storedEvent.metadata.sequenceNumber
|
|
9984
|
-
});
|
|
9985
|
-
switch (event.type) {
|
|
9986
|
-
case "yield:created": {
|
|
9987
|
-
const resource = this.buildResourceDescriptor(storedEvent);
|
|
9988
|
-
this.logger.debug("Creating resource in graph", { resourceUri: resource["@id"] });
|
|
9989
|
-
await graphDb.createResource(resource);
|
|
9990
|
-
this.logger.info("Resource created in graph", { resourceUri: resource["@id"] });
|
|
9991
|
-
break;
|
|
9782
|
+
});
|
|
9783
|
+
return {
|
|
9784
|
+
appliedUpTo: (resourceId10) => applied.get(resourceId10)?.seq,
|
|
9785
|
+
whenApplied: (resourceId10, sequenceNumber, timeoutMs) => {
|
|
9786
|
+
if (disposed) return Promise.resolve();
|
|
9787
|
+
const current = applied.get(resourceId10)?.seq;
|
|
9788
|
+
if (current !== void 0 && current >= sequenceNumber) return Promise.resolve();
|
|
9789
|
+
return new Promise((resolve2, reject) => {
|
|
9790
|
+
const waiter = {
|
|
9791
|
+
resourceId: resourceId10,
|
|
9792
|
+
sequenceNumber,
|
|
9793
|
+
resolve: resolve2,
|
|
9794
|
+
timer: setTimeout(() => {
|
|
9795
|
+
waiters.delete(waiter);
|
|
9796
|
+
reject(new WeaveProgressTimeout(resourceId10, sequenceNumber, timeoutMs));
|
|
9797
|
+
}, timeoutMs)
|
|
9798
|
+
};
|
|
9799
|
+
waiters.add(waiter);
|
|
9800
|
+
});
|
|
9801
|
+
},
|
|
9802
|
+
dispose: () => {
|
|
9803
|
+
if (disposed) return;
|
|
9804
|
+
disposed = true;
|
|
9805
|
+
subscription.unsubscribe();
|
|
9806
|
+
for (const waiter of waiters) {
|
|
9807
|
+
clearTimeout(waiter.timer);
|
|
9808
|
+
waiter.resolve();
|
|
9992
9809
|
}
|
|
9993
|
-
|
|
9994
|
-
|
|
9995
|
-
await graphDb.updateResource(resourceId(event.resourceId), {
|
|
9996
|
-
archived: true
|
|
9997
|
-
});
|
|
9998
|
-
break;
|
|
9999
|
-
case "mark:unarchived":
|
|
10000
|
-
if (!event.resourceId) throw new Error("mark:unarchived requires resourceId");
|
|
10001
|
-
await graphDb.updateResource(resourceId(event.resourceId), {
|
|
10002
|
-
archived: false
|
|
10003
|
-
});
|
|
10004
|
-
break;
|
|
10005
|
-
case "mark:added":
|
|
10006
|
-
this.logger.debug("Processing annotation.added event", {
|
|
10007
|
-
annotationId: event.payload.annotation.id
|
|
10008
|
-
});
|
|
10009
|
-
await graphDb.createAnnotation({
|
|
10010
|
-
...event.payload.annotation,
|
|
10011
|
-
creator: didToAgent(event.userId)
|
|
10012
|
-
});
|
|
10013
|
-
this.logger.info("Annotation created in graph", {
|
|
10014
|
-
annotationId: event.payload.annotation.id
|
|
10015
|
-
});
|
|
10016
|
-
break;
|
|
10017
|
-
case "mark:removed":
|
|
10018
|
-
await graphDb.deleteAnnotation(annotationId(event.payload.annotationId));
|
|
10019
|
-
break;
|
|
10020
|
-
case "mark:body-updated":
|
|
10021
|
-
this.logger.debug("Processing annotation.body.updated event", {
|
|
10022
|
-
annotationId: event.payload.annotationId,
|
|
10023
|
-
payload: event.payload
|
|
10024
|
-
});
|
|
10025
|
-
try {
|
|
10026
|
-
const annId = annotationId(event.payload.annotationId);
|
|
10027
|
-
const currentAnnotation = await graphDb.getAnnotation(annId);
|
|
10028
|
-
if (currentAnnotation) {
|
|
10029
|
-
let bodyArray = Array.isArray(currentAnnotation.body) ? [...currentAnnotation.body] : currentAnnotation.body ? [currentAnnotation.body] : [];
|
|
10030
|
-
for (const op of event.payload.operations) {
|
|
10031
|
-
if (op.op === "add") {
|
|
10032
|
-
const exists = findBodyItem(bodyArray, op.item) !== -1;
|
|
10033
|
-
if (!exists) {
|
|
10034
|
-
bodyArray.push(op.item);
|
|
10035
|
-
}
|
|
10036
|
-
} else if (op.op === "remove") {
|
|
10037
|
-
const index = findBodyItem(bodyArray, op.item);
|
|
10038
|
-
if (index !== -1) {
|
|
10039
|
-
bodyArray.splice(index, 1);
|
|
10040
|
-
}
|
|
10041
|
-
} else if (op.op === "replace") {
|
|
10042
|
-
const index = findBodyItem(bodyArray, op.oldItem);
|
|
10043
|
-
if (index !== -1) {
|
|
10044
|
-
bodyArray[index] = op.newItem;
|
|
10045
|
-
}
|
|
10046
|
-
}
|
|
10047
|
-
}
|
|
10048
|
-
await graphDb.updateAnnotation(annId, {
|
|
10049
|
-
body: bodyArray
|
|
10050
|
-
});
|
|
10051
|
-
this.logger.info("updateAnnotation completed successfully");
|
|
10052
|
-
} else {
|
|
10053
|
-
this.logger.warn("Annotation not found in graph, skipping update");
|
|
10054
|
-
}
|
|
10055
|
-
} catch (error) {
|
|
10056
|
-
this.logger.error("Error in annotation.body.updated handler", {
|
|
10057
|
-
annotationId: event.payload.annotationId,
|
|
10058
|
-
error: errField(error)
|
|
10059
|
-
});
|
|
10060
|
-
}
|
|
10061
|
-
break;
|
|
10062
|
-
case "mark:entity-tag-added":
|
|
10063
|
-
if (!event.resourceId) throw new Error("mark:entity-tag-added requires resourceId");
|
|
10064
|
-
{
|
|
10065
|
-
const rid = resourceId(event.resourceId);
|
|
10066
|
-
const doc = await graphDb.getResource(rid);
|
|
10067
|
-
if (doc && !(doc.entityTypes || []).includes(event.payload.entityType)) {
|
|
10068
|
-
await graphDb.updateResource(rid, {
|
|
10069
|
-
entityTypes: [...doc.entityTypes || [], event.payload.entityType]
|
|
10070
|
-
});
|
|
10071
|
-
}
|
|
10072
|
-
}
|
|
10073
|
-
break;
|
|
10074
|
-
case "mark:entity-tag-removed":
|
|
10075
|
-
if (!event.resourceId) throw new Error("mark:entity-tag-removed requires resourceId");
|
|
10076
|
-
{
|
|
10077
|
-
const rid = resourceId(event.resourceId);
|
|
10078
|
-
const doc = await graphDb.getResource(rid);
|
|
10079
|
-
if (doc) {
|
|
10080
|
-
await graphDb.updateResource(rid, {
|
|
10081
|
-
entityTypes: (doc.entityTypes || []).filter((t) => t !== event.payload.entityType)
|
|
10082
|
-
});
|
|
10083
|
-
}
|
|
10084
|
-
}
|
|
10085
|
-
break;
|
|
10086
|
-
case "frame:entity-type-added":
|
|
10087
|
-
await graphDb.addEntityType(event.payload.entityType);
|
|
10088
|
-
break;
|
|
10089
|
-
default:
|
|
10090
|
-
this.logger.warn("Unknown event type", { eventType: event.type });
|
|
9810
|
+
waiters.clear();
|
|
9811
|
+
applied.clear();
|
|
10091
9812
|
}
|
|
9813
|
+
};
|
|
9814
|
+
}
|
|
9815
|
+
|
|
9816
|
+
// src/smelt-progress.ts
|
|
9817
|
+
var SmeltProgressTimeout = class extends Error {
|
|
9818
|
+
constructor(resourceId10, contentChecksum, timeoutMs) {
|
|
9819
|
+
super(`smelt:settled not observed for ${resourceId10} (checksum ${contentChecksum.slice(0, 12)}\u2026) within ${timeoutMs}ms`);
|
|
9820
|
+
this.name = "SmeltProgressTimeout";
|
|
10092
9821
|
}
|
|
10093
|
-
|
|
10094
|
-
|
|
10095
|
-
|
|
10096
|
-
|
|
10097
|
-
|
|
10098
|
-
|
|
10099
|
-
|
|
10100
|
-
|
|
10101
|
-
|
|
10102
|
-
|
|
10103
|
-
|
|
10104
|
-
|
|
10105
|
-
|
|
10106
|
-
|
|
10107
|
-
|
|
10108
|
-
|
|
10109
|
-
}
|
|
10110
|
-
|
|
10111
|
-
|
|
10112
|
-
|
|
10113
|
-
|
|
10114
|
-
|
|
10115
|
-
* Bypasses the live pipeline — reads directly from event store.
|
|
10116
|
-
*/
|
|
10117
|
-
async rebuildAll() {
|
|
10118
|
-
const graphDb = this.ensureInitialized();
|
|
10119
|
-
this.logger.info("Rebuilding entire GraphDB from events");
|
|
10120
|
-
this.logger.info("Using two-pass approach: nodes first, then edges");
|
|
10121
|
-
await graphDb.clearDatabase();
|
|
10122
|
-
const query = new EventQuery(this.eventStore.log.storage);
|
|
10123
|
-
const allResourceIds = await this.eventStore.log.getAllResourceIds();
|
|
10124
|
-
this.logger.info("Found resources to rebuild", { count: allResourceIds.length });
|
|
10125
|
-
this.logger.info("PASS 1: Creating all nodes (resources + annotations)");
|
|
10126
|
-
for (const resourceId10 of allResourceIds) {
|
|
10127
|
-
const events = await query.getResourceEvents(resourceId(resourceId10));
|
|
10128
|
-
for (const storedEvent of events) {
|
|
10129
|
-
if (storedEvent.type === "mark:body-updated") {
|
|
10130
|
-
continue;
|
|
10131
|
-
}
|
|
10132
|
-
await this.safeApplyEvent(storedEvent);
|
|
9822
|
+
};
|
|
9823
|
+
var SETTLED_TTL_MS = 5 * 6e4;
|
|
9824
|
+
var SWEEP_INTERVAL_MS2 = 6e4;
|
|
9825
|
+
function createSmeltProgress(eventBus) {
|
|
9826
|
+
const settled = /* @__PURE__ */ new Map();
|
|
9827
|
+
const waiters = /* @__PURE__ */ new Set();
|
|
9828
|
+
let disposed = false;
|
|
9829
|
+
let lastSweep = Date.now();
|
|
9830
|
+
const subscription = eventBus.get("smelt:settled").subscribe(({ resourceId: resourceId10, contentChecksum, outcome }) => {
|
|
9831
|
+
const now = Date.now();
|
|
9832
|
+
if (now - lastSweep >= SWEEP_INTERVAL_MS2) {
|
|
9833
|
+
lastSweep = now;
|
|
9834
|
+
for (const [rid, entry] of settled) {
|
|
9835
|
+
if (now - entry.at >= SETTLED_TTL_MS) settled.delete(rid);
|
|
9836
|
+
}
|
|
9837
|
+
}
|
|
9838
|
+
settled.set(resourceId10, { contentChecksum, outcome, at: now });
|
|
9839
|
+
for (const waiter of waiters) {
|
|
9840
|
+
if (waiter.resourceId === resourceId10 && waiter.contentChecksum === contentChecksum) {
|
|
9841
|
+
clearTimeout(waiter.timer);
|
|
9842
|
+
waiters.delete(waiter);
|
|
9843
|
+
waiter.resolve(outcome);
|
|
10133
9844
|
}
|
|
10134
9845
|
}
|
|
10135
|
-
|
|
10136
|
-
|
|
10137
|
-
|
|
10138
|
-
const
|
|
10139
|
-
|
|
10140
|
-
|
|
10141
|
-
|
|
10142
|
-
|
|
9846
|
+
});
|
|
9847
|
+
return {
|
|
9848
|
+
settledAt: (resourceId10) => {
|
|
9849
|
+
const entry = settled.get(resourceId10);
|
|
9850
|
+
return entry ? { contentChecksum: entry.contentChecksum, outcome: entry.outcome } : void 0;
|
|
9851
|
+
},
|
|
9852
|
+
whenSettled: (resourceId10, contentChecksum, timeoutMs) => {
|
|
9853
|
+
if (disposed) return Promise.resolve("inert");
|
|
9854
|
+
const current = settled.get(resourceId10);
|
|
9855
|
+
if (current && current.contentChecksum === contentChecksum) {
|
|
9856
|
+
return Promise.resolve(current.outcome);
|
|
9857
|
+
}
|
|
9858
|
+
return new Promise((resolve2, reject) => {
|
|
9859
|
+
const waiter = {
|
|
9860
|
+
resourceId: resourceId10,
|
|
9861
|
+
contentChecksum,
|
|
9862
|
+
resolve: resolve2,
|
|
9863
|
+
timer: setTimeout(() => {
|
|
9864
|
+
waiters.delete(waiter);
|
|
9865
|
+
reject(new SmeltProgressTimeout(resourceId10, contentChecksum, timeoutMs));
|
|
9866
|
+
}, timeoutMs)
|
|
9867
|
+
};
|
|
9868
|
+
waiters.add(waiter);
|
|
9869
|
+
});
|
|
9870
|
+
},
|
|
9871
|
+
dispose: () => {
|
|
9872
|
+
if (disposed) return;
|
|
9873
|
+
disposed = true;
|
|
9874
|
+
subscription.unsubscribe();
|
|
9875
|
+
for (const waiter of waiters) {
|
|
9876
|
+
clearTimeout(waiter.timer);
|
|
9877
|
+
waiter.resolve("inert");
|
|
10143
9878
|
}
|
|
9879
|
+
waiters.clear();
|
|
9880
|
+
settled.clear();
|
|
10144
9881
|
}
|
|
10145
|
-
|
|
10146
|
-
|
|
10147
|
-
}
|
|
10148
|
-
/**
|
|
10149
|
-
* Get consumer health metrics.
|
|
10150
|
-
*/
|
|
10151
|
-
getHealthMetrics() {
|
|
10152
|
-
return {
|
|
10153
|
-
subscriptions: this._globalSubscriptions.length,
|
|
10154
|
-
lastProcessed: Object.fromEntries(this.lastProcessed),
|
|
10155
|
-
pipelineActive: !!this.pipelineSubscription
|
|
10156
|
-
};
|
|
10157
|
-
}
|
|
10158
|
-
/**
|
|
10159
|
-
* Shutdown consumer.
|
|
10160
|
-
*/
|
|
10161
|
-
async shutdown() {
|
|
10162
|
-
await this.stop();
|
|
10163
|
-
this.logger.info("GraphDB consumer shut down");
|
|
10164
|
-
}
|
|
10165
|
-
};
|
|
9882
|
+
};
|
|
9883
|
+
}
|
|
10166
9884
|
|
|
10167
9885
|
// src/knowledge-base.ts
|
|
10168
9886
|
async function createKnowledgeBase(eventStore, project, graphDb, eventBus, logger, options) {
|
|
@@ -10171,23 +9889,18 @@ async function createKnowledgeBase(eventStore, project, graphDb, eventBus, logge
|
|
|
10171
9889
|
project,
|
|
10172
9890
|
logger.child({ component: "working-tree-store" })
|
|
10173
9891
|
);
|
|
10174
|
-
const
|
|
10175
|
-
|
|
10176
|
-
graphDb,
|
|
10177
|
-
eventBus,
|
|
10178
|
-
logger.child({ component: "graph-consumer" })
|
|
10179
|
-
);
|
|
10180
|
-
await graphConsumer.initialize();
|
|
9892
|
+
const weaveProgress = createWeaveProgress(eventBus);
|
|
9893
|
+
const smeltProgress = createSmeltProgress(eventBus);
|
|
10181
9894
|
if (!options?.skipRebuild) {
|
|
10182
9895
|
await eventStore.views.rebuildAll(eventStore.log);
|
|
10183
|
-
await graphConsumer.rebuildAll();
|
|
10184
9896
|
}
|
|
10185
9897
|
const kb = {
|
|
10186
9898
|
eventStore,
|
|
10187
9899
|
views,
|
|
10188
9900
|
content,
|
|
10189
9901
|
graph: graphDb,
|
|
10190
|
-
|
|
9902
|
+
weaveProgress,
|
|
9903
|
+
smeltProgress,
|
|
10191
9904
|
projectionsDir: project.projectionsDir
|
|
10192
9905
|
};
|
|
10193
9906
|
if (options?.vectorStore) {
|
|
@@ -10197,8 +9910,8 @@ async function createKnowledgeBase(eventStore, project, graphDb, eventBus, logge
|
|
|
10197
9910
|
}
|
|
10198
9911
|
|
|
10199
9912
|
// src/gatherer.ts
|
|
10200
|
-
var
|
|
10201
|
-
var
|
|
9913
|
+
var import_rxjs = __toESM(require_cjs());
|
|
9914
|
+
var import_operators = __toESM(require_operators());
|
|
10202
9915
|
|
|
10203
9916
|
// src/generation/resource-generation.ts
|
|
10204
9917
|
async function generateResourceSummary(resourceName, content, entityTypes, client) {
|
|
@@ -10301,7 +10014,21 @@ var ResourceContext = class _ResourceContext {
|
|
|
10301
10014
|
return void 0;
|
|
10302
10015
|
}
|
|
10303
10016
|
};
|
|
10304
|
-
var GraphContext = class {
|
|
10017
|
+
var GraphContext = class _GraphContext {
|
|
10018
|
+
/**
|
|
10019
|
+
* Backoff schedule for the projection-lag grace in `buildKnowledgeGraph`
|
|
10020
|
+
* (GRAPH-PROJECTION-SYNC P1). Total wait is bounded at 375 ms — the Weaver
|
|
10021
|
+
* applies in tens of milliseconds when merely lagging; anything slower is
|
|
10022
|
+
* treated as a real miss.
|
|
10023
|
+
*/
|
|
10024
|
+
static PROJECTION_LAG_BACKOFF_MS = [25, 50, 100, 200];
|
|
10025
|
+
/**
|
|
10026
|
+
* Bounded wait for the applied-offset barrier (GRAPH-PROJECTION-SYNC P2).
|
|
10027
|
+
* The Weaver applies in tens of milliseconds when merely lagging; a
|
|
10028
|
+
* barrier that hasn't woken in 500 ms means signals have stalled and the
|
|
10029
|
+
* poll floor above owns the remainder.
|
|
10030
|
+
*/
|
|
10031
|
+
static PROJECTION_BARRIER_TIMEOUT_MS = 500;
|
|
10305
10032
|
/**
|
|
10306
10033
|
* Get all resources referencing this resource (backlinks)
|
|
10307
10034
|
* Requires graph traversal - must use graph database
|
|
@@ -10345,7 +10072,30 @@ var GraphContext = class {
|
|
|
10345
10072
|
* so siblingEntityTypes = union of those nodes' entityTypes
|
|
10346
10073
|
*/
|
|
10347
10074
|
static async buildKnowledgeGraph(resourceId10, kb) {
|
|
10348
|
-
|
|
10075
|
+
let mainDoc = await kb.graph.getResource(resourceId10);
|
|
10076
|
+
if (!mainDoc) {
|
|
10077
|
+
const view = await kb.views.get(resourceId10);
|
|
10078
|
+
if (view) {
|
|
10079
|
+
if (view.lastSequence !== void 0) {
|
|
10080
|
+
try {
|
|
10081
|
+
await kb.weaveProgress.whenApplied(
|
|
10082
|
+
String(resourceId10),
|
|
10083
|
+
view.lastSequence,
|
|
10084
|
+
_GraphContext.PROJECTION_BARRIER_TIMEOUT_MS
|
|
10085
|
+
);
|
|
10086
|
+
mainDoc = await kb.graph.getResource(resourceId10);
|
|
10087
|
+
} catch {
|
|
10088
|
+
}
|
|
10089
|
+
}
|
|
10090
|
+
if (!mainDoc) {
|
|
10091
|
+
for (const delayMs of _GraphContext.PROJECTION_LAG_BACKOFF_MS) {
|
|
10092
|
+
await new Promise((resolve2) => setTimeout(resolve2, delayMs));
|
|
10093
|
+
mainDoc = await kb.graph.getResource(resourceId10);
|
|
10094
|
+
if (mainDoc) break;
|
|
10095
|
+
}
|
|
10096
|
+
}
|
|
10097
|
+
}
|
|
10098
|
+
}
|
|
10349
10099
|
if (!mainDoc) {
|
|
10350
10100
|
throw new Error("Resource not found");
|
|
10351
10101
|
}
|
|
@@ -10811,12 +10561,13 @@ Entity types: ${entityTypes.join(", ")}`;
|
|
|
10811
10561
|
return inferenceClient.generateText(summaryPrompt, 500, 0.5);
|
|
10812
10562
|
}
|
|
10813
10563
|
};
|
|
10564
|
+
var SMELT_SETTLE_TIMEOUT_MS = 15e3;
|
|
10814
10565
|
var LLMContext = class {
|
|
10815
10566
|
/**
|
|
10816
10567
|
* Get comprehensive LLM context for a resource
|
|
10817
10568
|
* Includes: main resource, related resources, annotations, graph, content, summary, references
|
|
10818
10569
|
*/
|
|
10819
|
-
static async getResourceContext(resourceId10, options, kb, inferenceClient) {
|
|
10570
|
+
static async getResourceContext(resourceId10, options, kb, inferenceClient, logger) {
|
|
10820
10571
|
const mainDoc = await ResourceContext.getResourceMetadata(resourceId10, kb);
|
|
10821
10572
|
if (!mainDoc) {
|
|
10822
10573
|
throw new Error("Resource not found");
|
|
@@ -10856,13 +10607,33 @@ var LLMContext = class {
|
|
|
10856
10607
|
if (mainContent) content.main = mainContent;
|
|
10857
10608
|
if (options.includeContent) content.related = relatedContent;
|
|
10858
10609
|
let semanticContext;
|
|
10859
|
-
|
|
10610
|
+
const vectors = kb.vectors;
|
|
10611
|
+
if (vectors) {
|
|
10860
10612
|
const excludeEntityTypes = options.excludeEntityTypes ?? [];
|
|
10861
|
-
const
|
|
10613
|
+
const search = () => vectors.searchByResource(resourceId10, {
|
|
10862
10614
|
limit: options.maxResources,
|
|
10863
10615
|
scoreThreshold: 0.5,
|
|
10864
10616
|
...excludeEntityTypes.length ? { filter: { excludeEntityTypes } } : {}
|
|
10865
10617
|
});
|
|
10618
|
+
let matches = await search();
|
|
10619
|
+
if (matches.length === 0) {
|
|
10620
|
+
const contentChecksum = getPrimaryRepresentation(mainDoc)?.checksum;
|
|
10621
|
+
if (contentChecksum) {
|
|
10622
|
+
try {
|
|
10623
|
+
const outcome = await kb.smeltProgress.whenSettled(resourceIdStr, contentChecksum, SMELT_SETTLE_TIMEOUT_MS);
|
|
10624
|
+
if (outcome === "indexed") {
|
|
10625
|
+
matches = await search();
|
|
10626
|
+
}
|
|
10627
|
+
} catch (error) {
|
|
10628
|
+
if (!(error instanceof SmeltProgressTimeout)) throw error;
|
|
10629
|
+
logger.warn("[gather DEGRADED] semanticContext absent \u2014 the vector projection did not settle within the barrier", {
|
|
10630
|
+
resourceId: resourceIdStr,
|
|
10631
|
+
contentChecksum,
|
|
10632
|
+
timeoutMs: SMELT_SETTLE_TIMEOUT_MS
|
|
10633
|
+
});
|
|
10634
|
+
}
|
|
10635
|
+
}
|
|
10636
|
+
}
|
|
10866
10637
|
if (matches.length > 0) {
|
|
10867
10638
|
semanticContext = {
|
|
10868
10639
|
similar: matches.map((m) => ({
|
|
@@ -10913,21 +10684,21 @@ var Gatherer = class {
|
|
|
10913
10684
|
this.logger.info("Gatherer actor initialized");
|
|
10914
10685
|
const errorHandler = (err) => this.logger.error("Gatherer pipeline error", { error: err });
|
|
10915
10686
|
const annotationGather$ = this.eventBus.get("gather:requested").pipe(
|
|
10916
|
-
(0,
|
|
10917
|
-
(0,
|
|
10687
|
+
(0, import_operators.groupBy)((event) => event.resourceId),
|
|
10688
|
+
(0, import_operators.mergeMap)(
|
|
10918
10689
|
(group$) => group$.pipe(
|
|
10919
|
-
(0,
|
|
10920
|
-
(event) => (0,
|
|
10690
|
+
(0, import_operators.concatMap)(
|
|
10691
|
+
(event) => (0, import_rxjs.from)(withActorSpan("gatherer", "gather:requested", () => this.handleAnnotationGather(event)))
|
|
10921
10692
|
)
|
|
10922
10693
|
)
|
|
10923
10694
|
)
|
|
10924
10695
|
);
|
|
10925
10696
|
const resourceGather$ = this.eventBus.get("gather:resource-requested").pipe(
|
|
10926
|
-
(0,
|
|
10927
|
-
(0,
|
|
10697
|
+
(0, import_operators.groupBy)((event) => event.resourceId),
|
|
10698
|
+
(0, import_operators.mergeMap)(
|
|
10928
10699
|
(group$) => group$.pipe(
|
|
10929
|
-
(0,
|
|
10930
|
-
(event) => (0,
|
|
10700
|
+
(0, import_operators.concatMap)(
|
|
10701
|
+
(event) => (0, import_rxjs.from)(withActorSpan("gatherer", "gather:resource-requested", () => this.handleResourceGather(event)))
|
|
10931
10702
|
)
|
|
10932
10703
|
)
|
|
10933
10704
|
)
|
|
@@ -10981,7 +10752,8 @@ var Gatherer = class {
|
|
|
10981
10752
|
resourceId(event.resourceId),
|
|
10982
10753
|
event.options,
|
|
10983
10754
|
this.kb,
|
|
10984
|
-
this.inferenceClient
|
|
10755
|
+
this.inferenceClient,
|
|
10756
|
+
this.logger
|
|
10985
10757
|
);
|
|
10986
10758
|
this.eventBus.get("gather:resource-complete").next({
|
|
10987
10759
|
correlationId: event.correlationId,
|
|
@@ -11018,8 +10790,19 @@ var Gatherer = class {
|
|
|
11018
10790
|
};
|
|
11019
10791
|
|
|
11020
10792
|
// src/matcher.ts
|
|
11021
|
-
var
|
|
11022
|
-
var
|
|
10793
|
+
var import_rxjs2 = __toESM(require_cjs());
|
|
10794
|
+
var import_operators2 = __toESM(require_operators());
|
|
10795
|
+
|
|
10796
|
+
// src/graph-read-grace.ts
|
|
10797
|
+
async function resourceWithViewGrace(kb, rid) {
|
|
10798
|
+
const fromGraph = await kb.graph.getResource(rid).catch(() => null);
|
|
10799
|
+
if (fromGraph) return { resource: fromGraph, laggedBehindView: false };
|
|
10800
|
+
const view = await kb.views.get(rid);
|
|
10801
|
+
if (view) return { resource: view.resource, laggedBehindView: true };
|
|
10802
|
+
return { resource: null, laggedBehindView: false };
|
|
10803
|
+
}
|
|
10804
|
+
|
|
10805
|
+
// src/matcher.ts
|
|
11023
10806
|
var Matcher = class {
|
|
11024
10807
|
constructor(kb, eventBus, logger, inferenceClient, embeddingProvider) {
|
|
11025
10808
|
this.kb = kb;
|
|
@@ -11038,8 +10821,8 @@ var Matcher = class {
|
|
|
11038
10821
|
this.logger.info("Matcher actor initialized");
|
|
11039
10822
|
const errorHandler = (err) => this.logger.error("Matcher pipeline error", { error: err });
|
|
11040
10823
|
const search$ = this.eventBus.get("match:search-requested").pipe(
|
|
11041
|
-
(0,
|
|
11042
|
-
(event) => (0,
|
|
10824
|
+
(0, import_operators2.concatMap)(
|
|
10825
|
+
(event) => (0, import_rxjs2.from)(withActorSpan("matcher", "match:search-requested", () => this.handleSearch(event)))
|
|
11043
10826
|
)
|
|
11044
10827
|
);
|
|
11045
10828
|
this.subscriptions.push(
|
|
@@ -11113,11 +10896,14 @@ var Matcher = class {
|
|
|
11113
10896
|
// 4. Semantic match — vector similarity search (if vectors configured)
|
|
11114
10897
|
this.searchVectors(searchTerm)
|
|
11115
10898
|
]);
|
|
11116
|
-
const
|
|
11117
|
-
connections.map(
|
|
11118
|
-
(conn) => this.kb.graph.getResource(resourceId(conn.resourceId)).catch(() => null)
|
|
11119
|
-
)
|
|
10899
|
+
const neighborResolved = await Promise.all(
|
|
10900
|
+
connections.map((conn) => resourceWithViewGrace(this.kb, resourceId(conn.resourceId)))
|
|
11120
10901
|
);
|
|
10902
|
+
const laggedNeighbors = neighborResolved.filter((r) => r.laggedBehindView).length;
|
|
10903
|
+
if (laggedNeighbors > 0) {
|
|
10904
|
+
this.logger.info("[graph lag] neighborhood candidates hydrated from view", { count: laggedNeighbors });
|
|
10905
|
+
}
|
|
10906
|
+
const neighborResources = neighborResolved.map((r) => r.resource);
|
|
11121
10907
|
const candidateMap = /* @__PURE__ */ new Map();
|
|
11122
10908
|
const addCandidate = (resource, source) => {
|
|
11123
10909
|
const id = getResourceId(resource);
|
|
@@ -11135,11 +10921,16 @@ var Matcher = class {
|
|
|
11135
10921
|
if (r) addCandidate(r, "neighborhood");
|
|
11136
10922
|
}
|
|
11137
10923
|
const semanticScores = /* @__PURE__ */ new Map();
|
|
10924
|
+
let laggedSemantic = 0;
|
|
11138
10925
|
for (const sm of semanticMatches) {
|
|
11139
10926
|
semanticScores.set(sm.resourceId, sm.score);
|
|
11140
|
-
const resource = await this.kb
|
|
10927
|
+
const { resource, laggedBehindView } = await resourceWithViewGrace(this.kb, resourceId(sm.resourceId));
|
|
10928
|
+
if (laggedBehindView) laggedSemantic++;
|
|
11141
10929
|
if (resource) addCandidate(resource, "semantic");
|
|
11142
10930
|
}
|
|
10931
|
+
if (laggedSemantic > 0) {
|
|
10932
|
+
this.logger.info("[graph lag] semantic candidates hydrated from view", { count: laggedSemantic });
|
|
10933
|
+
}
|
|
11143
10934
|
this.logger.debug("Candidate retrieval", {
|
|
11144
10935
|
nameMatches: nameMatches.length,
|
|
11145
10936
|
entityTypeMatches: entityTypeMatches.length,
|
|
@@ -11352,8 +11143,8 @@ For each candidate, output a line with the number and score, like:
|
|
|
11352
11143
|
};
|
|
11353
11144
|
|
|
11354
11145
|
// src/stower.ts
|
|
11355
|
-
var
|
|
11356
|
-
var
|
|
11146
|
+
var import_rxjs3 = __toESM(require_cjs());
|
|
11147
|
+
var import_operators3 = __toESM(require_operators());
|
|
11357
11148
|
async function readEntityTypesProjection(project) {
|
|
11358
11149
|
const entityTypesPath = path3.join(
|
|
11359
11150
|
project.stateDir,
|
|
@@ -11412,11 +11203,11 @@ var Stower = class {
|
|
|
11412
11203
|
async initialize() {
|
|
11413
11204
|
this.logger.info("Stower actor initialized");
|
|
11414
11205
|
const pipe = (event, handler) => this.eventBus.get(event).pipe(
|
|
11415
|
-
(0,
|
|
11416
|
-
(e) => (0,
|
|
11206
|
+
(0, import_operators3.concatMap)(
|
|
11207
|
+
(e) => (0, import_rxjs3.from)(withActorSpan("stower", event, () => handler(e)))
|
|
11417
11208
|
)
|
|
11418
11209
|
);
|
|
11419
|
-
this.subscription = (0,
|
|
11210
|
+
this.subscription = (0, import_rxjs3.merge)(
|
|
11420
11211
|
pipe("yield:create", (e) => this.handleYieldCreate(e)),
|
|
11421
11212
|
pipe("yield:update", (e) => this.handleYieldUpdate(e)),
|
|
11422
11213
|
pipe("yield:mv", (e) => this.handleYieldMv(e)),
|
|
@@ -11835,8 +11626,8 @@ var Stower = class {
|
|
|
11835
11626
|
};
|
|
11836
11627
|
|
|
11837
11628
|
// src/browser.ts
|
|
11838
|
-
var
|
|
11839
|
-
var
|
|
11629
|
+
var import_rxjs4 = __toESM(require_cjs());
|
|
11630
|
+
var import_operators4 = __toESM(require_operators());
|
|
11840
11631
|
async function readTagSchemasProjection(project) {
|
|
11841
11632
|
const tagSchemasPath = path3.join(
|
|
11842
11633
|
project.stateDir,
|
|
@@ -11933,8 +11724,8 @@ var Browser = class {
|
|
|
11933
11724
|
this.logger.info("Browser actor initialized");
|
|
11934
11725
|
const errorHandler = (err) => this.logger.error("Browser pipeline error", { error: err });
|
|
11935
11726
|
const pipe = (name, handler) => this.eventBus.get(name).pipe(
|
|
11936
|
-
(0,
|
|
11937
|
-
(event) => (0,
|
|
11727
|
+
(0, import_operators4.mergeMap)(
|
|
11728
|
+
(event) => (0, import_rxjs4.from)(withActorSpan("browser", name, () => handler(event))).pipe(
|
|
11938
11729
|
// Isolate per-event failures: a single handler throw must NOT tear down the
|
|
11939
11730
|
// channel subscription for every future request — that's the browse:entity-types
|
|
11940
11731
|
// wedge (.plans/bugs/browse-entity-types-never-responds.md). Handlers emit their
|
|
@@ -11942,9 +11733,9 @@ var Browser = class {
|
|
|
11942
11733
|
// handler's try/catch — the channel survives, the offending request is logged.
|
|
11943
11734
|
// (A per-channel *-failed can't be emitted from this generic helper without the
|
|
11944
11735
|
// request→failure mapping — that's the Tier 1 operations registry.)
|
|
11945
|
-
(0,
|
|
11736
|
+
(0, import_operators4.catchError)((error) => {
|
|
11946
11737
|
this.logger.error(`browse handler threw on ${name}`, { error: errField(error) });
|
|
11947
|
-
return
|
|
11738
|
+
return import_rxjs4.EMPTY;
|
|
11948
11739
|
})
|
|
11949
11740
|
)
|
|
11950
11741
|
)
|
|
@@ -12144,13 +11935,19 @@ var Browser = class {
|
|
|
12144
11935
|
});
|
|
12145
11936
|
const references = await this.kb.graph.getResourceReferencedBy(resourceId(event.resourceId), event.motivation);
|
|
12146
11937
|
const sourceIds = [...new Set(references.map((ref) => getTargetSource(ref.target)))];
|
|
12147
|
-
const
|
|
11938
|
+
const resolved = await Promise.all(
|
|
11939
|
+
sourceIds.map((id) => resourceWithViewGrace(this.kb, resourceId(id)))
|
|
11940
|
+
);
|
|
11941
|
+
const docMap = new Map(
|
|
11942
|
+
resolved.filter((r) => r.resource !== null).map((r) => [r.resource["@id"], r.resource])
|
|
11943
|
+
);
|
|
12148
11944
|
for (let i = 0; i < sourceIds.length; i++) {
|
|
12149
|
-
if (
|
|
12150
|
-
this.logger.
|
|
11945
|
+
if (resolved[i].laggedBehindView) {
|
|
11946
|
+
this.logger.info("[graph lag] citer hydrated from view", { resourceId: sourceIds[i] });
|
|
11947
|
+
} else if (resolved[i].resource === null) {
|
|
11948
|
+
this.logger.warn("Referenced resource not found in graph or view", { resourceId: sourceIds[i] });
|
|
12151
11949
|
}
|
|
12152
11950
|
}
|
|
12153
|
-
const docMap = new Map(resources.filter((doc) => doc !== null).map((doc) => [doc["@id"], doc]));
|
|
12154
11951
|
const referencedBy = references.map((ref) => {
|
|
12155
11952
|
const targetSource = getTargetSource(ref.target);
|
|
12156
11953
|
const targetSelector = getTargetSelector(ref.target);
|
|
@@ -12347,8 +12144,8 @@ async function readAnnotationFromView(kb, resourceId10, annotationId5) {
|
|
|
12347
12144
|
}
|
|
12348
12145
|
|
|
12349
12146
|
// src/clone-token-manager.ts
|
|
12350
|
-
var
|
|
12351
|
-
var
|
|
12147
|
+
var import_rxjs5 = __toESM(require_cjs());
|
|
12148
|
+
var import_operators5 = __toESM(require_operators());
|
|
12352
12149
|
|
|
12353
12150
|
// src/bus-request-local.ts
|
|
12354
12151
|
function asBusRequestPrimitive(eventBus) {
|
|
@@ -12408,13 +12205,13 @@ var CloneTokenManager = class {
|
|
|
12408
12205
|
this.logger.info("CloneTokenManager actor initialized");
|
|
12409
12206
|
const errorHandler = (err) => this.logger.error("CloneTokenManager pipeline error", { error: err });
|
|
12410
12207
|
const generateToken$ = this.eventBus.get("yield:clone-token-requested").pipe(
|
|
12411
|
-
(0,
|
|
12208
|
+
(0, import_operators5.mergeMap)((event) => (0, import_rxjs5.from)(this.handleGenerateToken(event)))
|
|
12412
12209
|
);
|
|
12413
12210
|
const getResource$ = this.eventBus.get("yield:clone-resource-requested").pipe(
|
|
12414
|
-
(0,
|
|
12211
|
+
(0, import_operators5.mergeMap)((event) => (0, import_rxjs5.from)(this.handleGetResource(event)))
|
|
12415
12212
|
);
|
|
12416
12213
|
const createResource$ = this.eventBus.get("yield:clone-create").pipe(
|
|
12417
|
-
(0,
|
|
12214
|
+
(0, import_operators5.mergeMap)((event) => (0, import_rxjs5.from)(this.handleCreateResource(event)))
|
|
12418
12215
|
);
|
|
12419
12216
|
this.subscriptions.push(
|
|
12420
12217
|
generateToken$.subscribe({ error: errorHandler }),
|
|
@@ -12619,7 +12416,7 @@ async function stopKnowledgeSystem(ks) {
|
|
|
12619
12416
|
await ks.browser.stop();
|
|
12620
12417
|
await ks.cloneTokenManager.stop();
|
|
12621
12418
|
await ks.stower.stop();
|
|
12622
|
-
|
|
12419
|
+
ks.kb.weaveProgress.dispose();
|
|
12623
12420
|
await ks.kb.graph.disconnect();
|
|
12624
12421
|
}
|
|
12625
12422
|
function registerAnnotationAssemblyHandler(eventBus, parentLogger) {
|
|
@@ -12963,7 +12760,7 @@ async function createJobQueue(project, eventBus, logger) {
|
|
|
12963
12760
|
await jobQueue.initialize();
|
|
12964
12761
|
registerJobQueueProvider(() => jobQueue.getStats());
|
|
12965
12762
|
const jobStatusSubscription = eventBus.get("job:status-requested").pipe(
|
|
12966
|
-
(0,
|
|
12763
|
+
(0, import_operators6.mergeMap)((event) => (0, import_rxjs6.from)((async () => {
|
|
12967
12764
|
try {
|
|
12968
12765
|
const job = await jobQueue.getJob(jobId(event.jobId));
|
|
12969
12766
|
if (!job) {
|
|
@@ -13080,11 +12877,11 @@ async function startMakeMeaning(project, config, eventBus, logger, options) {
|
|
|
13080
12877
|
}
|
|
13081
12878
|
|
|
13082
12879
|
// src/local-transport.ts
|
|
13083
|
-
var
|
|
12880
|
+
var import_rxjs7 = __toESM(require_cjs());
|
|
13084
12881
|
var LocalTransport = class {
|
|
13085
12882
|
baseUrl;
|
|
13086
12883
|
state$;
|
|
13087
|
-
errorsSubject = new
|
|
12884
|
+
errorsSubject = new import_rxjs7.Subject();
|
|
13088
12885
|
/**
|
|
13089
12886
|
* Stream of `SemiontError` instances surfaced from transport-mediated
|
|
13090
12887
|
* round-trips (typed-wire methods on this transport that fail). The
|
|
@@ -13105,7 +12902,7 @@ var LocalTransport = class {
|
|
|
13105
12902
|
this.bus = cfg.eventBus;
|
|
13106
12903
|
this.userId = cfg.userId;
|
|
13107
12904
|
this.baseUrl = cfg.baseUrl ?? baseUrl("local://in-process");
|
|
13108
|
-
this.state$ = new
|
|
12905
|
+
this.state$ = new import_rxjs7.BehaviorSubject("open");
|
|
13109
12906
|
}
|
|
13110
12907
|
// ── Bus primitives ──────────────────────────────────────────────────────
|
|
13111
12908
|
async emit(channel, payload, resourceScope) {
|
|
@@ -13238,10 +13035,39 @@ var LocalContentTransport = class {
|
|
|
13238
13035
|
};
|
|
13239
13036
|
|
|
13240
13037
|
// src/smelter.ts
|
|
13241
|
-
var
|
|
13242
|
-
var
|
|
13038
|
+
var import_rxjs8 = __toESM(require_cjs());
|
|
13039
|
+
var import_operators7 = __toESM(require_operators());
|
|
13040
|
+
|
|
13041
|
+
// src/batch-utils.ts
|
|
13042
|
+
function partitionByType(events) {
|
|
13043
|
+
const runs = [];
|
|
13044
|
+
let currentRun = [];
|
|
13045
|
+
for (const event of events) {
|
|
13046
|
+
if (currentRun.length > 0 && currentRun[0].type !== event.type) {
|
|
13047
|
+
runs.push(currentRun);
|
|
13048
|
+
currentRun = [];
|
|
13049
|
+
}
|
|
13050
|
+
currentRun.push(event);
|
|
13051
|
+
}
|
|
13052
|
+
if (currentRun.length > 0) runs.push(currentRun);
|
|
13053
|
+
return runs;
|
|
13054
|
+
}
|
|
13055
|
+
|
|
13056
|
+
// src/smelter.ts
|
|
13057
|
+
function sameStringSet(a, b) {
|
|
13058
|
+
if (a.length !== b.length) return false;
|
|
13059
|
+
const set = new Set(a);
|
|
13060
|
+
return b.every((t) => set.has(t));
|
|
13061
|
+
}
|
|
13062
|
+
var WORK_ITEM_TYPES = /* @__PURE__ */ new Set([
|
|
13063
|
+
"smelt:embed",
|
|
13064
|
+
"smelt:restamp",
|
|
13065
|
+
"smelt:purge",
|
|
13066
|
+
"smelt:embed-annotation",
|
|
13067
|
+
"smelt:purge-annotation"
|
|
13068
|
+
]);
|
|
13243
13069
|
function isWorkItem(input) {
|
|
13244
|
-
return input.type
|
|
13070
|
+
return WORK_ITEM_TYPES.has(input.type);
|
|
13245
13071
|
}
|
|
13246
13072
|
var Smelter = class _Smelter {
|
|
13247
13073
|
constructor(events$, vectorStore, embeddingProvider, content, bus, chunkingConfig, timing, logger) {
|
|
@@ -13265,7 +13091,7 @@ var Smelter = class _Smelter {
|
|
|
13265
13091
|
static RECONCILE_PAGE_SIZE = 200;
|
|
13266
13092
|
/** Bound on concurrently in-flight reconcile work — a cold rebuild must not fan out unbounded embedding calls. */
|
|
13267
13093
|
static RECONCILE_WAVE = 8;
|
|
13268
|
-
eventSubject = new
|
|
13094
|
+
eventSubject = new import_rxjs8.Subject();
|
|
13269
13095
|
sourceSubscription = null;
|
|
13270
13096
|
pipelineSubscription = null;
|
|
13271
13097
|
_eventsProcessed = 0;
|
|
@@ -13280,23 +13106,23 @@ var Smelter = class _Smelter {
|
|
|
13280
13106
|
}
|
|
13281
13107
|
initialize() {
|
|
13282
13108
|
this.pipelineSubscription = this.eventSubject.pipe(
|
|
13283
|
-
(0,
|
|
13284
|
-
(0,
|
|
13109
|
+
(0, import_operators7.groupBy)((e) => e.resourceId ?? "__unknown__"),
|
|
13110
|
+
(0, import_operators7.mergeMap)(
|
|
13285
13111
|
(group) => group.pipe(
|
|
13286
13112
|
burstBuffer({
|
|
13287
13113
|
burstWindowMs: this.timing.burstWindowMs,
|
|
13288
13114
|
maxBatchSize: this.timing.maxBatchSize,
|
|
13289
13115
|
idleTimeoutMs: this.timing.idleTimeoutMs
|
|
13290
13116
|
}),
|
|
13291
|
-
(0,
|
|
13117
|
+
(0, import_operators7.concatMap)((inputOrBatch) => {
|
|
13292
13118
|
if (Array.isArray(inputOrBatch)) {
|
|
13293
|
-
return (0,
|
|
13119
|
+
return (0, import_rxjs8.from)(
|
|
13294
13120
|
withActorSpan("smelter", "batch", async () => {
|
|
13295
13121
|
this._eventsProcessed += await this.processBatch(inputOrBatch);
|
|
13296
13122
|
}, { "batch.size": inputOrBatch.length })
|
|
13297
13123
|
);
|
|
13298
13124
|
}
|
|
13299
|
-
return (0,
|
|
13125
|
+
return (0, import_rxjs8.from)(
|
|
13300
13126
|
withActorSpan("smelter", inputOrBatch.type, async () => {
|
|
13301
13127
|
const ok = await this.safeProcessEvent(inputOrBatch);
|
|
13302
13128
|
if (isWorkItem(inputOrBatch)) this.noteWorkDone(1);
|
|
@@ -13405,16 +13231,26 @@ var Smelter = class _Smelter {
|
|
|
13405
13231
|
case "mark:archived":
|
|
13406
13232
|
await this.handleResourceArchived(event);
|
|
13407
13233
|
break;
|
|
13234
|
+
case "mark:unarchived":
|
|
13235
|
+
await this.handleResourceUnarchived(event);
|
|
13236
|
+
break;
|
|
13408
13237
|
case "mark:added":
|
|
13409
13238
|
await this.handleAnnotationAdded(event);
|
|
13410
13239
|
break;
|
|
13411
13240
|
case "mark:removed":
|
|
13412
13241
|
await this.handleAnnotationRemoved(event);
|
|
13413
13242
|
break;
|
|
13243
|
+
case "mark:entity-tag-added":
|
|
13244
|
+
case "mark:entity-tag-removed":
|
|
13245
|
+
await this.restampResource(event);
|
|
13246
|
+
break;
|
|
13414
13247
|
// Reconcile work items — same handlers, distinct provenance.
|
|
13415
13248
|
case "smelt:embed":
|
|
13416
13249
|
await this.embedResource(event, "Reconcile-indexed resource");
|
|
13417
13250
|
break;
|
|
13251
|
+
case "smelt:restamp":
|
|
13252
|
+
await this.restampResource(event);
|
|
13253
|
+
break;
|
|
13418
13254
|
case "smelt:purge":
|
|
13419
13255
|
await this.handleResourcePurge(event);
|
|
13420
13256
|
break;
|
|
@@ -13426,6 +13262,21 @@ var Smelter = class _Smelter {
|
|
|
13426
13262
|
break;
|
|
13427
13263
|
}
|
|
13428
13264
|
}
|
|
13265
|
+
/**
|
|
13266
|
+
* Payload-only stamp refresh: re-read the resource's CURRENT entity types
|
|
13267
|
+
* (one code path — `resolveEntityTypes` — so any prior drift self-corrects
|
|
13268
|
+
* on first touch) and rewrite the stamp on its existing points. Never calls
|
|
13269
|
+
* the embedding provider (S13): content is unchanged by definition on every
|
|
13270
|
+
* path that lands here. A resource with no points is a no-op — the stamp
|
|
13271
|
+
* rides the next embed.
|
|
13272
|
+
*/
|
|
13273
|
+
async restampResource(event) {
|
|
13274
|
+
const rid = event.resourceId;
|
|
13275
|
+
if (!rid) return;
|
|
13276
|
+
const entityTypes = await this.resolveEntityTypes(rid);
|
|
13277
|
+
await this.vectorStore.updateResourceEntityTypes(resourceId(rid), entityTypes);
|
|
13278
|
+
this.logger.info("Restamped resource entity types", { resourceId: rid, entityTypes });
|
|
13279
|
+
}
|
|
13429
13280
|
async handleResourcePurge(event) {
|
|
13430
13281
|
const rid = event.resourceId;
|
|
13431
13282
|
if (!rid) return;
|
|
@@ -13443,16 +13294,30 @@ var Smelter = class _Smelter {
|
|
|
13443
13294
|
async fetchEmbeddableText(resourceId10) {
|
|
13444
13295
|
try {
|
|
13445
13296
|
const { data, contentType } = await this.content.getBinary(resourceId(resourceId10));
|
|
13297
|
+
const bytes = Buffer.from(data);
|
|
13298
|
+
const checksum = calculateChecksum(bytes);
|
|
13446
13299
|
if (textExtractionOf(contentType) !== "decode") {
|
|
13447
13300
|
this.logger.debug("Skipping resource that does not decode as text", { resourceId: resourceId10, contentType });
|
|
13448
|
-
return
|
|
13301
|
+
return { kind: "skipped", checksum };
|
|
13449
13302
|
}
|
|
13450
|
-
const bytes = Buffer.from(data);
|
|
13451
13303
|
const text = decodeRepresentation(bytes, contentType);
|
|
13452
|
-
return text.trim() ? { text, checksum
|
|
13304
|
+
return text.trim() ? { kind: "text", text, checksum } : { kind: "skipped", checksum };
|
|
13453
13305
|
} catch (error) {
|
|
13454
13306
|
this.logger.warn("Content unavailable for embedding", { resourceId: resourceId10, error: errField(error) });
|
|
13455
|
-
return
|
|
13307
|
+
return { kind: "unavailable" };
|
|
13308
|
+
}
|
|
13309
|
+
}
|
|
13310
|
+
/**
|
|
13311
|
+
* The Smelter's single outbound signal (SMELTER-AXIOMS D3 as amended by
|
|
13312
|
+
* SMELTER-INDEX-SYNC): a per-resource decision report for the barrier
|
|
13313
|
+
* fold. Best-effort — waiters degrade to their bounded timeout; a signal
|
|
13314
|
+
* failure must never fail the embed.
|
|
13315
|
+
*/
|
|
13316
|
+
async emitSettled(resourceId10, contentChecksum, outcome) {
|
|
13317
|
+
try {
|
|
13318
|
+
await this.bus.emit("smelt:settled", { resourceId: resourceId10, contentChecksum, outcome });
|
|
13319
|
+
} catch (error) {
|
|
13320
|
+
this.logger.warn("Failed to emit smelt:settled", { resourceId: resourceId10, outcome, error: errField(error) });
|
|
13456
13321
|
}
|
|
13457
13322
|
}
|
|
13458
13323
|
/**
|
|
@@ -13476,9 +13341,16 @@ var Smelter = class _Smelter {
|
|
|
13476
13341
|
const rid = event.resourceId;
|
|
13477
13342
|
if (!rid) return;
|
|
13478
13343
|
const fetched = await this.fetchEmbeddableText(rid);
|
|
13479
|
-
if (
|
|
13344
|
+
if (fetched.kind === "unavailable") return;
|
|
13345
|
+
if (fetched.kind === "skipped") {
|
|
13346
|
+
await this.emitSettled(rid, fetched.checksum, "skipped");
|
|
13347
|
+
return;
|
|
13348
|
+
}
|
|
13480
13349
|
const chunks = chunkText(fetched.text, this.chunkingConfig);
|
|
13481
|
-
if (chunks.length === 0)
|
|
13350
|
+
if (chunks.length === 0) {
|
|
13351
|
+
await this.emitSettled(rid, fetched.checksum, "skipped");
|
|
13352
|
+
return;
|
|
13353
|
+
}
|
|
13482
13354
|
const entityTypes = await this.resolveEntityTypes(rid);
|
|
13483
13355
|
const embeddings = await this.embeddingProvider.embedBatch(chunks);
|
|
13484
13356
|
const embeddingChunks = chunks.map((t, i) => ({
|
|
@@ -13487,6 +13359,7 @@ var Smelter = class _Smelter {
|
|
|
13487
13359
|
embedding: embeddings[i]
|
|
13488
13360
|
}));
|
|
13489
13361
|
await this.vectorStore.upsertResourceVectors(resourceId(rid), embeddingChunks, fetched.checksum, entityTypes);
|
|
13362
|
+
await this.emitSettled(rid, fetched.checksum, "indexed");
|
|
13490
13363
|
this.logger.info(logMessage, { resourceId: rid, chunks: chunks.length });
|
|
13491
13364
|
}
|
|
13492
13365
|
async handleResourceArchived(event) {
|
|
@@ -13496,11 +13369,34 @@ var Smelter = class _Smelter {
|
|
|
13496
13369
|
await this.vectorStore.deleteAnnotationVectorsForResource(resourceId(rid));
|
|
13497
13370
|
this.logger.info("Deleted vectors for archived resource", { resourceId: rid });
|
|
13498
13371
|
}
|
|
13372
|
+
/**
|
|
13373
|
+
* Restore what `handleResourceArchived` deleted, from CURRENT state: the
|
|
13374
|
+
* resource's vectors (media-gated, full-replace) and its current exact-text
|
|
13375
|
+
* annotations — the same catalog read `reconcile()` uses, so the live path
|
|
13376
|
+
* and a restart agree (bugs/smelter-misses-unarchive.md).
|
|
13377
|
+
*/
|
|
13378
|
+
async handleResourceUnarchived(event) {
|
|
13379
|
+
const rid = event.resourceId;
|
|
13380
|
+
if (!rid) return;
|
|
13381
|
+
await this.embedResource(event, "Re-embedded unarchived resource");
|
|
13382
|
+
const { annotations } = await busRequest(
|
|
13383
|
+
this.bus,
|
|
13384
|
+
"browse:annotations-requested",
|
|
13385
|
+
{ resourceId: rid }
|
|
13386
|
+
);
|
|
13387
|
+
for (const annotation of annotations) {
|
|
13388
|
+
await this.indexAnnotation(rid, annotation);
|
|
13389
|
+
}
|
|
13390
|
+
}
|
|
13499
13391
|
async handleAnnotationAdded(event) {
|
|
13500
13392
|
const annotation = event.payload.annotation;
|
|
13501
13393
|
if (!annotation?.id) return;
|
|
13502
13394
|
const rid = event.resourceId;
|
|
13503
13395
|
if (!rid) return;
|
|
13396
|
+
await this.indexAnnotation(rid, annotation);
|
|
13397
|
+
}
|
|
13398
|
+
async indexAnnotation(rid, annotation) {
|
|
13399
|
+
if (!annotation.id) return;
|
|
13504
13400
|
const selector = getTargetSelector(annotation.target);
|
|
13505
13401
|
const exactText = getExactText(selector);
|
|
13506
13402
|
if (!exactText?.trim()) return;
|
|
@@ -13534,9 +13430,16 @@ var Smelter = class _Smelter {
|
|
|
13534
13430
|
const rid = event.resourceId;
|
|
13535
13431
|
if (!rid) continue;
|
|
13536
13432
|
const fetched = await this.fetchEmbeddableText(rid);
|
|
13537
|
-
if (
|
|
13433
|
+
if (fetched.kind === "unavailable") continue;
|
|
13434
|
+
if (fetched.kind === "skipped") {
|
|
13435
|
+
await this.emitSettled(rid, fetched.checksum, "skipped");
|
|
13436
|
+
continue;
|
|
13437
|
+
}
|
|
13538
13438
|
const chunks = chunkText(fetched.text, this.chunkingConfig);
|
|
13539
|
-
if (chunks.length === 0)
|
|
13439
|
+
if (chunks.length === 0) {
|
|
13440
|
+
await this.emitSettled(rid, fetched.checksum, "skipped");
|
|
13441
|
+
continue;
|
|
13442
|
+
}
|
|
13540
13443
|
const entityTypes = await this.resolveEntityTypes(rid);
|
|
13541
13444
|
resourceData.push({ rid: resourceId(rid), chunks, checksum: fetched.checksum, entityTypes });
|
|
13542
13445
|
allChunks.push(...chunks);
|
|
@@ -13551,6 +13454,7 @@ var Smelter = class _Smelter {
|
|
|
13551
13454
|
embedding: allEmbeddings[offset + i]
|
|
13552
13455
|
}));
|
|
13553
13456
|
await this.vectorStore.upsertResourceVectors(rid, embeddingChunks, checksum, entityTypes);
|
|
13457
|
+
await this.emitSettled(String(rid), checksum, "indexed");
|
|
13554
13458
|
this.logger.info("Batch-indexed resource", { resourceId: String(rid), chunks: chunks.length });
|
|
13555
13459
|
offset += chunks.length;
|
|
13556
13460
|
}
|
|
@@ -13623,7 +13527,7 @@ var Smelter = class _Smelter {
|
|
|
13623
13527
|
this._reconcileState = { phase: "running" };
|
|
13624
13528
|
try {
|
|
13625
13529
|
const [indexedResources, indexedAnnotations] = await Promise.all([
|
|
13626
|
-
this.vectorStore.
|
|
13530
|
+
this.vectorStore.listResourceStamps(),
|
|
13627
13531
|
this.vectorStore.listAnnotationIds()
|
|
13628
13532
|
]);
|
|
13629
13533
|
const resources = await this.listAllResources();
|
|
@@ -13636,18 +13540,24 @@ var Smelter = class _Smelter {
|
|
|
13636
13540
|
for (const resource of resources) {
|
|
13637
13541
|
const mediaType = getPrimaryMediaType(resource);
|
|
13638
13542
|
if (resource["@id"] && mediaType && textExtractionOf(mediaType) === "decode") {
|
|
13639
|
-
embeddable.set(resource["@id"],
|
|
13543
|
+
embeddable.set(resource["@id"], {
|
|
13544
|
+
checksum: getPrimaryRepresentation(resource)?.checksum,
|
|
13545
|
+
entityTypes: getResourceEntityTypes(resource)
|
|
13546
|
+
});
|
|
13640
13547
|
}
|
|
13641
13548
|
}
|
|
13642
13549
|
const work = [];
|
|
13643
13550
|
for (const rid of indexedResources.keys()) {
|
|
13644
13551
|
if (!embeddable.has(rid)) work.push({ type: "smelt:purge", resourceId: rid, payload: {} });
|
|
13645
13552
|
}
|
|
13646
|
-
for (const [rid,
|
|
13647
|
-
|
|
13553
|
+
for (const [rid, catalog] of embeddable) {
|
|
13554
|
+
const indexed = indexedResources.get(rid);
|
|
13555
|
+
if (!indexed) {
|
|
13648
13556
|
work.push({ type: "smelt:embed", resourceId: rid, payload: {} });
|
|
13649
|
-
} else if (
|
|
13557
|
+
} else if (catalog.checksum !== void 0 && indexed.contentChecksum !== catalog.checksum) {
|
|
13650
13558
|
work.push({ type: "smelt:embed", resourceId: rid, payload: {} });
|
|
13559
|
+
} else if (!sameStringSet(indexed.entityTypes, catalog.entityTypes)) {
|
|
13560
|
+
work.push({ type: "smelt:restamp", resourceId: rid, payload: {} });
|
|
13651
13561
|
}
|
|
13652
13562
|
}
|
|
13653
13563
|
const liveAnnotationIds = /* @__PURE__ */ new Set();
|
|
@@ -13676,6 +13586,7 @@ var Smelter = class _Smelter {
|
|
|
13676
13586
|
await this.drain(work);
|
|
13677
13587
|
const summary = {
|
|
13678
13588
|
resourcesEmbedded: work.filter((w) => w.type === "smelt:embed").length,
|
|
13589
|
+
resourcesRestamped: work.filter((w) => w.type === "smelt:restamp").length,
|
|
13679
13590
|
resourceVectorsDeleted: work.filter((w) => w.type === "smelt:purge").length,
|
|
13680
13591
|
annotationsEmbedded: work.filter((w) => w.type === "smelt:embed-annotation").length,
|
|
13681
13592
|
annotationVectorsDeleted: work.filter((w) => w.type === "smelt:purge-annotation").length
|
|
@@ -13724,23 +13635,26 @@ var Smelter = class _Smelter {
|
|
|
13724
13635
|
};
|
|
13725
13636
|
|
|
13726
13637
|
// src/smelter-actor-state-unit.ts
|
|
13727
|
-
var
|
|
13728
|
-
var
|
|
13638
|
+
var import_rxjs9 = __toESM(require_cjs());
|
|
13639
|
+
var import_operators8 = __toESM(require_operators());
|
|
13729
13640
|
var SMELTER_CHANNELS = [
|
|
13730
13641
|
"yield:created",
|
|
13731
13642
|
"yield:updated",
|
|
13732
13643
|
"yield:representation-added",
|
|
13733
13644
|
"mark:archived",
|
|
13645
|
+
"mark:unarchived",
|
|
13734
13646
|
"mark:added",
|
|
13735
|
-
"mark:removed"
|
|
13647
|
+
"mark:removed",
|
|
13648
|
+
"mark:entity-tag-added",
|
|
13649
|
+
"mark:entity-tag-removed"
|
|
13736
13650
|
];
|
|
13737
13651
|
function createSmelterActorStateUnit(options) {
|
|
13738
13652
|
const { bus } = options;
|
|
13739
13653
|
let started = false;
|
|
13740
|
-
const events$ = (0,
|
|
13654
|
+
const events$ = (0, import_rxjs9.merge)(
|
|
13741
13655
|
...SMELTER_CHANNELS.map(
|
|
13742
13656
|
(channel) => bus.on$(channel).pipe(
|
|
13743
|
-
(0,
|
|
13657
|
+
(0, import_operators8.map)((payload) => ({
|
|
13744
13658
|
type: channel,
|
|
13745
13659
|
resourceId: payload.resourceId,
|
|
13746
13660
|
payload
|
|
@@ -13944,24 +13858,24 @@ function collectContentRefs(streamData) {
|
|
|
13944
13858
|
}
|
|
13945
13859
|
|
|
13946
13860
|
// src/exchange/await-reply.ts
|
|
13947
|
-
var
|
|
13948
|
-
var
|
|
13861
|
+
var import_rxjs10 = __toESM(require_cjs());
|
|
13862
|
+
var import_operators9 = __toESM(require_operators());
|
|
13949
13863
|
function awaitReply(eventBus, command, payload, okChannel, failedChannel, timeoutMs) {
|
|
13950
|
-
const result$ = (0,
|
|
13951
|
-
eventBus.get(okChannel).pipe((0,
|
|
13864
|
+
const result$ = (0, import_rxjs10.race)(
|
|
13865
|
+
eventBus.get(okChannel).pipe((0, import_operators9.map)(() => void 0)),
|
|
13952
13866
|
eventBus.get(failedChannel).pipe(
|
|
13953
|
-
(0,
|
|
13867
|
+
(0, import_operators9.map)((e) => {
|
|
13954
13868
|
throw new Error(e.message ?? `${command} failed`);
|
|
13955
13869
|
})
|
|
13956
13870
|
),
|
|
13957
|
-
(0,
|
|
13958
|
-
(0,
|
|
13871
|
+
(0, import_rxjs10.timer)(timeoutMs).pipe(
|
|
13872
|
+
(0, import_operators9.map)(() => {
|
|
13959
13873
|
throw new Error(`Timeout waiting for ${okChannel}`);
|
|
13960
13874
|
})
|
|
13961
13875
|
)
|
|
13962
13876
|
);
|
|
13963
13877
|
eventBus.get(command).next(payload);
|
|
13964
|
-
return (0,
|
|
13878
|
+
return (0, import_rxjs10.firstValueFrom)(result$);
|
|
13965
13879
|
}
|
|
13966
13880
|
var REPLAY_TIMEOUT_MS = 3e4;
|
|
13967
13881
|
async function replayEventStream(jsonl, eventBus, eventStore, resolveBlob, contentStore, logger) {
|
|
@@ -14619,6 +14533,6 @@ var AnnotationOperations = class {
|
|
|
14619
14533
|
}
|
|
14620
14534
|
};
|
|
14621
14535
|
|
|
14622
|
-
export { AnnotationContext, AnnotationOperations, BACKUP_FORMAT, Browser, CloneTokenManager, FORMAT_VERSION, Gatherer, GraphContext, LLMContext, LocalContentTransport, LocalTransport, Matcher, ResourceContext, ResourceOperations, Smelter, Stower, bootstrapEntityTypes, createKnowledgeBase, createSmelterActorStateUnit, exportBackup, exportLinkedData, generateReferenceSuggestions, generateResourceSummary, importBackup, importLinkedData, isBackupManifest, readEntityTypesProjection, registerAnnotationAssemblyHandler, registerAnnotationLookupHandlers, registerBindUpdateBodyHandler, registerBusHandlers, registerJobCommandHandlers, startMakeMeaning, stopKnowledgeSystem, validateManifestVersion };
|
|
14536
|
+
export { AnnotationContext, AnnotationOperations, BACKUP_FORMAT, Browser, CloneTokenManager, FORMAT_VERSION, Gatherer, GraphContext, LLMContext, LocalContentTransport, LocalTransport, Matcher, ResourceContext, ResourceOperations, Smelter, Stower, asBusRequestPrimitive, bootstrapEntityTypes, createKnowledgeBase, createSmelterActorStateUnit, exportBackup, exportLinkedData, generateReferenceSuggestions, generateResourceSummary, importBackup, importLinkedData, isBackupManifest, readEntityTypesProjection, registerAnnotationAssemblyHandler, registerAnnotationLookupHandlers, registerBindUpdateBodyHandler, registerBusHandlers, registerJobCommandHandlers, startMakeMeaning, stopKnowledgeSystem, validateManifestVersion };
|
|
14623
14537
|
//# sourceMappingURL=index.js.map
|
|
14624
14538
|
//# sourceMappingURL=index.js.map
|