@semiont/make-meaning 0.4.20 → 0.4.22
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/index.d.ts +238 -215
- package/dist/index.js +1018 -1208
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -7,11 +7,11 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
7
7
|
var __commonJS = (cb, mod) => function __require() {
|
|
8
8
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
9
|
};
|
|
10
|
-
var __copyProps = (to,
|
|
11
|
-
if (
|
|
12
|
-
for (let key of __getOwnPropNames(
|
|
10
|
+
var __copyProps = (to, from8, except, desc) => {
|
|
11
|
+
if (from8 && typeof from8 === "object" || typeof from8 === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from8))
|
|
13
13
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () =>
|
|
14
|
+
__defProp(to, key, { get: () => from8[key], enumerable: !(desc = __getOwnPropDesc(from8, key)) || desc.enumerable });
|
|
15
15
|
}
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
@@ -125,9 +125,9 @@ var require_Subscription = __commonJS({
|
|
|
125
125
|
}
|
|
126
126
|
return ar;
|
|
127
127
|
};
|
|
128
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
129
|
-
for (var i = 0, il =
|
|
130
|
-
to[j] =
|
|
128
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
129
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
130
|
+
to[j] = from8[i];
|
|
131
131
|
return to;
|
|
132
132
|
};
|
|
133
133
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -135,14 +135,14 @@ var require_Subscription = __commonJS({
|
|
|
135
135
|
var isFunction_1 = require_isFunction();
|
|
136
136
|
var UnsubscriptionError_1 = require_UnsubscriptionError();
|
|
137
137
|
var arrRemove_1 = require_arrRemove();
|
|
138
|
-
var
|
|
139
|
-
function
|
|
138
|
+
var Subscription7 = (function() {
|
|
139
|
+
function Subscription8(initialTeardown) {
|
|
140
140
|
this.initialTeardown = initialTeardown;
|
|
141
141
|
this.closed = false;
|
|
142
142
|
this._parentage = null;
|
|
143
143
|
this._finalizers = null;
|
|
144
144
|
}
|
|
145
|
-
|
|
145
|
+
Subscription8.prototype.unsubscribe = function() {
|
|
146
146
|
var e_1, _a, e_2, _b;
|
|
147
147
|
var errors;
|
|
148
148
|
if (!this.closed) {
|
|
@@ -209,13 +209,13 @@ var require_Subscription = __commonJS({
|
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
};
|
|
212
|
-
|
|
212
|
+
Subscription8.prototype.add = function(teardown) {
|
|
213
213
|
var _a;
|
|
214
214
|
if (teardown && teardown !== this) {
|
|
215
215
|
if (this.closed) {
|
|
216
216
|
execFinalizer(teardown);
|
|
217
217
|
} else {
|
|
218
|
-
if (teardown instanceof
|
|
218
|
+
if (teardown instanceof Subscription8) {
|
|
219
219
|
if (teardown.closed || teardown._hasParent(this)) {
|
|
220
220
|
return;
|
|
221
221
|
}
|
|
@@ -225,15 +225,15 @@ var require_Subscription = __commonJS({
|
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
};
|
|
228
|
-
|
|
228
|
+
Subscription8.prototype._hasParent = function(parent) {
|
|
229
229
|
var _parentage = this._parentage;
|
|
230
230
|
return _parentage === parent || Array.isArray(_parentage) && _parentage.includes(parent);
|
|
231
231
|
};
|
|
232
|
-
|
|
232
|
+
Subscription8.prototype._addParent = function(parent) {
|
|
233
233
|
var _parentage = this._parentage;
|
|
234
234
|
this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
|
|
235
235
|
};
|
|
236
|
-
|
|
236
|
+
Subscription8.prototype._removeParent = function(parent) {
|
|
237
237
|
var _parentage = this._parentage;
|
|
238
238
|
if (_parentage === parent) {
|
|
239
239
|
this._parentage = null;
|
|
@@ -241,24 +241,24 @@ var require_Subscription = __commonJS({
|
|
|
241
241
|
arrRemove_1.arrRemove(_parentage, parent);
|
|
242
242
|
}
|
|
243
243
|
};
|
|
244
|
-
|
|
244
|
+
Subscription8.prototype.remove = function(teardown) {
|
|
245
245
|
var _finalizers = this._finalizers;
|
|
246
246
|
_finalizers && arrRemove_1.arrRemove(_finalizers, teardown);
|
|
247
|
-
if (teardown instanceof
|
|
247
|
+
if (teardown instanceof Subscription8) {
|
|
248
248
|
teardown._removeParent(this);
|
|
249
249
|
}
|
|
250
250
|
};
|
|
251
|
-
|
|
252
|
-
var empty = new
|
|
251
|
+
Subscription8.EMPTY = (function() {
|
|
252
|
+
var empty = new Subscription8();
|
|
253
253
|
empty.closed = true;
|
|
254
254
|
return empty;
|
|
255
255
|
})();
|
|
256
|
-
return
|
|
256
|
+
return Subscription8;
|
|
257
257
|
})();
|
|
258
|
-
exports.Subscription =
|
|
259
|
-
exports.EMPTY_SUBSCRIPTION =
|
|
258
|
+
exports.Subscription = Subscription7;
|
|
259
|
+
exports.EMPTY_SUBSCRIPTION = Subscription7.EMPTY;
|
|
260
260
|
function isSubscription(value) {
|
|
261
|
-
return value instanceof
|
|
261
|
+
return value instanceof Subscription7 || value && "closed" in value && isFunction_1.isFunction(value.remove) && isFunction_1.isFunction(value.add) && isFunction_1.isFunction(value.unsubscribe);
|
|
262
262
|
}
|
|
263
263
|
exports.isSubscription = isSubscription;
|
|
264
264
|
function execFinalizer(finalizer) {
|
|
@@ -308,9 +308,9 @@ var require_timeoutProvider = __commonJS({
|
|
|
308
308
|
}
|
|
309
309
|
return ar;
|
|
310
310
|
};
|
|
311
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
312
|
-
for (var i = 0, il =
|
|
313
|
-
to[j] =
|
|
311
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
312
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
313
|
+
to[j] = from8[i];
|
|
314
314
|
return to;
|
|
315
315
|
};
|
|
316
316
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1068,9 +1068,9 @@ var require_animationFrameProvider = __commonJS({
|
|
|
1068
1068
|
}
|
|
1069
1069
|
return ar;
|
|
1070
1070
|
};
|
|
1071
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
1072
|
-
for (var i = 0, il =
|
|
1073
|
-
to[j] =
|
|
1071
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
1072
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
1073
|
+
to[j] = from8[i];
|
|
1074
1074
|
return to;
|
|
1075
1075
|
};
|
|
1076
1076
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1215,9 +1215,9 @@ var require_Subject = __commonJS({
|
|
|
1215
1215
|
var ObjectUnsubscribedError_1 = require_ObjectUnsubscribedError();
|
|
1216
1216
|
var arrRemove_1 = require_arrRemove();
|
|
1217
1217
|
var errorContext_1 = require_errorContext();
|
|
1218
|
-
var
|
|
1219
|
-
__extends(
|
|
1220
|
-
function
|
|
1218
|
+
var Subject2 = (function(_super) {
|
|
1219
|
+
__extends(Subject3, _super);
|
|
1220
|
+
function Subject3() {
|
|
1221
1221
|
var _this = _super.call(this) || this;
|
|
1222
1222
|
_this.closed = false;
|
|
1223
1223
|
_this.currentObservers = null;
|
|
@@ -1227,17 +1227,17 @@ var require_Subject = __commonJS({
|
|
|
1227
1227
|
_this.thrownError = null;
|
|
1228
1228
|
return _this;
|
|
1229
1229
|
}
|
|
1230
|
-
|
|
1230
|
+
Subject3.prototype.lift = function(operator) {
|
|
1231
1231
|
var subject = new AnonymousSubject(this, this);
|
|
1232
1232
|
subject.operator = operator;
|
|
1233
1233
|
return subject;
|
|
1234
1234
|
};
|
|
1235
|
-
|
|
1235
|
+
Subject3.prototype._throwIfClosed = function() {
|
|
1236
1236
|
if (this.closed) {
|
|
1237
1237
|
throw new ObjectUnsubscribedError_1.ObjectUnsubscribedError();
|
|
1238
1238
|
}
|
|
1239
1239
|
};
|
|
1240
|
-
|
|
1240
|
+
Subject3.prototype.next = function(value) {
|
|
1241
1241
|
var _this = this;
|
|
1242
1242
|
errorContext_1.errorContext(function() {
|
|
1243
1243
|
var e_1, _a;
|
|
@@ -1263,7 +1263,7 @@ var require_Subject = __commonJS({
|
|
|
1263
1263
|
}
|
|
1264
1264
|
});
|
|
1265
1265
|
};
|
|
1266
|
-
|
|
1266
|
+
Subject3.prototype.error = function(err) {
|
|
1267
1267
|
var _this = this;
|
|
1268
1268
|
errorContext_1.errorContext(function() {
|
|
1269
1269
|
_this._throwIfClosed();
|
|
@@ -1277,7 +1277,7 @@ var require_Subject = __commonJS({
|
|
|
1277
1277
|
}
|
|
1278
1278
|
});
|
|
1279
1279
|
};
|
|
1280
|
-
|
|
1280
|
+
Subject3.prototype.complete = function() {
|
|
1281
1281
|
var _this = this;
|
|
1282
1282
|
errorContext_1.errorContext(function() {
|
|
1283
1283
|
_this._throwIfClosed();
|
|
@@ -1290,11 +1290,11 @@ var require_Subject = __commonJS({
|
|
|
1290
1290
|
}
|
|
1291
1291
|
});
|
|
1292
1292
|
};
|
|
1293
|
-
|
|
1293
|
+
Subject3.prototype.unsubscribe = function() {
|
|
1294
1294
|
this.isStopped = this.closed = true;
|
|
1295
1295
|
this.observers = this.currentObservers = null;
|
|
1296
1296
|
};
|
|
1297
|
-
Object.defineProperty(
|
|
1297
|
+
Object.defineProperty(Subject3.prototype, "observed", {
|
|
1298
1298
|
get: function() {
|
|
1299
1299
|
var _a;
|
|
1300
1300
|
return ((_a = this.observers) === null || _a === void 0 ? void 0 : _a.length) > 0;
|
|
@@ -1302,16 +1302,16 @@ var require_Subject = __commonJS({
|
|
|
1302
1302
|
enumerable: false,
|
|
1303
1303
|
configurable: true
|
|
1304
1304
|
});
|
|
1305
|
-
|
|
1305
|
+
Subject3.prototype._trySubscribe = function(subscriber) {
|
|
1306
1306
|
this._throwIfClosed();
|
|
1307
1307
|
return _super.prototype._trySubscribe.call(this, subscriber);
|
|
1308
1308
|
};
|
|
1309
|
-
|
|
1309
|
+
Subject3.prototype._subscribe = function(subscriber) {
|
|
1310
1310
|
this._throwIfClosed();
|
|
1311
1311
|
this._checkFinalizedStatuses(subscriber);
|
|
1312
1312
|
return this._innerSubscribe(subscriber);
|
|
1313
1313
|
};
|
|
1314
|
-
|
|
1314
|
+
Subject3.prototype._innerSubscribe = function(subscriber) {
|
|
1315
1315
|
var _this = this;
|
|
1316
1316
|
var _a = this, hasError = _a.hasError, isStopped = _a.isStopped, observers = _a.observers;
|
|
1317
1317
|
if (hasError || isStopped) {
|
|
@@ -1324,7 +1324,7 @@ var require_Subject = __commonJS({
|
|
|
1324
1324
|
arrRemove_1.arrRemove(observers, subscriber);
|
|
1325
1325
|
});
|
|
1326
1326
|
};
|
|
1327
|
-
|
|
1327
|
+
Subject3.prototype._checkFinalizedStatuses = function(subscriber) {
|
|
1328
1328
|
var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, isStopped = _a.isStopped;
|
|
1329
1329
|
if (hasError) {
|
|
1330
1330
|
subscriber.error(thrownError);
|
|
@@ -1332,17 +1332,17 @@ var require_Subject = __commonJS({
|
|
|
1332
1332
|
subscriber.complete();
|
|
1333
1333
|
}
|
|
1334
1334
|
};
|
|
1335
|
-
|
|
1335
|
+
Subject3.prototype.asObservable = function() {
|
|
1336
1336
|
var observable = new Observable_1.Observable();
|
|
1337
1337
|
observable.source = this;
|
|
1338
1338
|
return observable;
|
|
1339
1339
|
};
|
|
1340
|
-
|
|
1340
|
+
Subject3.create = function(destination, source) {
|
|
1341
1341
|
return new AnonymousSubject(destination, source);
|
|
1342
1342
|
};
|
|
1343
|
-
return
|
|
1343
|
+
return Subject3;
|
|
1344
1344
|
})(Observable_1.Observable);
|
|
1345
|
-
exports.Subject =
|
|
1345
|
+
exports.Subject = Subject2;
|
|
1346
1346
|
var AnonymousSubject = (function(_super) {
|
|
1347
1347
|
__extends(AnonymousSubject2, _super);
|
|
1348
1348
|
function AnonymousSubject2(destination, source) {
|
|
@@ -1368,7 +1368,7 @@ var require_Subject = __commonJS({
|
|
|
1368
1368
|
return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : Subscription_1.EMPTY_SUBSCRIPTION;
|
|
1369
1369
|
};
|
|
1370
1370
|
return AnonymousSubject2;
|
|
1371
|
-
})(
|
|
1371
|
+
})(Subject2);
|
|
1372
1372
|
exports.AnonymousSubject = AnonymousSubject;
|
|
1373
1373
|
}
|
|
1374
1374
|
});
|
|
@@ -1399,26 +1399,26 @@ var require_BehaviorSubject = __commonJS({
|
|
|
1399
1399
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1400
1400
|
exports.BehaviorSubject = void 0;
|
|
1401
1401
|
var Subject_1 = require_Subject();
|
|
1402
|
-
var
|
|
1403
|
-
__extends(
|
|
1404
|
-
function
|
|
1402
|
+
var BehaviorSubject2 = (function(_super) {
|
|
1403
|
+
__extends(BehaviorSubject3, _super);
|
|
1404
|
+
function BehaviorSubject3(_value) {
|
|
1405
1405
|
var _this = _super.call(this) || this;
|
|
1406
1406
|
_this._value = _value;
|
|
1407
1407
|
return _this;
|
|
1408
1408
|
}
|
|
1409
|
-
Object.defineProperty(
|
|
1409
|
+
Object.defineProperty(BehaviorSubject3.prototype, "value", {
|
|
1410
1410
|
get: function() {
|
|
1411
1411
|
return this.getValue();
|
|
1412
1412
|
},
|
|
1413
1413
|
enumerable: false,
|
|
1414
1414
|
configurable: true
|
|
1415
1415
|
});
|
|
1416
|
-
|
|
1416
|
+
BehaviorSubject3.prototype._subscribe = function(subscriber) {
|
|
1417
1417
|
var subscription = _super.prototype._subscribe.call(this, subscriber);
|
|
1418
1418
|
!subscription.closed && subscriber.next(this._value);
|
|
1419
1419
|
return subscription;
|
|
1420
1420
|
};
|
|
1421
|
-
|
|
1421
|
+
BehaviorSubject3.prototype.getValue = function() {
|
|
1422
1422
|
var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, _value = _a._value;
|
|
1423
1423
|
if (hasError) {
|
|
1424
1424
|
throw thrownError;
|
|
@@ -1426,12 +1426,12 @@ var require_BehaviorSubject = __commonJS({
|
|
|
1426
1426
|
this._throwIfClosed();
|
|
1427
1427
|
return _value;
|
|
1428
1428
|
};
|
|
1429
|
-
|
|
1429
|
+
BehaviorSubject3.prototype.next = function(value) {
|
|
1430
1430
|
_super.prototype.next.call(this, this._value = value);
|
|
1431
1431
|
};
|
|
1432
|
-
return
|
|
1432
|
+
return BehaviorSubject3;
|
|
1433
1433
|
})(Subject_1.Subject);
|
|
1434
|
-
exports.BehaviorSubject =
|
|
1434
|
+
exports.BehaviorSubject = BehaviorSubject2;
|
|
1435
1435
|
}
|
|
1436
1436
|
});
|
|
1437
1437
|
|
|
@@ -1668,9 +1668,9 @@ var require_intervalProvider = __commonJS({
|
|
|
1668
1668
|
}
|
|
1669
1669
|
return ar;
|
|
1670
1670
|
};
|
|
1671
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
1672
|
-
for (var i = 0, il =
|
|
1673
|
-
to[j] =
|
|
1671
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
1672
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
1673
|
+
to[j] = from8[i];
|
|
1674
1674
|
return to;
|
|
1675
1675
|
};
|
|
1676
1676
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1877,9 +1877,9 @@ var require_immediateProvider = __commonJS({
|
|
|
1877
1877
|
}
|
|
1878
1878
|
return ar;
|
|
1879
1879
|
};
|
|
1880
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
1881
|
-
for (var i = 0, il =
|
|
1882
|
-
to[j] =
|
|
1880
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
1881
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
1882
|
+
to[j] = from8[i];
|
|
1883
1883
|
return to;
|
|
1884
1884
|
};
|
|
1885
1885
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -3441,10 +3441,10 @@ var require_from = __commonJS({
|
|
|
3441
3441
|
exports.from = void 0;
|
|
3442
3442
|
var scheduled_1 = require_scheduled();
|
|
3443
3443
|
var innerFrom_1 = require_innerFrom();
|
|
3444
|
-
function
|
|
3444
|
+
function from8(input, scheduler) {
|
|
3445
3445
|
return scheduler ? scheduled_1.scheduled(input, scheduler) : innerFrom_1.innerFrom(input);
|
|
3446
3446
|
}
|
|
3447
|
-
exports.from =
|
|
3447
|
+
exports.from = from8;
|
|
3448
3448
|
}
|
|
3449
3449
|
});
|
|
3450
3450
|
|
|
@@ -3832,9 +3832,9 @@ var require_mapOneOrManyArgs = __commonJS({
|
|
|
3832
3832
|
}
|
|
3833
3833
|
return ar;
|
|
3834
3834
|
};
|
|
3835
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
3836
|
-
for (var i = 0, il =
|
|
3837
|
-
to[j] =
|
|
3835
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
3836
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
3837
|
+
to[j] = from8[i];
|
|
3838
3838
|
return to;
|
|
3839
3839
|
};
|
|
3840
3840
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -3874,9 +3874,9 @@ var require_bindCallbackInternals = __commonJS({
|
|
|
3874
3874
|
}
|
|
3875
3875
|
return ar;
|
|
3876
3876
|
};
|
|
3877
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
3878
|
-
for (var i = 0, il =
|
|
3879
|
-
to[j] =
|
|
3877
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
3878
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
3879
|
+
to[j] = from8[i];
|
|
3880
3880
|
return to;
|
|
3881
3881
|
};
|
|
3882
3882
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -4196,12 +4196,12 @@ var require_mergeMap = __commonJS({
|
|
|
4196
4196
|
var lift_1 = require_lift();
|
|
4197
4197
|
var mergeInternals_1 = require_mergeInternals();
|
|
4198
4198
|
var isFunction_1 = require_isFunction();
|
|
4199
|
-
function
|
|
4199
|
+
function mergeMap6(project, resultSelector, concurrent) {
|
|
4200
4200
|
if (concurrent === void 0) {
|
|
4201
4201
|
concurrent = Infinity;
|
|
4202
4202
|
}
|
|
4203
4203
|
if (isFunction_1.isFunction(resultSelector)) {
|
|
4204
|
-
return
|
|
4204
|
+
return mergeMap6(function(a, i) {
|
|
4205
4205
|
return map_1.map(function(b, ii) {
|
|
4206
4206
|
return resultSelector(a, b, i, ii);
|
|
4207
4207
|
})(innerFrom_1.innerFrom(project(a, i)));
|
|
@@ -4213,7 +4213,7 @@ var require_mergeMap = __commonJS({
|
|
|
4213
4213
|
return mergeInternals_1.mergeInternals(source, subscriber, project, concurrent);
|
|
4214
4214
|
});
|
|
4215
4215
|
}
|
|
4216
|
-
exports.mergeMap =
|
|
4216
|
+
exports.mergeMap = mergeMap6;
|
|
4217
4217
|
}
|
|
4218
4218
|
});
|
|
4219
4219
|
|
|
@@ -5008,9 +5008,9 @@ var require_zip = __commonJS({
|
|
|
5008
5008
|
}
|
|
5009
5009
|
return ar;
|
|
5010
5010
|
};
|
|
5011
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
5012
|
-
for (var i = 0, il =
|
|
5013
|
-
to[j] =
|
|
5011
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
5012
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
5013
|
+
to[j] = from8[i];
|
|
5014
5014
|
return to;
|
|
5015
5015
|
};
|
|
5016
5016
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -5638,9 +5638,9 @@ var require_combineLatest2 = __commonJS({
|
|
|
5638
5638
|
}
|
|
5639
5639
|
return ar;
|
|
5640
5640
|
};
|
|
5641
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
5642
|
-
for (var i = 0, il =
|
|
5643
|
-
to[j] =
|
|
5641
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
5642
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
5643
|
+
to[j] = from8[i];
|
|
5644
5644
|
return to;
|
|
5645
5645
|
};
|
|
5646
5646
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -5686,9 +5686,9 @@ var require_combineLatestWith = __commonJS({
|
|
|
5686
5686
|
}
|
|
5687
5687
|
return ar;
|
|
5688
5688
|
};
|
|
5689
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
5690
|
-
for (var i = 0, il =
|
|
5691
|
-
to[j] =
|
|
5689
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
5690
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
5691
|
+
to[j] = from8[i];
|
|
5692
5692
|
return to;
|
|
5693
5693
|
};
|
|
5694
5694
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -5713,10 +5713,10 @@ var require_concatMap = __commonJS({
|
|
|
5713
5713
|
exports.concatMap = void 0;
|
|
5714
5714
|
var mergeMap_1 = require_mergeMap();
|
|
5715
5715
|
var isFunction_1 = require_isFunction();
|
|
5716
|
-
function
|
|
5716
|
+
function concatMap5(project, resultSelector) {
|
|
5717
5717
|
return isFunction_1.isFunction(resultSelector) ? mergeMap_1.mergeMap(project, resultSelector, 1) : mergeMap_1.mergeMap(project, 1);
|
|
5718
5718
|
}
|
|
5719
|
-
exports.concatMap =
|
|
5719
|
+
exports.concatMap = concatMap5;
|
|
5720
5720
|
}
|
|
5721
5721
|
});
|
|
5722
5722
|
|
|
@@ -5760,9 +5760,9 @@ var require_concat2 = __commonJS({
|
|
|
5760
5760
|
}
|
|
5761
5761
|
return ar;
|
|
5762
5762
|
};
|
|
5763
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
5764
|
-
for (var i = 0, il =
|
|
5765
|
-
to[j] =
|
|
5763
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
5764
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
5765
|
+
to[j] = from8[i];
|
|
5766
5766
|
return to;
|
|
5767
5767
|
};
|
|
5768
5768
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -5806,9 +5806,9 @@ var require_concatWith = __commonJS({
|
|
|
5806
5806
|
}
|
|
5807
5807
|
return ar;
|
|
5808
5808
|
};
|
|
5809
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
5810
|
-
for (var i = 0, il =
|
|
5811
|
-
to[j] =
|
|
5809
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
5810
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
5811
|
+
to[j] = from8[i];
|
|
5812
5812
|
return to;
|
|
5813
5813
|
};
|
|
5814
5814
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -6299,9 +6299,9 @@ var require_endWith = __commonJS({
|
|
|
6299
6299
|
}
|
|
6300
6300
|
return ar;
|
|
6301
6301
|
};
|
|
6302
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
6303
|
-
for (var i = 0, il =
|
|
6304
|
-
to[j] =
|
|
6302
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
6303
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
6304
|
+
to[j] = from8[i];
|
|
6305
6305
|
return to;
|
|
6306
6306
|
};
|
|
6307
6307
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -6540,7 +6540,7 @@ var require_groupBy = __commonJS({
|
|
|
6540
6540
|
var Subject_1 = require_Subject();
|
|
6541
6541
|
var lift_1 = require_lift();
|
|
6542
6542
|
var OperatorSubscriber_1 = require_OperatorSubscriber();
|
|
6543
|
-
function
|
|
6543
|
+
function groupBy3(keySelector, elementOrOptions, duration, connector) {
|
|
6544
6544
|
return lift_1.operate(function(source, subscriber) {
|
|
6545
6545
|
var element;
|
|
6546
6546
|
if (!elementOrOptions || typeof elementOrOptions === "function") {
|
|
@@ -6607,7 +6607,7 @@ var require_groupBy = __commonJS({
|
|
|
6607
6607
|
}
|
|
6608
6608
|
});
|
|
6609
6609
|
}
|
|
6610
|
-
exports.groupBy =
|
|
6610
|
+
exports.groupBy = groupBy3;
|
|
6611
6611
|
}
|
|
6612
6612
|
});
|
|
6613
6613
|
|
|
@@ -6846,9 +6846,9 @@ var require_merge2 = __commonJS({
|
|
|
6846
6846
|
}
|
|
6847
6847
|
return ar;
|
|
6848
6848
|
};
|
|
6849
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
6850
|
-
for (var i = 0, il =
|
|
6851
|
-
to[j] =
|
|
6849
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
6850
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
6851
|
+
to[j] = from8[i];
|
|
6852
6852
|
return to;
|
|
6853
6853
|
};
|
|
6854
6854
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -6893,9 +6893,9 @@ var require_mergeWith = __commonJS({
|
|
|
6893
6893
|
}
|
|
6894
6894
|
return ar;
|
|
6895
6895
|
};
|
|
6896
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
6897
|
-
for (var i = 0, il =
|
|
6898
|
-
to[j] =
|
|
6896
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
6897
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
6898
|
+
to[j] = from8[i];
|
|
6899
6899
|
return to;
|
|
6900
6900
|
};
|
|
6901
6901
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -6978,9 +6978,9 @@ var require_onErrorResumeNextWith = __commonJS({
|
|
|
6978
6978
|
}
|
|
6979
6979
|
return ar;
|
|
6980
6980
|
};
|
|
6981
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
6982
|
-
for (var i = 0, il =
|
|
6983
|
-
to[j] =
|
|
6981
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
6982
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
6983
|
+
to[j] = from8[i];
|
|
6984
6984
|
return to;
|
|
6985
6985
|
};
|
|
6986
6986
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -7162,9 +7162,9 @@ var require_raceWith = __commonJS({
|
|
|
7162
7162
|
}
|
|
7163
7163
|
return ar;
|
|
7164
7164
|
};
|
|
7165
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
7166
|
-
for (var i = 0, il =
|
|
7167
|
-
to[j] =
|
|
7165
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
7166
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
7167
|
+
to[j] = from8[i];
|
|
7168
7168
|
return to;
|
|
7169
7169
|
};
|
|
7170
7170
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -7560,9 +7560,9 @@ var require_share = __commonJS({
|
|
|
7560
7560
|
}
|
|
7561
7561
|
return ar;
|
|
7562
7562
|
};
|
|
7563
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
7564
|
-
for (var i = 0, il =
|
|
7565
|
-
to[j] =
|
|
7563
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
7564
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
7565
|
+
to[j] = from8[i];
|
|
7566
7566
|
return to;
|
|
7567
7567
|
};
|
|
7568
7568
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -8562,9 +8562,9 @@ var require_withLatestFrom = __commonJS({
|
|
|
8562
8562
|
}
|
|
8563
8563
|
return ar;
|
|
8564
8564
|
};
|
|
8565
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
8566
|
-
for (var i = 0, il =
|
|
8567
|
-
to[j] =
|
|
8565
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
8566
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
8567
|
+
to[j] = from8[i];
|
|
8568
8568
|
return to;
|
|
8569
8569
|
};
|
|
8570
8570
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -8648,9 +8648,9 @@ var require_zip2 = __commonJS({
|
|
|
8648
8648
|
}
|
|
8649
8649
|
return ar;
|
|
8650
8650
|
};
|
|
8651
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
8652
|
-
for (var i = 0, il =
|
|
8653
|
-
to[j] =
|
|
8651
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
8652
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
8653
|
+
to[j] = from8[i];
|
|
8654
8654
|
return to;
|
|
8655
8655
|
};
|
|
8656
8656
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -8691,9 +8691,9 @@ var require_zipWith = __commonJS({
|
|
|
8691
8691
|
}
|
|
8692
8692
|
return ar;
|
|
8693
8693
|
};
|
|
8694
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
8695
|
-
for (var i = 0, il =
|
|
8696
|
-
to[j] =
|
|
8694
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
8695
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
8696
|
+
to[j] = from8[i];
|
|
8697
8697
|
return to;
|
|
8698
8698
|
};
|
|
8699
8699
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -9459,9 +9459,9 @@ var require_race2 = __commonJS({
|
|
|
9459
9459
|
}
|
|
9460
9460
|
return ar;
|
|
9461
9461
|
};
|
|
9462
|
-
var __spreadArray = exports && exports.__spreadArray || function(to,
|
|
9463
|
-
for (var i = 0, il =
|
|
9464
|
-
to[j] =
|
|
9462
|
+
var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
|
|
9463
|
+
for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
|
|
9464
|
+
to[j] = from8[i];
|
|
9465
9465
|
return to;
|
|
9466
9466
|
};
|
|
9467
9467
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -9943,9 +9943,10 @@ var require_operators = __commonJS({
|
|
|
9943
9943
|
});
|
|
9944
9944
|
|
|
9945
9945
|
// src/service.ts
|
|
9946
|
-
import {
|
|
9946
|
+
import { FsJobQueue } from "@semiont/jobs";
|
|
9947
9947
|
import { createEventStore as createEventStoreCore } from "@semiont/event-sourcing";
|
|
9948
|
-
import { jobId } from "@semiont/core";
|
|
9948
|
+
import { jobId as jobId2 } from "@semiont/core";
|
|
9949
|
+
import { registerJobQueueProvider } from "@semiont/observability";
|
|
9949
9950
|
|
|
9950
9951
|
// src/config.ts
|
|
9951
9952
|
function resolveActorInference(config, actor) {
|
|
@@ -9955,42 +9956,12 @@ function resolveActorInference(config, actor) {
|
|
|
9955
9956
|
`No inference config found for actor '${actor}'. Set actors.${actor}.inference in your config.`
|
|
9956
9957
|
);
|
|
9957
9958
|
}
|
|
9958
|
-
function resolveWorkerInference(config, workerType) {
|
|
9959
|
-
const specific = config.workers?.[workerType];
|
|
9960
|
-
if (specific) return specific;
|
|
9961
|
-
const defaultWorker = config.workers?.default;
|
|
9962
|
-
if (defaultWorker) return defaultWorker;
|
|
9963
|
-
throw new Error(
|
|
9964
|
-
`No inference config found for worker '${workerType}'. Set workers.${workerType}.inference or workers.default.inference in your config.`
|
|
9965
|
-
);
|
|
9966
|
-
}
|
|
9967
|
-
|
|
9968
|
-
// src/agent-utils.ts
|
|
9969
|
-
function inferenceConfigToGenerator(workerType, config) {
|
|
9970
|
-
const providerLabel = config.type === "ollama" ? `Ollama ${config.model}` : config.type === "anthropic" ? `Anthropic ${config.model}` : config.type != null ? `${config.type} ${config.model}` : void 0;
|
|
9971
|
-
return {
|
|
9972
|
-
"@type": "SoftwareAgent",
|
|
9973
|
-
name: providerLabel ? `${workerType} / ${providerLabel}` : workerType,
|
|
9974
|
-
worker: workerType,
|
|
9975
|
-
inferenceProvider: config.type,
|
|
9976
|
-
model: config.model
|
|
9977
|
-
};
|
|
9978
|
-
}
|
|
9979
9959
|
|
|
9980
9960
|
// src/service.ts
|
|
9981
|
-
var
|
|
9982
|
-
var
|
|
9983
|
-
import { Readable } from "stream";
|
|
9961
|
+
var import_rxjs9 = __toESM(require_cjs(), 1);
|
|
9962
|
+
var import_operators9 = __toESM(require_operators(), 1);
|
|
9984
9963
|
import { createInferenceClient } from "@semiont/inference";
|
|
9985
9964
|
import { getGraphDatabase } from "@semiont/graph";
|
|
9986
|
-
import {
|
|
9987
|
-
ReferenceAnnotationWorker,
|
|
9988
|
-
GenerationWorker,
|
|
9989
|
-
HighlightAnnotationWorker,
|
|
9990
|
-
AssessmentAnnotationWorker,
|
|
9991
|
-
CommentAnnotationWorker,
|
|
9992
|
-
TagAnnotationWorker
|
|
9993
|
-
} from "@semiont/jobs";
|
|
9994
9965
|
|
|
9995
9966
|
// src/knowledge-base.ts
|
|
9996
9967
|
import { FilesystemViewStorage } from "@semiont/event-sourcing";
|
|
@@ -10344,20 +10315,20 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10344
10315
|
* Rebuild entire resource from events.
|
|
10345
10316
|
* Bypasses the live pipeline — reads directly from event store.
|
|
10346
10317
|
*/
|
|
10347
|
-
async rebuildResource(
|
|
10318
|
+
async rebuildResource(resourceId10) {
|
|
10348
10319
|
const graphDb = this.ensureInitialized();
|
|
10349
|
-
this.logger.info("Rebuilding resource from events", { resourceId:
|
|
10320
|
+
this.logger.info("Rebuilding resource from events", { resourceId: resourceId10 });
|
|
10350
10321
|
try {
|
|
10351
|
-
await graphDb.deleteResource(
|
|
10322
|
+
await graphDb.deleteResource(resourceId10);
|
|
10352
10323
|
} catch (error) {
|
|
10353
|
-
this.logger.debug("No existing resource to delete", { resourceId:
|
|
10324
|
+
this.logger.debug("No existing resource to delete", { resourceId: resourceId10 });
|
|
10354
10325
|
}
|
|
10355
10326
|
const query = new EventQuery(this.eventStore.log.storage);
|
|
10356
|
-
const events = await query.getResourceEvents(
|
|
10327
|
+
const events = await query.getResourceEvents(resourceId10);
|
|
10357
10328
|
for (const storedEvent of events) {
|
|
10358
|
-
await this.
|
|
10329
|
+
await this.safeApplyEvent(storedEvent);
|
|
10359
10330
|
}
|
|
10360
|
-
this.logger.info("Resource rebuild complete", { resourceId:
|
|
10331
|
+
this.logger.info("Resource rebuild complete", { resourceId: resourceId10, eventCount: events.length });
|
|
10361
10332
|
}
|
|
10362
10333
|
/**
|
|
10363
10334
|
* Rebuild entire GraphDB from all events.
|
|
@@ -10373,22 +10344,22 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10373
10344
|
const allResourceIds = await this.eventStore.log.getAllResourceIds();
|
|
10374
10345
|
this.logger.info("Found resources to rebuild", { count: allResourceIds.length });
|
|
10375
10346
|
this.logger.info("PASS 1: Creating all nodes (resources + annotations)");
|
|
10376
|
-
for (const
|
|
10377
|
-
const events = await query.getResourceEvents(makeResourceId(
|
|
10347
|
+
for (const resourceId10 of allResourceIds) {
|
|
10348
|
+
const events = await query.getResourceEvents(makeResourceId(resourceId10));
|
|
10378
10349
|
for (const storedEvent of events) {
|
|
10379
10350
|
if (storedEvent.type === "mark:body-updated") {
|
|
10380
10351
|
continue;
|
|
10381
10352
|
}
|
|
10382
|
-
await this.
|
|
10353
|
+
await this.safeApplyEvent(storedEvent);
|
|
10383
10354
|
}
|
|
10384
10355
|
}
|
|
10385
10356
|
this.logger.info("Pass 1 complete - all nodes created");
|
|
10386
10357
|
this.logger.info("PASS 2: Creating all REFERENCES edges");
|
|
10387
|
-
for (const
|
|
10388
|
-
const events = await query.getResourceEvents(makeResourceId(
|
|
10358
|
+
for (const resourceId10 of allResourceIds) {
|
|
10359
|
+
const events = await query.getResourceEvents(makeResourceId(resourceId10));
|
|
10389
10360
|
for (const storedEvent of events) {
|
|
10390
10361
|
if (storedEvent.type === "mark:body-updated") {
|
|
10391
|
-
await this.
|
|
10362
|
+
await this.safeApplyEvent(storedEvent);
|
|
10392
10363
|
}
|
|
10393
10364
|
}
|
|
10394
10365
|
}
|
|
@@ -10414,635 +10385,9 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10414
10385
|
}
|
|
10415
10386
|
};
|
|
10416
10387
|
|
|
10417
|
-
// src/smelter.ts
|
|
10418
|
-
var import_rxjs2 = __toESM(require_cjs(), 1);
|
|
10419
|
-
var import_operators2 = __toESM(require_operators(), 1);
|
|
10420
|
-
import { burstBuffer as burstBuffer2, errField as errField2 } from "@semiont/core";
|
|
10421
|
-
import { resourceId as makeResourceId2, annotationId as makeAnnotationId2 } from "@semiont/core";
|
|
10422
|
-
import { chunkText, DEFAULT_CHUNKING_CONFIG } from "@semiont/vectors";
|
|
10423
|
-
import { getExactText, getTargetSelector } from "@semiont/api-client";
|
|
10424
|
-
var Smelter = class _Smelter {
|
|
10425
|
-
constructor(_eventStore, eventBus, vectorStore, embeddingProvider, contentStore, embeddingStore, viewStorage, logger, chunkingConfig) {
|
|
10426
|
-
this.eventBus = eventBus;
|
|
10427
|
-
this.vectorStore = vectorStore;
|
|
10428
|
-
this.embeddingProvider = embeddingProvider;
|
|
10429
|
-
this.contentStore = contentStore;
|
|
10430
|
-
this.embeddingStore = embeddingStore;
|
|
10431
|
-
this.viewStorage = viewStorage;
|
|
10432
|
-
this.logger = logger;
|
|
10433
|
-
this.chunkingConfig = chunkingConfig ?? DEFAULT_CHUNKING_CONFIG;
|
|
10434
|
-
}
|
|
10435
|
-
static SMELTER_RELEVANT_EVENTS = /* @__PURE__ */ new Set([
|
|
10436
|
-
"yield:created",
|
|
10437
|
-
"yield:updated",
|
|
10438
|
-
"yield:representation-added",
|
|
10439
|
-
"mark:archived",
|
|
10440
|
-
"mark:added",
|
|
10441
|
-
"mark:removed"
|
|
10442
|
-
]);
|
|
10443
|
-
static BURST_WINDOW_MS = 50;
|
|
10444
|
-
static MAX_BATCH_SIZE = 100;
|
|
10445
|
-
static IDLE_TIMEOUT_MS = 200;
|
|
10446
|
-
_globalSubscriptions = [];
|
|
10447
|
-
eventSubject = new import_rxjs2.Subject();
|
|
10448
|
-
pipelineSubscription = null;
|
|
10449
|
-
logger;
|
|
10450
|
-
chunkingConfig;
|
|
10451
|
-
async initialize() {
|
|
10452
|
-
this.logger.info("Smelter actor initializing");
|
|
10453
|
-
for (const eventType of _Smelter.SMELTER_RELEVANT_EVENTS) {
|
|
10454
|
-
this._globalSubscriptions.push(
|
|
10455
|
-
this.eventBus.getDomainEvent(eventType).subscribe(
|
|
10456
|
-
(storedEvent) => this.eventSubject.next(storedEvent)
|
|
10457
|
-
)
|
|
10458
|
-
);
|
|
10459
|
-
}
|
|
10460
|
-
this.pipelineSubscription = this.eventSubject.pipe(
|
|
10461
|
-
(0, import_operators2.groupBy)((se) => se.resourceId ?? "__unknown__"),
|
|
10462
|
-
(0, import_operators2.mergeMap)(
|
|
10463
|
-
(group) => group.pipe(
|
|
10464
|
-
burstBuffer2({
|
|
10465
|
-
burstWindowMs: _Smelter.BURST_WINDOW_MS,
|
|
10466
|
-
maxBatchSize: _Smelter.MAX_BATCH_SIZE,
|
|
10467
|
-
idleTimeoutMs: _Smelter.IDLE_TIMEOUT_MS
|
|
10468
|
-
}),
|
|
10469
|
-
(0, import_operators2.concatMap)((eventOrBatch) => {
|
|
10470
|
-
if (Array.isArray(eventOrBatch)) {
|
|
10471
|
-
return (0, import_rxjs2.from)(this.processBatch(eventOrBatch));
|
|
10472
|
-
}
|
|
10473
|
-
return (0, import_rxjs2.from)(this.safeProcessEvent(eventOrBatch));
|
|
10474
|
-
})
|
|
10475
|
-
)
|
|
10476
|
-
)
|
|
10477
|
-
).subscribe({
|
|
10478
|
-
error: (err) => this.logger.error("Smelter pipeline error", { error: err })
|
|
10479
|
-
});
|
|
10480
|
-
this.logger.info("Smelter actor initialized");
|
|
10481
|
-
}
|
|
10482
|
-
async stop() {
|
|
10483
|
-
for (const sub of this._globalSubscriptions) sub.unsubscribe();
|
|
10484
|
-
this._globalSubscriptions = [];
|
|
10485
|
-
this.pipelineSubscription?.unsubscribe();
|
|
10486
|
-
this.eventSubject.complete();
|
|
10487
|
-
this.logger.info("Smelter actor stopped");
|
|
10488
|
-
}
|
|
10489
|
-
/**
|
|
10490
|
-
* Rebuild the vector store from the EmbeddingStore (.semiont/embeddings/).
|
|
10491
|
-
*
|
|
10492
|
-
* For each stored file, checks whether the model matches the configured
|
|
10493
|
-
* provider. On mismatch, re-embeds from the stored text and overwrites the
|
|
10494
|
-
* file before upserting into Qdrant. On match, loads the stored vectors
|
|
10495
|
-
* directly — no embedding provider calls needed.
|
|
10496
|
-
*/
|
|
10497
|
-
async rebuildAll() {
|
|
10498
|
-
this.logger.info("Rebuilding vector store from EmbeddingStore");
|
|
10499
|
-
await this.vectorStore.clearAll();
|
|
10500
|
-
const currentModel = this.embeddingProvider.model();
|
|
10501
|
-
const currentDimensions = this.embeddingProvider.dimensions();
|
|
10502
|
-
const resourceIds = await this.embeddingStore.getAllResourceIds();
|
|
10503
|
-
this.logger.info("Found resource embedding files", { count: resourceIds.length });
|
|
10504
|
-
let resourcesIndexed = 0;
|
|
10505
|
-
for (const rid of resourceIds) {
|
|
10506
|
-
const resourceId7 = makeResourceId2(rid);
|
|
10507
|
-
const stored = await this.embeddingStore.readResourceEmbeddings(resourceId7);
|
|
10508
|
-
if (!stored || stored.chunks.length === 0) continue;
|
|
10509
|
-
let chunks;
|
|
10510
|
-
if (stored.model !== currentModel) {
|
|
10511
|
-
this.logger.info("Re-embedding resource (model mismatch)", {
|
|
10512
|
-
resourceId: rid,
|
|
10513
|
-
storedModel: stored.model,
|
|
10514
|
-
currentModel
|
|
10515
|
-
});
|
|
10516
|
-
const texts = stored.chunks.map((c) => c.text);
|
|
10517
|
-
const embeddings = await this.embeddingProvider.embedBatch(texts);
|
|
10518
|
-
chunks = stored.chunks.map((c, i) => ({
|
|
10519
|
-
chunkIndex: c.chunkIndex,
|
|
10520
|
-
text: c.text,
|
|
10521
|
-
embedding: embeddings[i]
|
|
10522
|
-
}));
|
|
10523
|
-
await this.embeddingStore.writeResourceChunks(resourceId7, currentModel, currentDimensions, chunks);
|
|
10524
|
-
} else {
|
|
10525
|
-
chunks = stored.chunks;
|
|
10526
|
-
}
|
|
10527
|
-
await this.vectorStore.upsertResourceVectors(resourceId7, chunks);
|
|
10528
|
-
resourcesIndexed++;
|
|
10529
|
-
}
|
|
10530
|
-
const annotationIds = await this.embeddingStore.getAllAnnotationIds();
|
|
10531
|
-
this.logger.info("Found annotation embedding files", { count: annotationIds.length });
|
|
10532
|
-
let annotationsIndexed = 0;
|
|
10533
|
-
for (const aid of annotationIds) {
|
|
10534
|
-
const annotationId3 = makeAnnotationId2(aid);
|
|
10535
|
-
const stored = await this.embeddingStore.readAnnotationEmbedding(annotationId3);
|
|
10536
|
-
if (!stored) continue;
|
|
10537
|
-
let embedding;
|
|
10538
|
-
if (stored.model !== currentModel) {
|
|
10539
|
-
this.logger.info("Re-embedding annotation (model mismatch)", {
|
|
10540
|
-
annotationId: aid,
|
|
10541
|
-
storedModel: stored.model,
|
|
10542
|
-
currentModel
|
|
10543
|
-
});
|
|
10544
|
-
embedding = await this.embeddingProvider.embed(stored.text);
|
|
10545
|
-
await this.embeddingStore.writeAnnotationEmbedding(
|
|
10546
|
-
annotationId3,
|
|
10547
|
-
makeResourceId2(stored.resourceId),
|
|
10548
|
-
currentModel,
|
|
10549
|
-
currentDimensions,
|
|
10550
|
-
stored.text,
|
|
10551
|
-
embedding,
|
|
10552
|
-
stored.motivation,
|
|
10553
|
-
stored.entityTypes
|
|
10554
|
-
);
|
|
10555
|
-
} else {
|
|
10556
|
-
embedding = stored.embedding;
|
|
10557
|
-
}
|
|
10558
|
-
const payload = {
|
|
10559
|
-
annotationId: annotationId3,
|
|
10560
|
-
resourceId: makeResourceId2(stored.resourceId),
|
|
10561
|
-
motivation: stored.motivation,
|
|
10562
|
-
entityTypes: stored.entityTypes,
|
|
10563
|
-
exactText: stored.text
|
|
10564
|
-
};
|
|
10565
|
-
await this.vectorStore.upsertAnnotationVector(annotationId3, embedding, payload);
|
|
10566
|
-
annotationsIndexed++;
|
|
10567
|
-
}
|
|
10568
|
-
const storedResourceIdSet = new Set(resourceIds);
|
|
10569
|
-
const allViews = await this.viewStorage.getAll();
|
|
10570
|
-
let backfilled = 0;
|
|
10571
|
-
for (const view of allViews) {
|
|
10572
|
-
const ridStr = view.resource["@id"];
|
|
10573
|
-
if (storedResourceIdSet.has(ridStr)) continue;
|
|
10574
|
-
if (view.resource.archived) continue;
|
|
10575
|
-
if (!view.resource.storageUri) continue;
|
|
10576
|
-
let content;
|
|
10577
|
-
try {
|
|
10578
|
-
content = await this.contentStore.retrieve(view.resource.storageUri);
|
|
10579
|
-
} catch (err) {
|
|
10580
|
-
this.logger.warn("Smelter back-fill skipped \u2014 content missing", {
|
|
10581
|
-
resourceId: ridStr,
|
|
10582
|
-
storageUri: view.resource.storageUri,
|
|
10583
|
-
error: err instanceof Error ? err.message : String(err)
|
|
10584
|
-
});
|
|
10585
|
-
continue;
|
|
10586
|
-
}
|
|
10587
|
-
const text = new TextDecoder().decode(content);
|
|
10588
|
-
if (!text.trim()) continue;
|
|
10589
|
-
const chunks = chunkText(text, this.chunkingConfig);
|
|
10590
|
-
if (chunks.length === 0) continue;
|
|
10591
|
-
const rid = makeResourceId2(ridStr);
|
|
10592
|
-
const embeddings = await this.embeddingProvider.embedBatch(chunks);
|
|
10593
|
-
const embeddingChunks = chunks.map((chunkText2, i) => ({
|
|
10594
|
-
chunkIndex: i,
|
|
10595
|
-
text: chunkText2,
|
|
10596
|
-
embedding: embeddings[i]
|
|
10597
|
-
}));
|
|
10598
|
-
await this.embeddingStore.writeResourceChunks(rid, currentModel, currentDimensions, embeddingChunks);
|
|
10599
|
-
await this.vectorStore.upsertResourceVectors(rid, embeddingChunks);
|
|
10600
|
-
backfilled++;
|
|
10601
|
-
resourcesIndexed++;
|
|
10602
|
-
this.logger.info("Smelter back-filled missing resource embedding", { resourceId: ridStr });
|
|
10603
|
-
}
|
|
10604
|
-
this.logger.info("Vector store rebuild complete", { resourcesIndexed, annotationsIndexed, backfilled });
|
|
10605
|
-
}
|
|
10606
|
-
async processBatch(events) {
|
|
10607
|
-
const runs = partitionByType(events);
|
|
10608
|
-
for (const run of runs) {
|
|
10609
|
-
try {
|
|
10610
|
-
if (run.length === 1) {
|
|
10611
|
-
await this.safeProcessEvent(run[0]);
|
|
10612
|
-
} else {
|
|
10613
|
-
await this.applyBatchByType(run);
|
|
10614
|
-
}
|
|
10615
|
-
} catch (error) {
|
|
10616
|
-
this.logger.error("Smelter failed to process batch run", {
|
|
10617
|
-
eventType: run[0].type,
|
|
10618
|
-
runSize: run.length,
|
|
10619
|
-
error: errField2(error)
|
|
10620
|
-
});
|
|
10621
|
-
}
|
|
10622
|
-
}
|
|
10623
|
-
}
|
|
10624
|
-
/**
|
|
10625
|
-
* Batch-optimized processing for consecutive events of the same type.
|
|
10626
|
-
*/
|
|
10627
|
-
async applyBatchByType(events) {
|
|
10628
|
-
const type = events[0].type;
|
|
10629
|
-
switch (type) {
|
|
10630
|
-
case "yield:created":
|
|
10631
|
-
await this.batchResourceCreated(events);
|
|
10632
|
-
break;
|
|
10633
|
-
case "mark:added":
|
|
10634
|
-
await this.batchAnnotationAdded(events);
|
|
10635
|
-
break;
|
|
10636
|
-
default:
|
|
10637
|
-
for (const event of events) {
|
|
10638
|
-
await this.safeProcessEvent(event);
|
|
10639
|
-
}
|
|
10640
|
-
}
|
|
10641
|
-
}
|
|
10642
|
-
/**
|
|
10643
|
-
* Batch-embed chunks from multiple yield:created events in a single
|
|
10644
|
-
* embedBatch() call, then write to EmbeddingStore and index per resource.
|
|
10645
|
-
*/
|
|
10646
|
-
async batchResourceCreated(events) {
|
|
10647
|
-
const resourceData = [];
|
|
10648
|
-
const allChunks = [];
|
|
10649
|
-
for (const storedEvent of events) {
|
|
10650
|
-
const event = storedEvent;
|
|
10651
|
-
const rid = makeResourceId2(event.resourceId);
|
|
10652
|
-
const storageUri = event.payload.storageUri;
|
|
10653
|
-
if (!storageUri) continue;
|
|
10654
|
-
const content = await this.contentStore.retrieve(storageUri);
|
|
10655
|
-
if (!content) continue;
|
|
10656
|
-
const text = new TextDecoder().decode(content);
|
|
10657
|
-
if (!text.trim()) continue;
|
|
10658
|
-
const chunks = chunkText(text, this.chunkingConfig);
|
|
10659
|
-
if (chunks.length === 0) continue;
|
|
10660
|
-
resourceData.push({ rid, chunks });
|
|
10661
|
-
allChunks.push(...chunks);
|
|
10662
|
-
}
|
|
10663
|
-
if (allChunks.length === 0) return;
|
|
10664
|
-
const allEmbeddings = await this.embeddingProvider.embedBatch(allChunks);
|
|
10665
|
-
const model = this.embeddingProvider.model();
|
|
10666
|
-
const dimensions = this.embeddingProvider.dimensions();
|
|
10667
|
-
let offset = 0;
|
|
10668
|
-
for (const { rid, chunks } of resourceData) {
|
|
10669
|
-
const embeddingChunks = chunks.map((text, i) => ({
|
|
10670
|
-
chunkIndex: i,
|
|
10671
|
-
text,
|
|
10672
|
-
embedding: allEmbeddings[offset + i]
|
|
10673
|
-
}));
|
|
10674
|
-
await this.embeddingStore.writeResourceChunks(rid, model, dimensions, embeddingChunks);
|
|
10675
|
-
await this.vectorStore.upsertResourceVectors(rid, embeddingChunks);
|
|
10676
|
-
this.logger.debug("Smelter batch-indexed resource", {
|
|
10677
|
-
resourceId: String(rid),
|
|
10678
|
-
chunks: embeddingChunks.length
|
|
10679
|
-
});
|
|
10680
|
-
offset += chunks.length;
|
|
10681
|
-
}
|
|
10682
|
-
}
|
|
10683
|
-
/**
|
|
10684
|
-
* Batch-embed exact texts from multiple mark:added events in a single
|
|
10685
|
-
* embedBatch() call, then write to EmbeddingStore and index per annotation.
|
|
10686
|
-
*/
|
|
10687
|
-
async batchAnnotationAdded(events) {
|
|
10688
|
-
const annotationData = [];
|
|
10689
|
-
for (const storedEvent of events) {
|
|
10690
|
-
const event = storedEvent;
|
|
10691
|
-
const annotation = event.payload.annotation;
|
|
10692
|
-
if (!annotation?.id) continue;
|
|
10693
|
-
const selector = getTargetSelector(annotation.target);
|
|
10694
|
-
const exactText = getExactText(selector);
|
|
10695
|
-
if (!exactText?.trim()) continue;
|
|
10696
|
-
annotationData.push({
|
|
10697
|
-
rid: makeResourceId2(event.resourceId),
|
|
10698
|
-
aid: makeAnnotationId2(annotation.id),
|
|
10699
|
-
exactText,
|
|
10700
|
-
motivation: annotation.motivation ?? "",
|
|
10701
|
-
entityTypes: annotation.entityTypes ?? []
|
|
10702
|
-
});
|
|
10703
|
-
}
|
|
10704
|
-
if (annotationData.length === 0) return;
|
|
10705
|
-
const allEmbeddings = await this.embeddingProvider.embedBatch(
|
|
10706
|
-
annotationData.map((a) => a.exactText)
|
|
10707
|
-
);
|
|
10708
|
-
const model = this.embeddingProvider.model();
|
|
10709
|
-
const dimensions = this.embeddingProvider.dimensions();
|
|
10710
|
-
for (let i = 0; i < annotationData.length; i++) {
|
|
10711
|
-
const { rid, aid, exactText, motivation, entityTypes } = annotationData[i];
|
|
10712
|
-
const embedding = allEmbeddings[i];
|
|
10713
|
-
await this.embeddingStore.writeAnnotationEmbedding(
|
|
10714
|
-
aid,
|
|
10715
|
-
rid,
|
|
10716
|
-
model,
|
|
10717
|
-
dimensions,
|
|
10718
|
-
exactText,
|
|
10719
|
-
embedding,
|
|
10720
|
-
motivation,
|
|
10721
|
-
entityTypes
|
|
10722
|
-
);
|
|
10723
|
-
const payload = {
|
|
10724
|
-
annotationId: aid,
|
|
10725
|
-
resourceId: rid,
|
|
10726
|
-
motivation,
|
|
10727
|
-
entityTypes,
|
|
10728
|
-
exactText
|
|
10729
|
-
};
|
|
10730
|
-
await this.vectorStore.upsertAnnotationVector(aid, embedding, payload);
|
|
10731
|
-
this.logger.debug("Smelter batch-indexed annotation", {
|
|
10732
|
-
annotationId: String(aid),
|
|
10733
|
-
resourceId: String(rid)
|
|
10734
|
-
});
|
|
10735
|
-
}
|
|
10736
|
-
}
|
|
10737
|
-
async safeProcessEvent(storedEvent) {
|
|
10738
|
-
try {
|
|
10739
|
-
await this.processEvent(storedEvent);
|
|
10740
|
-
} catch (err) {
|
|
10741
|
-
this.logger.error("Smelter failed to process event", {
|
|
10742
|
-
type: storedEvent.type,
|
|
10743
|
-
resourceId: storedEvent.resourceId,
|
|
10744
|
-
error: err instanceof Error ? err.message : String(err),
|
|
10745
|
-
stack: err instanceof Error ? err.stack : void 0
|
|
10746
|
-
});
|
|
10747
|
-
}
|
|
10748
|
-
}
|
|
10749
|
-
async processEvent(storedEvent) {
|
|
10750
|
-
switch (storedEvent.type) {
|
|
10751
|
-
case "yield:created":
|
|
10752
|
-
await this.handleResourceCreated(storedEvent);
|
|
10753
|
-
break;
|
|
10754
|
-
case "yield:updated":
|
|
10755
|
-
await this.handleResourceUpdated(storedEvent);
|
|
10756
|
-
break;
|
|
10757
|
-
case "yield:representation-added":
|
|
10758
|
-
await this.handleRepresentationAdded(storedEvent);
|
|
10759
|
-
break;
|
|
10760
|
-
case "mark:archived":
|
|
10761
|
-
await this.handleResourceArchived(storedEvent);
|
|
10762
|
-
break;
|
|
10763
|
-
case "mark:added":
|
|
10764
|
-
await this.handleAnnotationAdded(storedEvent);
|
|
10765
|
-
break;
|
|
10766
|
-
case "mark:removed":
|
|
10767
|
-
await this.handleAnnotationRemoved(storedEvent);
|
|
10768
|
-
break;
|
|
10769
|
-
}
|
|
10770
|
-
}
|
|
10771
|
-
async handleResourceCreated(event) {
|
|
10772
|
-
await new Promise((resolve2) => setTimeout(resolve2, 0));
|
|
10773
|
-
const rid = makeResourceId2(event.resourceId);
|
|
10774
|
-
const storageUri = event.payload.storageUri;
|
|
10775
|
-
if (!storageUri) return;
|
|
10776
|
-
this.logger.info("Smelter handleResourceCreated start", {
|
|
10777
|
-
resourceId: String(rid),
|
|
10778
|
-
storageUri,
|
|
10779
|
-
heapMB: Math.round(process.memoryUsage().heapUsed / 1024 / 1024)
|
|
10780
|
-
});
|
|
10781
|
-
const content = await this.contentStore.retrieve(storageUri);
|
|
10782
|
-
if (!content) return;
|
|
10783
|
-
const text = new TextDecoder().decode(content);
|
|
10784
|
-
if (!text.trim()) return;
|
|
10785
|
-
const chunks = chunkText(text, this.chunkingConfig);
|
|
10786
|
-
if (chunks.length === 0) return;
|
|
10787
|
-
this.logger.info("Smelter chunked resource", {
|
|
10788
|
-
resourceId: String(rid),
|
|
10789
|
-
textBytes: text.length,
|
|
10790
|
-
chunkCount: chunks.length,
|
|
10791
|
-
heapMB: Math.round(process.memoryUsage().heapUsed / 1024 / 1024)
|
|
10792
|
-
});
|
|
10793
|
-
const embeddings = await this.embeddingProvider.embedBatch(chunks);
|
|
10794
|
-
const model = this.embeddingProvider.model();
|
|
10795
|
-
const dimensions = this.embeddingProvider.dimensions();
|
|
10796
|
-
this.logger.info("Smelter embedded resource", {
|
|
10797
|
-
resourceId: String(rid),
|
|
10798
|
-
chunkCount: chunks.length,
|
|
10799
|
-
dimensions,
|
|
10800
|
-
heapMB: Math.round(process.memoryUsage().heapUsed / 1024 / 1024)
|
|
10801
|
-
});
|
|
10802
|
-
const embeddingChunks = chunks.map((text2, i) => ({
|
|
10803
|
-
chunkIndex: i,
|
|
10804
|
-
text: text2,
|
|
10805
|
-
embedding: embeddings[i]
|
|
10806
|
-
}));
|
|
10807
|
-
await this.embeddingStore.writeResourceChunks(rid, model, dimensions, embeddingChunks);
|
|
10808
|
-
this.logger.info("Smelter wrote resource embeddings to store", {
|
|
10809
|
-
resourceId: String(rid),
|
|
10810
|
-
chunkCount: embeddingChunks.length,
|
|
10811
|
-
heapMB: Math.round(process.memoryUsage().heapUsed / 1024 / 1024)
|
|
10812
|
-
});
|
|
10813
|
-
await this.vectorStore.upsertResourceVectors(rid, embeddingChunks);
|
|
10814
|
-
this.logger.info("Smelter indexed resource", {
|
|
10815
|
-
resourceId: String(rid),
|
|
10816
|
-
chunks: embeddingChunks.length,
|
|
10817
|
-
heapMB: Math.round(process.memoryUsage().heapUsed / 1024 / 1024)
|
|
10818
|
-
});
|
|
10819
|
-
}
|
|
10820
|
-
/**
|
|
10821
|
-
* Re-embed a resource whose content has changed in-place.
|
|
10822
|
-
*
|
|
10823
|
-
* Used by yield:updated and yield:representation-added handlers. Reads the
|
|
10824
|
-
* current storageUri from the materialized view (which is updated before the
|
|
10825
|
-
* EventBus fires), deletes stale Qdrant vectors, and overwrites the
|
|
10826
|
-
* EmbeddingStore file with fresh chunks.
|
|
10827
|
-
*/
|
|
10828
|
-
async reembedResource(rid) {
|
|
10829
|
-
const view = await this.viewStorage.get(rid);
|
|
10830
|
-
const storageUri = view?.resource.storageUri;
|
|
10831
|
-
if (!storageUri) return;
|
|
10832
|
-
const content = await this.contentStore.retrieve(storageUri);
|
|
10833
|
-
if (!content) return;
|
|
10834
|
-
const text = new TextDecoder().decode(content);
|
|
10835
|
-
if (!text.trim()) return;
|
|
10836
|
-
const chunks = chunkText(text, this.chunkingConfig);
|
|
10837
|
-
if (chunks.length === 0) return;
|
|
10838
|
-
const embeddings = await this.embeddingProvider.embedBatch(chunks);
|
|
10839
|
-
const model = this.embeddingProvider.model();
|
|
10840
|
-
const dimensions = this.embeddingProvider.dimensions();
|
|
10841
|
-
const embeddingChunks = chunks.map((chunkText2, i) => ({
|
|
10842
|
-
chunkIndex: i,
|
|
10843
|
-
text: chunkText2,
|
|
10844
|
-
embedding: embeddings[i]
|
|
10845
|
-
}));
|
|
10846
|
-
await this.embeddingStore.writeResourceChunks(rid, model, dimensions, embeddingChunks);
|
|
10847
|
-
await this.vectorStore.deleteResourceVectors(rid);
|
|
10848
|
-
await this.vectorStore.upsertResourceVectors(rid, embeddingChunks);
|
|
10849
|
-
this.logger.debug("Smelter re-embedded resource", {
|
|
10850
|
-
resourceId: String(rid),
|
|
10851
|
-
chunks: embeddingChunks.length
|
|
10852
|
-
});
|
|
10853
|
-
}
|
|
10854
|
-
async handleResourceUpdated(event) {
|
|
10855
|
-
await this.reembedResource(makeResourceId2(event.resourceId));
|
|
10856
|
-
}
|
|
10857
|
-
async handleRepresentationAdded(event) {
|
|
10858
|
-
await this.reembedResource(makeResourceId2(event.resourceId));
|
|
10859
|
-
}
|
|
10860
|
-
async handleResourceArchived(event) {
|
|
10861
|
-
const rid = makeResourceId2(event.resourceId);
|
|
10862
|
-
await this.vectorStore.deleteResourceVectors(rid);
|
|
10863
|
-
await this.embeddingStore.deleteResourceEmbeddings(rid);
|
|
10864
|
-
this.logger.debug("Smelter deleted resource vectors", { resourceId: String(rid) });
|
|
10865
|
-
}
|
|
10866
|
-
async handleAnnotationAdded(event) {
|
|
10867
|
-
await new Promise((resolve2) => setTimeout(resolve2, 0));
|
|
10868
|
-
const annotation = event.payload.annotation;
|
|
10869
|
-
if (!annotation || !annotation.id) return;
|
|
10870
|
-
const rid = makeResourceId2(event.resourceId);
|
|
10871
|
-
const aid = makeAnnotationId2(annotation.id);
|
|
10872
|
-
const selector = getTargetSelector(annotation.target);
|
|
10873
|
-
const exactText = getExactText(selector);
|
|
10874
|
-
if (!exactText || !exactText.trim()) return;
|
|
10875
|
-
this.logger.info("Smelter handleAnnotationAdded start", {
|
|
10876
|
-
annotationId: String(aid),
|
|
10877
|
-
resourceId: String(rid),
|
|
10878
|
-
textLength: exactText.length,
|
|
10879
|
-
heapMB: Math.round(process.memoryUsage().heapUsed / 1024 / 1024)
|
|
10880
|
-
});
|
|
10881
|
-
const embedding = await this.embeddingProvider.embed(exactText);
|
|
10882
|
-
const model = this.embeddingProvider.model();
|
|
10883
|
-
const dimensions = this.embeddingProvider.dimensions();
|
|
10884
|
-
const motivation = annotation.motivation ?? "";
|
|
10885
|
-
const entityTypes = annotation.entityTypes ?? [];
|
|
10886
|
-
await this.embeddingStore.writeAnnotationEmbedding(
|
|
10887
|
-
aid,
|
|
10888
|
-
rid,
|
|
10889
|
-
model,
|
|
10890
|
-
dimensions,
|
|
10891
|
-
exactText,
|
|
10892
|
-
embedding,
|
|
10893
|
-
motivation,
|
|
10894
|
-
entityTypes
|
|
10895
|
-
);
|
|
10896
|
-
const payload = {
|
|
10897
|
-
annotationId: aid,
|
|
10898
|
-
resourceId: rid,
|
|
10899
|
-
motivation,
|
|
10900
|
-
entityTypes,
|
|
10901
|
-
exactText
|
|
10902
|
-
};
|
|
10903
|
-
await this.vectorStore.upsertAnnotationVector(aid, embedding, payload);
|
|
10904
|
-
this.logger.info("Smelter indexed annotation", {
|
|
10905
|
-
annotationId: String(aid),
|
|
10906
|
-
resourceId: String(rid)
|
|
10907
|
-
});
|
|
10908
|
-
}
|
|
10909
|
-
async handleAnnotationRemoved(event) {
|
|
10910
|
-
const annotationId3 = String(event.payload.annotationId);
|
|
10911
|
-
if (!annotationId3) return;
|
|
10912
|
-
const aid = makeAnnotationId2(annotationId3);
|
|
10913
|
-
await this.vectorStore.deleteAnnotationVector(aid);
|
|
10914
|
-
await this.embeddingStore.deleteAnnotationEmbedding(aid);
|
|
10915
|
-
this.logger.debug("Smelter deleted annotation vector", { annotationId: String(aid) });
|
|
10916
|
-
}
|
|
10917
|
-
};
|
|
10918
|
-
|
|
10919
|
-
// src/embedding-store.ts
|
|
10920
|
-
import { promises as fs } from "fs";
|
|
10921
|
-
import * as path from "path";
|
|
10922
|
-
import { getShardPath } from "@semiont/event-sourcing";
|
|
10923
|
-
var EmbeddingStore = class {
|
|
10924
|
-
constructor(project) {
|
|
10925
|
-
this.project = project;
|
|
10926
|
-
}
|
|
10927
|
-
// ── Path helpers ────────────────────────────────────────────────────────────
|
|
10928
|
-
resourceFilePath(resourceId7) {
|
|
10929
|
-
const [ab, cd] = getShardPath(String(resourceId7));
|
|
10930
|
-
return path.join(this.project.embeddingsDir, ab, cd, `${String(resourceId7)}.jsonl`);
|
|
10931
|
-
}
|
|
10932
|
-
annotationFilePath(annotationId3) {
|
|
10933
|
-
const [ab, cd] = getShardPath(String(annotationId3));
|
|
10934
|
-
return path.join(this.project.embeddingsDir, ab, cd, `${String(annotationId3)}.json`);
|
|
10935
|
-
}
|
|
10936
|
-
// ── Resource embeddings ─────────────────────────────────────────────────────
|
|
10937
|
-
async writeResourceChunks(resourceId7, model, dimensions, chunks) {
|
|
10938
|
-
const filePath = this.resourceFilePath(resourceId7);
|
|
10939
|
-
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
10940
|
-
const header = JSON.stringify({ model, dimensions });
|
|
10941
|
-
const lines = chunks.map(
|
|
10942
|
-
(c) => JSON.stringify({ chunkIndex: c.chunkIndex, text: c.text, embedding: c.embedding })
|
|
10943
|
-
);
|
|
10944
|
-
await fs.writeFile(filePath, [header, ...lines].join("\n") + "\n", "utf-8");
|
|
10945
|
-
}
|
|
10946
|
-
async readResourceEmbeddings(resourceId7) {
|
|
10947
|
-
const filePath = this.resourceFilePath(resourceId7);
|
|
10948
|
-
try {
|
|
10949
|
-
const content = await fs.readFile(filePath, "utf-8");
|
|
10950
|
-
const lines = content.trim().split("\n").filter((l) => l.trim());
|
|
10951
|
-
if (lines.length === 0) return null;
|
|
10952
|
-
const header = JSON.parse(lines[0]);
|
|
10953
|
-
const chunks = lines.slice(1).map((l) => JSON.parse(l));
|
|
10954
|
-
return { model: header.model, dimensions: header.dimensions, chunks };
|
|
10955
|
-
} catch (err) {
|
|
10956
|
-
if (err.code === "ENOENT") return null;
|
|
10957
|
-
throw err;
|
|
10958
|
-
}
|
|
10959
|
-
}
|
|
10960
|
-
async deleteResourceEmbeddings(resourceId7) {
|
|
10961
|
-
const filePath = this.resourceFilePath(resourceId7);
|
|
10962
|
-
try {
|
|
10963
|
-
await fs.unlink(filePath);
|
|
10964
|
-
} catch (err) {
|
|
10965
|
-
if (err.code !== "ENOENT") throw err;
|
|
10966
|
-
}
|
|
10967
|
-
}
|
|
10968
|
-
// ── Annotation embeddings ───────────────────────────────────────────────────
|
|
10969
|
-
async writeAnnotationEmbedding(annotationId3, resourceId7, model, dimensions, text, embedding, motivation, entityTypes) {
|
|
10970
|
-
const filePath = this.annotationFilePath(annotationId3);
|
|
10971
|
-
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
10972
|
-
const data = {
|
|
10973
|
-
model,
|
|
10974
|
-
dimensions,
|
|
10975
|
-
resourceId: String(resourceId7),
|
|
10976
|
-
text,
|
|
10977
|
-
embedding,
|
|
10978
|
-
motivation,
|
|
10979
|
-
entityTypes
|
|
10980
|
-
};
|
|
10981
|
-
await fs.writeFile(filePath, JSON.stringify(data), "utf-8");
|
|
10982
|
-
}
|
|
10983
|
-
async readAnnotationEmbedding(annotationId3) {
|
|
10984
|
-
const filePath = this.annotationFilePath(annotationId3);
|
|
10985
|
-
try {
|
|
10986
|
-
const content = await fs.readFile(filePath, "utf-8");
|
|
10987
|
-
return JSON.parse(content);
|
|
10988
|
-
} catch (err) {
|
|
10989
|
-
if (err.code === "ENOENT") return null;
|
|
10990
|
-
throw err;
|
|
10991
|
-
}
|
|
10992
|
-
}
|
|
10993
|
-
async deleteAnnotationEmbedding(annotationId3) {
|
|
10994
|
-
const filePath = this.annotationFilePath(annotationId3);
|
|
10995
|
-
try {
|
|
10996
|
-
await fs.unlink(filePath);
|
|
10997
|
-
} catch (err) {
|
|
10998
|
-
if (err.code !== "ENOENT") throw err;
|
|
10999
|
-
}
|
|
11000
|
-
}
|
|
11001
|
-
// ── Scan ────────────────────────────────────────────────────────────────────
|
|
11002
|
-
/**
|
|
11003
|
-
* Scan embeddings directory and return all resource IDs (from *.jsonl files).
|
|
11004
|
-
*/
|
|
11005
|
-
async getAllResourceIds() {
|
|
11006
|
-
return this.scanIds((name) => name.endsWith(".jsonl"), ".jsonl");
|
|
11007
|
-
}
|
|
11008
|
-
/**
|
|
11009
|
-
* Scan embeddings directory and return all annotation IDs (from *.json files).
|
|
11010
|
-
*/
|
|
11011
|
-
async getAllAnnotationIds() {
|
|
11012
|
-
return this.scanIds((name) => name.endsWith(".json"), ".json");
|
|
11013
|
-
}
|
|
11014
|
-
async scanIds(filter, ext) {
|
|
11015
|
-
const base = this.project.embeddingsDir;
|
|
11016
|
-
try {
|
|
11017
|
-
await fs.access(base);
|
|
11018
|
-
} catch {
|
|
11019
|
-
return [];
|
|
11020
|
-
}
|
|
11021
|
-
const results = [];
|
|
11022
|
-
const scan = async (dir) => {
|
|
11023
|
-
let entries;
|
|
11024
|
-
try {
|
|
11025
|
-
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
11026
|
-
} catch {
|
|
11027
|
-
return;
|
|
11028
|
-
}
|
|
11029
|
-
for (const entry of entries) {
|
|
11030
|
-
const full = path.join(dir, entry.name);
|
|
11031
|
-
if (entry.isDirectory()) {
|
|
11032
|
-
await scan(full);
|
|
11033
|
-
} else if (filter(entry.name)) {
|
|
11034
|
-
results.push(entry.name.slice(0, -ext.length));
|
|
11035
|
-
}
|
|
11036
|
-
}
|
|
11037
|
-
};
|
|
11038
|
-
await scan(base);
|
|
11039
|
-
return results;
|
|
11040
|
-
}
|
|
11041
|
-
};
|
|
11042
|
-
|
|
11043
10388
|
// src/knowledge-base.ts
|
|
11044
10389
|
async function createKnowledgeBase(eventStore, project, graphDb, eventBus, logger, options) {
|
|
11045
|
-
const views = new FilesystemViewStorage(project);
|
|
10390
|
+
const views = new FilesystemViewStorage(project, logger.child({ component: "view-storage" }));
|
|
11046
10391
|
const content = new WorkingTreeStore(
|
|
11047
10392
|
project,
|
|
11048
10393
|
logger.child({ component: "working-tree-store" })
|
|
@@ -11066,32 +10411,17 @@ async function createKnowledgeBase(eventStore, project, graphDb, eventBus, logge
|
|
|
11066
10411
|
graphConsumer,
|
|
11067
10412
|
projectionsDir: project.projectionsDir
|
|
11068
10413
|
};
|
|
11069
|
-
if (options?.vectorStore
|
|
10414
|
+
if (options?.vectorStore) {
|
|
11070
10415
|
kb.vectors = options.vectorStore;
|
|
11071
|
-
const embeddingStore = new EmbeddingStore(project);
|
|
11072
|
-
kb.smelter = new Smelter(
|
|
11073
|
-
eventStore,
|
|
11074
|
-
eventBus,
|
|
11075
|
-
options.vectorStore,
|
|
11076
|
-
options.embeddingProvider,
|
|
11077
|
-
content,
|
|
11078
|
-
embeddingStore,
|
|
11079
|
-
views,
|
|
11080
|
-
logger.child({ component: "smelter" }),
|
|
11081
|
-
options.chunkingConfig
|
|
11082
|
-
);
|
|
11083
|
-
await kb.smelter.initialize();
|
|
11084
|
-
if (!options.skipRebuild) {
|
|
11085
|
-
await kb.smelter.rebuildAll();
|
|
11086
|
-
}
|
|
11087
10416
|
}
|
|
11088
10417
|
return kb;
|
|
11089
10418
|
}
|
|
11090
10419
|
|
|
11091
10420
|
// src/gatherer.ts
|
|
11092
|
-
var
|
|
11093
|
-
var
|
|
11094
|
-
import { annotationId as
|
|
10421
|
+
var import_rxjs2 = __toESM(require_cjs(), 1);
|
|
10422
|
+
var import_operators2 = __toESM(require_operators(), 1);
|
|
10423
|
+
import { annotationId as makeAnnotationId2, resourceId, errField as errField2 } from "@semiont/core";
|
|
10424
|
+
import { withActorSpan } from "@semiont/observability";
|
|
11095
10425
|
|
|
11096
10426
|
// src/generation/resource-generation.ts
|
|
11097
10427
|
async function generateResourceSummary(resourceName, content, entityTypes, client) {
|
|
@@ -11103,10 +10433,10 @@ Resource content:
|
|
|
11103
10433
|
${truncatedContent}
|
|
11104
10434
|
|
|
11105
10435
|
Write a 2-3 sentence summary that captures the key points and would help someone understand what this resource contains.`;
|
|
11106
|
-
return
|
|
10436
|
+
return client.generateText(prompt, 150, 0.5);
|
|
11107
10437
|
}
|
|
11108
|
-
async function generateReferenceSuggestions(referenceTitle, client,
|
|
11109
|
-
const prompt = `For a reference titled "${referenceTitle}"${
|
|
10438
|
+
async function generateReferenceSuggestions(referenceTitle, client, entityType2, currentContent) {
|
|
10439
|
+
const prompt = `For a reference titled "${referenceTitle}"${entityType2 ? ` (type: ${entityType2})` : ""}${currentContent ? ` with current stub: "${currentContent}"` : ""}, suggest 3 specific, actionable next steps or related topics to explore.
|
|
11110
10440
|
|
|
11111
10441
|
Format as a simple list, one suggestion per line.`;
|
|
11112
10442
|
const response = await client.generateText(prompt, 200, 0.8);
|
|
@@ -11117,27 +10447,18 @@ Format as a simple list, one suggestion per line.`;
|
|
|
11117
10447
|
}
|
|
11118
10448
|
|
|
11119
10449
|
// src/annotation-context.ts
|
|
11120
|
-
import {
|
|
11121
|
-
getBodySource,
|
|
11122
|
-
getResourceId,
|
|
11123
|
-
getTargetSource,
|
|
11124
|
-
getTargetSelector as getTargetSelector2,
|
|
11125
|
-
getResourceEntityTypes,
|
|
11126
|
-
getTextPositionSelector,
|
|
11127
|
-
getPrimaryRepresentation as getPrimaryRepresentation2,
|
|
11128
|
-
decodeRepresentation as decodeRepresentation2
|
|
11129
|
-
} from "@semiont/api-client";
|
|
10450
|
+
import { getBodySource, getResourceId, getTargetSource, getTargetSelector, getResourceEntityTypes, getTextPositionSelector, getPrimaryRepresentation as getPrimaryRepresentation2, decodeRepresentation as decodeRepresentation2 } from "@semiont/core";
|
|
11130
10451
|
import { resourceId as createResourceId } from "@semiont/core";
|
|
11131
10452
|
import { getEntityTypes } from "@semiont/ontology";
|
|
11132
10453
|
|
|
11133
10454
|
// src/resource-context.ts
|
|
11134
|
-
import { getPrimaryRepresentation, decodeRepresentation } from "@semiont/
|
|
10455
|
+
import { getPrimaryRepresentation, decodeRepresentation } from "@semiont/core";
|
|
11135
10456
|
var ResourceContext = class _ResourceContext {
|
|
11136
10457
|
/**
|
|
11137
10458
|
* Get resource metadata from view storage
|
|
11138
10459
|
*/
|
|
11139
|
-
static async getResourceMetadata(
|
|
11140
|
-
const view = await kb.views.get(
|
|
10460
|
+
static async getResourceMetadata(resourceId10, kb) {
|
|
10461
|
+
const view = await kb.views.get(resourceId10);
|
|
11141
10462
|
if (!view) {
|
|
11142
10463
|
return null;
|
|
11143
10464
|
}
|
|
@@ -11182,7 +10503,7 @@ var ResourceContext = class _ResourceContext {
|
|
|
11182
10503
|
* Retrieves and decodes the first 200 characters of each resource's primary representation
|
|
11183
10504
|
*/
|
|
11184
10505
|
static async addContentPreviews(resources, kb) {
|
|
11185
|
-
return
|
|
10506
|
+
return Promise.all(
|
|
11186
10507
|
resources.map(async (doc) => {
|
|
11187
10508
|
try {
|
|
11188
10509
|
if (doc.storageUri) {
|
|
@@ -11225,7 +10546,7 @@ var AnnotationContext = class {
|
|
|
11225
10546
|
* @returns Rich context for LLM processing
|
|
11226
10547
|
* @throws Error if annotation or resource not found
|
|
11227
10548
|
*/
|
|
11228
|
-
static async buildLLMContext(
|
|
10549
|
+
static async buildLLMContext(annotationId5, resourceId10, kb, options = {}, inferenceClient, logger, embeddingProvider) {
|
|
11229
10550
|
const {
|
|
11230
10551
|
includeSourceContext = true,
|
|
11231
10552
|
includeTargetContext = true,
|
|
@@ -11234,34 +10555,34 @@ var AnnotationContext = class {
|
|
|
11234
10555
|
if (contextWindow < 100 || contextWindow > 5e3) {
|
|
11235
10556
|
throw new Error("contextWindow must be between 100 and 5000");
|
|
11236
10557
|
}
|
|
11237
|
-
logger?.debug("Building LLM context", { annotationId:
|
|
11238
|
-
logger?.debug("Getting view for resource", { resourceId:
|
|
10558
|
+
logger?.debug("Building LLM context", { annotationId: annotationId5, resourceId: resourceId10 });
|
|
10559
|
+
logger?.debug("Getting view for resource", { resourceId: resourceId10 });
|
|
11239
10560
|
let sourceView;
|
|
11240
10561
|
try {
|
|
11241
|
-
sourceView = await kb.views.get(
|
|
10562
|
+
sourceView = await kb.views.get(resourceId10);
|
|
11242
10563
|
logger?.debug("Retrieved view", { hasView: !!sourceView });
|
|
11243
10564
|
if (!sourceView) {
|
|
11244
10565
|
throw new Error("Source resource not found");
|
|
11245
10566
|
}
|
|
11246
10567
|
} catch (error) {
|
|
11247
|
-
logger?.error("Error getting view", { resourceId:
|
|
10568
|
+
logger?.error("Error getting view", { resourceId: resourceId10, error });
|
|
11248
10569
|
throw error;
|
|
11249
10570
|
}
|
|
11250
10571
|
logger?.debug("Looking for annotation in resource", {
|
|
11251
|
-
annotationId:
|
|
11252
|
-
resourceId:
|
|
10572
|
+
annotationId: annotationId5,
|
|
10573
|
+
resourceId: resourceId10,
|
|
11253
10574
|
totalAnnotations: sourceView.annotations.annotations.length,
|
|
11254
10575
|
firstFiveIds: sourceView.annotations.annotations.slice(0, 5).map((a) => a.id)
|
|
11255
10576
|
});
|
|
11256
|
-
const annotation = sourceView.annotations.annotations.find((a) => a.id ===
|
|
10577
|
+
const annotation = sourceView.annotations.annotations.find((a) => a.id === annotationId5);
|
|
11257
10578
|
logger?.debug("Annotation search result", { found: !!annotation });
|
|
11258
10579
|
if (!annotation) {
|
|
11259
10580
|
throw new Error("Annotation not found in view");
|
|
11260
10581
|
}
|
|
11261
10582
|
const targetSource = getTargetSource(annotation.target);
|
|
11262
|
-
logger?.debug("Validating target resource", { targetSource, expectedResourceId:
|
|
11263
|
-
if (targetSource !== String(
|
|
11264
|
-
throw new Error(`Annotation target resource ID (${targetSource}) does not match expected resource ID (${
|
|
10583
|
+
logger?.debug("Validating target resource", { targetSource, expectedResourceId: resourceId10 });
|
|
10584
|
+
if (targetSource !== String(resourceId10)) {
|
|
10585
|
+
throw new Error(`Annotation target resource ID (${targetSource}) does not match expected resource ID (${resourceId10})`);
|
|
11265
10586
|
}
|
|
11266
10587
|
const sourceDoc = sourceView.resource;
|
|
11267
10588
|
const bodySource = getBodySource(annotation.body);
|
|
@@ -11279,7 +10600,7 @@ var AnnotationContext = class {
|
|
|
11279
10600
|
const primaryRep = getPrimaryRepresentation2(sourceDoc);
|
|
11280
10601
|
const sourceContent = await kb.content.retrieve(sourceDoc.storageUri);
|
|
11281
10602
|
const contentStr = decodeRepresentation2(sourceContent, primaryRep?.mediaType ?? "text/plain");
|
|
11282
|
-
const targetSelectorRaw =
|
|
10603
|
+
const targetSelectorRaw = getTargetSelector(annotation.target);
|
|
11283
10604
|
const targetSelector = Array.isArray(targetSelectorRaw) ? targetSelectorRaw[0] : targetSelectorRaw;
|
|
11284
10605
|
logger?.debug("Target selector", { type: targetSelector?.type });
|
|
11285
10606
|
if (!targetSelector) {
|
|
@@ -11325,16 +10646,16 @@ var AnnotationContext = class {
|
|
|
11325
10646
|
}
|
|
11326
10647
|
}
|
|
11327
10648
|
const suggestedResolution = void 0;
|
|
11328
|
-
logger?.debug("Building graph context", { resourceId:
|
|
10649
|
+
logger?.debug("Building graph context", { resourceId: resourceId10 });
|
|
11329
10650
|
const [connections, referencedByAnnotations, entityTypeStats] = await Promise.all([
|
|
11330
|
-
kb.graph.getResourceConnections(
|
|
11331
|
-
kb.graph.getResourceReferencedBy(
|
|
10651
|
+
kb.graph.getResourceConnections(resourceId10),
|
|
10652
|
+
kb.graph.getResourceReferencedBy(resourceId10),
|
|
11332
10653
|
kb.graph.getEntityTypeStats()
|
|
11333
10654
|
]);
|
|
11334
10655
|
const citedByMap = /* @__PURE__ */ new Map();
|
|
11335
10656
|
for (const ann of referencedByAnnotations) {
|
|
11336
10657
|
const source = getTargetSource(ann.target);
|
|
11337
|
-
if (source && source !== String(
|
|
10658
|
+
if (source && source !== String(resourceId10)) {
|
|
11338
10659
|
const sourceResId = createResourceId(source);
|
|
11339
10660
|
const sourceView2 = await kb.views.get(sourceResId);
|
|
11340
10661
|
if (sourceView2?.resource) {
|
|
@@ -11345,7 +10666,7 @@ var AnnotationContext = class {
|
|
|
11345
10666
|
const annotationEntityTypes = getEntityTypes(annotation);
|
|
11346
10667
|
const siblingEntityTypes = /* @__PURE__ */ new Set();
|
|
11347
10668
|
for (const ann of sourceView.annotations.annotations) {
|
|
11348
|
-
if (ann.id !==
|
|
10669
|
+
if (ann.id !== annotationId5) {
|
|
11349
10670
|
for (const et of getEntityTypes(ann)) {
|
|
11350
10671
|
siblingEntityTypes.add(et);
|
|
11351
10672
|
}
|
|
@@ -11406,7 +10727,7 @@ Summary:`;
|
|
|
11406
10727
|
const results = await kb.vectors.searchAnnotations(focalEmbedding, {
|
|
11407
10728
|
limit: 10,
|
|
11408
10729
|
scoreThreshold: 0.5,
|
|
11409
|
-
filter: { excludeResourceId:
|
|
10730
|
+
filter: { excludeResourceId: resourceId10 }
|
|
11410
10731
|
});
|
|
11411
10732
|
if (results.length > 0) {
|
|
11412
10733
|
semanticContext = {
|
|
@@ -11458,10 +10779,10 @@ Summary:`;
|
|
|
11458
10779
|
* Get resource annotations from view storage (fast path)
|
|
11459
10780
|
* Throws if view missing
|
|
11460
10781
|
*/
|
|
11461
|
-
static async getResourceAnnotations(
|
|
11462
|
-
const view = await kb.views.get(
|
|
10782
|
+
static async getResourceAnnotations(resourceId10, kb) {
|
|
10783
|
+
const view = await kb.views.get(resourceId10);
|
|
11463
10784
|
if (!view) {
|
|
11464
|
-
throw new Error(`Resource ${
|
|
10785
|
+
throw new Error(`Resource ${resourceId10} not found in view storage`);
|
|
11465
10786
|
}
|
|
11466
10787
|
return view.annotations;
|
|
11467
10788
|
}
|
|
@@ -11469,9 +10790,9 @@ Summary:`;
|
|
|
11469
10790
|
* Get all annotations
|
|
11470
10791
|
* @returns Array of all annotation objects
|
|
11471
10792
|
*/
|
|
11472
|
-
static async getAllAnnotations(
|
|
11473
|
-
const annotations = await this.getResourceAnnotations(
|
|
11474
|
-
return
|
|
10793
|
+
static async getAllAnnotations(resourceId10, kb) {
|
|
10794
|
+
const annotations = await this.getResourceAnnotations(resourceId10, kb);
|
|
10795
|
+
return this.enrichResolvedReferences(annotations.annotations, kb);
|
|
11475
10796
|
}
|
|
11476
10797
|
/**
|
|
11477
10798
|
* Enrich reference annotations with resolved document names
|
|
@@ -11539,8 +10860,8 @@ Summary:`;
|
|
|
11539
10860
|
* Get resource stats (version info)
|
|
11540
10861
|
* @returns Version and timestamp info for the annotations
|
|
11541
10862
|
*/
|
|
11542
|
-
static async getResourceStats(
|
|
11543
|
-
const annotations = await this.getResourceAnnotations(
|
|
10863
|
+
static async getResourceStats(resourceId10, kb) {
|
|
10864
|
+
const annotations = await this.getResourceAnnotations(resourceId10, kb);
|
|
11544
10865
|
return {
|
|
11545
10866
|
resourceId: annotations.resourceId,
|
|
11546
10867
|
version: annotations.version,
|
|
@@ -11550,16 +10871,16 @@ Summary:`;
|
|
|
11550
10871
|
/**
|
|
11551
10872
|
* Check if resource exists in view storage
|
|
11552
10873
|
*/
|
|
11553
|
-
static async resourceExists(
|
|
11554
|
-
return
|
|
10874
|
+
static async resourceExists(resourceId10, kb) {
|
|
10875
|
+
return kb.views.exists(resourceId10);
|
|
11555
10876
|
}
|
|
11556
10877
|
/**
|
|
11557
10878
|
* Get a single annotation by ID
|
|
11558
10879
|
* O(1) lookup using resource ID to access view storage
|
|
11559
10880
|
*/
|
|
11560
|
-
static async getAnnotation(
|
|
11561
|
-
const annotations = await this.getResourceAnnotations(
|
|
11562
|
-
return annotations.annotations.find((a) => a.id ===
|
|
10881
|
+
static async getAnnotation(annotationId5, resourceId10, kb) {
|
|
10882
|
+
const annotations = await this.getResourceAnnotations(resourceId10, kb);
|
|
10883
|
+
return annotations.annotations.find((a) => a.id === annotationId5) || null;
|
|
11563
10884
|
}
|
|
11564
10885
|
/**
|
|
11565
10886
|
* List annotations with optional filtering
|
|
@@ -11570,13 +10891,13 @@ Summary:`;
|
|
|
11570
10891
|
if (!filters?.resourceId) {
|
|
11571
10892
|
throw new Error("resourceId is required for annotation listing - cross-resource queries not supported in view storage");
|
|
11572
10893
|
}
|
|
11573
|
-
return
|
|
10894
|
+
return this.getAllAnnotations(filters.resourceId, kb);
|
|
11574
10895
|
}
|
|
11575
10896
|
/**
|
|
11576
10897
|
* Get annotation context (selected text with surrounding context)
|
|
11577
10898
|
*/
|
|
11578
|
-
static async getAnnotationContext(
|
|
11579
|
-
const annotation = await this.getAnnotation(
|
|
10899
|
+
static async getAnnotationContext(annotationId5, resourceId10, contextBefore, contextAfter, kb) {
|
|
10900
|
+
const annotation = await this.getAnnotation(annotationId5, resourceId10, kb);
|
|
11580
10901
|
if (!annotation) {
|
|
11581
10902
|
throw new Error("Annotation not found");
|
|
11582
10903
|
}
|
|
@@ -11608,8 +10929,8 @@ Summary:`;
|
|
|
11608
10929
|
/**
|
|
11609
10930
|
* Generate AI summary of annotation in context
|
|
11610
10931
|
*/
|
|
11611
|
-
static async generateAnnotationSummary(
|
|
11612
|
-
const annotation = await this.getAnnotation(
|
|
10932
|
+
static async generateAnnotationSummary(annotationId5, resourceId10, kb, inferenceClient) {
|
|
10933
|
+
const annotation = await this.getAnnotation(annotationId5, resourceId10, kb);
|
|
11613
10934
|
if (!annotation) {
|
|
11614
10935
|
throw new Error("Annotation not found");
|
|
11615
10936
|
}
|
|
@@ -11656,7 +10977,7 @@ Summary:`;
|
|
|
11656
10977
|
* Extract annotation context from resource content
|
|
11657
10978
|
*/
|
|
11658
10979
|
static extractAnnotationContext(annotation, contentStr, contextBefore, contextAfter) {
|
|
11659
|
-
const targetSelector =
|
|
10980
|
+
const targetSelector = getTargetSelector(annotation.target);
|
|
11660
10981
|
const posSelector = targetSelector ? getTextPositionSelector(targetSelector) : null;
|
|
11661
10982
|
if (!posSelector) {
|
|
11662
10983
|
throw new Error("TextPositionSelector required for context");
|
|
@@ -11684,51 +11005,51 @@ Context after: "${context.after.substring(0, 200)}"
|
|
|
11684
11005
|
|
|
11685
11006
|
Resource: ${resource.name}
|
|
11686
11007
|
Entity types: ${entityTypes.join(", ")}`;
|
|
11687
|
-
return
|
|
11008
|
+
return inferenceClient.generateText(summaryPrompt, 500, 0.5);
|
|
11688
11009
|
}
|
|
11689
11010
|
};
|
|
11690
11011
|
|
|
11691
11012
|
// src/graph-context.ts
|
|
11692
|
-
import { getResourceId as getResourceId2, getResourceEntityTypes as getResourceEntityTypes2 } from "@semiont/
|
|
11013
|
+
import { getResourceId as getResourceId2, getResourceEntityTypes as getResourceEntityTypes2 } from "@semiont/core";
|
|
11693
11014
|
var GraphContext = class {
|
|
11694
11015
|
/**
|
|
11695
11016
|
* Get all resources referencing this resource (backlinks)
|
|
11696
11017
|
* Requires graph traversal - must use graph database
|
|
11697
11018
|
*/
|
|
11698
|
-
static async getBacklinks(
|
|
11699
|
-
return
|
|
11019
|
+
static async getBacklinks(resourceId10, kb) {
|
|
11020
|
+
return kb.graph.getResourceReferencedBy(resourceId10);
|
|
11700
11021
|
}
|
|
11701
11022
|
/**
|
|
11702
11023
|
* Find shortest path between two resources
|
|
11703
11024
|
* Requires graph traversal - must use graph database
|
|
11704
11025
|
*/
|
|
11705
11026
|
static async findPath(fromResourceId, toResourceId, kb, maxDepth) {
|
|
11706
|
-
return
|
|
11027
|
+
return kb.graph.findPath(fromResourceId, toResourceId, maxDepth);
|
|
11707
11028
|
}
|
|
11708
11029
|
/**
|
|
11709
11030
|
* Get resource connections (graph edges)
|
|
11710
11031
|
* Requires graph traversal - must use graph database
|
|
11711
11032
|
*/
|
|
11712
|
-
static async getResourceConnections(
|
|
11713
|
-
return
|
|
11033
|
+
static async getResourceConnections(resourceId10, kb) {
|
|
11034
|
+
return kb.graph.getResourceConnections(resourceId10);
|
|
11714
11035
|
}
|
|
11715
11036
|
/**
|
|
11716
11037
|
* Search resources by name (cross-resource query)
|
|
11717
11038
|
* Requires full-text search - must use graph database
|
|
11718
11039
|
*/
|
|
11719
11040
|
static async searchResources(query, kb, limit) {
|
|
11720
|
-
return
|
|
11041
|
+
return kb.graph.searchResources(query, limit);
|
|
11721
11042
|
}
|
|
11722
11043
|
/**
|
|
11723
11044
|
* Build graph representation with nodes and edges for a resource and its connections
|
|
11724
11045
|
* Retrieves connections from graph and builds visualization-ready structure
|
|
11725
11046
|
*/
|
|
11726
|
-
static async buildGraphRepresentation(
|
|
11727
|
-
const mainDoc = await kb.graph.getResource(
|
|
11047
|
+
static async buildGraphRepresentation(resourceId10, maxRelated, kb) {
|
|
11048
|
+
const mainDoc = await kb.graph.getResource(resourceId10);
|
|
11728
11049
|
if (!mainDoc) {
|
|
11729
11050
|
throw new Error("Resource not found");
|
|
11730
11051
|
}
|
|
11731
|
-
const connections = await kb.graph.getResourceConnections(
|
|
11052
|
+
const connections = await kb.graph.getResourceConnections(resourceId10);
|
|
11732
11053
|
const relatedDocs = connections.map((conn) => conn.targetResource).slice(0, maxRelated - 1);
|
|
11733
11054
|
const nodes = [
|
|
11734
11055
|
{
|
|
@@ -11745,7 +11066,7 @@ var GraphContext = class {
|
|
|
11745
11066
|
}))
|
|
11746
11067
|
].filter((node) => node.id !== void 0);
|
|
11747
11068
|
const edges = connections.slice(0, maxRelated - 1).map((conn) => ({
|
|
11748
|
-
source:
|
|
11069
|
+
source: resourceId10,
|
|
11749
11070
|
target: getResourceId2(conn.targetResource),
|
|
11750
11071
|
type: conn.relationshipType || "link",
|
|
11751
11072
|
metadata: {}
|
|
@@ -11755,29 +11076,29 @@ var GraphContext = class {
|
|
|
11755
11076
|
};
|
|
11756
11077
|
|
|
11757
11078
|
// src/llm-context.ts
|
|
11758
|
-
import { getResourceEntityTypes as getResourceEntityTypes3, getResourceId as getResourceId3 } from "@semiont/
|
|
11759
|
-
import { resourceId as
|
|
11079
|
+
import { getResourceEntityTypes as getResourceEntityTypes3, getResourceId as getResourceId3 } from "@semiont/core";
|
|
11080
|
+
import { resourceId as makeResourceId2 } from "@semiont/core";
|
|
11760
11081
|
var LLMContext = class {
|
|
11761
11082
|
/**
|
|
11762
11083
|
* Get comprehensive LLM context for a resource
|
|
11763
11084
|
* Includes: main resource, related resources, annotations, graph, content, summary, references
|
|
11764
11085
|
*/
|
|
11765
|
-
static async getResourceContext(
|
|
11766
|
-
const mainDoc = await ResourceContext.getResourceMetadata(
|
|
11086
|
+
static async getResourceContext(resourceId10, options, kb, inferenceClient) {
|
|
11087
|
+
const mainDoc = await ResourceContext.getResourceMetadata(resourceId10, kb);
|
|
11767
11088
|
if (!mainDoc) {
|
|
11768
11089
|
throw new Error("Resource not found");
|
|
11769
11090
|
}
|
|
11770
11091
|
const mainContent = options.includeContent ? await ResourceContext.getResourceContent(mainDoc, kb) : void 0;
|
|
11771
11092
|
const graph = await GraphContext.buildGraphRepresentation(
|
|
11772
|
-
|
|
11093
|
+
resourceId10,
|
|
11773
11094
|
options.maxResources,
|
|
11774
11095
|
kb
|
|
11775
11096
|
);
|
|
11776
11097
|
const relatedDocs = [];
|
|
11777
|
-
const resourceIdStr =
|
|
11098
|
+
const resourceIdStr = resourceId10.toString();
|
|
11778
11099
|
for (const node of graph.nodes) {
|
|
11779
11100
|
if (node.id !== resourceIdStr) {
|
|
11780
|
-
const relatedDoc = await ResourceContext.getResourceMetadata(
|
|
11101
|
+
const relatedDoc = await ResourceContext.getResourceMetadata(makeResourceId2(node.id), kb);
|
|
11781
11102
|
if (relatedDoc) {
|
|
11782
11103
|
relatedDocs.push(relatedDoc);
|
|
11783
11104
|
}
|
|
@@ -11796,7 +11117,7 @@ var LLMContext = class {
|
|
|
11796
11117
|
})
|
|
11797
11118
|
);
|
|
11798
11119
|
}
|
|
11799
|
-
const annotations = await AnnotationContext.getAllAnnotations(
|
|
11120
|
+
const annotations = await AnnotationContext.getAllAnnotations(resourceId10, kb);
|
|
11800
11121
|
const summary = options.includeSummary && mainContent ? await generateResourceSummary(
|
|
11801
11122
|
mainDoc.name,
|
|
11802
11123
|
mainContent,
|
|
@@ -11832,18 +11153,22 @@ var Gatherer = class {
|
|
|
11832
11153
|
this.logger.info("Gatherer actor initialized");
|
|
11833
11154
|
const errorHandler = (err) => this.logger.error("Gatherer pipeline error", { error: err });
|
|
11834
11155
|
const annotationGather$ = this.eventBus.get("gather:requested").pipe(
|
|
11835
|
-
(0,
|
|
11836
|
-
(0,
|
|
11156
|
+
(0, import_operators2.groupBy)((event) => event.resourceId),
|
|
11157
|
+
(0, import_operators2.mergeMap)(
|
|
11837
11158
|
(group$) => group$.pipe(
|
|
11838
|
-
(0,
|
|
11159
|
+
(0, import_operators2.concatMap)(
|
|
11160
|
+
(event) => (0, import_rxjs2.from)(withActorSpan("gatherer", "gather:requested", () => this.handleAnnotationGather(event)))
|
|
11161
|
+
)
|
|
11839
11162
|
)
|
|
11840
11163
|
)
|
|
11841
11164
|
);
|
|
11842
11165
|
const resourceGather$ = this.eventBus.get("gather:resource-requested").pipe(
|
|
11843
|
-
(0,
|
|
11844
|
-
(0,
|
|
11166
|
+
(0, import_operators2.groupBy)((event) => event.resourceId),
|
|
11167
|
+
(0, import_operators2.mergeMap)(
|
|
11845
11168
|
(group$) => group$.pipe(
|
|
11846
|
-
(0,
|
|
11169
|
+
(0, import_operators2.concatMap)(
|
|
11170
|
+
(event) => (0, import_rxjs2.from)(withActorSpan("gatherer", "gather:resource-requested", () => this.handleResourceGather(event)))
|
|
11171
|
+
)
|
|
11847
11172
|
)
|
|
11848
11173
|
)
|
|
11849
11174
|
);
|
|
@@ -11856,14 +11181,13 @@ var Gatherer = class {
|
|
|
11856
11181
|
// Gather handlers (existing)
|
|
11857
11182
|
// ========================================================================
|
|
11858
11183
|
async handleAnnotationGather(event) {
|
|
11859
|
-
const resultBus = this.eventBus.scope(event.resourceId);
|
|
11860
11184
|
try {
|
|
11861
11185
|
this.logger.debug("Gathering annotation context", {
|
|
11862
11186
|
annotationId: event.annotationId,
|
|
11863
11187
|
resourceId: event.resourceId
|
|
11864
11188
|
});
|
|
11865
11189
|
const response = await AnnotationContext.buildLLMContext(
|
|
11866
|
-
|
|
11190
|
+
makeAnnotationId2(event.annotationId),
|
|
11867
11191
|
resourceId(event.resourceId),
|
|
11868
11192
|
this.kb,
|
|
11869
11193
|
event.options ?? {},
|
|
@@ -11871,7 +11195,7 @@ var Gatherer = class {
|
|
|
11871
11195
|
this.logger,
|
|
11872
11196
|
this.embeddingProvider
|
|
11873
11197
|
);
|
|
11874
|
-
|
|
11198
|
+
this.eventBus.get("gather:complete").next({
|
|
11875
11199
|
correlationId: event.correlationId,
|
|
11876
11200
|
annotationId: event.annotationId,
|
|
11877
11201
|
response
|
|
@@ -11879,9 +11203,9 @@ var Gatherer = class {
|
|
|
11879
11203
|
} catch (error) {
|
|
11880
11204
|
this.logger.error("Gather annotation context failed", {
|
|
11881
11205
|
annotationId: event.annotationId,
|
|
11882
|
-
error:
|
|
11206
|
+
error: errField2(error)
|
|
11883
11207
|
});
|
|
11884
|
-
|
|
11208
|
+
this.eventBus.get("gather:failed").next({
|
|
11885
11209
|
correlationId: event.correlationId,
|
|
11886
11210
|
annotationId: event.annotationId,
|
|
11887
11211
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -11889,7 +11213,6 @@ var Gatherer = class {
|
|
|
11889
11213
|
}
|
|
11890
11214
|
}
|
|
11891
11215
|
async handleResourceGather(event) {
|
|
11892
|
-
const resultBus = this.eventBus.scope(event.resourceId);
|
|
11893
11216
|
try {
|
|
11894
11217
|
this.logger.debug("Gathering resource context", {
|
|
11895
11218
|
resourceId: event.resourceId
|
|
@@ -11900,7 +11223,7 @@ var Gatherer = class {
|
|
|
11900
11223
|
this.kb,
|
|
11901
11224
|
this.inferenceClient
|
|
11902
11225
|
);
|
|
11903
|
-
|
|
11226
|
+
this.eventBus.get("gather:resource-complete").next({
|
|
11904
11227
|
correlationId: event.correlationId,
|
|
11905
11228
|
resourceId: event.resourceId,
|
|
11906
11229
|
response: result
|
|
@@ -11908,19 +11231,19 @@ var Gatherer = class {
|
|
|
11908
11231
|
} catch (error) {
|
|
11909
11232
|
this.logger.error("Gather resource context failed", {
|
|
11910
11233
|
resourceId: event.resourceId,
|
|
11911
|
-
error:
|
|
11234
|
+
error: errField2(error)
|
|
11912
11235
|
});
|
|
11913
|
-
|
|
11236
|
+
this.eventBus.get("gather:resource-failed").next({
|
|
11914
11237
|
correlationId: event.correlationId,
|
|
11915
11238
|
resourceId: event.resourceId,
|
|
11916
11239
|
message: error instanceof Error ? error.message : String(error)
|
|
11917
11240
|
});
|
|
11918
11241
|
}
|
|
11919
11242
|
}
|
|
11920
|
-
async generateAnnotationSummary(
|
|
11243
|
+
async generateAnnotationSummary(annotationId5, resourceId10) {
|
|
11921
11244
|
return AnnotationContext.generateAnnotationSummary(
|
|
11922
|
-
|
|
11923
|
-
|
|
11245
|
+
annotationId5,
|
|
11246
|
+
resourceId10,
|
|
11924
11247
|
this.kb,
|
|
11925
11248
|
this.inferenceClient
|
|
11926
11249
|
);
|
|
@@ -11935,10 +11258,11 @@ var Gatherer = class {
|
|
|
11935
11258
|
};
|
|
11936
11259
|
|
|
11937
11260
|
// src/matcher.ts
|
|
11938
|
-
var
|
|
11939
|
-
var
|
|
11940
|
-
import { resourceId as resourceId2, errField as
|
|
11941
|
-
import { getResourceId as getResourceId4, getResourceEntityTypes as getResourceEntityTypes4 } from "@semiont/
|
|
11261
|
+
var import_rxjs3 = __toESM(require_cjs(), 1);
|
|
11262
|
+
var import_operators3 = __toESM(require_operators(), 1);
|
|
11263
|
+
import { resourceId as resourceId2, errField as errField3 } from "@semiont/core";
|
|
11264
|
+
import { getResourceId as getResourceId4, getResourceEntityTypes as getResourceEntityTypes4 } from "@semiont/core";
|
|
11265
|
+
import { withActorSpan as withActorSpan2 } from "@semiont/observability";
|
|
11942
11266
|
var Matcher = class {
|
|
11943
11267
|
constructor(kb, eventBus, logger, inferenceClient, embeddingProvider) {
|
|
11944
11268
|
this.kb = kb;
|
|
@@ -11953,7 +11277,9 @@ var Matcher = class {
|
|
|
11953
11277
|
this.logger.info("Matcher actor initialized");
|
|
11954
11278
|
const errorHandler = (err) => this.logger.error("Matcher pipeline error", { error: err });
|
|
11955
11279
|
const search$ = this.eventBus.get("match:search-requested").pipe(
|
|
11956
|
-
(0,
|
|
11280
|
+
(0, import_operators3.concatMap)(
|
|
11281
|
+
(event) => (0, import_rxjs3.from)(withActorSpan2("matcher", "match:search-requested", () => this.handleSearch(event)))
|
|
11282
|
+
)
|
|
11957
11283
|
);
|
|
11958
11284
|
this.subscriptions.push(
|
|
11959
11285
|
search$.subscribe({ error: errorHandler })
|
|
@@ -11961,7 +11287,6 @@ var Matcher = class {
|
|
|
11961
11287
|
}
|
|
11962
11288
|
async handleSearch(event) {
|
|
11963
11289
|
try {
|
|
11964
|
-
const resultBus = this.eventBus.scope(event.resourceId);
|
|
11965
11290
|
const context = event.context;
|
|
11966
11291
|
const selectedText = context.sourceContext?.selected ?? "";
|
|
11967
11292
|
const userHint = context.userHint ?? "";
|
|
@@ -11978,7 +11303,7 @@ var Matcher = class {
|
|
|
11978
11303
|
event.useSemanticScoring
|
|
11979
11304
|
);
|
|
11980
11305
|
const limited = event.limit ? scored.slice(0, event.limit) : scored;
|
|
11981
|
-
|
|
11306
|
+
this.eventBus.get("match:search-results").next({
|
|
11982
11307
|
correlationId: event.correlationId,
|
|
11983
11308
|
referenceId: event.referenceId,
|
|
11984
11309
|
response: limited
|
|
@@ -11986,9 +11311,9 @@ var Matcher = class {
|
|
|
11986
11311
|
} catch (error) {
|
|
11987
11312
|
this.logger.error("Bind search failed", {
|
|
11988
11313
|
referenceId: event.referenceId,
|
|
11989
|
-
error:
|
|
11314
|
+
error: errField3(error)
|
|
11990
11315
|
});
|
|
11991
|
-
this.eventBus.
|
|
11316
|
+
this.eventBus.get("match:search-failed").next({
|
|
11992
11317
|
correlationId: event.correlationId,
|
|
11993
11318
|
referenceId: event.referenceId,
|
|
11994
11319
|
error: error instanceof Error ? error.message : String(error)
|
|
@@ -12254,10 +11579,11 @@ For each candidate, output a line with the number and score, like:
|
|
|
12254
11579
|
};
|
|
12255
11580
|
|
|
12256
11581
|
// src/stower.ts
|
|
12257
|
-
var
|
|
12258
|
-
var
|
|
12259
|
-
import { promises as
|
|
12260
|
-
import {
|
|
11582
|
+
var import_rxjs4 = __toESM(require_cjs(), 1);
|
|
11583
|
+
var import_operators4 = __toESM(require_operators(), 1);
|
|
11584
|
+
import { promises as fs } from "fs";
|
|
11585
|
+
import { annotationId, errField as errField4, resourceId as resourceId3, userId as makeUserId, CREATION_METHODS, generateUuid } from "@semiont/core";
|
|
11586
|
+
import { withActorSpan as withActorSpan3 } from "@semiont/observability";
|
|
12261
11587
|
import { resolveStorageUri } from "@semiont/event-sourcing";
|
|
12262
11588
|
var Stower = class {
|
|
12263
11589
|
constructor(kb, eventBus, logger) {
|
|
@@ -12269,8 +11595,12 @@ var Stower = class {
|
|
|
12269
11595
|
logger;
|
|
12270
11596
|
async initialize() {
|
|
12271
11597
|
this.logger.info("Stower actor initialized");
|
|
12272
|
-
const pipe = (event, handler) => this.eventBus.get(event).pipe(
|
|
12273
|
-
|
|
11598
|
+
const pipe = (event, handler) => this.eventBus.get(event).pipe(
|
|
11599
|
+
(0, import_operators4.concatMap)(
|
|
11600
|
+
(e) => (0, import_rxjs4.from)(withActorSpan3("stower", event, () => handler(e)))
|
|
11601
|
+
)
|
|
11602
|
+
);
|
|
11603
|
+
this.subscription = (0, import_rxjs4.merge)(
|
|
12274
11604
|
pipe("yield:create", (e) => this.handleYieldCreate(e)),
|
|
12275
11605
|
pipe("yield:update", (e) => this.handleYieldUpdate(e)),
|
|
12276
11606
|
pipe("yield:mv", (e) => this.handleYieldMv(e)),
|
|
@@ -12282,7 +11612,6 @@ var Stower = class {
|
|
|
12282
11612
|
pipe("mark:unarchive", (e) => this.handleMarkUnarchive(e)),
|
|
12283
11613
|
pipe("mark:update-entity-types", (e) => this.handleUpdateEntityTypes(e)),
|
|
12284
11614
|
pipe("job:start", (e) => this.handleJobStart(e)),
|
|
12285
|
-
pipe("job:report-progress", (e) => this.handleJobReportProgress(e)),
|
|
12286
11615
|
pipe("job:complete", (e) => this.handleJobComplete(e)),
|
|
12287
11616
|
pipe("job:fail", (e) => this.handleJobFail(e))
|
|
12288
11617
|
).subscribe({
|
|
@@ -12293,6 +11622,10 @@ var Stower = class {
|
|
|
12293
11622
|
// Event handlers
|
|
12294
11623
|
// ========================================================================
|
|
12295
11624
|
async handleYieldCreate(event) {
|
|
11625
|
+
if (!event._userId) {
|
|
11626
|
+
throw new Error("yield:create missing _userId (gateway injection)");
|
|
11627
|
+
}
|
|
11628
|
+
const uid = makeUserId(event._userId);
|
|
12296
11629
|
try {
|
|
12297
11630
|
const rId = resourceId3(generateUuid());
|
|
12298
11631
|
const stored = await this.kb.content.register(event.storageUri, event.contentChecksum, { noGit: event.noGit });
|
|
@@ -12300,11 +11633,14 @@ var Stower = class {
|
|
|
12300
11633
|
const byteSize = event.byteSize;
|
|
12301
11634
|
const validCreationMethods = Object.values(CREATION_METHODS);
|
|
12302
11635
|
const validatedCreationMethod = event.creationMethod && validCreationMethods.includes(event.creationMethod) ? event.creationMethod : CREATION_METHODS.API;
|
|
12303
|
-
const generatedFrom = event.generatedFrom?.resourceId && event.generatedFrom?.annotationId ? {
|
|
11636
|
+
const generatedFrom = event.generatedFrom?.resourceId && event.generatedFrom?.annotationId ? {
|
|
11637
|
+
resourceId: resourceId3(event.generatedFrom.resourceId),
|
|
11638
|
+
annotationId: annotationId(event.generatedFrom.annotationId)
|
|
11639
|
+
} : void 0;
|
|
12304
11640
|
await this.kb.eventStore.appendEvent({
|
|
12305
11641
|
type: "yield:created",
|
|
12306
11642
|
resourceId: rId,
|
|
12307
|
-
userId:
|
|
11643
|
+
userId: uid,
|
|
12308
11644
|
version: 1,
|
|
12309
11645
|
payload: {
|
|
12310
11646
|
name: event.name,
|
|
@@ -12342,20 +11678,45 @@ var Stower = class {
|
|
|
12342
11678
|
]
|
|
12343
11679
|
};
|
|
12344
11680
|
this.eventBus.get("yield:create-ok").next({ resourceId: rId, resource });
|
|
11681
|
+
if (generatedFrom) {
|
|
11682
|
+
this.eventBus.get("mark:update-body").next({
|
|
11683
|
+
annotationId: generatedFrom.annotationId,
|
|
11684
|
+
_userId: event._userId,
|
|
11685
|
+
resourceId: generatedFrom.resourceId,
|
|
11686
|
+
operations: [
|
|
11687
|
+
{
|
|
11688
|
+
op: "add",
|
|
11689
|
+
item: {
|
|
11690
|
+
type: "SpecificResource",
|
|
11691
|
+
source: rId,
|
|
11692
|
+
purpose: "linking"
|
|
11693
|
+
}
|
|
11694
|
+
}
|
|
11695
|
+
]
|
|
11696
|
+
});
|
|
11697
|
+
this.logger.info("Auto-bound generated resource to source reference", {
|
|
11698
|
+
resourceId: rId,
|
|
11699
|
+
sourceAnnotationId: generatedFrom.annotationId,
|
|
11700
|
+
sourceResourceId: generatedFrom.resourceId
|
|
11701
|
+
});
|
|
11702
|
+
}
|
|
12345
11703
|
} catch (error) {
|
|
12346
|
-
this.logger.error("Failed to create resource", { error });
|
|
11704
|
+
this.logger.error("Failed to create resource", { error: errField4(error) });
|
|
12347
11705
|
this.eventBus.get("yield:create-failed").next({
|
|
12348
11706
|
message: error instanceof Error ? error.message : String(error)
|
|
12349
11707
|
});
|
|
12350
11708
|
}
|
|
12351
11709
|
}
|
|
12352
11710
|
async handleYieldUpdate(event) {
|
|
11711
|
+
if (!event._userId) {
|
|
11712
|
+
throw new Error("yield:update missing _userId (gateway injection)");
|
|
11713
|
+
}
|
|
12353
11714
|
try {
|
|
12354
11715
|
await this.kb.content.register(event.storageUri, event.contentChecksum, { noGit: event.noGit });
|
|
12355
11716
|
await this.kb.eventStore.appendEvent({
|
|
12356
11717
|
type: "yield:updated",
|
|
12357
11718
|
resourceId: resourceId3(event.resourceId),
|
|
12358
|
-
userId: makeUserId(event.
|
|
11719
|
+
userId: makeUserId(event._userId),
|
|
12359
11720
|
version: 1,
|
|
12360
11721
|
payload: {
|
|
12361
11722
|
contentChecksum: event.contentChecksum,
|
|
@@ -12364,7 +11725,7 @@ var Stower = class {
|
|
|
12364
11725
|
});
|
|
12365
11726
|
this.eventBus.get("yield:update-ok").next({ resourceId: event.resourceId });
|
|
12366
11727
|
} catch (error) {
|
|
12367
|
-
this.logger.error("Failed to update resource", { error });
|
|
11728
|
+
this.logger.error("Failed to update resource", { error: errField4(error) });
|
|
12368
11729
|
this.eventBus.get("yield:update-failed").next({
|
|
12369
11730
|
resourceId: event.resourceId,
|
|
12370
11731
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -12384,12 +11745,15 @@ var Stower = class {
|
|
|
12384
11745
|
});
|
|
12385
11746
|
return;
|
|
12386
11747
|
}
|
|
11748
|
+
if (!event._userId) {
|
|
11749
|
+
throw new Error("yield:mv missing _userId (gateway injection)");
|
|
11750
|
+
}
|
|
12387
11751
|
try {
|
|
12388
11752
|
await this.kb.content.move(event.fromUri, event.toUri, { noGit: event.noGit });
|
|
12389
11753
|
await this.kb.eventStore.appendEvent({
|
|
12390
11754
|
type: "yield:moved",
|
|
12391
11755
|
resourceId: rId,
|
|
12392
|
-
userId: makeUserId(event.
|
|
11756
|
+
userId: makeUserId(event._userId),
|
|
12393
11757
|
version: 1,
|
|
12394
11758
|
payload: {
|
|
12395
11759
|
fromUri: event.fromUri,
|
|
@@ -12398,7 +11762,7 @@ var Stower = class {
|
|
|
12398
11762
|
});
|
|
12399
11763
|
this.eventBus.get("yield:move-ok").next({ resourceId: rId });
|
|
12400
11764
|
} catch (error) {
|
|
12401
|
-
this.logger.error("Failed to move resource", { error });
|
|
11765
|
+
this.logger.error("Failed to move resource", { error: errField4(error) });
|
|
12402
11766
|
this.eventBus.get("yield:move-failed").next({
|
|
12403
11767
|
fromUri: event.fromUri,
|
|
12404
11768
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -12406,50 +11770,62 @@ var Stower = class {
|
|
|
12406
11770
|
}
|
|
12407
11771
|
}
|
|
12408
11772
|
async handleMarkCreate(event) {
|
|
11773
|
+
if (!event._userId) {
|
|
11774
|
+
throw new Error("mark:create missing _userId (gateway injection)");
|
|
11775
|
+
}
|
|
12409
11776
|
try {
|
|
12410
11777
|
this.logger.debug("Stowing annotation", { annotationId: event.annotation.id });
|
|
12411
|
-
await this.kb.eventStore.appendEvent(
|
|
12412
|
-
|
|
12413
|
-
|
|
12414
|
-
|
|
12415
|
-
|
|
12416
|
-
|
|
12417
|
-
|
|
12418
|
-
|
|
11778
|
+
await this.kb.eventStore.appendEvent(
|
|
11779
|
+
{
|
|
11780
|
+
type: "mark:added",
|
|
11781
|
+
resourceId: resourceId3(event.resourceId),
|
|
11782
|
+
userId: makeUserId(event._userId),
|
|
11783
|
+
version: 1,
|
|
11784
|
+
payload: { annotation: event.annotation }
|
|
11785
|
+
},
|
|
11786
|
+
event.correlationId ? { correlationId: event.correlationId } : void 0
|
|
11787
|
+
);
|
|
12419
11788
|
} catch (error) {
|
|
12420
|
-
this.logger.error("Failed to create annotation", { error });
|
|
11789
|
+
this.logger.error("Failed to create annotation", { error: errField4(error) });
|
|
12421
11790
|
this.eventBus.get("mark:create-failed").next({
|
|
11791
|
+
correlationId: event.correlationId,
|
|
12422
11792
|
message: error instanceof Error ? error.message : String(error)
|
|
12423
11793
|
});
|
|
12424
11794
|
}
|
|
12425
11795
|
}
|
|
12426
11796
|
async handleMarkDelete(event) {
|
|
12427
|
-
if (!event.
|
|
12428
|
-
|
|
11797
|
+
if (!event._userId) {
|
|
11798
|
+
throw new Error("mark:delete missing _userId (gateway injection)");
|
|
11799
|
+
}
|
|
11800
|
+
if (!event.resourceId) {
|
|
11801
|
+
throw new Error("mark:delete missing resourceId");
|
|
12429
11802
|
}
|
|
12430
11803
|
try {
|
|
12431
11804
|
await this.kb.eventStore.appendEvent({
|
|
12432
11805
|
type: "mark:removed",
|
|
12433
11806
|
resourceId: resourceId3(event.resourceId),
|
|
12434
|
-
userId: makeUserId(event.
|
|
11807
|
+
userId: makeUserId(event._userId),
|
|
12435
11808
|
version: 1,
|
|
12436
|
-
payload: { annotationId: event.annotationId }
|
|
11809
|
+
payload: { annotationId: annotationId(event.annotationId) }
|
|
12437
11810
|
});
|
|
12438
11811
|
this.eventBus.get("mark:delete-ok").next({ annotationId: event.annotationId });
|
|
12439
11812
|
} catch (error) {
|
|
12440
|
-
this.logger.error("Failed to delete annotation", { error });
|
|
11813
|
+
this.logger.error("Failed to delete annotation", { error: errField4(error) });
|
|
12441
11814
|
this.eventBus.get("mark:delete-failed").next({
|
|
12442
11815
|
message: error instanceof Error ? error.message : String(error)
|
|
12443
11816
|
});
|
|
12444
11817
|
}
|
|
12445
11818
|
}
|
|
12446
11819
|
async handleMarkUpdateBody(event) {
|
|
11820
|
+
if (!event._userId) {
|
|
11821
|
+
throw new Error("mark:update-body missing _userId (gateway injection)");
|
|
11822
|
+
}
|
|
12447
11823
|
try {
|
|
12448
11824
|
await this.kb.eventStore.appendEvent(
|
|
12449
11825
|
{
|
|
12450
11826
|
type: "mark:body-updated",
|
|
12451
11827
|
resourceId: resourceId3(event.resourceId),
|
|
12452
|
-
userId: makeUserId(event.
|
|
11828
|
+
userId: makeUserId(event._userId),
|
|
12453
11829
|
version: 1,
|
|
12454
11830
|
payload: { annotationId: event.annotationId, operations: event.operations }
|
|
12455
11831
|
},
|
|
@@ -12458,16 +11834,16 @@ var Stower = class {
|
|
|
12458
11834
|
event.correlationId ? { correlationId: event.correlationId } : void 0
|
|
12459
11835
|
);
|
|
12460
11836
|
} catch (error) {
|
|
12461
|
-
this.logger.error("Failed to update annotation body", { error });
|
|
11837
|
+
this.logger.error("Failed to update annotation body", { error: errField4(error) });
|
|
12462
11838
|
this.eventBus.get("mark:body-update-failed").next({
|
|
11839
|
+
correlationId: event.correlationId,
|
|
12463
11840
|
message: error instanceof Error ? error.message : String(error)
|
|
12464
11841
|
});
|
|
12465
11842
|
}
|
|
12466
11843
|
}
|
|
12467
11844
|
async handleMarkArchive(event) {
|
|
12468
|
-
if (!event.
|
|
12469
|
-
|
|
12470
|
-
return;
|
|
11845
|
+
if (!event._userId) {
|
|
11846
|
+
throw new Error("mark:archive missing _userId (gateway injection)");
|
|
12471
11847
|
}
|
|
12472
11848
|
if (event.storageUri) {
|
|
12473
11849
|
await this.kb.content.remove(event.storageUri, { keepFile: event.keepFile, noGit: event.noGit });
|
|
@@ -12475,20 +11851,19 @@ var Stower = class {
|
|
|
12475
11851
|
await this.kb.eventStore.appendEvent({
|
|
12476
11852
|
type: "mark:archived",
|
|
12477
11853
|
resourceId: resourceId3(event.resourceId),
|
|
12478
|
-
userId: makeUserId(event.
|
|
11854
|
+
userId: makeUserId(event._userId),
|
|
12479
11855
|
version: 1,
|
|
12480
11856
|
payload: { reason: void 0 }
|
|
12481
11857
|
});
|
|
12482
11858
|
}
|
|
12483
11859
|
async handleMarkUnarchive(event) {
|
|
12484
|
-
if (!event.
|
|
12485
|
-
|
|
12486
|
-
return;
|
|
11860
|
+
if (!event._userId) {
|
|
11861
|
+
throw new Error("mark:unarchive missing _userId (gateway injection)");
|
|
12487
11862
|
}
|
|
12488
11863
|
if (event.storageUri) {
|
|
12489
11864
|
const absPath = this.kb.content.resolveUri(event.storageUri);
|
|
12490
11865
|
try {
|
|
12491
|
-
await
|
|
11866
|
+
await fs.access(absPath);
|
|
12492
11867
|
} catch {
|
|
12493
11868
|
this.logger.warn("Unarchive failed: file not found at storageUri", { storageUri: event.storageUri });
|
|
12494
11869
|
return;
|
|
@@ -12497,93 +11872,101 @@ var Stower = class {
|
|
|
12497
11872
|
await this.kb.eventStore.appendEvent({
|
|
12498
11873
|
type: "mark:unarchived",
|
|
12499
11874
|
resourceId: resourceId3(event.resourceId),
|
|
12500
|
-
userId: makeUserId(event.
|
|
11875
|
+
userId: makeUserId(event._userId),
|
|
12501
11876
|
version: 1,
|
|
12502
11877
|
payload: {}
|
|
12503
11878
|
});
|
|
12504
11879
|
}
|
|
12505
11880
|
async handleAddEntityType(event) {
|
|
11881
|
+
if (!event._userId) {
|
|
11882
|
+
throw new Error("mark:add-entity-type missing _userId (gateway injection)");
|
|
11883
|
+
}
|
|
12506
11884
|
try {
|
|
12507
11885
|
await this.kb.eventStore.appendEvent({
|
|
12508
11886
|
type: "mark:entity-type-added",
|
|
12509
|
-
userId: makeUserId(event.
|
|
11887
|
+
userId: makeUserId(event._userId),
|
|
12510
11888
|
version: 1,
|
|
12511
11889
|
payload: { entityType: event.tag }
|
|
12512
11890
|
});
|
|
12513
11891
|
} catch (error) {
|
|
12514
|
-
this.logger.error("Failed to add entity type", { error });
|
|
11892
|
+
this.logger.error("Failed to add entity type", { error: errField4(error) });
|
|
12515
11893
|
this.eventBus.get("mark:entity-type-add-failed").next({
|
|
12516
11894
|
message: error instanceof Error ? error.message : String(error)
|
|
12517
11895
|
});
|
|
12518
11896
|
}
|
|
12519
11897
|
}
|
|
12520
11898
|
async handleUpdateEntityTypes(event) {
|
|
11899
|
+
if (!event._userId) {
|
|
11900
|
+
throw new Error("mark:update-entity-types missing _userId (gateway injection)");
|
|
11901
|
+
}
|
|
11902
|
+
const uid = makeUserId(event._userId);
|
|
12521
11903
|
const added = event.updatedEntityTypes.filter((et) => !event.currentEntityTypes.includes(et));
|
|
12522
11904
|
const removed = event.currentEntityTypes.filter((et) => !event.updatedEntityTypes.includes(et));
|
|
12523
|
-
for (const
|
|
11905
|
+
for (const entityType2 of added) {
|
|
12524
11906
|
await this.kb.eventStore.appendEvent({
|
|
12525
11907
|
type: "mark:entity-tag-added",
|
|
12526
11908
|
resourceId: resourceId3(event.resourceId),
|
|
12527
|
-
userId:
|
|
11909
|
+
userId: uid,
|
|
12528
11910
|
version: 1,
|
|
12529
|
-
payload: { entityType }
|
|
11911
|
+
payload: { entityType: entityType2 }
|
|
12530
11912
|
});
|
|
12531
11913
|
}
|
|
12532
|
-
for (const
|
|
11914
|
+
for (const entityType2 of removed) {
|
|
12533
11915
|
await this.kb.eventStore.appendEvent({
|
|
12534
11916
|
type: "mark:entity-tag-removed",
|
|
12535
11917
|
resourceId: resourceId3(event.resourceId),
|
|
12536
|
-
userId:
|
|
11918
|
+
userId: uid,
|
|
12537
11919
|
version: 1,
|
|
12538
|
-
payload: { entityType }
|
|
11920
|
+
payload: { entityType: entityType2 }
|
|
12539
11921
|
});
|
|
12540
11922
|
}
|
|
12541
11923
|
}
|
|
12542
11924
|
async handleJobStart(event) {
|
|
11925
|
+
if (!event._userId) {
|
|
11926
|
+
throw new Error("job:start missing _userId (gateway injection)");
|
|
11927
|
+
}
|
|
12543
11928
|
await this.kb.eventStore.appendEvent({
|
|
12544
11929
|
type: "job:started",
|
|
12545
11930
|
resourceId: resourceId3(event.resourceId),
|
|
12546
|
-
userId: makeUserId(event.
|
|
12547
|
-
version: 1,
|
|
12548
|
-
payload: { jobId: event.jobId, jobType: event.jobType }
|
|
12549
|
-
});
|
|
12550
|
-
}
|
|
12551
|
-
async handleJobReportProgress(event) {
|
|
12552
|
-
await this.kb.eventStore.appendEvent({
|
|
12553
|
-
type: "job:progress",
|
|
12554
|
-
resourceId: resourceId3(event.resourceId),
|
|
12555
|
-
userId: makeUserId(event.userId),
|
|
11931
|
+
userId: makeUserId(event._userId),
|
|
12556
11932
|
version: 1,
|
|
12557
11933
|
payload: {
|
|
12558
11934
|
jobId: event.jobId,
|
|
12559
11935
|
jobType: event.jobType,
|
|
12560
|
-
|
|
12561
|
-
progress: event.progress
|
|
11936
|
+
...event.annotationId ? { annotationId: event.annotationId } : {}
|
|
12562
11937
|
}
|
|
12563
11938
|
});
|
|
12564
11939
|
}
|
|
12565
11940
|
async handleJobComplete(event) {
|
|
11941
|
+
if (!event._userId) {
|
|
11942
|
+
throw new Error("job:complete missing _userId (gateway injection)");
|
|
11943
|
+
}
|
|
12566
11944
|
await this.kb.eventStore.appendEvent({
|
|
12567
11945
|
type: "job:completed",
|
|
12568
11946
|
resourceId: resourceId3(event.resourceId),
|
|
12569
|
-
userId: makeUserId(event.
|
|
11947
|
+
userId: makeUserId(event._userId),
|
|
12570
11948
|
version: 1,
|
|
12571
11949
|
payload: {
|
|
12572
11950
|
jobId: event.jobId,
|
|
12573
11951
|
jobType: event.jobType,
|
|
11952
|
+
...event.annotationId ? { annotationId: event.annotationId } : {},
|
|
12574
11953
|
result: event.result
|
|
12575
11954
|
}
|
|
12576
11955
|
});
|
|
12577
11956
|
}
|
|
12578
11957
|
async handleJobFail(event) {
|
|
11958
|
+
if (!event._userId) {
|
|
11959
|
+
throw new Error("job:fail missing _userId (gateway injection)");
|
|
11960
|
+
}
|
|
12579
11961
|
await this.kb.eventStore.appendEvent({
|
|
12580
11962
|
type: "job:failed",
|
|
12581
11963
|
resourceId: resourceId3(event.resourceId),
|
|
12582
|
-
userId: makeUserId(event.
|
|
11964
|
+
userId: makeUserId(event._userId),
|
|
12583
11965
|
version: 1,
|
|
12584
11966
|
payload: {
|
|
12585
11967
|
jobId: event.jobId,
|
|
12586
11968
|
jobType: event.jobType,
|
|
11969
|
+
...event.annotationId ? { annotationId: event.annotationId } : {},
|
|
12587
11970
|
error: event.error
|
|
12588
11971
|
}
|
|
12589
11972
|
});
|
|
@@ -12596,27 +11979,28 @@ var Stower = class {
|
|
|
12596
11979
|
};
|
|
12597
11980
|
|
|
12598
11981
|
// src/browser.ts
|
|
12599
|
-
var
|
|
12600
|
-
var
|
|
12601
|
-
import { promises as
|
|
12602
|
-
import * as
|
|
12603
|
-
import { resourceId as resourceId4, annotationId, errField as errField5 } from "@semiont/core";
|
|
12604
|
-
import {
|
|
11982
|
+
var import_rxjs5 = __toESM(require_cjs(), 1);
|
|
11983
|
+
var import_operators5 = __toESM(require_operators(), 1);
|
|
11984
|
+
import { promises as fs3 } from "fs";
|
|
11985
|
+
import * as path2 from "path";
|
|
11986
|
+
import { resourceId as resourceId4, annotationId as annotationId2, errField as errField5 } from "@semiont/core";
|
|
11987
|
+
import { withActorSpan as withActorSpan4 } from "@semiont/observability";
|
|
11988
|
+
import { getExactText, getTargetSource as getTargetSource2, getTargetSelector as getTargetSelector2, getResourceEntityTypes as getResourceEntityTypes5, getBodySource as getBodySource2 } from "@semiont/core";
|
|
12605
11989
|
import { EventQuery as EventQuery2 } from "@semiont/event-sourcing";
|
|
12606
11990
|
import { getEntityTypes as getEntityTypes2 } from "@semiont/ontology";
|
|
12607
11991
|
|
|
12608
11992
|
// src/views/entity-types-reader.ts
|
|
12609
|
-
import { promises as
|
|
12610
|
-
import * as
|
|
11993
|
+
import { promises as fs2 } from "fs";
|
|
11994
|
+
import * as path from "path";
|
|
12611
11995
|
async function readEntityTypesProjection(project) {
|
|
12612
|
-
const entityTypesPath =
|
|
11996
|
+
const entityTypesPath = path.join(
|
|
12613
11997
|
project.stateDir,
|
|
12614
11998
|
"projections",
|
|
12615
11999
|
"__system__",
|
|
12616
12000
|
"entitytypes.json"
|
|
12617
12001
|
);
|
|
12618
12002
|
try {
|
|
12619
|
-
const content = await
|
|
12003
|
+
const content = await fs2.readFile(entityTypesPath, "utf-8");
|
|
12620
12004
|
const projection = JSON.parse(content);
|
|
12621
12005
|
return projection.entityTypes || [];
|
|
12622
12006
|
} catch (error) {
|
|
@@ -12641,7 +12025,11 @@ var Browser = class {
|
|
|
12641
12025
|
async initialize() {
|
|
12642
12026
|
this.logger.info("Browser actor initialized");
|
|
12643
12027
|
const errorHandler = (err) => this.logger.error("Browser pipeline error", { error: err });
|
|
12644
|
-
const pipe = (name, handler) => this.eventBus.get(name).pipe(
|
|
12028
|
+
const pipe = (name, handler) => this.eventBus.get(name).pipe(
|
|
12029
|
+
(0, import_operators5.mergeMap)(
|
|
12030
|
+
(event) => (0, import_rxjs5.from)(withActorSpan4("browser", name, () => handler(event)))
|
|
12031
|
+
)
|
|
12032
|
+
);
|
|
12645
12033
|
this.subscriptions.push(
|
|
12646
12034
|
pipe("browse:resource-requested", (e) => this.handleBrowseResource(e)).subscribe({ error: errorHandler }),
|
|
12647
12035
|
pipe("browse:resources-requested", (e) => this.handleBrowseResources(e)).subscribe({ error: errorHandler }),
|
|
@@ -12740,7 +12128,7 @@ var Browser = class {
|
|
|
12740
12128
|
}
|
|
12741
12129
|
async handleBrowseAnnotation(event) {
|
|
12742
12130
|
try {
|
|
12743
|
-
const annotation = await AnnotationContext.getAnnotation(
|
|
12131
|
+
const annotation = await AnnotationContext.getAnnotation(annotationId2(event.annotationId), resourceId4(event.resourceId), this.kb);
|
|
12744
12132
|
if (!annotation) {
|
|
12745
12133
|
this.eventBus.get("browse:annotation-failed").next({
|
|
12746
12134
|
correlationId: event.correlationId,
|
|
@@ -12804,7 +12192,7 @@ var Browser = class {
|
|
|
12804
12192
|
}
|
|
12805
12193
|
async handleBrowseAnnotationHistory(event) {
|
|
12806
12194
|
try {
|
|
12807
|
-
const annotation = await AnnotationContext.getAnnotation(
|
|
12195
|
+
const annotation = await AnnotationContext.getAnnotation(annotationId2(event.annotationId), resourceId4(event.resourceId), this.kb);
|
|
12808
12196
|
if (!annotation) {
|
|
12809
12197
|
this.eventBus.get("browse:annotation-history-failed").next({
|
|
12810
12198
|
correlationId: event.correlationId,
|
|
@@ -12855,15 +12243,15 @@ var Browser = class {
|
|
|
12855
12243
|
const docMap = new Map(resources.filter((doc) => doc !== null).map((doc) => [doc["@id"], doc]));
|
|
12856
12244
|
const referencedBy = references.map((ref) => {
|
|
12857
12245
|
const targetSource = getTargetSource2(ref.target);
|
|
12858
|
-
const targetSelector =
|
|
12859
|
-
const doc = docMap.get(targetSource);
|
|
12246
|
+
const targetSelector = getTargetSelector2(ref.target);
|
|
12247
|
+
const doc = targetSource ? docMap.get(resourceId4(targetSource)) : void 0;
|
|
12860
12248
|
return {
|
|
12861
12249
|
id: ref.id,
|
|
12862
12250
|
resourceName: doc?.name || "Untitled Resource",
|
|
12863
12251
|
target: {
|
|
12864
12252
|
source: targetSource,
|
|
12865
12253
|
selector: {
|
|
12866
|
-
exact: targetSelector ?
|
|
12254
|
+
exact: targetSelector ? getExactText(targetSelector) : ""
|
|
12867
12255
|
}
|
|
12868
12256
|
}
|
|
12869
12257
|
};
|
|
@@ -12901,8 +12289,8 @@ var Browser = class {
|
|
|
12901
12289
|
async handleBrowseDirectory(event) {
|
|
12902
12290
|
const { correlationId, path: reqPath, sort = "name" } = event;
|
|
12903
12291
|
const projectRoot = this.project.root;
|
|
12904
|
-
const resolved =
|
|
12905
|
-
if (!resolved.startsWith(projectRoot +
|
|
12292
|
+
const resolved = path2.resolve(projectRoot, reqPath);
|
|
12293
|
+
if (!resolved.startsWith(projectRoot + path2.sep) && resolved !== projectRoot) {
|
|
12906
12294
|
this.eventBus.get("browse:directory-failed").next({
|
|
12907
12295
|
correlationId,
|
|
12908
12296
|
path: reqPath,
|
|
@@ -12912,7 +12300,7 @@ var Browser = class {
|
|
|
12912
12300
|
}
|
|
12913
12301
|
let dirents;
|
|
12914
12302
|
try {
|
|
12915
|
-
dirents = await
|
|
12303
|
+
dirents = await fs3.readdir(resolved, { withFileTypes: true, encoding: "utf8" });
|
|
12916
12304
|
} catch (err) {
|
|
12917
12305
|
const msg = err.code === "ENOENT" ? "path not found" : String(err);
|
|
12918
12306
|
this.eventBus.get("browse:directory-failed").next({
|
|
@@ -12926,16 +12314,16 @@ var Browser = class {
|
|
|
12926
12314
|
const allViews = await this.views.getAll();
|
|
12927
12315
|
const prefix = `file://${resolved}`;
|
|
12928
12316
|
const viewsByUri = new Map(
|
|
12929
|
-
allViews.filter((v) => v.resource.storageUri?.startsWith(prefix + "/") || v.resource.storageUri?.startsWith(prefix +
|
|
12317
|
+
allViews.filter((v) => v.resource.storageUri?.startsWith(prefix + "/") || v.resource.storageUri?.startsWith(prefix + path2.sep)).map((v) => [v.resource.storageUri, v])
|
|
12930
12318
|
);
|
|
12931
12319
|
const entries = [];
|
|
12932
12320
|
for (const dirent of visible) {
|
|
12933
|
-
const entryPath =
|
|
12934
|
-
const relPath =
|
|
12321
|
+
const entryPath = path2.join(resolved, dirent.name);
|
|
12322
|
+
const relPath = path2.relative(projectRoot, entryPath);
|
|
12935
12323
|
if (dirent.isDirectory()) {
|
|
12936
12324
|
let mtime = (/* @__PURE__ */ new Date(0)).toISOString();
|
|
12937
12325
|
try {
|
|
12938
|
-
const stat = await
|
|
12326
|
+
const stat = await fs3.stat(entryPath);
|
|
12939
12327
|
mtime = stat.mtime.toISOString();
|
|
12940
12328
|
} catch {
|
|
12941
12329
|
}
|
|
@@ -12945,7 +12333,7 @@ var Browser = class {
|
|
|
12945
12333
|
let size = 0;
|
|
12946
12334
|
let mtime = (/* @__PURE__ */ new Date(0)).toISOString();
|
|
12947
12335
|
try {
|
|
12948
|
-
const stat = await
|
|
12336
|
+
const stat = await fs3.stat(entryPath);
|
|
12949
12337
|
size = stat.size;
|
|
12950
12338
|
mtime = stat.mtime.toISOString();
|
|
12951
12339
|
} catch {
|
|
@@ -13000,33 +12388,51 @@ var Browser = class {
|
|
|
13000
12388
|
}
|
|
13001
12389
|
};
|
|
13002
12390
|
|
|
12391
|
+
// src/event-enrichment.ts
|
|
12392
|
+
function eventAnnotationId(event) {
|
|
12393
|
+
switch (event.type) {
|
|
12394
|
+
case "mark:added":
|
|
12395
|
+
return event.payload.annotation.id;
|
|
12396
|
+
case "mark:body-updated":
|
|
12397
|
+
return event.payload.annotationId;
|
|
12398
|
+
case "mark:removed":
|
|
12399
|
+
return event.payload.annotationId;
|
|
12400
|
+
default:
|
|
12401
|
+
return null;
|
|
12402
|
+
}
|
|
12403
|
+
}
|
|
12404
|
+
async function readAnnotationFromView(kb, resourceId10, annotationId5) {
|
|
12405
|
+
const allAnnotations = await AnnotationContext.getAllAnnotations(resourceId10, kb);
|
|
12406
|
+
return allAnnotations.find((a) => a.id === annotationId5) ?? null;
|
|
12407
|
+
}
|
|
12408
|
+
|
|
13003
12409
|
// src/clone-token-manager.ts
|
|
13004
|
-
var
|
|
13005
|
-
var
|
|
12410
|
+
var import_rxjs7 = __toESM(require_cjs(), 1);
|
|
12411
|
+
var import_operators7 = __toESM(require_operators(), 1);
|
|
13006
12412
|
import { CREATION_METHODS as CREATION_METHODS2, cloneToken as makeCloneToken, resourceId as resourceId5, userId as makeUserId2 } from "@semiont/core";
|
|
13007
|
-
import { getPrimaryRepresentation as getPrimaryRepresentation3, getResourceEntityTypes as getResourceEntityTypes6 } from "@semiont/
|
|
12413
|
+
import { getPrimaryRepresentation as getPrimaryRepresentation3, getResourceEntityTypes as getResourceEntityTypes6 } from "@semiont/core";
|
|
13008
12414
|
import { deriveStorageUri } from "@semiont/content";
|
|
13009
12415
|
|
|
13010
12416
|
// src/resource-operations.ts
|
|
13011
|
-
var
|
|
13012
|
-
var
|
|
13013
|
-
import { resourceId as
|
|
12417
|
+
var import_rxjs6 = __toESM(require_cjs(), 1);
|
|
12418
|
+
var import_operators6 = __toESM(require_operators(), 1);
|
|
12419
|
+
import { resourceId as makeResourceId3 } from "@semiont/core";
|
|
13014
12420
|
var ResourceOperations = class {
|
|
13015
12421
|
/**
|
|
13016
12422
|
* Create a new resource via EventBus → Stower
|
|
13017
12423
|
*/
|
|
13018
|
-
static async createResource(input,
|
|
13019
|
-
const result$ = (0,
|
|
12424
|
+
static async createResource(input, userId3, eventBus) {
|
|
12425
|
+
const result$ = (0, import_rxjs6.race)(
|
|
13020
12426
|
eventBus.get("yield:create-ok").pipe(
|
|
13021
|
-
(0,
|
|
13022
|
-
(0,
|
|
12427
|
+
(0, import_operators6.take)(1),
|
|
12428
|
+
(0, import_operators6.map)((result) => ({ ok: true, result }))
|
|
13023
12429
|
),
|
|
13024
12430
|
eventBus.get("yield:create-failed").pipe(
|
|
13025
|
-
(0,
|
|
13026
|
-
(0,
|
|
12431
|
+
(0, import_operators6.take)(1),
|
|
12432
|
+
(0, import_operators6.map)((failure) => ({ ok: false, error: new Error(failure.message) }))
|
|
13027
12433
|
),
|
|
13028
|
-
(0,
|
|
13029
|
-
(0,
|
|
12434
|
+
(0, import_rxjs6.timer)(3e4).pipe(
|
|
12435
|
+
(0, import_operators6.map)(() => ({ ok: false, error: new Error("Resource creation timed out") }))
|
|
13030
12436
|
)
|
|
13031
12437
|
);
|
|
13032
12438
|
eventBus.get("yield:create").next({
|
|
@@ -13035,36 +12441,20 @@ var ResourceOperations = class {
|
|
|
13035
12441
|
contentChecksum: input.contentChecksum,
|
|
13036
12442
|
byteSize: input.byteSize,
|
|
13037
12443
|
format: input.format,
|
|
13038
|
-
|
|
12444
|
+
_userId: userId3,
|
|
13039
12445
|
language: input.language,
|
|
13040
12446
|
entityTypes: input.entityTypes,
|
|
13041
|
-
creationMethod: input.creationMethod
|
|
12447
|
+
creationMethod: input.creationMethod,
|
|
12448
|
+
generatedFrom: input.generatedFrom,
|
|
12449
|
+
generationPrompt: input.generationPrompt,
|
|
12450
|
+
generator: input.generator,
|
|
12451
|
+
isDraft: input.isDraft
|
|
13042
12452
|
});
|
|
13043
|
-
const outcome = await (0,
|
|
12453
|
+
const outcome = await (0, import_rxjs6.firstValueFrom)(result$);
|
|
13044
12454
|
if (!outcome.ok) {
|
|
13045
12455
|
throw outcome.error;
|
|
13046
12456
|
}
|
|
13047
|
-
return
|
|
13048
|
-
}
|
|
13049
|
-
/**
|
|
13050
|
-
* Update resource metadata via EventBus → Stower
|
|
13051
|
-
*/
|
|
13052
|
-
static async updateResource(input, eventBus) {
|
|
13053
|
-
if (input.updatedArchived !== void 0 && input.updatedArchived !== input.currentArchived) {
|
|
13054
|
-
if (input.updatedArchived) {
|
|
13055
|
-
eventBus.get("mark:archive").next({ userId: input.userId, resourceId: input.resourceId });
|
|
13056
|
-
} else {
|
|
13057
|
-
eventBus.get("mark:unarchive").next({ userId: input.userId, resourceId: input.resourceId });
|
|
13058
|
-
}
|
|
13059
|
-
}
|
|
13060
|
-
if (input.updatedEntityTypes && input.currentEntityTypes) {
|
|
13061
|
-
eventBus.get("mark:update-entity-types").next({
|
|
13062
|
-
resourceId: input.resourceId,
|
|
13063
|
-
userId: input.userId,
|
|
13064
|
-
currentEntityTypes: input.currentEntityTypes,
|
|
13065
|
-
updatedEntityTypes: input.updatedEntityTypes
|
|
13066
|
-
});
|
|
13067
|
-
}
|
|
12457
|
+
return makeResourceId3(outcome.result.resourceId);
|
|
13068
12458
|
}
|
|
13069
12459
|
};
|
|
13070
12460
|
|
|
@@ -13082,13 +12472,13 @@ var CloneTokenManager = class {
|
|
|
13082
12472
|
this.logger.info("CloneTokenManager actor initialized");
|
|
13083
12473
|
const errorHandler = (err) => this.logger.error("CloneTokenManager pipeline error", { error: err });
|
|
13084
12474
|
const generateToken$ = this.eventBus.get("yield:clone-token-requested").pipe(
|
|
13085
|
-
(0,
|
|
12475
|
+
(0, import_operators7.mergeMap)((event) => (0, import_rxjs7.from)(this.handleGenerateToken(event)))
|
|
13086
12476
|
);
|
|
13087
12477
|
const getResource$ = this.eventBus.get("yield:clone-resource-requested").pipe(
|
|
13088
|
-
(0,
|
|
12478
|
+
(0, import_operators7.mergeMap)((event) => (0, import_rxjs7.from)(this.handleGetResource(event)))
|
|
13089
12479
|
);
|
|
13090
12480
|
const createResource$ = this.eventBus.get("yield:clone-create").pipe(
|
|
13091
|
-
(0,
|
|
12481
|
+
(0, import_operators7.mergeMap)((event) => (0, import_rxjs7.from)(this.handleCreateResource(event)))
|
|
13092
12482
|
);
|
|
13093
12483
|
this.subscriptions.push(
|
|
13094
12484
|
generateToken$.subscribe({ error: errorHandler }),
|
|
@@ -13230,16 +12620,11 @@ var CloneTokenManager = class {
|
|
|
13230
12620
|
makeUserId2(event.userId),
|
|
13231
12621
|
this.eventBus
|
|
13232
12622
|
);
|
|
13233
|
-
if (event.archiveOriginal) {
|
|
13234
|
-
|
|
13235
|
-
|
|
13236
|
-
|
|
13237
|
-
|
|
13238
|
-
currentArchived: sourceDoc.archived,
|
|
13239
|
-
updatedArchived: true
|
|
13240
|
-
},
|
|
13241
|
-
this.eventBus
|
|
13242
|
-
);
|
|
12623
|
+
if (event.archiveOriginal && !sourceDoc.archived) {
|
|
12624
|
+
this.eventBus.get("mark:archive").next({
|
|
12625
|
+
_userId: event.userId,
|
|
12626
|
+
resourceId: tokenData.resourceId
|
|
12627
|
+
});
|
|
13243
12628
|
}
|
|
13244
12629
|
this.tokens.delete(token);
|
|
13245
12630
|
this.eventBus.get("yield:clone-created").next({
|
|
@@ -13265,8 +12650,8 @@ var CloneTokenManager = class {
|
|
|
13265
12650
|
};
|
|
13266
12651
|
|
|
13267
12652
|
// src/bootstrap/entity-types.ts
|
|
13268
|
-
var
|
|
13269
|
-
var
|
|
12653
|
+
var import_rxjs8 = __toESM(require_cjs(), 1);
|
|
12654
|
+
var import_operators8 = __toESM(require_operators(), 1);
|
|
13270
12655
|
import { DEFAULT_ENTITY_TYPES } from "@semiont/ontology";
|
|
13271
12656
|
import { userId, resourceId as resourceId6 } from "@semiont/core";
|
|
13272
12657
|
async function bootstrapEntityTypes(eventBus, eventStore, logger) {
|
|
@@ -13281,15 +12666,15 @@ async function bootstrapEntityTypes(eventBus, eventStore, logger) {
|
|
|
13281
12666
|
}
|
|
13282
12667
|
logger?.info("Bootstrapping missing entity types", { missing: missing.length, existing: existingTypes.size });
|
|
13283
12668
|
const SYSTEM_USER_ID = userId("00000000-0000-0000-0000-000000000000");
|
|
13284
|
-
for (const
|
|
13285
|
-
logger?.debug("Adding entity type via EventBus", { entityType });
|
|
13286
|
-
const result$ = (0,
|
|
13287
|
-
eventBus.get("mark:entity-type-added").pipe((0,
|
|
13288
|
-
eventBus.get("mark:entity-type-add-failed").pipe((0,
|
|
13289
|
-
(0,
|
|
12669
|
+
for (const entityType2 of missing) {
|
|
12670
|
+
logger?.debug("Adding entity type via EventBus", { entityType: entityType2 });
|
|
12671
|
+
const result$ = (0, import_rxjs8.race)(
|
|
12672
|
+
eventBus.get("mark:entity-type-added").pipe((0, import_operators8.take)(1), (0, import_operators8.map)(() => ({ ok: true }))),
|
|
12673
|
+
eventBus.get("mark:entity-type-add-failed").pipe((0, import_operators8.take)(1), (0, import_operators8.map)((f) => ({ ok: false, error: new Error(f.message) }))),
|
|
12674
|
+
(0, import_rxjs8.timer)(1e4).pipe((0, import_operators8.map)(() => ({ ok: false, error: new Error(`Timeout adding entity type: ${entityType2}`) })))
|
|
13290
12675
|
);
|
|
13291
|
-
eventBus.get("mark:add-entity-type").next({ tag:
|
|
13292
|
-
const outcome = await (0,
|
|
12676
|
+
eventBus.get("mark:add-entity-type").next({ tag: entityType2, _userId: SYSTEM_USER_ID });
|
|
12677
|
+
const outcome = await (0, import_rxjs8.firstValueFrom)(result$);
|
|
13293
12678
|
if (!outcome.ok) {
|
|
13294
12679
|
throw outcome.error;
|
|
13295
12680
|
}
|
|
@@ -13308,15 +12693,281 @@ async function stopKnowledgeSystem(ks) {
|
|
|
13308
12693
|
await ks.kb.graph.disconnect();
|
|
13309
12694
|
}
|
|
13310
12695
|
|
|
12696
|
+
// src/handlers/annotation-assembly.ts
|
|
12697
|
+
import { resourceId as resourceId7, didToAgent as didToAgent2, assembleAnnotation } from "@semiont/core";
|
|
12698
|
+
function registerAnnotationAssemblyHandler(eventBus, parentLogger) {
|
|
12699
|
+
const logger = parentLogger.child({ component: "annotation-assembly" });
|
|
12700
|
+
const inflight = /* @__PURE__ */ new Map();
|
|
12701
|
+
eventBus.get("mark:create-request").subscribe((command) => {
|
|
12702
|
+
const { correlationId, resourceId: resId, request, _userId } = command;
|
|
12703
|
+
const cid = correlationId;
|
|
12704
|
+
try {
|
|
12705
|
+
if (!_userId || typeof _userId !== "string") {
|
|
12706
|
+
throw new Error("_userId is required (injected by bus gateway)");
|
|
12707
|
+
}
|
|
12708
|
+
if (!cid) {
|
|
12709
|
+
throw new Error("correlationId is required on mark:create-request");
|
|
12710
|
+
}
|
|
12711
|
+
const agent = didToAgent2(_userId);
|
|
12712
|
+
const { annotation } = assembleAnnotation(request, agent);
|
|
12713
|
+
inflight.set(cid, { annotationId: annotation.id });
|
|
12714
|
+
eventBus.get("mark:create").next({
|
|
12715
|
+
correlationId: cid,
|
|
12716
|
+
annotation,
|
|
12717
|
+
_userId,
|
|
12718
|
+
resourceId: resourceId7(resId)
|
|
12719
|
+
});
|
|
12720
|
+
logger.info("Annotation assembled, awaiting persistence", {
|
|
12721
|
+
annotationId: annotation.id,
|
|
12722
|
+
correlationId: cid
|
|
12723
|
+
});
|
|
12724
|
+
} catch (error) {
|
|
12725
|
+
logger.warn("mark:create-request failed during assembly", {
|
|
12726
|
+
correlationId: cid,
|
|
12727
|
+
error: error.message
|
|
12728
|
+
});
|
|
12729
|
+
eventBus.get("mark:create-failed").next({
|
|
12730
|
+
correlationId: cid,
|
|
12731
|
+
message: error.message
|
|
12732
|
+
});
|
|
12733
|
+
}
|
|
12734
|
+
});
|
|
12735
|
+
eventBus.get("mark:added").subscribe((event) => {
|
|
12736
|
+
const cid = event.metadata?.correlationId;
|
|
12737
|
+
if (!cid) return;
|
|
12738
|
+
const pending = inflight.get(cid);
|
|
12739
|
+
if (!pending) return;
|
|
12740
|
+
inflight.delete(cid);
|
|
12741
|
+
eventBus.get("mark:create-ok").next({
|
|
12742
|
+
correlationId: cid,
|
|
12743
|
+
response: { annotationId: pending.annotationId }
|
|
12744
|
+
});
|
|
12745
|
+
logger.info("Annotation persisted", { annotationId: pending.annotationId, correlationId: cid });
|
|
12746
|
+
});
|
|
12747
|
+
eventBus.get("mark:create-failed").subscribe((event) => {
|
|
12748
|
+
const cid = event.correlationId;
|
|
12749
|
+
if (!cid || !inflight.has(cid)) return;
|
|
12750
|
+
inflight.delete(cid);
|
|
12751
|
+
});
|
|
12752
|
+
}
|
|
12753
|
+
|
|
12754
|
+
// src/handlers/annotation-lookups.ts
|
|
12755
|
+
import { annotationId as makeAnnotationId3, resourceId as makeResourceId4 } from "@semiont/core";
|
|
12756
|
+
function registerAnnotationLookupHandlers(eventBus, kb, gatherer, parentLogger) {
|
|
12757
|
+
const logger = parentLogger.child({ component: "annotation-lookups" });
|
|
12758
|
+
eventBus.get("browse:annotation-context-requested").subscribe(async (command) => {
|
|
12759
|
+
const { correlationId } = command;
|
|
12760
|
+
const annId = command.annotationId;
|
|
12761
|
+
const resId = command.resourceId;
|
|
12762
|
+
const contextBefore = command.contextBefore ?? 100;
|
|
12763
|
+
const contextAfter = command.contextAfter ?? 100;
|
|
12764
|
+
try {
|
|
12765
|
+
const response = await AnnotationContext.getAnnotationContext(
|
|
12766
|
+
makeAnnotationId3(annId),
|
|
12767
|
+
makeResourceId4(resId),
|
|
12768
|
+
contextBefore,
|
|
12769
|
+
contextAfter,
|
|
12770
|
+
kb
|
|
12771
|
+
);
|
|
12772
|
+
eventBus.get("browse:annotation-context-result").next({
|
|
12773
|
+
correlationId,
|
|
12774
|
+
response
|
|
12775
|
+
});
|
|
12776
|
+
} catch (error) {
|
|
12777
|
+
logger.warn("annotation-context failed", { correlationId, error: error.message });
|
|
12778
|
+
eventBus.get("browse:annotation-context-failed").next({
|
|
12779
|
+
correlationId,
|
|
12780
|
+
message: error.message
|
|
12781
|
+
});
|
|
12782
|
+
}
|
|
12783
|
+
});
|
|
12784
|
+
eventBus.get("gather:summary-requested").subscribe(async (command) => {
|
|
12785
|
+
const { correlationId } = command;
|
|
12786
|
+
const annId = command.annotationId;
|
|
12787
|
+
const resId = command.resourceId;
|
|
12788
|
+
try {
|
|
12789
|
+
const response = await gatherer.generateAnnotationSummary(
|
|
12790
|
+
makeAnnotationId3(annId),
|
|
12791
|
+
makeResourceId4(resId)
|
|
12792
|
+
);
|
|
12793
|
+
eventBus.get("gather:summary-result").next({
|
|
12794
|
+
correlationId,
|
|
12795
|
+
response
|
|
12796
|
+
});
|
|
12797
|
+
} catch (error) {
|
|
12798
|
+
logger.warn("gather:summary failed", { correlationId, error: error.message });
|
|
12799
|
+
eventBus.get("gather:summary-failed").next({
|
|
12800
|
+
correlationId,
|
|
12801
|
+
message: error.message
|
|
12802
|
+
});
|
|
12803
|
+
}
|
|
12804
|
+
});
|
|
12805
|
+
}
|
|
12806
|
+
|
|
12807
|
+
// src/handlers/bind-update-body.ts
|
|
12808
|
+
import { resourceId as resourceId8, annotationId as annotationId3 } from "@semiont/core";
|
|
12809
|
+
function registerBindUpdateBodyHandler(eventBus, parentLogger) {
|
|
12810
|
+
const logger = parentLogger.child({ component: "bind-update-body" });
|
|
12811
|
+
const inflight = /* @__PURE__ */ new Set();
|
|
12812
|
+
eventBus.get("bind:update-body").subscribe((command) => {
|
|
12813
|
+
const { correlationId, annotationId: annId, resourceId: resId, operations, _userId } = command;
|
|
12814
|
+
const cid = correlationId;
|
|
12815
|
+
try {
|
|
12816
|
+
if (!_userId || typeof _userId !== "string") {
|
|
12817
|
+
throw new Error("_userId is required (injected by bus gateway)");
|
|
12818
|
+
}
|
|
12819
|
+
if (!cid) {
|
|
12820
|
+
throw new Error("correlationId is required on bind:update-body");
|
|
12821
|
+
}
|
|
12822
|
+
inflight.add(cid);
|
|
12823
|
+
eventBus.get("mark:update-body").next({
|
|
12824
|
+
correlationId: cid,
|
|
12825
|
+
annotationId: annotationId3(annId),
|
|
12826
|
+
_userId,
|
|
12827
|
+
resourceId: resourceId8(resId),
|
|
12828
|
+
operations
|
|
12829
|
+
});
|
|
12830
|
+
logger.info("Bind update-body forwarded to mark:update-body, awaiting persistence", {
|
|
12831
|
+
annotationId: annId,
|
|
12832
|
+
correlationId: cid
|
|
12833
|
+
});
|
|
12834
|
+
} catch (error) {
|
|
12835
|
+
logger.warn("bind:update-body failed before forwarding", {
|
|
12836
|
+
correlationId: cid,
|
|
12837
|
+
error: error.message
|
|
12838
|
+
});
|
|
12839
|
+
eventBus.get("bind:body-update-failed").next({
|
|
12840
|
+
correlationId: cid,
|
|
12841
|
+
message: error.message
|
|
12842
|
+
});
|
|
12843
|
+
}
|
|
12844
|
+
});
|
|
12845
|
+
eventBus.get("mark:body-updated").subscribe((event) => {
|
|
12846
|
+
const cid = event.metadata?.correlationId;
|
|
12847
|
+
if (!cid || !inflight.has(cid)) return;
|
|
12848
|
+
inflight.delete(cid);
|
|
12849
|
+
const annId = event.payload?.annotationId;
|
|
12850
|
+
eventBus.get("bind:body-updated").next({
|
|
12851
|
+
correlationId: cid,
|
|
12852
|
+
annotationId: annId
|
|
12853
|
+
});
|
|
12854
|
+
logger.info("Bind body-updated confirmed", { annotationId: annId, correlationId: cid });
|
|
12855
|
+
});
|
|
12856
|
+
eventBus.get("mark:body-update-failed").subscribe((event) => {
|
|
12857
|
+
const cid = event.correlationId;
|
|
12858
|
+
if (!cid || !inflight.has(cid)) return;
|
|
12859
|
+
inflight.delete(cid);
|
|
12860
|
+
const message = event.message ?? "Unknown error";
|
|
12861
|
+
eventBus.get("bind:body-update-failed").next({
|
|
12862
|
+
correlationId: cid,
|
|
12863
|
+
message
|
|
12864
|
+
});
|
|
12865
|
+
logger.warn("Bind body-update failed after forwarding", { correlationId: cid, message });
|
|
12866
|
+
});
|
|
12867
|
+
}
|
|
12868
|
+
|
|
12869
|
+
// src/handlers/job-commands.ts
|
|
12870
|
+
import { generateUuid as generateUuid2, jobId, userId as userId2, resourceId as resourceId9, entityType } from "@semiont/core";
|
|
12871
|
+
function parseDidUser(did) {
|
|
12872
|
+
const parts = did.split(":");
|
|
12873
|
+
const usersIdx = parts.indexOf("users");
|
|
12874
|
+
const domain = parts.slice(2, usersIdx).join(":");
|
|
12875
|
+
const email = decodeURIComponent(parts.slice(usersIdx + 1).join(":"));
|
|
12876
|
+
return { userId: did, email, domain };
|
|
12877
|
+
}
|
|
12878
|
+
function registerJobCommandHandlers(eventBus, jobQueue, parentLogger) {
|
|
12879
|
+
const logger = parentLogger.child({ component: "job-commands" });
|
|
12880
|
+
eventBus.get("job:create").subscribe(async (command) => {
|
|
12881
|
+
const { correlationId, jobType, resourceId: resId, params, _userId } = command;
|
|
12882
|
+
try {
|
|
12883
|
+
if (!_userId || typeof _userId !== "string") {
|
|
12884
|
+
throw new Error("_userId is required (injected by bus gateway)");
|
|
12885
|
+
}
|
|
12886
|
+
const user = parseDidUser(_userId);
|
|
12887
|
+
const job = {
|
|
12888
|
+
status: "pending",
|
|
12889
|
+
metadata: {
|
|
12890
|
+
id: jobId(`job-${generateUuid2()}`),
|
|
12891
|
+
type: jobType,
|
|
12892
|
+
userId: userId2(_userId),
|
|
12893
|
+
userName: user.email,
|
|
12894
|
+
userEmail: user.email,
|
|
12895
|
+
userDomain: user.domain,
|
|
12896
|
+
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
12897
|
+
retryCount: 0,
|
|
12898
|
+
maxRetries: jobType === "generation" ? 3 : 1
|
|
12899
|
+
},
|
|
12900
|
+
params: {
|
|
12901
|
+
resourceId: resourceId9(resId),
|
|
12902
|
+
...params
|
|
12903
|
+
}
|
|
12904
|
+
};
|
|
12905
|
+
const jobParams = job.params;
|
|
12906
|
+
if (jobType === "reference-annotation" && jobParams.entityTypes) {
|
|
12907
|
+
jobParams.entityTypes = jobParams.entityTypes.map((et) => entityType(et));
|
|
12908
|
+
}
|
|
12909
|
+
await jobQueue.createJob(job);
|
|
12910
|
+
logger.info("Job created via bus", { jobId: job.metadata.id, jobType, correlationId });
|
|
12911
|
+
eventBus.get("job:created").next({
|
|
12912
|
+
correlationId,
|
|
12913
|
+
response: { jobId: job.metadata.id }
|
|
12914
|
+
});
|
|
12915
|
+
} catch (error) {
|
|
12916
|
+
logger.error("job:create failed", { correlationId, error: error.message });
|
|
12917
|
+
eventBus.get("job:create-failed").next({
|
|
12918
|
+
correlationId,
|
|
12919
|
+
message: error.message
|
|
12920
|
+
});
|
|
12921
|
+
}
|
|
12922
|
+
});
|
|
12923
|
+
eventBus.get("job:claim").subscribe(async (command) => {
|
|
12924
|
+
const { correlationId, jobId: jid } = command;
|
|
12925
|
+
try {
|
|
12926
|
+
const job = await jobQueue.getJob(jobId(jid));
|
|
12927
|
+
if (!job) {
|
|
12928
|
+
throw new Error("Job not found");
|
|
12929
|
+
}
|
|
12930
|
+
if (job.status !== "pending") {
|
|
12931
|
+
throw new Error("Job already claimed");
|
|
12932
|
+
}
|
|
12933
|
+
const runningJob = {
|
|
12934
|
+
...job,
|
|
12935
|
+
status: "running",
|
|
12936
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
12937
|
+
progress: {}
|
|
12938
|
+
};
|
|
12939
|
+
await jobQueue.updateJob(runningJob, "pending");
|
|
12940
|
+
eventBus.get("job:claimed").next({
|
|
12941
|
+
correlationId,
|
|
12942
|
+
response: runningJob
|
|
12943
|
+
});
|
|
12944
|
+
} catch (error) {
|
|
12945
|
+
eventBus.get("job:claim-failed").next({
|
|
12946
|
+
correlationId,
|
|
12947
|
+
message: error.message
|
|
12948
|
+
});
|
|
12949
|
+
}
|
|
12950
|
+
});
|
|
12951
|
+
}
|
|
12952
|
+
|
|
12953
|
+
// src/handlers/index.ts
|
|
12954
|
+
function registerBusHandlers(eventBus, knowledgeSystem, jobQueue, logger) {
|
|
12955
|
+
registerAnnotationAssemblyHandler(eventBus, logger);
|
|
12956
|
+
registerAnnotationLookupHandlers(eventBus, knowledgeSystem.kb, knowledgeSystem.gatherer, logger);
|
|
12957
|
+
registerBindUpdateBodyHandler(eventBus, logger);
|
|
12958
|
+
registerJobCommandHandlers(eventBus, jobQueue, logger);
|
|
12959
|
+
}
|
|
12960
|
+
|
|
13311
12961
|
// src/service.ts
|
|
13312
12962
|
async function createJobQueue(project, eventBus, logger) {
|
|
13313
12963
|
const jobQueueLogger = logger.child({ component: "job-queue" });
|
|
13314
|
-
const jobQueue = new
|
|
12964
|
+
const jobQueue = new FsJobQueue(project, jobQueueLogger, eventBus);
|
|
13315
12965
|
await jobQueue.initialize();
|
|
12966
|
+
registerJobQueueProvider(() => jobQueue.getStats());
|
|
13316
12967
|
const jobStatusSubscription = eventBus.get("job:status-requested").pipe(
|
|
13317
|
-
(0,
|
|
12968
|
+
(0, import_operators9.mergeMap)((event) => (0, import_rxjs9.from)((async () => {
|
|
13318
12969
|
try {
|
|
13319
|
-
const job = await jobQueue.getJob(
|
|
12970
|
+
const job = await jobQueue.getJob(jobId2(event.jobId));
|
|
13320
12971
|
if (!job) {
|
|
13321
12972
|
eventBus.get("job:status-failed").next({ correlationId: event.correlationId, message: "Job not found" });
|
|
13322
12973
|
return;
|
|
@@ -13373,13 +13024,15 @@ async function createKnowledgeSystemFromConfig(project, config, eventBus, logger
|
|
|
13373
13024
|
}
|
|
13374
13025
|
const kb = await createKnowledgeBase(eventStore, project, graphDb, eventBus, logger, {
|
|
13375
13026
|
vectorStore,
|
|
13376
|
-
embeddingProvider,
|
|
13377
|
-
chunkingConfig: embeddingConfig?.chunking ? {
|
|
13378
|
-
chunkSize: embeddingConfig.chunking.chunkSize ?? 512,
|
|
13379
|
-
overlap: embeddingConfig.chunking.overlap ?? 64
|
|
13380
|
-
} : void 0,
|
|
13381
13027
|
skipRebuild
|
|
13382
13028
|
});
|
|
13029
|
+
eventStore.setEnrichEvent(async (event, resourceId10) => {
|
|
13030
|
+
const annId = eventAnnotationId(event);
|
|
13031
|
+
if (annId === null) return event;
|
|
13032
|
+
const annotation = await readAnnotationFromView(kb, resourceId10, annId);
|
|
13033
|
+
if (annotation === null) return event;
|
|
13034
|
+
return { ...event, annotation };
|
|
13035
|
+
});
|
|
13383
13036
|
const stower = new Stower(kb, eventBus, logger.child({ component: "stower" }));
|
|
13384
13037
|
await stower.initialize();
|
|
13385
13038
|
await bootstrapEntityTypes(eventBus, eventStore, logger.child({ component: "entity-types-bootstrap" }));
|
|
@@ -13406,57 +13059,6 @@ async function createKnowledgeSystemFromConfig(project, config, eventBus, logger
|
|
|
13406
13059
|
const ks = { kb, stower, gatherer, matcher, browser, cloneTokenManager, stop: () => stopKnowledgeSystem(ks) };
|
|
13407
13060
|
return ks;
|
|
13408
13061
|
}
|
|
13409
|
-
function createContentFetcher(ks) {
|
|
13410
|
-
return async (resourceId7) => {
|
|
13411
|
-
const view = await ks.kb.views.get(resourceId7);
|
|
13412
|
-
if (!view?.resource.storageUri) return null;
|
|
13413
|
-
const buffer = await ks.kb.content.retrieve(view.resource.storageUri);
|
|
13414
|
-
if (!buffer) return null;
|
|
13415
|
-
return Readable.from([buffer]);
|
|
13416
|
-
};
|
|
13417
|
-
}
|
|
13418
|
-
function createWorkers(jobQueue, contentFetcher, contentStore, eventBus, config, logger) {
|
|
13419
|
-
const detection = (() => {
|
|
13420
|
-
const cfg = resolveWorkerInference(config, "reference-annotation");
|
|
13421
|
-
return new ReferenceAnnotationWorker(jobQueue, createInferenceClient(cfg, logger.child({ component: "inference-client-reference-annotation" })), inferenceConfigToGenerator("Reference Worker", cfg), eventBus, contentFetcher, logger.child({ component: "reference-detection-worker" }));
|
|
13422
|
-
})();
|
|
13423
|
-
const generation = (() => {
|
|
13424
|
-
const cfg = resolveWorkerInference(config, "generation");
|
|
13425
|
-
return new GenerationWorker(jobQueue, createInferenceClient(cfg, logger.child({ component: "inference-client-generation" })), inferenceConfigToGenerator("Generation Worker", cfg), eventBus, contentStore, logger.child({ component: "generation-worker" }));
|
|
13426
|
-
})();
|
|
13427
|
-
const highlight = (() => {
|
|
13428
|
-
const cfg = resolveWorkerInference(config, "highlight-annotation");
|
|
13429
|
-
return new HighlightAnnotationWorker(jobQueue, createInferenceClient(cfg, logger.child({ component: "inference-client-highlight-annotation" })), inferenceConfigToGenerator("Highlight Worker", cfg), eventBus, contentFetcher, logger.child({ component: "highlight-detection-worker" }));
|
|
13430
|
-
})();
|
|
13431
|
-
const assessment = (() => {
|
|
13432
|
-
const cfg = resolveWorkerInference(config, "assessment-annotation");
|
|
13433
|
-
return new AssessmentAnnotationWorker(jobQueue, createInferenceClient(cfg, logger.child({ component: "inference-client-assessment-annotation" })), inferenceConfigToGenerator("Assessment Worker", cfg), eventBus, contentFetcher, logger.child({ component: "assessment-detection-worker" }));
|
|
13434
|
-
})();
|
|
13435
|
-
const comment = (() => {
|
|
13436
|
-
const cfg = resolveWorkerInference(config, "comment-annotation");
|
|
13437
|
-
return new CommentAnnotationWorker(jobQueue, createInferenceClient(cfg, logger.child({ component: "inference-client-comment-annotation" })), inferenceConfigToGenerator("Comment Worker", cfg), eventBus, contentFetcher, logger.child({ component: "comment-detection-worker" }));
|
|
13438
|
-
})();
|
|
13439
|
-
const tag = (() => {
|
|
13440
|
-
const cfg = resolveWorkerInference(config, "tag-annotation");
|
|
13441
|
-
return new TagAnnotationWorker(jobQueue, createInferenceClient(cfg, logger.child({ component: "inference-client-tag-annotation" })), inferenceConfigToGenerator("Tag Worker", cfg), eventBus, contentFetcher, logger.child({ component: "tag-detection-worker" }));
|
|
13442
|
-
})();
|
|
13443
|
-
return { detection, generation, highlight, assessment, comment, tag };
|
|
13444
|
-
}
|
|
13445
|
-
function startWorkers(workers, logger) {
|
|
13446
|
-
const entries = [
|
|
13447
|
-
["detection", "reference-detection-worker"],
|
|
13448
|
-
["generation", "generation-worker"],
|
|
13449
|
-
["highlight", "highlight-detection-worker"],
|
|
13450
|
-
["assessment", "assessment-detection-worker"],
|
|
13451
|
-
["comment", "comment-detection-worker"],
|
|
13452
|
-
["tag", "tag-detection-worker"]
|
|
13453
|
-
];
|
|
13454
|
-
for (const [key, component] of entries) {
|
|
13455
|
-
workers[key].start().catch((error) => {
|
|
13456
|
-
logger.child({ component }).error("Worker stopped unexpectedly", { error });
|
|
13457
|
-
});
|
|
13458
|
-
}
|
|
13459
|
-
}
|
|
13460
13062
|
async function startMakeMeaning(project, config, eventBus, logger, options) {
|
|
13461
13063
|
if (!config.services?.graph) {
|
|
13462
13064
|
throw new Error("services.graph is required for make-meaning service");
|
|
@@ -13464,16 +13066,12 @@ async function startMakeMeaning(project, config, eventBus, logger, options) {
|
|
|
13464
13066
|
const skipRebuild = options?.skipRebuild ?? process.env.SEMIONT_SKIP_REBUILD === "true";
|
|
13465
13067
|
const { jobQueue, jobStatusSubscription } = await createJobQueue(project, eventBus, logger);
|
|
13466
13068
|
const knowledgeSystem = await createKnowledgeSystemFromConfig(project, config, eventBus, logger, skipRebuild);
|
|
13467
|
-
|
|
13468
|
-
const workers = createWorkers(jobQueue, contentFetcher, knowledgeSystem.kb.content, eventBus, config, logger);
|
|
13469
|
-
startWorkers(workers, logger);
|
|
13069
|
+
registerBusHandlers(eventBus, knowledgeSystem, jobQueue, logger);
|
|
13470
13070
|
return {
|
|
13471
13071
|
knowledgeSystem,
|
|
13472
13072
|
jobQueue,
|
|
13473
|
-
workers,
|
|
13474
13073
|
stop: async () => {
|
|
13475
13074
|
logger.info("Stopping Make-Meaning service");
|
|
13476
|
-
await Promise.all(Object.values(workers).map((w) => w.stop()));
|
|
13477
13075
|
jobStatusSubscription.unsubscribe();
|
|
13478
13076
|
await knowledgeSystem.stop();
|
|
13479
13077
|
logger.info("Make-Meaning service stopped");
|
|
@@ -13481,12 +13079,218 @@ async function startMakeMeaning(project, config, eventBus, logger, options) {
|
|
|
13481
13079
|
};
|
|
13482
13080
|
}
|
|
13483
13081
|
|
|
13082
|
+
// src/local-transport.ts
|
|
13083
|
+
var import_rxjs10 = __toESM(require_cjs(), 1);
|
|
13084
|
+
import { baseUrl as makeBaseUrl, busLog } from "@semiont/core";
|
|
13085
|
+
import { SpanKind, recordBusEmit, withSpan } from "@semiont/observability";
|
|
13086
|
+
import {
|
|
13087
|
+
BRIDGED_CHANNELS
|
|
13088
|
+
} from "@semiont/core";
|
|
13089
|
+
var NOT_SUPPORTED = (method) => new Error(`LocalTransport does not support ${method}() \u2014 local mode runs as a single host-process identity`);
|
|
13090
|
+
var LocalTransport = class {
|
|
13091
|
+
baseUrl;
|
|
13092
|
+
state$;
|
|
13093
|
+
bus;
|
|
13094
|
+
userId;
|
|
13095
|
+
bridges = [];
|
|
13096
|
+
bridgeSubs = [];
|
|
13097
|
+
disposed = false;
|
|
13098
|
+
constructor(cfg) {
|
|
13099
|
+
this.bus = cfg.eventBus;
|
|
13100
|
+
this.userId = cfg.userId;
|
|
13101
|
+
this.baseUrl = cfg.baseUrl ?? makeBaseUrl("local://in-process");
|
|
13102
|
+
this.state$ = new import_rxjs10.BehaviorSubject("open");
|
|
13103
|
+
}
|
|
13104
|
+
// ── Bus primitives ──────────────────────────────────────────────────────
|
|
13105
|
+
async emit(channel, payload, resourceScope) {
|
|
13106
|
+
busLog("EMIT", channel, payload, resourceScope);
|
|
13107
|
+
recordBusEmit(channel, resourceScope);
|
|
13108
|
+
await withSpan(
|
|
13109
|
+
`bus.emit:${channel}`,
|
|
13110
|
+
() => {
|
|
13111
|
+
const stamped = { ...payload, _userId: this.userId };
|
|
13112
|
+
const target = resourceScope === void 0 ? this.bus.get(channel) : this.bus.scope(resourceScope).get(channel);
|
|
13113
|
+
target.next(stamped);
|
|
13114
|
+
},
|
|
13115
|
+
{
|
|
13116
|
+
kind: SpanKind.PRODUCER,
|
|
13117
|
+
attrs: {
|
|
13118
|
+
"bus.channel": channel,
|
|
13119
|
+
...resourceScope ? { "bus.scope": resourceScope } : {}
|
|
13120
|
+
}
|
|
13121
|
+
}
|
|
13122
|
+
);
|
|
13123
|
+
}
|
|
13124
|
+
on(channel, handler) {
|
|
13125
|
+
const sub = this.bus.get(channel).subscribe(handler);
|
|
13126
|
+
return () => sub.unsubscribe();
|
|
13127
|
+
}
|
|
13128
|
+
stream(channel) {
|
|
13129
|
+
return this.bus.get(channel);
|
|
13130
|
+
}
|
|
13131
|
+
subscribeToResource(_resourceId) {
|
|
13132
|
+
return () => {
|
|
13133
|
+
};
|
|
13134
|
+
}
|
|
13135
|
+
bridgeInto(bus) {
|
|
13136
|
+
if (this.bridges.includes(bus)) return;
|
|
13137
|
+
this.bridges.push(bus);
|
|
13138
|
+
for (const channel of BRIDGED_CHANNELS) {
|
|
13139
|
+
const upstream = this.bus.get(channel);
|
|
13140
|
+
this.bridgeSubs.push(
|
|
13141
|
+
upstream.subscribe((payload) => {
|
|
13142
|
+
busLog("RECV", channel, payload);
|
|
13143
|
+
void withSpan(
|
|
13144
|
+
`bus.recv:${channel}`,
|
|
13145
|
+
() => {
|
|
13146
|
+
bus.get(channel).next(payload);
|
|
13147
|
+
},
|
|
13148
|
+
{ kind: SpanKind.CONSUMER, attrs: { "bus.channel": channel } }
|
|
13149
|
+
);
|
|
13150
|
+
})
|
|
13151
|
+
);
|
|
13152
|
+
}
|
|
13153
|
+
}
|
|
13154
|
+
// ── Auth (not supported) ────────────────────────────────────────────────
|
|
13155
|
+
async authenticatePassword(_email, _password) {
|
|
13156
|
+
throw NOT_SUPPORTED("authenticatePassword");
|
|
13157
|
+
}
|
|
13158
|
+
async authenticateGoogle(_credential) {
|
|
13159
|
+
throw NOT_SUPPORTED("authenticateGoogle");
|
|
13160
|
+
}
|
|
13161
|
+
async refreshAccessToken(_token) {
|
|
13162
|
+
throw NOT_SUPPORTED("refreshAccessToken");
|
|
13163
|
+
}
|
|
13164
|
+
async logout() {
|
|
13165
|
+
}
|
|
13166
|
+
async acceptTerms() {
|
|
13167
|
+
}
|
|
13168
|
+
async getCurrentUser() {
|
|
13169
|
+
return {
|
|
13170
|
+
did: this.userId,
|
|
13171
|
+
email: "",
|
|
13172
|
+
isAdmin: false,
|
|
13173
|
+
isModerator: false,
|
|
13174
|
+
termsAcceptedAt: null
|
|
13175
|
+
};
|
|
13176
|
+
}
|
|
13177
|
+
async generateMcpToken() {
|
|
13178
|
+
throw NOT_SUPPORTED("generateMcpToken");
|
|
13179
|
+
}
|
|
13180
|
+
async getMediaToken(_resourceId) {
|
|
13181
|
+
throw NOT_SUPPORTED("getMediaToken");
|
|
13182
|
+
}
|
|
13183
|
+
// ── Admin (not supported) ───────────────────────────────────────────────
|
|
13184
|
+
async listUsers() {
|
|
13185
|
+
throw NOT_SUPPORTED("listUsers");
|
|
13186
|
+
}
|
|
13187
|
+
async getUserStats() {
|
|
13188
|
+
throw NOT_SUPPORTED("getUserStats");
|
|
13189
|
+
}
|
|
13190
|
+
async updateUser(_id, _data) {
|
|
13191
|
+
throw NOT_SUPPORTED("updateUser");
|
|
13192
|
+
}
|
|
13193
|
+
async getOAuthConfig() {
|
|
13194
|
+
throw NOT_SUPPORTED("getOAuthConfig");
|
|
13195
|
+
}
|
|
13196
|
+
// ── Exchange (not supported) ────────────────────────────────────────────
|
|
13197
|
+
async backupKnowledgeBase() {
|
|
13198
|
+
throw NOT_SUPPORTED("backupKnowledgeBase");
|
|
13199
|
+
}
|
|
13200
|
+
async restoreKnowledgeBase(_file, _onProgress) {
|
|
13201
|
+
throw NOT_SUPPORTED("restoreKnowledgeBase");
|
|
13202
|
+
}
|
|
13203
|
+
async exportKnowledgeBase(_params) {
|
|
13204
|
+
throw NOT_SUPPORTED("exportKnowledgeBase");
|
|
13205
|
+
}
|
|
13206
|
+
async importKnowledgeBase(_file, _onProgress) {
|
|
13207
|
+
throw NOT_SUPPORTED("importKnowledgeBase");
|
|
13208
|
+
}
|
|
13209
|
+
// ── System ──────────────────────────────────────────────────────────────
|
|
13210
|
+
async healthCheck() {
|
|
13211
|
+
return { status: "ok" };
|
|
13212
|
+
}
|
|
13213
|
+
async getStatus() {
|
|
13214
|
+
return { status: "ok" };
|
|
13215
|
+
}
|
|
13216
|
+
// ── Lifecycle ───────────────────────────────────────────────────────────
|
|
13217
|
+
dispose() {
|
|
13218
|
+
if (this.disposed) return;
|
|
13219
|
+
this.disposed = true;
|
|
13220
|
+
for (const sub of this.bridgeSubs) sub.unsubscribe();
|
|
13221
|
+
this.bridgeSubs.length = 0;
|
|
13222
|
+
this.bridges.length = 0;
|
|
13223
|
+
this.state$.next("closed");
|
|
13224
|
+
this.state$.complete();
|
|
13225
|
+
}
|
|
13226
|
+
};
|
|
13227
|
+
|
|
13228
|
+
// src/local-content-transport.ts
|
|
13229
|
+
import { busLog as busLog2 } from "@semiont/core";
|
|
13230
|
+
import { SpanKind as SpanKind2, withSpan as withSpan2 } from "@semiont/observability";
|
|
13231
|
+
function primaryRepresentation(reps) {
|
|
13232
|
+
if (!reps) return void 0;
|
|
13233
|
+
return Array.isArray(reps) ? reps[0] : reps;
|
|
13234
|
+
}
|
|
13235
|
+
var LocalContentTransport = class {
|
|
13236
|
+
constructor(ks) {
|
|
13237
|
+
this.ks = ks;
|
|
13238
|
+
}
|
|
13239
|
+
async putBinary(_request, _options) {
|
|
13240
|
+
throw new Error(
|
|
13241
|
+
"LocalContentTransport does not support putBinary() \u2014 create resources via bus emits (mark/yield namespaces) in local mode"
|
|
13242
|
+
);
|
|
13243
|
+
}
|
|
13244
|
+
async getBinary(resourceId10, options) {
|
|
13245
|
+
busLog2("GET", "content", { resourceId: resourceId10, accept: options?.accept });
|
|
13246
|
+
return withSpan2(
|
|
13247
|
+
"content.get",
|
|
13248
|
+
() => this.loadBinary(resourceId10),
|
|
13249
|
+
{ kind: SpanKind2.INTERNAL, attrs: { "resource.id": resourceId10 } }
|
|
13250
|
+
);
|
|
13251
|
+
}
|
|
13252
|
+
async getBinaryStream(resourceId10, options) {
|
|
13253
|
+
busLog2("GET", "content", { resourceId: resourceId10, accept: options?.accept, stream: true });
|
|
13254
|
+
return withSpan2(
|
|
13255
|
+
"content.get",
|
|
13256
|
+
async () => {
|
|
13257
|
+
const { data, contentType } = await this.loadBinary(resourceId10);
|
|
13258
|
+
const bytes = new Uint8Array(data);
|
|
13259
|
+
const stream = new ReadableStream({
|
|
13260
|
+
start(controller) {
|
|
13261
|
+
controller.enqueue(bytes);
|
|
13262
|
+
controller.close();
|
|
13263
|
+
}
|
|
13264
|
+
});
|
|
13265
|
+
return { stream, contentType };
|
|
13266
|
+
},
|
|
13267
|
+
{
|
|
13268
|
+
kind: SpanKind2.INTERNAL,
|
|
13269
|
+
attrs: { "resource.id": resourceId10, "content.stream": true }
|
|
13270
|
+
}
|
|
13271
|
+
);
|
|
13272
|
+
}
|
|
13273
|
+
async loadBinary(resourceId10) {
|
|
13274
|
+
const view = await this.ks.kb.views.get(resourceId10);
|
|
13275
|
+
if (!view) throw new Error(`Resource not found: ${resourceId10}`);
|
|
13276
|
+
const rep = primaryRepresentation(view.resource.representations);
|
|
13277
|
+
if (!rep?.storageUri) {
|
|
13278
|
+
throw new Error(`Resource ${resourceId10} has no representation with a storageUri`);
|
|
13279
|
+
}
|
|
13280
|
+
const buf = await this.ks.kb.content.retrieve(rep.storageUri);
|
|
13281
|
+
const data = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
13282
|
+
return { data, contentType: rep.mediaType };
|
|
13283
|
+
}
|
|
13284
|
+
dispose() {
|
|
13285
|
+
}
|
|
13286
|
+
};
|
|
13287
|
+
|
|
13484
13288
|
// src/exchange/backup-exporter.ts
|
|
13485
13289
|
import { getExtensionForMimeType } from "@semiont/content";
|
|
13486
13290
|
|
|
13487
13291
|
// src/exchange/tar.ts
|
|
13488
13292
|
import { createGzip, createGunzip } from "zlib";
|
|
13489
|
-
import { Readable
|
|
13293
|
+
import { Readable, pipeline } from "stream";
|
|
13490
13294
|
import { promisify } from "util";
|
|
13491
13295
|
var pipelineAsync = promisify(pipeline);
|
|
13492
13296
|
var BLOCK_SIZE = 512;
|
|
@@ -13516,7 +13320,7 @@ function paddingBytes(size) {
|
|
|
13516
13320
|
}
|
|
13517
13321
|
async function writeTarGz(entries, output) {
|
|
13518
13322
|
const gzip = createGzip();
|
|
13519
|
-
const tarStream = new
|
|
13323
|
+
const tarStream = new Readable({ read() {
|
|
13520
13324
|
} });
|
|
13521
13325
|
const pipePromise = pipelineAsync(tarStream, gzip, output);
|
|
13522
13326
|
for await (const entry of entries) {
|
|
@@ -13673,7 +13477,7 @@ function collectContentRefs(streamData) {
|
|
|
13673
13477
|
|
|
13674
13478
|
// src/exchange/replay.ts
|
|
13675
13479
|
var import_rxjs11 = __toESM(require_cjs(), 1);
|
|
13676
|
-
var
|
|
13480
|
+
var import_operators10 = __toESM(require_operators(), 1);
|
|
13677
13481
|
import { deriveStorageUri as deriveStorageUri2 } from "@semiont/content";
|
|
13678
13482
|
var REPLAY_TIMEOUT_MS = 3e4;
|
|
13679
13483
|
async function replayEventStream(jsonl, eventBus, resolveBlob, contentStore, logger) {
|
|
@@ -13739,17 +13543,17 @@ async function replayEvent(event, eventBus, resolveBlob, contentStore, stats, lo
|
|
|
13739
13543
|
}
|
|
13740
13544
|
async function replayEntityTypeAdded(event, eventBus, logger) {
|
|
13741
13545
|
const result$ = (0, import_rxjs11.race)(
|
|
13742
|
-
eventBus.get("mark:entity-type-added").pipe((0,
|
|
13743
|
-
eventBus.get("mark:entity-type-add-failed").pipe((0,
|
|
13546
|
+
eventBus.get("mark:entity-type-added").pipe((0, import_operators10.map)(() => "ok")),
|
|
13547
|
+
eventBus.get("mark:entity-type-add-failed").pipe((0, import_operators10.map)((e) => {
|
|
13744
13548
|
throw new Error(e.message);
|
|
13745
13549
|
})),
|
|
13746
|
-
(0, import_rxjs11.timer)(REPLAY_TIMEOUT_MS).pipe((0,
|
|
13550
|
+
(0, import_rxjs11.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators10.map)(() => {
|
|
13747
13551
|
throw new Error("Timeout waiting for mark:entity-type-added");
|
|
13748
13552
|
}))
|
|
13749
13553
|
);
|
|
13750
13554
|
eventBus.get("mark:add-entity-type").next({
|
|
13751
13555
|
tag: event.payload.entityType,
|
|
13752
|
-
|
|
13556
|
+
_userId: event.userId
|
|
13753
13557
|
});
|
|
13754
13558
|
await (0, import_rxjs11.firstValueFrom)(result$);
|
|
13755
13559
|
logger?.debug("Replayed entitytype.added", { entityType: event.payload.entityType });
|
|
@@ -13763,11 +13567,11 @@ async function replayResourceCreated(event, eventBus, resolveBlob, contentStore,
|
|
|
13763
13567
|
const resolvedUri = payload.storageUri || deriveStorageUri2(payload.name, payload.format);
|
|
13764
13568
|
const stored = await contentStore.store(blob, resolvedUri);
|
|
13765
13569
|
const result$ = (0, import_rxjs11.race)(
|
|
13766
|
-
eventBus.get("yield:create-ok").pipe((0,
|
|
13767
|
-
eventBus.get("yield:create-failed").pipe((0,
|
|
13570
|
+
eventBus.get("yield:create-ok").pipe((0, import_operators10.map)((r) => r)),
|
|
13571
|
+
eventBus.get("yield:create-failed").pipe((0, import_operators10.map)((e) => {
|
|
13768
13572
|
throw new Error(e.message);
|
|
13769
13573
|
})),
|
|
13770
|
-
(0, import_rxjs11.timer)(REPLAY_TIMEOUT_MS).pipe((0,
|
|
13574
|
+
(0, import_rxjs11.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators10.map)(() => {
|
|
13771
13575
|
throw new Error("Timeout waiting for yield:create-ok");
|
|
13772
13576
|
}))
|
|
13773
13577
|
);
|
|
@@ -13777,7 +13581,7 @@ async function replayResourceCreated(event, eventBus, resolveBlob, contentStore,
|
|
|
13777
13581
|
contentChecksum: stored.checksum,
|
|
13778
13582
|
byteSize: stored.byteSize,
|
|
13779
13583
|
format: payload.format,
|
|
13780
|
-
|
|
13584
|
+
_userId: event.userId,
|
|
13781
13585
|
language: payload.language,
|
|
13782
13586
|
entityTypes: payload.entityTypes,
|
|
13783
13587
|
creationMethod: payload.creationMethod,
|
|
@@ -13790,17 +13594,17 @@ async function replayResourceCreated(event, eventBus, resolveBlob, contentStore,
|
|
|
13790
13594
|
}
|
|
13791
13595
|
async function replayAnnotationAdded(event, eventBus, logger) {
|
|
13792
13596
|
const result$ = (0, import_rxjs11.race)(
|
|
13793
|
-
eventBus.get("mark:create-ok").pipe((0,
|
|
13794
|
-
eventBus.get("mark:create-failed").pipe((0,
|
|
13597
|
+
eventBus.get("mark:create-ok").pipe((0, import_operators10.map)(() => "ok")),
|
|
13598
|
+
eventBus.get("mark:create-failed").pipe((0, import_operators10.map)((e) => {
|
|
13795
13599
|
throw new Error(e.message);
|
|
13796
13600
|
})),
|
|
13797
|
-
(0, import_rxjs11.timer)(REPLAY_TIMEOUT_MS).pipe((0,
|
|
13601
|
+
(0, import_rxjs11.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators10.map)(() => {
|
|
13798
13602
|
throw new Error("Timeout waiting for mark:create-ok");
|
|
13799
13603
|
}))
|
|
13800
13604
|
);
|
|
13801
13605
|
eventBus.get("mark:create").next({
|
|
13802
13606
|
annotation: event.payload.annotation,
|
|
13803
|
-
|
|
13607
|
+
_userId: event.userId,
|
|
13804
13608
|
resourceId: event.resourceId
|
|
13805
13609
|
});
|
|
13806
13610
|
await (0, import_rxjs11.firstValueFrom)(result$);
|
|
@@ -13808,17 +13612,17 @@ async function replayAnnotationAdded(event, eventBus, logger) {
|
|
|
13808
13612
|
}
|
|
13809
13613
|
async function replayAnnotationBodyUpdated(event, eventBus, logger) {
|
|
13810
13614
|
const result$ = (0, import_rxjs11.race)(
|
|
13811
|
-
eventBus.get("mark:body-updated").pipe((0,
|
|
13812
|
-
eventBus.get("mark:body-update-failed").pipe((0,
|
|
13615
|
+
eventBus.get("mark:body-updated").pipe((0, import_operators10.map)(() => "ok")),
|
|
13616
|
+
eventBus.get("mark:body-update-failed").pipe((0, import_operators10.map)((e) => {
|
|
13813
13617
|
throw new Error(e.message);
|
|
13814
13618
|
})),
|
|
13815
|
-
(0, import_rxjs11.timer)(REPLAY_TIMEOUT_MS).pipe((0,
|
|
13619
|
+
(0, import_rxjs11.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators10.map)(() => {
|
|
13816
13620
|
throw new Error("Timeout waiting for mark:body-updated");
|
|
13817
13621
|
}))
|
|
13818
13622
|
);
|
|
13819
13623
|
eventBus.get("mark:update-body").next({
|
|
13820
13624
|
annotationId: event.payload.annotationId,
|
|
13821
|
-
|
|
13625
|
+
_userId: event.userId,
|
|
13822
13626
|
resourceId: event.resourceId,
|
|
13823
13627
|
operations: event.payload.operations
|
|
13824
13628
|
});
|
|
@@ -13827,17 +13631,17 @@ async function replayAnnotationBodyUpdated(event, eventBus, logger) {
|
|
|
13827
13631
|
}
|
|
13828
13632
|
async function replayAnnotationRemoved(event, eventBus, logger) {
|
|
13829
13633
|
const result$ = (0, import_rxjs11.race)(
|
|
13830
|
-
eventBus.get("mark:delete-ok").pipe((0,
|
|
13831
|
-
eventBus.get("mark:delete-failed").pipe((0,
|
|
13634
|
+
eventBus.get("mark:delete-ok").pipe((0, import_operators10.map)(() => "ok")),
|
|
13635
|
+
eventBus.get("mark:delete-failed").pipe((0, import_operators10.map)((e) => {
|
|
13832
13636
|
throw new Error(e.message);
|
|
13833
13637
|
})),
|
|
13834
|
-
(0, import_rxjs11.timer)(REPLAY_TIMEOUT_MS).pipe((0,
|
|
13638
|
+
(0, import_rxjs11.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators10.map)(() => {
|
|
13835
13639
|
throw new Error("Timeout waiting for mark:delete-ok");
|
|
13836
13640
|
}))
|
|
13837
13641
|
);
|
|
13838
13642
|
eventBus.get("mark:delete").next({
|
|
13839
13643
|
annotationId: event.payload.annotationId,
|
|
13840
|
-
|
|
13644
|
+
_userId: event.userId,
|
|
13841
13645
|
resourceId: event.resourceId
|
|
13842
13646
|
});
|
|
13843
13647
|
await (0, import_rxjs11.firstValueFrom)(result$);
|
|
@@ -13845,37 +13649,37 @@ async function replayAnnotationRemoved(event, eventBus, logger) {
|
|
|
13845
13649
|
}
|
|
13846
13650
|
async function replayResourceArchived(event, eventBus, logger) {
|
|
13847
13651
|
eventBus.get("mark:archive").next({
|
|
13848
|
-
|
|
13652
|
+
_userId: event.userId,
|
|
13849
13653
|
resourceId: event.resourceId
|
|
13850
13654
|
});
|
|
13851
13655
|
logger?.debug("Replayed resource.archived", { resourceId: event.resourceId });
|
|
13852
13656
|
}
|
|
13853
13657
|
async function replayResourceUnarchived(event, eventBus, logger) {
|
|
13854
13658
|
eventBus.get("mark:unarchive").next({
|
|
13855
|
-
|
|
13659
|
+
_userId: event.userId,
|
|
13856
13660
|
resourceId: event.resourceId
|
|
13857
13661
|
});
|
|
13858
13662
|
logger?.debug("Replayed resource.unarchived", { resourceId: event.resourceId });
|
|
13859
13663
|
}
|
|
13860
13664
|
async function replayEntityTagChange(event, eventBus, logger) {
|
|
13861
|
-
const
|
|
13862
|
-
const
|
|
13665
|
+
const resourceId10 = event.resourceId;
|
|
13666
|
+
const entityType2 = event.payload.entityType;
|
|
13863
13667
|
if (event.type === "mark:entity-tag-added") {
|
|
13864
13668
|
eventBus.get("mark:update-entity-types").next({
|
|
13865
|
-
resourceId:
|
|
13866
|
-
|
|
13669
|
+
resourceId: resourceId10,
|
|
13670
|
+
_userId: event.userId,
|
|
13867
13671
|
currentEntityTypes: [],
|
|
13868
|
-
updatedEntityTypes: [
|
|
13672
|
+
updatedEntityTypes: [entityType2]
|
|
13869
13673
|
});
|
|
13870
13674
|
} else {
|
|
13871
13675
|
eventBus.get("mark:update-entity-types").next({
|
|
13872
|
-
resourceId:
|
|
13873
|
-
|
|
13874
|
-
currentEntityTypes: [
|
|
13676
|
+
resourceId: resourceId10,
|
|
13677
|
+
_userId: event.userId,
|
|
13678
|
+
currentEntityTypes: [entityType2],
|
|
13875
13679
|
updatedEntityTypes: []
|
|
13876
13680
|
});
|
|
13877
13681
|
}
|
|
13878
|
-
logger?.debug("Replayed entity tag change", { type: event.type, entityType });
|
|
13682
|
+
logger?.debug("Replayed entity tag change", { type: event.type, entityType: entityType2 });
|
|
13879
13683
|
}
|
|
13880
13684
|
|
|
13881
13685
|
// src/exchange/backup-importer.ts
|
|
@@ -14049,10 +13853,10 @@ async function exportLinkedData(options, output) {
|
|
|
14049
13853
|
data: Buffer.from(JSON.stringify(manifest, null, 2), "utf8")
|
|
14050
13854
|
};
|
|
14051
13855
|
for (const view of resourceViews) {
|
|
14052
|
-
const
|
|
13856
|
+
const resourceId10 = view.resource["@id"];
|
|
14053
13857
|
const jsonld = buildResourceJsonLd(view.resource, view.annotations.annotations, sourceUrl);
|
|
14054
13858
|
yield {
|
|
14055
|
-
name: `.semiont/resources/${
|
|
13859
|
+
name: `.semiont/resources/${resourceId10}.jsonld`,
|
|
14056
13860
|
data: Buffer.from(JSON.stringify(jsonld, null, 2), "utf8")
|
|
14057
13861
|
};
|
|
14058
13862
|
}
|
|
@@ -14069,8 +13873,8 @@ async function exportLinkedData(options, output) {
|
|
|
14069
13873
|
return manifest;
|
|
14070
13874
|
}
|
|
14071
13875
|
function buildResourceJsonLd(resource, annotations, sourceUrl) {
|
|
14072
|
-
const
|
|
14073
|
-
const resourceUri =
|
|
13876
|
+
const resourceId10 = resource["@id"];
|
|
13877
|
+
const resourceUri = resourceId10.startsWith("http") ? resourceId10 : `${sourceUrl}/resources/${resourceId10}`;
|
|
14074
13878
|
const doc = {
|
|
14075
13879
|
"@context": SEMIONT_CONTEXT,
|
|
14076
13880
|
"@id": resourceUri,
|
|
@@ -14131,8 +13935,8 @@ function collectContentRefsFromResource(resource, refs) {
|
|
|
14131
13935
|
|
|
14132
13936
|
// src/exchange/linked-data-importer.ts
|
|
14133
13937
|
var import_rxjs12 = __toESM(require_cjs(), 1);
|
|
14134
|
-
var
|
|
14135
|
-
import { resourceId as makeResourceId5 } from "@semiont/core";
|
|
13938
|
+
var import_operators11 = __toESM(require_operators(), 1);
|
|
13939
|
+
import { annotationId as annotationIdFactory, resourceId as makeResourceId5 } from "@semiont/core";
|
|
14136
13940
|
import { deriveStorageUri as deriveStorageUri3 } from "@semiont/content";
|
|
14137
13941
|
var IMPORT_TIMEOUT_MS = 3e4;
|
|
14138
13942
|
function stripUriToId(uri) {
|
|
@@ -14143,7 +13947,7 @@ function stripUriToId(uri) {
|
|
|
14143
13947
|
function dehydrateAnnotation(annotation) {
|
|
14144
13948
|
const dehydrated = { ...annotation };
|
|
14145
13949
|
if (dehydrated.id) {
|
|
14146
|
-
dehydrated.id = stripUriToId(dehydrated.id);
|
|
13950
|
+
dehydrated.id = annotationIdFactory(stripUriToId(dehydrated.id));
|
|
14147
13951
|
}
|
|
14148
13952
|
if (typeof dehydrated.target === "string") {
|
|
14149
13953
|
dehydrated.target = stripUriToId(dehydrated.target);
|
|
@@ -14187,7 +13991,7 @@ function buildBlobResolver2(entries) {
|
|
|
14187
13991
|
};
|
|
14188
13992
|
}
|
|
14189
13993
|
async function importLinkedData(archive, options) {
|
|
14190
|
-
const { eventBus, contentStore, userId:
|
|
13994
|
+
const { eventBus, contentStore, userId: userId3, logger } = options;
|
|
14191
13995
|
const entries = /* @__PURE__ */ new Map();
|
|
14192
13996
|
for await (const entry of readTarGz(archive)) {
|
|
14193
13997
|
entries.set(entry.name, entry.data);
|
|
@@ -14209,8 +14013,8 @@ async function importLinkedData(archive, options) {
|
|
|
14209
14013
|
});
|
|
14210
14014
|
const resolveBlob = buildBlobResolver2(entries);
|
|
14211
14015
|
let entityTypesAdded = 0;
|
|
14212
|
-
for (const
|
|
14213
|
-
await addEntityType(
|
|
14016
|
+
for (const entityType2 of manifest["semiont:entityTypes"]) {
|
|
14017
|
+
await addEntityType(entityType2, userId3, eventBus, logger);
|
|
14214
14018
|
entityTypesAdded++;
|
|
14215
14019
|
}
|
|
14216
14020
|
const resourceEntries = [...entries.keys()].filter((name) => name.startsWith(".semiont/resources/") && name.endsWith(".jsonld")).sort();
|
|
@@ -14218,7 +14022,7 @@ async function importLinkedData(archive, options) {
|
|
|
14218
14022
|
let annotationsCreated = 0;
|
|
14219
14023
|
for (const entryName of resourceEntries) {
|
|
14220
14024
|
const resourceDoc = JSON.parse(entries.get(entryName).toString("utf8"));
|
|
14221
|
-
const result = await importResource(resourceDoc,
|
|
14025
|
+
const result = await importResource(resourceDoc, userId3, eventBus, contentStore, resolveBlob, logger);
|
|
14222
14026
|
resourcesCreated++;
|
|
14223
14027
|
annotationsCreated += result.annotationsCreated;
|
|
14224
14028
|
}
|
|
@@ -14234,24 +14038,24 @@ async function importLinkedData(archive, options) {
|
|
|
14234
14038
|
entityTypesAdded
|
|
14235
14039
|
};
|
|
14236
14040
|
}
|
|
14237
|
-
async function addEntityType(
|
|
14041
|
+
async function addEntityType(entityType2, userId3, eventBus, logger) {
|
|
14238
14042
|
const result$ = (0, import_rxjs12.race)(
|
|
14239
|
-
eventBus.get("mark:entity-type-added").pipe((0,
|
|
14240
|
-
eventBus.get("mark:entity-type-add-failed").pipe((0,
|
|
14043
|
+
eventBus.get("mark:entity-type-added").pipe((0, import_operators11.map)(() => "ok")),
|
|
14044
|
+
eventBus.get("mark:entity-type-add-failed").pipe((0, import_operators11.map)((e) => {
|
|
14241
14045
|
throw new Error(e.message);
|
|
14242
14046
|
})),
|
|
14243
|
-
(0, import_rxjs12.timer)(IMPORT_TIMEOUT_MS).pipe((0,
|
|
14047
|
+
(0, import_rxjs12.timer)(IMPORT_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
|
|
14244
14048
|
throw new Error("Timeout waiting for mark:entity-type-added");
|
|
14245
14049
|
}))
|
|
14246
14050
|
);
|
|
14247
14051
|
eventBus.get("mark:add-entity-type").next({
|
|
14248
|
-
tag:
|
|
14249
|
-
|
|
14052
|
+
tag: entityType2,
|
|
14053
|
+
_userId: userId3
|
|
14250
14054
|
});
|
|
14251
14055
|
await (0, import_rxjs12.firstValueFrom)(result$);
|
|
14252
|
-
logger?.debug("Added entity type", { entityType });
|
|
14056
|
+
logger?.debug("Added entity type", { entityType: entityType2 });
|
|
14253
14057
|
}
|
|
14254
|
-
async function importResource(doc,
|
|
14058
|
+
async function importResource(doc, userId3, eventBus, contentStore, resolveBlob, logger) {
|
|
14255
14059
|
const name = doc["name"];
|
|
14256
14060
|
const representations = doc["representations"];
|
|
14257
14061
|
const annotations = doc["annotations"];
|
|
@@ -14276,11 +14080,11 @@ async function importResource(doc, userId2, eventBus, contentStore, resolveBlob,
|
|
|
14276
14080
|
const resolvedUri = deriveStorageUri3(name, format);
|
|
14277
14081
|
const stored = await contentStore.store(blob, resolvedUri);
|
|
14278
14082
|
const createResult$ = (0, import_rxjs12.race)(
|
|
14279
|
-
eventBus.get("yield:create-ok").pipe((0,
|
|
14280
|
-
eventBus.get("yield:create-failed").pipe((0,
|
|
14083
|
+
eventBus.get("yield:create-ok").pipe((0, import_operators11.map)((r) => r)),
|
|
14084
|
+
eventBus.get("yield:create-failed").pipe((0, import_operators11.map)((e) => {
|
|
14281
14085
|
throw new Error(e.message);
|
|
14282
14086
|
})),
|
|
14283
|
-
(0, import_rxjs12.timer)(IMPORT_TIMEOUT_MS).pipe((0,
|
|
14087
|
+
(0, import_rxjs12.timer)(IMPORT_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
|
|
14284
14088
|
throw new Error("Timeout waiting for yield:create-ok");
|
|
14285
14089
|
}))
|
|
14286
14090
|
);
|
|
@@ -14290,37 +14094,37 @@ async function importResource(doc, userId2, eventBus, contentStore, resolveBlob,
|
|
|
14290
14094
|
contentChecksum: stored.checksum,
|
|
14291
14095
|
byteSize: stored.byteSize,
|
|
14292
14096
|
format,
|
|
14293
|
-
|
|
14097
|
+
_userId: userId3,
|
|
14294
14098
|
language,
|
|
14295
14099
|
entityTypes: entityTypes ?? [],
|
|
14296
14100
|
creationMethod
|
|
14297
14101
|
});
|
|
14298
14102
|
const created = await (0, import_rxjs12.firstValueFrom)(createResult$);
|
|
14299
|
-
const
|
|
14300
|
-
logger?.debug("Created resource from JSON-LD", { name, resourceId:
|
|
14103
|
+
const resourceId10 = makeResourceId5(created.resourceId);
|
|
14104
|
+
logger?.debug("Created resource from JSON-LD", { name, resourceId: resourceId10 });
|
|
14301
14105
|
let annotationsCreated = 0;
|
|
14302
14106
|
if (annotations && annotations.length > 0) {
|
|
14303
14107
|
for (const annotation of annotations) {
|
|
14304
|
-
await createAnnotation(annotation,
|
|
14108
|
+
await createAnnotation(annotation, resourceId10, userId3, eventBus, logger);
|
|
14305
14109
|
annotationsCreated++;
|
|
14306
14110
|
}
|
|
14307
14111
|
}
|
|
14308
14112
|
return { annotationsCreated };
|
|
14309
14113
|
}
|
|
14310
|
-
async function createAnnotation(annotation,
|
|
14114
|
+
async function createAnnotation(annotation, resourceId10, userId3, eventBus, logger) {
|
|
14311
14115
|
const result$ = (0, import_rxjs12.race)(
|
|
14312
|
-
eventBus.get("mark:create-ok").pipe((0,
|
|
14313
|
-
eventBus.get("mark:create-failed").pipe((0,
|
|
14116
|
+
eventBus.get("mark:create-ok").pipe((0, import_operators11.map)(() => "ok")),
|
|
14117
|
+
eventBus.get("mark:create-failed").pipe((0, import_operators11.map)((e) => {
|
|
14314
14118
|
throw new Error(e.message);
|
|
14315
14119
|
})),
|
|
14316
|
-
(0, import_rxjs12.timer)(IMPORT_TIMEOUT_MS).pipe((0,
|
|
14120
|
+
(0, import_rxjs12.timer)(IMPORT_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
|
|
14317
14121
|
throw new Error("Timeout waiting for mark:create-ok");
|
|
14318
14122
|
}))
|
|
14319
14123
|
);
|
|
14320
14124
|
eventBus.get("mark:create").next({
|
|
14321
14125
|
annotation: dehydrateAnnotation(annotation),
|
|
14322
|
-
|
|
14323
|
-
resourceId:
|
|
14126
|
+
_userId: userId3,
|
|
14127
|
+
resourceId: resourceId10
|
|
14324
14128
|
});
|
|
14325
14129
|
await (0, import_rxjs12.firstValueFrom)(result$);
|
|
14326
14130
|
logger?.debug("Created annotation", { annotationId: annotation.id });
|
|
@@ -14328,22 +14132,22 @@ async function createAnnotation(annotation, resourceId7, userId2, eventBus, logg
|
|
|
14328
14132
|
|
|
14329
14133
|
// src/annotation-assembly.ts
|
|
14330
14134
|
import {
|
|
14331
|
-
assembleAnnotation,
|
|
14135
|
+
assembleAnnotation as assembleAnnotation2,
|
|
14332
14136
|
applyBodyOperations
|
|
14333
14137
|
} from "@semiont/core";
|
|
14334
14138
|
|
|
14335
14139
|
// src/annotation-operations.ts
|
|
14336
|
-
import { annotationId as
|
|
14140
|
+
import { annotationId as annotationId4, resourceId as makeResourceId6, assembleAnnotation as assembleAnnotation3, applyBodyOperations as applyBodyOperations2 } from "@semiont/core";
|
|
14337
14141
|
var AnnotationOperations = class {
|
|
14338
14142
|
/**
|
|
14339
14143
|
* Create a new annotation via EventBus → Stower
|
|
14340
14144
|
*/
|
|
14341
|
-
static async createAnnotation(request,
|
|
14342
|
-
const { annotation } =
|
|
14145
|
+
static async createAnnotation(request, userId3, creator, eventBus) {
|
|
14146
|
+
const { annotation } = assembleAnnotation3(request, creator);
|
|
14343
14147
|
const resId = makeResourceId6(request.target.source);
|
|
14344
14148
|
eventBus.get("mark:create").next({
|
|
14345
14149
|
annotation,
|
|
14346
|
-
|
|
14150
|
+
_userId: userId3,
|
|
14347
14151
|
resourceId: resId
|
|
14348
14152
|
});
|
|
14349
14153
|
return { annotation };
|
|
@@ -14351,10 +14155,10 @@ var AnnotationOperations = class {
|
|
|
14351
14155
|
/**
|
|
14352
14156
|
* Update annotation body via EventBus → Stower
|
|
14353
14157
|
*/
|
|
14354
|
-
static async updateAnnotationBody(id, request,
|
|
14158
|
+
static async updateAnnotationBody(id, request, userId3, eventBus, kb) {
|
|
14355
14159
|
const resId = makeResourceId6(request.resourceId);
|
|
14356
14160
|
const annotation = await AnnotationContext.getAnnotation(
|
|
14357
|
-
|
|
14161
|
+
annotationId4(id),
|
|
14358
14162
|
resId,
|
|
14359
14163
|
kb
|
|
14360
14164
|
);
|
|
@@ -14362,8 +14166,8 @@ var AnnotationOperations = class {
|
|
|
14362
14166
|
throw new Error("Annotation not found");
|
|
14363
14167
|
}
|
|
14364
14168
|
eventBus.get("mark:update-body").next({
|
|
14365
|
-
annotationId:
|
|
14366
|
-
|
|
14169
|
+
annotationId: annotationId4(id),
|
|
14170
|
+
_userId: userId3,
|
|
14367
14171
|
resourceId: resId,
|
|
14368
14172
|
operations: request.operations
|
|
14369
14173
|
});
|
|
@@ -14378,7 +14182,7 @@ var AnnotationOperations = class {
|
|
|
14378
14182
|
/**
|
|
14379
14183
|
* Delete an annotation via EventBus → Stower
|
|
14380
14184
|
*/
|
|
14381
|
-
static async deleteAnnotation(id, resourceIdStr,
|
|
14185
|
+
static async deleteAnnotation(id, resourceIdStr, userId3, eventBus, kb, logger) {
|
|
14382
14186
|
const resId = makeResourceId6(resourceIdStr);
|
|
14383
14187
|
const projection = await AnnotationContext.getResourceAnnotations(resId, kb);
|
|
14384
14188
|
const annotation = projection.annotations.find((a) => a.id === id);
|
|
@@ -14387,8 +14191,8 @@ var AnnotationOperations = class {
|
|
|
14387
14191
|
}
|
|
14388
14192
|
logger?.debug("Removing annotation via EventBus", { annotationId: id });
|
|
14389
14193
|
eventBus.get("mark:delete").next({
|
|
14390
|
-
annotationId:
|
|
14391
|
-
|
|
14194
|
+
annotationId: annotationId4(id),
|
|
14195
|
+
_userId: userId3,
|
|
14392
14196
|
resourceId: resId
|
|
14393
14197
|
});
|
|
14394
14198
|
logger?.debug("Annotation delete event emitted");
|
|
@@ -14408,15 +14212,16 @@ export {
|
|
|
14408
14212
|
Gatherer,
|
|
14409
14213
|
GraphContext,
|
|
14410
14214
|
LLMContext,
|
|
14215
|
+
LocalContentTransport,
|
|
14216
|
+
LocalTransport,
|
|
14411
14217
|
Matcher,
|
|
14412
14218
|
PACKAGE_NAME,
|
|
14413
14219
|
ResourceContext,
|
|
14414
14220
|
ResourceOperations,
|
|
14415
|
-
Smelter,
|
|
14416
14221
|
Stower,
|
|
14417
14222
|
VERSION,
|
|
14418
14223
|
applyBodyOperations,
|
|
14419
|
-
assembleAnnotation,
|
|
14224
|
+
assembleAnnotation2 as assembleAnnotation,
|
|
14420
14225
|
bootstrapEntityTypes,
|
|
14421
14226
|
createKnowledgeBase,
|
|
14422
14227
|
exportBackup,
|
|
@@ -14427,6 +14232,11 @@ export {
|
|
|
14427
14232
|
importLinkedData,
|
|
14428
14233
|
isBackupManifest,
|
|
14429
14234
|
readEntityTypesProjection,
|
|
14235
|
+
registerAnnotationAssemblyHandler,
|
|
14236
|
+
registerAnnotationLookupHandlers,
|
|
14237
|
+
registerBindUpdateBodyHandler,
|
|
14238
|
+
registerBusHandlers,
|
|
14239
|
+
registerJobCommandHandlers,
|
|
14430
14240
|
startMakeMeaning,
|
|
14431
14241
|
stopKnowledgeSystem,
|
|
14432
14242
|
validateManifestVersion
|