@semiont/make-meaning 0.4.19 → 0.4.21
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 +39 -162
- package/dist/index.js +342 -1034
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
});
|
|
@@ -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,7 +9943,7 @@ 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
9948
|
import { jobId } from "@semiont/core";
|
|
9949
9949
|
|
|
@@ -9955,42 +9955,12 @@ function resolveActorInference(config, actor) {
|
|
|
9955
9955
|
`No inference config found for actor '${actor}'. Set actors.${actor}.inference in your config.`
|
|
9956
9956
|
);
|
|
9957
9957
|
}
|
|
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
9958
|
|
|
9980
9959
|
// src/service.ts
|
|
9981
|
-
var
|
|
9982
|
-
var
|
|
9983
|
-
import { Readable } from "stream";
|
|
9960
|
+
var import_rxjs9 = __toESM(require_cjs(), 1);
|
|
9961
|
+
var import_operators9 = __toESM(require_operators(), 1);
|
|
9984
9962
|
import { createInferenceClient } from "@semiont/inference";
|
|
9985
9963
|
import { getGraphDatabase } from "@semiont/graph";
|
|
9986
|
-
import {
|
|
9987
|
-
ReferenceAnnotationWorker,
|
|
9988
|
-
GenerationWorker,
|
|
9989
|
-
HighlightAnnotationWorker,
|
|
9990
|
-
AssessmentAnnotationWorker,
|
|
9991
|
-
CommentAnnotationWorker,
|
|
9992
|
-
TagAnnotationWorker
|
|
9993
|
-
} from "@semiont/jobs";
|
|
9994
9964
|
|
|
9995
9965
|
// src/knowledge-base.ts
|
|
9996
9966
|
import { FilesystemViewStorage } from "@semiont/event-sourcing";
|
|
@@ -10000,7 +9970,7 @@ import { WorkingTreeStore } from "@semiont/content";
|
|
|
10000
9970
|
var import_rxjs = __toESM(require_cjs(), 1);
|
|
10001
9971
|
var import_operators = __toESM(require_operators(), 1);
|
|
10002
9972
|
import { EventQuery } from "@semiont/event-sourcing";
|
|
10003
|
-
import { didToAgent, burstBuffer } from "@semiont/core";
|
|
9973
|
+
import { didToAgent, burstBuffer, errField } from "@semiont/core";
|
|
10004
9974
|
import { resourceId as makeResourceId, annotationId as makeAnnotationId, findBodyItem } from "@semiont/core";
|
|
10005
9975
|
|
|
10006
9976
|
// src/batch-utils.ts
|
|
@@ -10109,7 +10079,7 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10109
10079
|
this.logger.error("Failed to apply event to graph", {
|
|
10110
10080
|
eventType: storedEvent.type,
|
|
10111
10081
|
resourceId: storedEvent.resourceId,
|
|
10112
|
-
error
|
|
10082
|
+
error: errField(error)
|
|
10113
10083
|
});
|
|
10114
10084
|
}
|
|
10115
10085
|
}
|
|
@@ -10148,7 +10118,7 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10148
10118
|
this.logger.error("Failed to process batch run", {
|
|
10149
10119
|
eventType: run[0].type,
|
|
10150
10120
|
runSize: run.length,
|
|
10151
|
-
error
|
|
10121
|
+
error: errField(error)
|
|
10152
10122
|
});
|
|
10153
10123
|
}
|
|
10154
10124
|
const last = run[run.length - 1];
|
|
@@ -10305,8 +10275,7 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10305
10275
|
} catch (error) {
|
|
10306
10276
|
this.logger.error("Error in annotation.body.updated handler", {
|
|
10307
10277
|
annotationId: event.payload.annotationId,
|
|
10308
|
-
error
|
|
10309
|
-
stack: error instanceof Error ? error.stack : void 0
|
|
10278
|
+
error: errField(error)
|
|
10310
10279
|
});
|
|
10311
10280
|
}
|
|
10312
10281
|
break;
|
|
@@ -10356,7 +10325,7 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10356
10325
|
const query = new EventQuery(this.eventStore.log.storage);
|
|
10357
10326
|
const events = await query.getResourceEvents(resourceId7);
|
|
10358
10327
|
for (const storedEvent of events) {
|
|
10359
|
-
await this.
|
|
10328
|
+
await this.safeApplyEvent(storedEvent);
|
|
10360
10329
|
}
|
|
10361
10330
|
this.logger.info("Resource rebuild complete", { resourceId: resourceId7, eventCount: events.length });
|
|
10362
10331
|
}
|
|
@@ -10380,7 +10349,7 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10380
10349
|
if (storedEvent.type === "mark:body-updated") {
|
|
10381
10350
|
continue;
|
|
10382
10351
|
}
|
|
10383
|
-
await this.
|
|
10352
|
+
await this.safeApplyEvent(storedEvent);
|
|
10384
10353
|
}
|
|
10385
10354
|
}
|
|
10386
10355
|
this.logger.info("Pass 1 complete - all nodes created");
|
|
@@ -10389,7 +10358,7 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10389
10358
|
const events = await query.getResourceEvents(makeResourceId(resourceId7));
|
|
10390
10359
|
for (const storedEvent of events) {
|
|
10391
10360
|
if (storedEvent.type === "mark:body-updated") {
|
|
10392
|
-
await this.
|
|
10361
|
+
await this.safeApplyEvent(storedEvent);
|
|
10393
10362
|
}
|
|
10394
10363
|
}
|
|
10395
10364
|
}
|
|
@@ -10415,635 +10384,9 @@ var GraphDBConsumer = class _GraphDBConsumer {
|
|
|
10415
10384
|
}
|
|
10416
10385
|
};
|
|
10417
10386
|
|
|
10418
|
-
// src/smelter.ts
|
|
10419
|
-
var import_rxjs2 = __toESM(require_cjs(), 1);
|
|
10420
|
-
var import_operators2 = __toESM(require_operators(), 1);
|
|
10421
|
-
import { burstBuffer as burstBuffer2 } from "@semiont/core";
|
|
10422
|
-
import { resourceId as makeResourceId2, annotationId as makeAnnotationId2 } from "@semiont/core";
|
|
10423
|
-
import { chunkText, DEFAULT_CHUNKING_CONFIG } from "@semiont/vectors";
|
|
10424
|
-
import { getExactText, getTargetSelector } from "@semiont/api-client";
|
|
10425
|
-
var Smelter = class _Smelter {
|
|
10426
|
-
constructor(_eventStore, eventBus, vectorStore, embeddingProvider, contentStore, embeddingStore, viewStorage, logger, chunkingConfig) {
|
|
10427
|
-
this.eventBus = eventBus;
|
|
10428
|
-
this.vectorStore = vectorStore;
|
|
10429
|
-
this.embeddingProvider = embeddingProvider;
|
|
10430
|
-
this.contentStore = contentStore;
|
|
10431
|
-
this.embeddingStore = embeddingStore;
|
|
10432
|
-
this.viewStorage = viewStorage;
|
|
10433
|
-
this.logger = logger;
|
|
10434
|
-
this.chunkingConfig = chunkingConfig ?? DEFAULT_CHUNKING_CONFIG;
|
|
10435
|
-
}
|
|
10436
|
-
static SMELTER_RELEVANT_EVENTS = /* @__PURE__ */ new Set([
|
|
10437
|
-
"yield:created",
|
|
10438
|
-
"yield:updated",
|
|
10439
|
-
"yield:representation-added",
|
|
10440
|
-
"mark:archived",
|
|
10441
|
-
"mark:added",
|
|
10442
|
-
"mark:removed"
|
|
10443
|
-
]);
|
|
10444
|
-
static BURST_WINDOW_MS = 50;
|
|
10445
|
-
static MAX_BATCH_SIZE = 100;
|
|
10446
|
-
static IDLE_TIMEOUT_MS = 200;
|
|
10447
|
-
_globalSubscriptions = [];
|
|
10448
|
-
eventSubject = new import_rxjs2.Subject();
|
|
10449
|
-
pipelineSubscription = null;
|
|
10450
|
-
logger;
|
|
10451
|
-
chunkingConfig;
|
|
10452
|
-
async initialize() {
|
|
10453
|
-
this.logger.info("Smelter actor initializing");
|
|
10454
|
-
for (const eventType of _Smelter.SMELTER_RELEVANT_EVENTS) {
|
|
10455
|
-
this._globalSubscriptions.push(
|
|
10456
|
-
this.eventBus.getDomainEvent(eventType).subscribe(
|
|
10457
|
-
(storedEvent) => this.eventSubject.next(storedEvent)
|
|
10458
|
-
)
|
|
10459
|
-
);
|
|
10460
|
-
}
|
|
10461
|
-
this.pipelineSubscription = this.eventSubject.pipe(
|
|
10462
|
-
(0, import_operators2.groupBy)((se) => se.resourceId ?? "__unknown__"),
|
|
10463
|
-
(0, import_operators2.mergeMap)(
|
|
10464
|
-
(group) => group.pipe(
|
|
10465
|
-
burstBuffer2({
|
|
10466
|
-
burstWindowMs: _Smelter.BURST_WINDOW_MS,
|
|
10467
|
-
maxBatchSize: _Smelter.MAX_BATCH_SIZE,
|
|
10468
|
-
idleTimeoutMs: _Smelter.IDLE_TIMEOUT_MS
|
|
10469
|
-
}),
|
|
10470
|
-
(0, import_operators2.concatMap)((eventOrBatch) => {
|
|
10471
|
-
if (Array.isArray(eventOrBatch)) {
|
|
10472
|
-
return (0, import_rxjs2.from)(this.processBatch(eventOrBatch));
|
|
10473
|
-
}
|
|
10474
|
-
return (0, import_rxjs2.from)(this.safeProcessEvent(eventOrBatch));
|
|
10475
|
-
})
|
|
10476
|
-
)
|
|
10477
|
-
)
|
|
10478
|
-
).subscribe({
|
|
10479
|
-
error: (err) => this.logger.error("Smelter pipeline error", { error: err })
|
|
10480
|
-
});
|
|
10481
|
-
this.logger.info("Smelter actor initialized");
|
|
10482
|
-
}
|
|
10483
|
-
async stop() {
|
|
10484
|
-
for (const sub of this._globalSubscriptions) sub.unsubscribe();
|
|
10485
|
-
this._globalSubscriptions = [];
|
|
10486
|
-
this.pipelineSubscription?.unsubscribe();
|
|
10487
|
-
this.eventSubject.complete();
|
|
10488
|
-
this.logger.info("Smelter actor stopped");
|
|
10489
|
-
}
|
|
10490
|
-
/**
|
|
10491
|
-
* Rebuild the vector store from the EmbeddingStore (.semiont/embeddings/).
|
|
10492
|
-
*
|
|
10493
|
-
* For each stored file, checks whether the model matches the configured
|
|
10494
|
-
* provider. On mismatch, re-embeds from the stored text and overwrites the
|
|
10495
|
-
* file before upserting into Qdrant. On match, loads the stored vectors
|
|
10496
|
-
* directly — no embedding provider calls needed.
|
|
10497
|
-
*/
|
|
10498
|
-
async rebuildAll() {
|
|
10499
|
-
this.logger.info("Rebuilding vector store from EmbeddingStore");
|
|
10500
|
-
await this.vectorStore.clearAll();
|
|
10501
|
-
const currentModel = this.embeddingProvider.model();
|
|
10502
|
-
const currentDimensions = this.embeddingProvider.dimensions();
|
|
10503
|
-
const resourceIds = await this.embeddingStore.getAllResourceIds();
|
|
10504
|
-
this.logger.info("Found resource embedding files", { count: resourceIds.length });
|
|
10505
|
-
let resourcesIndexed = 0;
|
|
10506
|
-
for (const rid of resourceIds) {
|
|
10507
|
-
const resourceId7 = makeResourceId2(rid);
|
|
10508
|
-
const stored = await this.embeddingStore.readResourceEmbeddings(resourceId7);
|
|
10509
|
-
if (!stored || stored.chunks.length === 0) continue;
|
|
10510
|
-
let chunks;
|
|
10511
|
-
if (stored.model !== currentModel) {
|
|
10512
|
-
this.logger.info("Re-embedding resource (model mismatch)", {
|
|
10513
|
-
resourceId: rid,
|
|
10514
|
-
storedModel: stored.model,
|
|
10515
|
-
currentModel
|
|
10516
|
-
});
|
|
10517
|
-
const texts = stored.chunks.map((c) => c.text);
|
|
10518
|
-
const embeddings = await this.embeddingProvider.embedBatch(texts);
|
|
10519
|
-
chunks = stored.chunks.map((c, i) => ({
|
|
10520
|
-
chunkIndex: c.chunkIndex,
|
|
10521
|
-
text: c.text,
|
|
10522
|
-
embedding: embeddings[i]
|
|
10523
|
-
}));
|
|
10524
|
-
await this.embeddingStore.writeResourceChunks(resourceId7, currentModel, currentDimensions, chunks);
|
|
10525
|
-
} else {
|
|
10526
|
-
chunks = stored.chunks;
|
|
10527
|
-
}
|
|
10528
|
-
await this.vectorStore.upsertResourceVectors(resourceId7, chunks);
|
|
10529
|
-
resourcesIndexed++;
|
|
10530
|
-
}
|
|
10531
|
-
const annotationIds = await this.embeddingStore.getAllAnnotationIds();
|
|
10532
|
-
this.logger.info("Found annotation embedding files", { count: annotationIds.length });
|
|
10533
|
-
let annotationsIndexed = 0;
|
|
10534
|
-
for (const aid of annotationIds) {
|
|
10535
|
-
const annotationId3 = makeAnnotationId2(aid);
|
|
10536
|
-
const stored = await this.embeddingStore.readAnnotationEmbedding(annotationId3);
|
|
10537
|
-
if (!stored) continue;
|
|
10538
|
-
let embedding;
|
|
10539
|
-
if (stored.model !== currentModel) {
|
|
10540
|
-
this.logger.info("Re-embedding annotation (model mismatch)", {
|
|
10541
|
-
annotationId: aid,
|
|
10542
|
-
storedModel: stored.model,
|
|
10543
|
-
currentModel
|
|
10544
|
-
});
|
|
10545
|
-
embedding = await this.embeddingProvider.embed(stored.text);
|
|
10546
|
-
await this.embeddingStore.writeAnnotationEmbedding(
|
|
10547
|
-
annotationId3,
|
|
10548
|
-
makeResourceId2(stored.resourceId),
|
|
10549
|
-
currentModel,
|
|
10550
|
-
currentDimensions,
|
|
10551
|
-
stored.text,
|
|
10552
|
-
embedding,
|
|
10553
|
-
stored.motivation,
|
|
10554
|
-
stored.entityTypes
|
|
10555
|
-
);
|
|
10556
|
-
} else {
|
|
10557
|
-
embedding = stored.embedding;
|
|
10558
|
-
}
|
|
10559
|
-
const payload = {
|
|
10560
|
-
annotationId: annotationId3,
|
|
10561
|
-
resourceId: makeResourceId2(stored.resourceId),
|
|
10562
|
-
motivation: stored.motivation,
|
|
10563
|
-
entityTypes: stored.entityTypes,
|
|
10564
|
-
exactText: stored.text
|
|
10565
|
-
};
|
|
10566
|
-
await this.vectorStore.upsertAnnotationVector(annotationId3, embedding, payload);
|
|
10567
|
-
annotationsIndexed++;
|
|
10568
|
-
}
|
|
10569
|
-
const storedResourceIdSet = new Set(resourceIds);
|
|
10570
|
-
const allViews = await this.viewStorage.getAll();
|
|
10571
|
-
let backfilled = 0;
|
|
10572
|
-
for (const view of allViews) {
|
|
10573
|
-
const ridStr = view.resource["@id"];
|
|
10574
|
-
if (storedResourceIdSet.has(ridStr)) continue;
|
|
10575
|
-
if (view.resource.archived) continue;
|
|
10576
|
-
if (!view.resource.storageUri) continue;
|
|
10577
|
-
let content;
|
|
10578
|
-
try {
|
|
10579
|
-
content = await this.contentStore.retrieve(view.resource.storageUri);
|
|
10580
|
-
} catch (err) {
|
|
10581
|
-
this.logger.warn("Smelter back-fill skipped \u2014 content missing", {
|
|
10582
|
-
resourceId: ridStr,
|
|
10583
|
-
storageUri: view.resource.storageUri,
|
|
10584
|
-
error: err instanceof Error ? err.message : String(err)
|
|
10585
|
-
});
|
|
10586
|
-
continue;
|
|
10587
|
-
}
|
|
10588
|
-
const text = new TextDecoder().decode(content);
|
|
10589
|
-
if (!text.trim()) continue;
|
|
10590
|
-
const chunks = chunkText(text, this.chunkingConfig);
|
|
10591
|
-
if (chunks.length === 0) continue;
|
|
10592
|
-
const rid = makeResourceId2(ridStr);
|
|
10593
|
-
const embeddings = await this.embeddingProvider.embedBatch(chunks);
|
|
10594
|
-
const embeddingChunks = chunks.map((chunkText2, i) => ({
|
|
10595
|
-
chunkIndex: i,
|
|
10596
|
-
text: chunkText2,
|
|
10597
|
-
embedding: embeddings[i]
|
|
10598
|
-
}));
|
|
10599
|
-
await this.embeddingStore.writeResourceChunks(rid, currentModel, currentDimensions, embeddingChunks);
|
|
10600
|
-
await this.vectorStore.upsertResourceVectors(rid, embeddingChunks);
|
|
10601
|
-
backfilled++;
|
|
10602
|
-
resourcesIndexed++;
|
|
10603
|
-
this.logger.info("Smelter back-filled missing resource embedding", { resourceId: ridStr });
|
|
10604
|
-
}
|
|
10605
|
-
this.logger.info("Vector store rebuild complete", { resourcesIndexed, annotationsIndexed, backfilled });
|
|
10606
|
-
}
|
|
10607
|
-
async processBatch(events) {
|
|
10608
|
-
const runs = partitionByType(events);
|
|
10609
|
-
for (const run of runs) {
|
|
10610
|
-
try {
|
|
10611
|
-
if (run.length === 1) {
|
|
10612
|
-
await this.safeProcessEvent(run[0]);
|
|
10613
|
-
} else {
|
|
10614
|
-
await this.applyBatchByType(run);
|
|
10615
|
-
}
|
|
10616
|
-
} catch (error) {
|
|
10617
|
-
this.logger.error("Smelter failed to process batch run", {
|
|
10618
|
-
eventType: run[0].type,
|
|
10619
|
-
runSize: run.length,
|
|
10620
|
-
error
|
|
10621
|
-
});
|
|
10622
|
-
}
|
|
10623
|
-
}
|
|
10624
|
-
}
|
|
10625
|
-
/**
|
|
10626
|
-
* Batch-optimized processing for consecutive events of the same type.
|
|
10627
|
-
*/
|
|
10628
|
-
async applyBatchByType(events) {
|
|
10629
|
-
const type = events[0].type;
|
|
10630
|
-
switch (type) {
|
|
10631
|
-
case "yield:created":
|
|
10632
|
-
await this.batchResourceCreated(events);
|
|
10633
|
-
break;
|
|
10634
|
-
case "mark:added":
|
|
10635
|
-
await this.batchAnnotationAdded(events);
|
|
10636
|
-
break;
|
|
10637
|
-
default:
|
|
10638
|
-
for (const event of events) {
|
|
10639
|
-
await this.safeProcessEvent(event);
|
|
10640
|
-
}
|
|
10641
|
-
}
|
|
10642
|
-
}
|
|
10643
|
-
/**
|
|
10644
|
-
* Batch-embed chunks from multiple yield:created events in a single
|
|
10645
|
-
* embedBatch() call, then write to EmbeddingStore and index per resource.
|
|
10646
|
-
*/
|
|
10647
|
-
async batchResourceCreated(events) {
|
|
10648
|
-
const resourceData = [];
|
|
10649
|
-
const allChunks = [];
|
|
10650
|
-
for (const storedEvent of events) {
|
|
10651
|
-
const event = storedEvent;
|
|
10652
|
-
const rid = makeResourceId2(event.resourceId);
|
|
10653
|
-
const storageUri = event.payload.storageUri;
|
|
10654
|
-
if (!storageUri) continue;
|
|
10655
|
-
const content = await this.contentStore.retrieve(storageUri);
|
|
10656
|
-
if (!content) continue;
|
|
10657
|
-
const text = new TextDecoder().decode(content);
|
|
10658
|
-
if (!text.trim()) continue;
|
|
10659
|
-
const chunks = chunkText(text, this.chunkingConfig);
|
|
10660
|
-
if (chunks.length === 0) continue;
|
|
10661
|
-
resourceData.push({ rid, chunks });
|
|
10662
|
-
allChunks.push(...chunks);
|
|
10663
|
-
}
|
|
10664
|
-
if (allChunks.length === 0) return;
|
|
10665
|
-
const allEmbeddings = await this.embeddingProvider.embedBatch(allChunks);
|
|
10666
|
-
const model = this.embeddingProvider.model();
|
|
10667
|
-
const dimensions = this.embeddingProvider.dimensions();
|
|
10668
|
-
let offset = 0;
|
|
10669
|
-
for (const { rid, chunks } of resourceData) {
|
|
10670
|
-
const embeddingChunks = chunks.map((text, i) => ({
|
|
10671
|
-
chunkIndex: i,
|
|
10672
|
-
text,
|
|
10673
|
-
embedding: allEmbeddings[offset + i]
|
|
10674
|
-
}));
|
|
10675
|
-
await this.embeddingStore.writeResourceChunks(rid, model, dimensions, embeddingChunks);
|
|
10676
|
-
await this.vectorStore.upsertResourceVectors(rid, embeddingChunks);
|
|
10677
|
-
this.logger.debug("Smelter batch-indexed resource", {
|
|
10678
|
-
resourceId: String(rid),
|
|
10679
|
-
chunks: embeddingChunks.length
|
|
10680
|
-
});
|
|
10681
|
-
offset += chunks.length;
|
|
10682
|
-
}
|
|
10683
|
-
}
|
|
10684
|
-
/**
|
|
10685
|
-
* Batch-embed exact texts from multiple mark:added events in a single
|
|
10686
|
-
* embedBatch() call, then write to EmbeddingStore and index per annotation.
|
|
10687
|
-
*/
|
|
10688
|
-
async batchAnnotationAdded(events) {
|
|
10689
|
-
const annotationData = [];
|
|
10690
|
-
for (const storedEvent of events) {
|
|
10691
|
-
const event = storedEvent;
|
|
10692
|
-
const annotation = event.payload.annotation;
|
|
10693
|
-
if (!annotation?.id) continue;
|
|
10694
|
-
const selector = getTargetSelector(annotation.target);
|
|
10695
|
-
const exactText = getExactText(selector);
|
|
10696
|
-
if (!exactText?.trim()) continue;
|
|
10697
|
-
annotationData.push({
|
|
10698
|
-
rid: makeResourceId2(event.resourceId),
|
|
10699
|
-
aid: makeAnnotationId2(annotation.id),
|
|
10700
|
-
exactText,
|
|
10701
|
-
motivation: annotation.motivation ?? "",
|
|
10702
|
-
entityTypes: annotation.entityTypes ?? []
|
|
10703
|
-
});
|
|
10704
|
-
}
|
|
10705
|
-
if (annotationData.length === 0) return;
|
|
10706
|
-
const allEmbeddings = await this.embeddingProvider.embedBatch(
|
|
10707
|
-
annotationData.map((a) => a.exactText)
|
|
10708
|
-
);
|
|
10709
|
-
const model = this.embeddingProvider.model();
|
|
10710
|
-
const dimensions = this.embeddingProvider.dimensions();
|
|
10711
|
-
for (let i = 0; i < annotationData.length; i++) {
|
|
10712
|
-
const { rid, aid, exactText, motivation, entityTypes } = annotationData[i];
|
|
10713
|
-
const embedding = allEmbeddings[i];
|
|
10714
|
-
await this.embeddingStore.writeAnnotationEmbedding(
|
|
10715
|
-
aid,
|
|
10716
|
-
rid,
|
|
10717
|
-
model,
|
|
10718
|
-
dimensions,
|
|
10719
|
-
exactText,
|
|
10720
|
-
embedding,
|
|
10721
|
-
motivation,
|
|
10722
|
-
entityTypes
|
|
10723
|
-
);
|
|
10724
|
-
const payload = {
|
|
10725
|
-
annotationId: aid,
|
|
10726
|
-
resourceId: rid,
|
|
10727
|
-
motivation,
|
|
10728
|
-
entityTypes,
|
|
10729
|
-
exactText
|
|
10730
|
-
};
|
|
10731
|
-
await this.vectorStore.upsertAnnotationVector(aid, embedding, payload);
|
|
10732
|
-
this.logger.debug("Smelter batch-indexed annotation", {
|
|
10733
|
-
annotationId: String(aid),
|
|
10734
|
-
resourceId: String(rid)
|
|
10735
|
-
});
|
|
10736
|
-
}
|
|
10737
|
-
}
|
|
10738
|
-
async safeProcessEvent(storedEvent) {
|
|
10739
|
-
try {
|
|
10740
|
-
await this.processEvent(storedEvent);
|
|
10741
|
-
} catch (err) {
|
|
10742
|
-
this.logger.error("Smelter failed to process event", {
|
|
10743
|
-
type: storedEvent.type,
|
|
10744
|
-
resourceId: storedEvent.resourceId,
|
|
10745
|
-
error: err instanceof Error ? err.message : String(err),
|
|
10746
|
-
stack: err instanceof Error ? err.stack : void 0
|
|
10747
|
-
});
|
|
10748
|
-
}
|
|
10749
|
-
}
|
|
10750
|
-
async processEvent(storedEvent) {
|
|
10751
|
-
switch (storedEvent.type) {
|
|
10752
|
-
case "yield:created":
|
|
10753
|
-
await this.handleResourceCreated(storedEvent);
|
|
10754
|
-
break;
|
|
10755
|
-
case "yield:updated":
|
|
10756
|
-
await this.handleResourceUpdated(storedEvent);
|
|
10757
|
-
break;
|
|
10758
|
-
case "yield:representation-added":
|
|
10759
|
-
await this.handleRepresentationAdded(storedEvent);
|
|
10760
|
-
break;
|
|
10761
|
-
case "mark:archived":
|
|
10762
|
-
await this.handleResourceArchived(storedEvent);
|
|
10763
|
-
break;
|
|
10764
|
-
case "mark:added":
|
|
10765
|
-
await this.handleAnnotationAdded(storedEvent);
|
|
10766
|
-
break;
|
|
10767
|
-
case "mark:removed":
|
|
10768
|
-
await this.handleAnnotationRemoved(storedEvent);
|
|
10769
|
-
break;
|
|
10770
|
-
}
|
|
10771
|
-
}
|
|
10772
|
-
async handleResourceCreated(event) {
|
|
10773
|
-
await new Promise((resolve2) => setTimeout(resolve2, 0));
|
|
10774
|
-
const rid = makeResourceId2(event.resourceId);
|
|
10775
|
-
const storageUri = event.payload.storageUri;
|
|
10776
|
-
if (!storageUri) return;
|
|
10777
|
-
this.logger.info("Smelter handleResourceCreated start", {
|
|
10778
|
-
resourceId: String(rid),
|
|
10779
|
-
storageUri,
|
|
10780
|
-
heapMB: Math.round(process.memoryUsage().heapUsed / 1024 / 1024)
|
|
10781
|
-
});
|
|
10782
|
-
const content = await this.contentStore.retrieve(storageUri);
|
|
10783
|
-
if (!content) return;
|
|
10784
|
-
const text = new TextDecoder().decode(content);
|
|
10785
|
-
if (!text.trim()) return;
|
|
10786
|
-
const chunks = chunkText(text, this.chunkingConfig);
|
|
10787
|
-
if (chunks.length === 0) return;
|
|
10788
|
-
this.logger.info("Smelter chunked resource", {
|
|
10789
|
-
resourceId: String(rid),
|
|
10790
|
-
textBytes: text.length,
|
|
10791
|
-
chunkCount: chunks.length,
|
|
10792
|
-
heapMB: Math.round(process.memoryUsage().heapUsed / 1024 / 1024)
|
|
10793
|
-
});
|
|
10794
|
-
const embeddings = await this.embeddingProvider.embedBatch(chunks);
|
|
10795
|
-
const model = this.embeddingProvider.model();
|
|
10796
|
-
const dimensions = this.embeddingProvider.dimensions();
|
|
10797
|
-
this.logger.info("Smelter embedded resource", {
|
|
10798
|
-
resourceId: String(rid),
|
|
10799
|
-
chunkCount: chunks.length,
|
|
10800
|
-
dimensions,
|
|
10801
|
-
heapMB: Math.round(process.memoryUsage().heapUsed / 1024 / 1024)
|
|
10802
|
-
});
|
|
10803
|
-
const embeddingChunks = chunks.map((text2, i) => ({
|
|
10804
|
-
chunkIndex: i,
|
|
10805
|
-
text: text2,
|
|
10806
|
-
embedding: embeddings[i]
|
|
10807
|
-
}));
|
|
10808
|
-
await this.embeddingStore.writeResourceChunks(rid, model, dimensions, embeddingChunks);
|
|
10809
|
-
this.logger.info("Smelter wrote resource embeddings to store", {
|
|
10810
|
-
resourceId: String(rid),
|
|
10811
|
-
chunkCount: embeddingChunks.length,
|
|
10812
|
-
heapMB: Math.round(process.memoryUsage().heapUsed / 1024 / 1024)
|
|
10813
|
-
});
|
|
10814
|
-
await this.vectorStore.upsertResourceVectors(rid, embeddingChunks);
|
|
10815
|
-
this.logger.info("Smelter indexed resource", {
|
|
10816
|
-
resourceId: String(rid),
|
|
10817
|
-
chunks: embeddingChunks.length,
|
|
10818
|
-
heapMB: Math.round(process.memoryUsage().heapUsed / 1024 / 1024)
|
|
10819
|
-
});
|
|
10820
|
-
}
|
|
10821
|
-
/**
|
|
10822
|
-
* Re-embed a resource whose content has changed in-place.
|
|
10823
|
-
*
|
|
10824
|
-
* Used by yield:updated and yield:representation-added handlers. Reads the
|
|
10825
|
-
* current storageUri from the materialized view (which is updated before the
|
|
10826
|
-
* EventBus fires), deletes stale Qdrant vectors, and overwrites the
|
|
10827
|
-
* EmbeddingStore file with fresh chunks.
|
|
10828
|
-
*/
|
|
10829
|
-
async reembedResource(rid) {
|
|
10830
|
-
const view = await this.viewStorage.get(rid);
|
|
10831
|
-
const storageUri = view?.resource.storageUri;
|
|
10832
|
-
if (!storageUri) return;
|
|
10833
|
-
const content = await this.contentStore.retrieve(storageUri);
|
|
10834
|
-
if (!content) return;
|
|
10835
|
-
const text = new TextDecoder().decode(content);
|
|
10836
|
-
if (!text.trim()) return;
|
|
10837
|
-
const chunks = chunkText(text, this.chunkingConfig);
|
|
10838
|
-
if (chunks.length === 0) return;
|
|
10839
|
-
const embeddings = await this.embeddingProvider.embedBatch(chunks);
|
|
10840
|
-
const model = this.embeddingProvider.model();
|
|
10841
|
-
const dimensions = this.embeddingProvider.dimensions();
|
|
10842
|
-
const embeddingChunks = chunks.map((chunkText2, i) => ({
|
|
10843
|
-
chunkIndex: i,
|
|
10844
|
-
text: chunkText2,
|
|
10845
|
-
embedding: embeddings[i]
|
|
10846
|
-
}));
|
|
10847
|
-
await this.embeddingStore.writeResourceChunks(rid, model, dimensions, embeddingChunks);
|
|
10848
|
-
await this.vectorStore.deleteResourceVectors(rid);
|
|
10849
|
-
await this.vectorStore.upsertResourceVectors(rid, embeddingChunks);
|
|
10850
|
-
this.logger.debug("Smelter re-embedded resource", {
|
|
10851
|
-
resourceId: String(rid),
|
|
10852
|
-
chunks: embeddingChunks.length
|
|
10853
|
-
});
|
|
10854
|
-
}
|
|
10855
|
-
async handleResourceUpdated(event) {
|
|
10856
|
-
await this.reembedResource(makeResourceId2(event.resourceId));
|
|
10857
|
-
}
|
|
10858
|
-
async handleRepresentationAdded(event) {
|
|
10859
|
-
await this.reembedResource(makeResourceId2(event.resourceId));
|
|
10860
|
-
}
|
|
10861
|
-
async handleResourceArchived(event) {
|
|
10862
|
-
const rid = makeResourceId2(event.resourceId);
|
|
10863
|
-
await this.vectorStore.deleteResourceVectors(rid);
|
|
10864
|
-
await this.embeddingStore.deleteResourceEmbeddings(rid);
|
|
10865
|
-
this.logger.debug("Smelter deleted resource vectors", { resourceId: String(rid) });
|
|
10866
|
-
}
|
|
10867
|
-
async handleAnnotationAdded(event) {
|
|
10868
|
-
await new Promise((resolve2) => setTimeout(resolve2, 0));
|
|
10869
|
-
const annotation = event.payload.annotation;
|
|
10870
|
-
if (!annotation || !annotation.id) return;
|
|
10871
|
-
const rid = makeResourceId2(event.resourceId);
|
|
10872
|
-
const aid = makeAnnotationId2(annotation.id);
|
|
10873
|
-
const selector = getTargetSelector(annotation.target);
|
|
10874
|
-
const exactText = getExactText(selector);
|
|
10875
|
-
if (!exactText || !exactText.trim()) return;
|
|
10876
|
-
this.logger.info("Smelter handleAnnotationAdded start", {
|
|
10877
|
-
annotationId: String(aid),
|
|
10878
|
-
resourceId: String(rid),
|
|
10879
|
-
textLength: exactText.length,
|
|
10880
|
-
heapMB: Math.round(process.memoryUsage().heapUsed / 1024 / 1024)
|
|
10881
|
-
});
|
|
10882
|
-
const embedding = await this.embeddingProvider.embed(exactText);
|
|
10883
|
-
const model = this.embeddingProvider.model();
|
|
10884
|
-
const dimensions = this.embeddingProvider.dimensions();
|
|
10885
|
-
const motivation = annotation.motivation ?? "";
|
|
10886
|
-
const entityTypes = annotation.entityTypes ?? [];
|
|
10887
|
-
await this.embeddingStore.writeAnnotationEmbedding(
|
|
10888
|
-
aid,
|
|
10889
|
-
rid,
|
|
10890
|
-
model,
|
|
10891
|
-
dimensions,
|
|
10892
|
-
exactText,
|
|
10893
|
-
embedding,
|
|
10894
|
-
motivation,
|
|
10895
|
-
entityTypes
|
|
10896
|
-
);
|
|
10897
|
-
const payload = {
|
|
10898
|
-
annotationId: aid,
|
|
10899
|
-
resourceId: rid,
|
|
10900
|
-
motivation,
|
|
10901
|
-
entityTypes,
|
|
10902
|
-
exactText
|
|
10903
|
-
};
|
|
10904
|
-
await this.vectorStore.upsertAnnotationVector(aid, embedding, payload);
|
|
10905
|
-
this.logger.info("Smelter indexed annotation", {
|
|
10906
|
-
annotationId: String(aid),
|
|
10907
|
-
resourceId: String(rid)
|
|
10908
|
-
});
|
|
10909
|
-
}
|
|
10910
|
-
async handleAnnotationRemoved(event) {
|
|
10911
|
-
const annotationId3 = String(event.payload.annotationId);
|
|
10912
|
-
if (!annotationId3) return;
|
|
10913
|
-
const aid = makeAnnotationId2(annotationId3);
|
|
10914
|
-
await this.vectorStore.deleteAnnotationVector(aid);
|
|
10915
|
-
await this.embeddingStore.deleteAnnotationEmbedding(aid);
|
|
10916
|
-
this.logger.debug("Smelter deleted annotation vector", { annotationId: String(aid) });
|
|
10917
|
-
}
|
|
10918
|
-
};
|
|
10919
|
-
|
|
10920
|
-
// src/embedding-store.ts
|
|
10921
|
-
import { promises as fs } from "fs";
|
|
10922
|
-
import * as path from "path";
|
|
10923
|
-
import { getShardPath } from "@semiont/event-sourcing";
|
|
10924
|
-
var EmbeddingStore = class {
|
|
10925
|
-
constructor(project) {
|
|
10926
|
-
this.project = project;
|
|
10927
|
-
}
|
|
10928
|
-
// ── Path helpers ────────────────────────────────────────────────────────────
|
|
10929
|
-
resourceFilePath(resourceId7) {
|
|
10930
|
-
const [ab, cd] = getShardPath(String(resourceId7));
|
|
10931
|
-
return path.join(this.project.embeddingsDir, ab, cd, `${String(resourceId7)}.jsonl`);
|
|
10932
|
-
}
|
|
10933
|
-
annotationFilePath(annotationId3) {
|
|
10934
|
-
const [ab, cd] = getShardPath(String(annotationId3));
|
|
10935
|
-
return path.join(this.project.embeddingsDir, ab, cd, `${String(annotationId3)}.json`);
|
|
10936
|
-
}
|
|
10937
|
-
// ── Resource embeddings ─────────────────────────────────────────────────────
|
|
10938
|
-
async writeResourceChunks(resourceId7, model, dimensions, chunks) {
|
|
10939
|
-
const filePath = this.resourceFilePath(resourceId7);
|
|
10940
|
-
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
10941
|
-
const header = JSON.stringify({ model, dimensions });
|
|
10942
|
-
const lines = chunks.map(
|
|
10943
|
-
(c) => JSON.stringify({ chunkIndex: c.chunkIndex, text: c.text, embedding: c.embedding })
|
|
10944
|
-
);
|
|
10945
|
-
await fs.writeFile(filePath, [header, ...lines].join("\n") + "\n", "utf-8");
|
|
10946
|
-
}
|
|
10947
|
-
async readResourceEmbeddings(resourceId7) {
|
|
10948
|
-
const filePath = this.resourceFilePath(resourceId7);
|
|
10949
|
-
try {
|
|
10950
|
-
const content = await fs.readFile(filePath, "utf-8");
|
|
10951
|
-
const lines = content.trim().split("\n").filter((l) => l.trim());
|
|
10952
|
-
if (lines.length === 0) return null;
|
|
10953
|
-
const header = JSON.parse(lines[0]);
|
|
10954
|
-
const chunks = lines.slice(1).map((l) => JSON.parse(l));
|
|
10955
|
-
return { model: header.model, dimensions: header.dimensions, chunks };
|
|
10956
|
-
} catch (err) {
|
|
10957
|
-
if (err.code === "ENOENT") return null;
|
|
10958
|
-
throw err;
|
|
10959
|
-
}
|
|
10960
|
-
}
|
|
10961
|
-
async deleteResourceEmbeddings(resourceId7) {
|
|
10962
|
-
const filePath = this.resourceFilePath(resourceId7);
|
|
10963
|
-
try {
|
|
10964
|
-
await fs.unlink(filePath);
|
|
10965
|
-
} catch (err) {
|
|
10966
|
-
if (err.code !== "ENOENT") throw err;
|
|
10967
|
-
}
|
|
10968
|
-
}
|
|
10969
|
-
// ── Annotation embeddings ───────────────────────────────────────────────────
|
|
10970
|
-
async writeAnnotationEmbedding(annotationId3, resourceId7, model, dimensions, text, embedding, motivation, entityTypes) {
|
|
10971
|
-
const filePath = this.annotationFilePath(annotationId3);
|
|
10972
|
-
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
10973
|
-
const data = {
|
|
10974
|
-
model,
|
|
10975
|
-
dimensions,
|
|
10976
|
-
resourceId: String(resourceId7),
|
|
10977
|
-
text,
|
|
10978
|
-
embedding,
|
|
10979
|
-
motivation,
|
|
10980
|
-
entityTypes
|
|
10981
|
-
};
|
|
10982
|
-
await fs.writeFile(filePath, JSON.stringify(data), "utf-8");
|
|
10983
|
-
}
|
|
10984
|
-
async readAnnotationEmbedding(annotationId3) {
|
|
10985
|
-
const filePath = this.annotationFilePath(annotationId3);
|
|
10986
|
-
try {
|
|
10987
|
-
const content = await fs.readFile(filePath, "utf-8");
|
|
10988
|
-
return JSON.parse(content);
|
|
10989
|
-
} catch (err) {
|
|
10990
|
-
if (err.code === "ENOENT") return null;
|
|
10991
|
-
throw err;
|
|
10992
|
-
}
|
|
10993
|
-
}
|
|
10994
|
-
async deleteAnnotationEmbedding(annotationId3) {
|
|
10995
|
-
const filePath = this.annotationFilePath(annotationId3);
|
|
10996
|
-
try {
|
|
10997
|
-
await fs.unlink(filePath);
|
|
10998
|
-
} catch (err) {
|
|
10999
|
-
if (err.code !== "ENOENT") throw err;
|
|
11000
|
-
}
|
|
11001
|
-
}
|
|
11002
|
-
// ── Scan ────────────────────────────────────────────────────────────────────
|
|
11003
|
-
/**
|
|
11004
|
-
* Scan embeddings directory and return all resource IDs (from *.jsonl files).
|
|
11005
|
-
*/
|
|
11006
|
-
async getAllResourceIds() {
|
|
11007
|
-
return this.scanIds((name) => name.endsWith(".jsonl"), ".jsonl");
|
|
11008
|
-
}
|
|
11009
|
-
/**
|
|
11010
|
-
* Scan embeddings directory and return all annotation IDs (from *.json files).
|
|
11011
|
-
*/
|
|
11012
|
-
async getAllAnnotationIds() {
|
|
11013
|
-
return this.scanIds((name) => name.endsWith(".json"), ".json");
|
|
11014
|
-
}
|
|
11015
|
-
async scanIds(filter, ext) {
|
|
11016
|
-
const base = this.project.embeddingsDir;
|
|
11017
|
-
try {
|
|
11018
|
-
await fs.access(base);
|
|
11019
|
-
} catch {
|
|
11020
|
-
return [];
|
|
11021
|
-
}
|
|
11022
|
-
const results = [];
|
|
11023
|
-
const scan = async (dir) => {
|
|
11024
|
-
let entries;
|
|
11025
|
-
try {
|
|
11026
|
-
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
11027
|
-
} catch {
|
|
11028
|
-
return;
|
|
11029
|
-
}
|
|
11030
|
-
for (const entry of entries) {
|
|
11031
|
-
const full = path.join(dir, entry.name);
|
|
11032
|
-
if (entry.isDirectory()) {
|
|
11033
|
-
await scan(full);
|
|
11034
|
-
} else if (filter(entry.name)) {
|
|
11035
|
-
results.push(entry.name.slice(0, -ext.length));
|
|
11036
|
-
}
|
|
11037
|
-
}
|
|
11038
|
-
};
|
|
11039
|
-
await scan(base);
|
|
11040
|
-
return results;
|
|
11041
|
-
}
|
|
11042
|
-
};
|
|
11043
|
-
|
|
11044
10387
|
// src/knowledge-base.ts
|
|
11045
10388
|
async function createKnowledgeBase(eventStore, project, graphDb, eventBus, logger, options) {
|
|
11046
|
-
const views = new FilesystemViewStorage(project);
|
|
10389
|
+
const views = new FilesystemViewStorage(project, logger.child({ component: "view-storage" }));
|
|
11047
10390
|
const content = new WorkingTreeStore(
|
|
11048
10391
|
project,
|
|
11049
10392
|
logger.child({ component: "working-tree-store" })
|
|
@@ -11067,32 +10410,16 @@ async function createKnowledgeBase(eventStore, project, graphDb, eventBus, logge
|
|
|
11067
10410
|
graphConsumer,
|
|
11068
10411
|
projectionsDir: project.projectionsDir
|
|
11069
10412
|
};
|
|
11070
|
-
if (options?.vectorStore
|
|
10413
|
+
if (options?.vectorStore) {
|
|
11071
10414
|
kb.vectors = options.vectorStore;
|
|
11072
|
-
const embeddingStore = new EmbeddingStore(project);
|
|
11073
|
-
kb.smelter = new Smelter(
|
|
11074
|
-
eventStore,
|
|
11075
|
-
eventBus,
|
|
11076
|
-
options.vectorStore,
|
|
11077
|
-
options.embeddingProvider,
|
|
11078
|
-
content,
|
|
11079
|
-
embeddingStore,
|
|
11080
|
-
views,
|
|
11081
|
-
logger.child({ component: "smelter" }),
|
|
11082
|
-
options.chunkingConfig
|
|
11083
|
-
);
|
|
11084
|
-
await kb.smelter.initialize();
|
|
11085
|
-
if (!options.skipRebuild) {
|
|
11086
|
-
await kb.smelter.rebuildAll();
|
|
11087
|
-
}
|
|
11088
10415
|
}
|
|
11089
10416
|
return kb;
|
|
11090
10417
|
}
|
|
11091
10418
|
|
|
11092
10419
|
// src/gatherer.ts
|
|
11093
|
-
var
|
|
11094
|
-
var
|
|
11095
|
-
import { annotationId as
|
|
10420
|
+
var import_rxjs2 = __toESM(require_cjs(), 1);
|
|
10421
|
+
var import_operators2 = __toESM(require_operators(), 1);
|
|
10422
|
+
import { annotationId as makeAnnotationId2, resourceId, errField as errField2 } from "@semiont/core";
|
|
11096
10423
|
|
|
11097
10424
|
// src/generation/resource-generation.ts
|
|
11098
10425
|
async function generateResourceSummary(resourceName, content, entityTypes, client) {
|
|
@@ -11122,7 +10449,7 @@ import {
|
|
|
11122
10449
|
getBodySource,
|
|
11123
10450
|
getResourceId,
|
|
11124
10451
|
getTargetSource,
|
|
11125
|
-
getTargetSelector
|
|
10452
|
+
getTargetSelector,
|
|
11126
10453
|
getResourceEntityTypes,
|
|
11127
10454
|
getTextPositionSelector,
|
|
11128
10455
|
getPrimaryRepresentation as getPrimaryRepresentation2,
|
|
@@ -11280,7 +10607,7 @@ var AnnotationContext = class {
|
|
|
11280
10607
|
const primaryRep = getPrimaryRepresentation2(sourceDoc);
|
|
11281
10608
|
const sourceContent = await kb.content.retrieve(sourceDoc.storageUri);
|
|
11282
10609
|
const contentStr = decodeRepresentation2(sourceContent, primaryRep?.mediaType ?? "text/plain");
|
|
11283
|
-
const targetSelectorRaw =
|
|
10610
|
+
const targetSelectorRaw = getTargetSelector(annotation.target);
|
|
11284
10611
|
const targetSelector = Array.isArray(targetSelectorRaw) ? targetSelectorRaw[0] : targetSelectorRaw;
|
|
11285
10612
|
logger?.debug("Target selector", { type: targetSelector?.type });
|
|
11286
10613
|
if (!targetSelector) {
|
|
@@ -11657,7 +10984,7 @@ Summary:`;
|
|
|
11657
10984
|
* Extract annotation context from resource content
|
|
11658
10985
|
*/
|
|
11659
10986
|
static extractAnnotationContext(annotation, contentStr, contextBefore, contextAfter) {
|
|
11660
|
-
const targetSelector =
|
|
10987
|
+
const targetSelector = getTargetSelector(annotation.target);
|
|
11661
10988
|
const posSelector = targetSelector ? getTextPositionSelector(targetSelector) : null;
|
|
11662
10989
|
if (!posSelector) {
|
|
11663
10990
|
throw new Error("TextPositionSelector required for context");
|
|
@@ -11757,7 +11084,7 @@ var GraphContext = class {
|
|
|
11757
11084
|
|
|
11758
11085
|
// src/llm-context.ts
|
|
11759
11086
|
import { getResourceEntityTypes as getResourceEntityTypes3, getResourceId as getResourceId3 } from "@semiont/api-client";
|
|
11760
|
-
import { resourceId as
|
|
11087
|
+
import { resourceId as makeResourceId2 } from "@semiont/core";
|
|
11761
11088
|
var LLMContext = class {
|
|
11762
11089
|
/**
|
|
11763
11090
|
* Get comprehensive LLM context for a resource
|
|
@@ -11778,7 +11105,7 @@ var LLMContext = class {
|
|
|
11778
11105
|
const resourceIdStr = resourceId7.toString();
|
|
11779
11106
|
for (const node of graph.nodes) {
|
|
11780
11107
|
if (node.id !== resourceIdStr) {
|
|
11781
|
-
const relatedDoc = await ResourceContext.getResourceMetadata(
|
|
11108
|
+
const relatedDoc = await ResourceContext.getResourceMetadata(makeResourceId2(node.id), kb);
|
|
11782
11109
|
if (relatedDoc) {
|
|
11783
11110
|
relatedDocs.push(relatedDoc);
|
|
11784
11111
|
}
|
|
@@ -11833,18 +11160,18 @@ var Gatherer = class {
|
|
|
11833
11160
|
this.logger.info("Gatherer actor initialized");
|
|
11834
11161
|
const errorHandler = (err) => this.logger.error("Gatherer pipeline error", { error: err });
|
|
11835
11162
|
const annotationGather$ = this.eventBus.get("gather:requested").pipe(
|
|
11836
|
-
(0,
|
|
11837
|
-
(0,
|
|
11163
|
+
(0, import_operators2.groupBy)((event) => event.resourceId),
|
|
11164
|
+
(0, import_operators2.mergeMap)(
|
|
11838
11165
|
(group$) => group$.pipe(
|
|
11839
|
-
(0,
|
|
11166
|
+
(0, import_operators2.concatMap)((event) => (0, import_rxjs2.from)(this.handleAnnotationGather(event)))
|
|
11840
11167
|
)
|
|
11841
11168
|
)
|
|
11842
11169
|
);
|
|
11843
11170
|
const resourceGather$ = this.eventBus.get("gather:resource-requested").pipe(
|
|
11844
|
-
(0,
|
|
11845
|
-
(0,
|
|
11171
|
+
(0, import_operators2.groupBy)((event) => event.resourceId),
|
|
11172
|
+
(0, import_operators2.mergeMap)(
|
|
11846
11173
|
(group$) => group$.pipe(
|
|
11847
|
-
(0,
|
|
11174
|
+
(0, import_operators2.concatMap)((event) => (0, import_rxjs2.from)(this.handleResourceGather(event)))
|
|
11848
11175
|
)
|
|
11849
11176
|
)
|
|
11850
11177
|
);
|
|
@@ -11857,14 +11184,13 @@ var Gatherer = class {
|
|
|
11857
11184
|
// Gather handlers (existing)
|
|
11858
11185
|
// ========================================================================
|
|
11859
11186
|
async handleAnnotationGather(event) {
|
|
11860
|
-
const resultBus = this.eventBus.scope(event.resourceId);
|
|
11861
11187
|
try {
|
|
11862
11188
|
this.logger.debug("Gathering annotation context", {
|
|
11863
11189
|
annotationId: event.annotationId,
|
|
11864
11190
|
resourceId: event.resourceId
|
|
11865
11191
|
});
|
|
11866
11192
|
const response = await AnnotationContext.buildLLMContext(
|
|
11867
|
-
|
|
11193
|
+
makeAnnotationId2(event.annotationId),
|
|
11868
11194
|
resourceId(event.resourceId),
|
|
11869
11195
|
this.kb,
|
|
11870
11196
|
event.options ?? {},
|
|
@@ -11872,7 +11198,7 @@ var Gatherer = class {
|
|
|
11872
11198
|
this.logger,
|
|
11873
11199
|
this.embeddingProvider
|
|
11874
11200
|
);
|
|
11875
|
-
|
|
11201
|
+
this.eventBus.get("gather:complete").next({
|
|
11876
11202
|
correlationId: event.correlationId,
|
|
11877
11203
|
annotationId: event.annotationId,
|
|
11878
11204
|
response
|
|
@@ -11880,9 +11206,9 @@ var Gatherer = class {
|
|
|
11880
11206
|
} catch (error) {
|
|
11881
11207
|
this.logger.error("Gather annotation context failed", {
|
|
11882
11208
|
annotationId: event.annotationId,
|
|
11883
|
-
error
|
|
11209
|
+
error: errField2(error)
|
|
11884
11210
|
});
|
|
11885
|
-
|
|
11211
|
+
this.eventBus.get("gather:failed").next({
|
|
11886
11212
|
correlationId: event.correlationId,
|
|
11887
11213
|
annotationId: event.annotationId,
|
|
11888
11214
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -11890,7 +11216,6 @@ var Gatherer = class {
|
|
|
11890
11216
|
}
|
|
11891
11217
|
}
|
|
11892
11218
|
async handleResourceGather(event) {
|
|
11893
|
-
const resultBus = this.eventBus.scope(event.resourceId);
|
|
11894
11219
|
try {
|
|
11895
11220
|
this.logger.debug("Gathering resource context", {
|
|
11896
11221
|
resourceId: event.resourceId
|
|
@@ -11901,7 +11226,7 @@ var Gatherer = class {
|
|
|
11901
11226
|
this.kb,
|
|
11902
11227
|
this.inferenceClient
|
|
11903
11228
|
);
|
|
11904
|
-
|
|
11229
|
+
this.eventBus.get("gather:resource-complete").next({
|
|
11905
11230
|
correlationId: event.correlationId,
|
|
11906
11231
|
resourceId: event.resourceId,
|
|
11907
11232
|
response: result
|
|
@@ -11909,9 +11234,9 @@ var Gatherer = class {
|
|
|
11909
11234
|
} catch (error) {
|
|
11910
11235
|
this.logger.error("Gather resource context failed", {
|
|
11911
11236
|
resourceId: event.resourceId,
|
|
11912
|
-
error
|
|
11237
|
+
error: errField2(error)
|
|
11913
11238
|
});
|
|
11914
|
-
|
|
11239
|
+
this.eventBus.get("gather:resource-failed").next({
|
|
11915
11240
|
correlationId: event.correlationId,
|
|
11916
11241
|
resourceId: event.resourceId,
|
|
11917
11242
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -11936,9 +11261,9 @@ var Gatherer = class {
|
|
|
11936
11261
|
};
|
|
11937
11262
|
|
|
11938
11263
|
// src/matcher.ts
|
|
11939
|
-
var
|
|
11940
|
-
var
|
|
11941
|
-
import { resourceId as resourceId2 } from "@semiont/core";
|
|
11264
|
+
var import_rxjs3 = __toESM(require_cjs(), 1);
|
|
11265
|
+
var import_operators3 = __toESM(require_operators(), 1);
|
|
11266
|
+
import { resourceId as resourceId2, errField as errField3 } from "@semiont/core";
|
|
11942
11267
|
import { getResourceId as getResourceId4, getResourceEntityTypes as getResourceEntityTypes4 } from "@semiont/api-client";
|
|
11943
11268
|
var Matcher = class {
|
|
11944
11269
|
constructor(kb, eventBus, logger, inferenceClient, embeddingProvider) {
|
|
@@ -11954,7 +11279,7 @@ var Matcher = class {
|
|
|
11954
11279
|
this.logger.info("Matcher actor initialized");
|
|
11955
11280
|
const errorHandler = (err) => this.logger.error("Matcher pipeline error", { error: err });
|
|
11956
11281
|
const search$ = this.eventBus.get("match:search-requested").pipe(
|
|
11957
|
-
(0,
|
|
11282
|
+
(0, import_operators3.concatMap)((event) => (0, import_rxjs3.from)(this.handleSearch(event)))
|
|
11958
11283
|
);
|
|
11959
11284
|
this.subscriptions.push(
|
|
11960
11285
|
search$.subscribe({ error: errorHandler })
|
|
@@ -11962,7 +11287,6 @@ var Matcher = class {
|
|
|
11962
11287
|
}
|
|
11963
11288
|
async handleSearch(event) {
|
|
11964
11289
|
try {
|
|
11965
|
-
const resultBus = this.eventBus.scope(event.resourceId);
|
|
11966
11290
|
const context = event.context;
|
|
11967
11291
|
const selectedText = context.sourceContext?.selected ?? "";
|
|
11968
11292
|
const userHint = context.userHint ?? "";
|
|
@@ -11979,7 +11303,7 @@ var Matcher = class {
|
|
|
11979
11303
|
event.useSemanticScoring
|
|
11980
11304
|
);
|
|
11981
11305
|
const limited = event.limit ? scored.slice(0, event.limit) : scored;
|
|
11982
|
-
|
|
11306
|
+
this.eventBus.get("match:search-results").next({
|
|
11983
11307
|
correlationId: event.correlationId,
|
|
11984
11308
|
referenceId: event.referenceId,
|
|
11985
11309
|
response: limited
|
|
@@ -11987,9 +11311,9 @@ var Matcher = class {
|
|
|
11987
11311
|
} catch (error) {
|
|
11988
11312
|
this.logger.error("Bind search failed", {
|
|
11989
11313
|
referenceId: event.referenceId,
|
|
11990
|
-
error
|
|
11314
|
+
error: errField3(error)
|
|
11991
11315
|
});
|
|
11992
|
-
this.eventBus.
|
|
11316
|
+
this.eventBus.get("match:search-failed").next({
|
|
11993
11317
|
correlationId: event.correlationId,
|
|
11994
11318
|
referenceId: event.referenceId,
|
|
11995
11319
|
error: error instanceof Error ? error.message : String(error)
|
|
@@ -12255,10 +11579,10 @@ For each candidate, output a line with the number and score, like:
|
|
|
12255
11579
|
};
|
|
12256
11580
|
|
|
12257
11581
|
// src/stower.ts
|
|
12258
|
-
var
|
|
12259
|
-
var
|
|
12260
|
-
import { promises as
|
|
12261
|
-
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 { errField as errField4, resourceId as resourceId3, userId as makeUserId, CREATION_METHODS, generateUuid } from "@semiont/core";
|
|
12262
11586
|
import { resolveStorageUri } from "@semiont/event-sourcing";
|
|
12263
11587
|
var Stower = class {
|
|
12264
11588
|
constructor(kb, eventBus, logger) {
|
|
@@ -12270,8 +11594,8 @@ var Stower = class {
|
|
|
12270
11594
|
logger;
|
|
12271
11595
|
async initialize() {
|
|
12272
11596
|
this.logger.info("Stower actor initialized");
|
|
12273
|
-
const pipe = (event, handler) => this.eventBus.get(event).pipe((0,
|
|
12274
|
-
this.subscription = (0,
|
|
11597
|
+
const pipe = (event, handler) => this.eventBus.get(event).pipe((0, import_operators4.concatMap)((e) => (0, import_rxjs4.from)(handler(e))));
|
|
11598
|
+
this.subscription = (0, import_rxjs4.merge)(
|
|
12275
11599
|
pipe("yield:create", (e) => this.handleYieldCreate(e)),
|
|
12276
11600
|
pipe("yield:update", (e) => this.handleYieldUpdate(e)),
|
|
12277
11601
|
pipe("yield:mv", (e) => this.handleYieldMv(e)),
|
|
@@ -12283,7 +11607,6 @@ var Stower = class {
|
|
|
12283
11607
|
pipe("mark:unarchive", (e) => this.handleMarkUnarchive(e)),
|
|
12284
11608
|
pipe("mark:update-entity-types", (e) => this.handleUpdateEntityTypes(e)),
|
|
12285
11609
|
pipe("job:start", (e) => this.handleJobStart(e)),
|
|
12286
|
-
pipe("job:report-progress", (e) => this.handleJobReportProgress(e)),
|
|
12287
11610
|
pipe("job:complete", (e) => this.handleJobComplete(e)),
|
|
12288
11611
|
pipe("job:fail", (e) => this.handleJobFail(e))
|
|
12289
11612
|
).subscribe({
|
|
@@ -12343,8 +11666,30 @@ var Stower = class {
|
|
|
12343
11666
|
]
|
|
12344
11667
|
};
|
|
12345
11668
|
this.eventBus.get("yield:create-ok").next({ resourceId: rId, resource });
|
|
11669
|
+
if (generatedFrom) {
|
|
11670
|
+
this.eventBus.get("mark:update-body").next({
|
|
11671
|
+
annotationId: generatedFrom.annotationId,
|
|
11672
|
+
userId: event.userId,
|
|
11673
|
+
resourceId: generatedFrom.resourceId,
|
|
11674
|
+
operations: [
|
|
11675
|
+
{
|
|
11676
|
+
op: "add",
|
|
11677
|
+
item: {
|
|
11678
|
+
type: "SpecificResource",
|
|
11679
|
+
source: rId,
|
|
11680
|
+
purpose: "linking"
|
|
11681
|
+
}
|
|
11682
|
+
}
|
|
11683
|
+
]
|
|
11684
|
+
});
|
|
11685
|
+
this.logger.info("Auto-bound generated resource to source reference", {
|
|
11686
|
+
resourceId: rId,
|
|
11687
|
+
sourceAnnotationId: generatedFrom.annotationId,
|
|
11688
|
+
sourceResourceId: generatedFrom.resourceId
|
|
11689
|
+
});
|
|
11690
|
+
}
|
|
12346
11691
|
} catch (error) {
|
|
12347
|
-
this.logger.error("Failed to create resource", { error });
|
|
11692
|
+
this.logger.error("Failed to create resource", { error: errField4(error) });
|
|
12348
11693
|
this.eventBus.get("yield:create-failed").next({
|
|
12349
11694
|
message: error instanceof Error ? error.message : String(error)
|
|
12350
11695
|
});
|
|
@@ -12365,7 +11710,7 @@ var Stower = class {
|
|
|
12365
11710
|
});
|
|
12366
11711
|
this.eventBus.get("yield:update-ok").next({ resourceId: event.resourceId });
|
|
12367
11712
|
} catch (error) {
|
|
12368
|
-
this.logger.error("Failed to update resource", { error });
|
|
11713
|
+
this.logger.error("Failed to update resource", { error: errField4(error) });
|
|
12369
11714
|
this.eventBus.get("yield:update-failed").next({
|
|
12370
11715
|
resourceId: event.resourceId,
|
|
12371
11716
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -12399,7 +11744,7 @@ var Stower = class {
|
|
|
12399
11744
|
});
|
|
12400
11745
|
this.eventBus.get("yield:move-ok").next({ resourceId: rId });
|
|
12401
11746
|
} catch (error) {
|
|
12402
|
-
this.logger.error("Failed to move resource", { error });
|
|
11747
|
+
this.logger.error("Failed to move resource", { error: errField4(error) });
|
|
12403
11748
|
this.eventBus.get("yield:move-failed").next({
|
|
12404
11749
|
fromUri: event.fromUri,
|
|
12405
11750
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -12409,17 +11754,20 @@ var Stower = class {
|
|
|
12409
11754
|
async handleMarkCreate(event) {
|
|
12410
11755
|
try {
|
|
12411
11756
|
this.logger.debug("Stowing annotation", { annotationId: event.annotation.id });
|
|
12412
|
-
await this.kb.eventStore.appendEvent(
|
|
12413
|
-
|
|
12414
|
-
|
|
12415
|
-
|
|
12416
|
-
|
|
12417
|
-
|
|
12418
|
-
|
|
12419
|
-
|
|
11757
|
+
await this.kb.eventStore.appendEvent(
|
|
11758
|
+
{
|
|
11759
|
+
type: "mark:added",
|
|
11760
|
+
resourceId: resourceId3(event.resourceId),
|
|
11761
|
+
userId: makeUserId(event.userId),
|
|
11762
|
+
version: 1,
|
|
11763
|
+
payload: { annotation: event.annotation }
|
|
11764
|
+
},
|
|
11765
|
+
event.correlationId ? { correlationId: event.correlationId } : void 0
|
|
11766
|
+
);
|
|
12420
11767
|
} catch (error) {
|
|
12421
|
-
this.logger.error("Failed to create annotation", { error });
|
|
11768
|
+
this.logger.error("Failed to create annotation", { error: errField4(error) });
|
|
12422
11769
|
this.eventBus.get("mark:create-failed").next({
|
|
11770
|
+
correlationId: event.correlationId,
|
|
12423
11771
|
message: error instanceof Error ? error.message : String(error)
|
|
12424
11772
|
});
|
|
12425
11773
|
}
|
|
@@ -12438,7 +11786,7 @@ var Stower = class {
|
|
|
12438
11786
|
});
|
|
12439
11787
|
this.eventBus.get("mark:delete-ok").next({ annotationId: event.annotationId });
|
|
12440
11788
|
} catch (error) {
|
|
12441
|
-
this.logger.error("Failed to delete annotation", { error });
|
|
11789
|
+
this.logger.error("Failed to delete annotation", { error: errField4(error) });
|
|
12442
11790
|
this.eventBus.get("mark:delete-failed").next({
|
|
12443
11791
|
message: error instanceof Error ? error.message : String(error)
|
|
12444
11792
|
});
|
|
@@ -12459,8 +11807,9 @@ var Stower = class {
|
|
|
12459
11807
|
event.correlationId ? { correlationId: event.correlationId } : void 0
|
|
12460
11808
|
);
|
|
12461
11809
|
} catch (error) {
|
|
12462
|
-
this.logger.error("Failed to update annotation body", { error });
|
|
11810
|
+
this.logger.error("Failed to update annotation body", { error: errField4(error) });
|
|
12463
11811
|
this.eventBus.get("mark:body-update-failed").next({
|
|
11812
|
+
correlationId: event.correlationId,
|
|
12464
11813
|
message: error instanceof Error ? error.message : String(error)
|
|
12465
11814
|
});
|
|
12466
11815
|
}
|
|
@@ -12489,7 +11838,7 @@ var Stower = class {
|
|
|
12489
11838
|
if (event.storageUri) {
|
|
12490
11839
|
const absPath = this.kb.content.resolveUri(event.storageUri);
|
|
12491
11840
|
try {
|
|
12492
|
-
await
|
|
11841
|
+
await fs.access(absPath);
|
|
12493
11842
|
} catch {
|
|
12494
11843
|
this.logger.warn("Unarchive failed: file not found at storageUri", { storageUri: event.storageUri });
|
|
12495
11844
|
return;
|
|
@@ -12512,7 +11861,7 @@ var Stower = class {
|
|
|
12512
11861
|
payload: { entityType: event.tag }
|
|
12513
11862
|
});
|
|
12514
11863
|
} catch (error) {
|
|
12515
|
-
this.logger.error("Failed to add entity type", { error });
|
|
11864
|
+
this.logger.error("Failed to add entity type", { error: errField4(error) });
|
|
12516
11865
|
this.eventBus.get("mark:entity-type-add-failed").next({
|
|
12517
11866
|
message: error instanceof Error ? error.message : String(error)
|
|
12518
11867
|
});
|
|
@@ -12546,20 +11895,10 @@ var Stower = class {
|
|
|
12546
11895
|
resourceId: resourceId3(event.resourceId),
|
|
12547
11896
|
userId: makeUserId(event.userId),
|
|
12548
11897
|
version: 1,
|
|
12549
|
-
payload: { jobId: event.jobId, jobType: event.jobType }
|
|
12550
|
-
});
|
|
12551
|
-
}
|
|
12552
|
-
async handleJobReportProgress(event) {
|
|
12553
|
-
await this.kb.eventStore.appendEvent({
|
|
12554
|
-
type: "job:progress",
|
|
12555
|
-
resourceId: resourceId3(event.resourceId),
|
|
12556
|
-
userId: makeUserId(event.userId),
|
|
12557
|
-
version: 1,
|
|
12558
11898
|
payload: {
|
|
12559
11899
|
jobId: event.jobId,
|
|
12560
11900
|
jobType: event.jobType,
|
|
12561
|
-
|
|
12562
|
-
progress: event.progress
|
|
11901
|
+
...event.annotationId ? { annotationId: event.annotationId } : {}
|
|
12563
11902
|
}
|
|
12564
11903
|
});
|
|
12565
11904
|
}
|
|
@@ -12572,6 +11911,7 @@ var Stower = class {
|
|
|
12572
11911
|
payload: {
|
|
12573
11912
|
jobId: event.jobId,
|
|
12574
11913
|
jobType: event.jobType,
|
|
11914
|
+
...event.annotationId ? { annotationId: event.annotationId } : {},
|
|
12575
11915
|
result: event.result
|
|
12576
11916
|
}
|
|
12577
11917
|
});
|
|
@@ -12585,6 +11925,7 @@ var Stower = class {
|
|
|
12585
11925
|
payload: {
|
|
12586
11926
|
jobId: event.jobId,
|
|
12587
11927
|
jobType: event.jobType,
|
|
11928
|
+
...event.annotationId ? { annotationId: event.annotationId } : {},
|
|
12588
11929
|
error: event.error
|
|
12589
11930
|
}
|
|
12590
11931
|
});
|
|
@@ -12597,27 +11938,27 @@ var Stower = class {
|
|
|
12597
11938
|
};
|
|
12598
11939
|
|
|
12599
11940
|
// src/browser.ts
|
|
12600
|
-
var
|
|
12601
|
-
var
|
|
12602
|
-
import { promises as
|
|
12603
|
-
import * as
|
|
12604
|
-
import { resourceId as resourceId4, annotationId } from "@semiont/core";
|
|
12605
|
-
import { getExactText
|
|
11941
|
+
var import_rxjs5 = __toESM(require_cjs(), 1);
|
|
11942
|
+
var import_operators5 = __toESM(require_operators(), 1);
|
|
11943
|
+
import { promises as fs3 } from "fs";
|
|
11944
|
+
import * as path2 from "path";
|
|
11945
|
+
import { resourceId as resourceId4, annotationId, errField as errField5 } from "@semiont/core";
|
|
11946
|
+
import { getExactText, getTargetSource as getTargetSource2, getTargetSelector as getTargetSelector2, getResourceEntityTypes as getResourceEntityTypes5, getBodySource as getBodySource2 } from "@semiont/api-client";
|
|
12606
11947
|
import { EventQuery as EventQuery2 } from "@semiont/event-sourcing";
|
|
12607
11948
|
import { getEntityTypes as getEntityTypes2 } from "@semiont/ontology";
|
|
12608
11949
|
|
|
12609
11950
|
// src/views/entity-types-reader.ts
|
|
12610
|
-
import { promises as
|
|
12611
|
-
import * as
|
|
11951
|
+
import { promises as fs2 } from "fs";
|
|
11952
|
+
import * as path from "path";
|
|
12612
11953
|
async function readEntityTypesProjection(project) {
|
|
12613
|
-
const entityTypesPath =
|
|
11954
|
+
const entityTypesPath = path.join(
|
|
12614
11955
|
project.stateDir,
|
|
12615
11956
|
"projections",
|
|
12616
11957
|
"__system__",
|
|
12617
11958
|
"entitytypes.json"
|
|
12618
11959
|
);
|
|
12619
11960
|
try {
|
|
12620
|
-
const content = await
|
|
11961
|
+
const content = await fs2.readFile(entityTypesPath, "utf-8");
|
|
12621
11962
|
const projection = JSON.parse(content);
|
|
12622
11963
|
return projection.entityTypes || [];
|
|
12623
11964
|
} catch (error) {
|
|
@@ -12642,7 +11983,7 @@ var Browser = class {
|
|
|
12642
11983
|
async initialize() {
|
|
12643
11984
|
this.logger.info("Browser actor initialized");
|
|
12644
11985
|
const errorHandler = (err) => this.logger.error("Browser pipeline error", { error: err });
|
|
12645
|
-
const pipe = (name, handler) => this.eventBus.get(name).pipe((0,
|
|
11986
|
+
const pipe = (name, handler) => this.eventBus.get(name).pipe((0, import_operators5.mergeMap)((event) => (0, import_rxjs5.from)(handler(event))));
|
|
12646
11987
|
this.subscriptions.push(
|
|
12647
11988
|
pipe("browse:resource-requested", (e) => this.handleBrowseResource(e)).subscribe({ error: errorHandler }),
|
|
12648
11989
|
pipe("browse:resources-requested", (e) => this.handleBrowseResources(e)).subscribe({ error: errorHandler }),
|
|
@@ -12684,7 +12025,7 @@ var Browser = class {
|
|
|
12684
12025
|
}
|
|
12685
12026
|
});
|
|
12686
12027
|
} catch (error) {
|
|
12687
|
-
this.logger.error("Browse resource failed", { resourceId: event.resourceId, error });
|
|
12028
|
+
this.logger.error("Browse resource failed", { resourceId: event.resourceId, error: errField5(error) });
|
|
12688
12029
|
this.eventBus.get("browse:resource-failed").next({
|
|
12689
12030
|
correlationId: event.correlationId,
|
|
12690
12031
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -12714,7 +12055,7 @@ var Browser = class {
|
|
|
12714
12055
|
}
|
|
12715
12056
|
});
|
|
12716
12057
|
} catch (error) {
|
|
12717
|
-
this.logger.error("Browse resources failed", { error });
|
|
12058
|
+
this.logger.error("Browse resources failed", { error: errField5(error) });
|
|
12718
12059
|
this.eventBus.get("browse:resources-failed").next({
|
|
12719
12060
|
correlationId: event.correlationId,
|
|
12720
12061
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -12732,7 +12073,7 @@ var Browser = class {
|
|
|
12732
12073
|
}
|
|
12733
12074
|
});
|
|
12734
12075
|
} catch (error) {
|
|
12735
|
-
this.logger.error("Browse annotations failed", { resourceId: event.resourceId, error });
|
|
12076
|
+
this.logger.error("Browse annotations failed", { resourceId: event.resourceId, error: errField5(error) });
|
|
12736
12077
|
this.eventBus.get("browse:annotations-failed").next({
|
|
12737
12078
|
correlationId: event.correlationId,
|
|
12738
12079
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -12764,7 +12105,7 @@ var Browser = class {
|
|
|
12764
12105
|
}
|
|
12765
12106
|
});
|
|
12766
12107
|
} catch (error) {
|
|
12767
|
-
this.logger.error("Browse annotation failed", { resourceId: event.resourceId, annotationId: event.annotationId, error });
|
|
12108
|
+
this.logger.error("Browse annotation failed", { resourceId: event.resourceId, annotationId: event.annotationId, error: errField5(error) });
|
|
12768
12109
|
this.eventBus.get("browse:annotation-failed").next({
|
|
12769
12110
|
correlationId: event.correlationId,
|
|
12770
12111
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -12796,7 +12137,7 @@ var Browser = class {
|
|
|
12796
12137
|
}
|
|
12797
12138
|
});
|
|
12798
12139
|
} catch (error) {
|
|
12799
|
-
this.logger.error("Browse events failed", { resourceId: event.resourceId, error });
|
|
12140
|
+
this.logger.error("Browse events failed", { resourceId: event.resourceId, error: errField5(error) });
|
|
12800
12141
|
this.eventBus.get("browse:events-failed").next({
|
|
12801
12142
|
correlationId: event.correlationId,
|
|
12802
12143
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -12832,7 +12173,7 @@ var Browser = class {
|
|
|
12832
12173
|
}
|
|
12833
12174
|
});
|
|
12834
12175
|
} catch (error) {
|
|
12835
|
-
this.logger.error("Browse annotation history failed", { resourceId: event.resourceId, annotationId: event.annotationId, error });
|
|
12176
|
+
this.logger.error("Browse annotation history failed", { resourceId: event.resourceId, annotationId: event.annotationId, error: errField5(error) });
|
|
12836
12177
|
this.eventBus.get("browse:annotation-history-failed").next({
|
|
12837
12178
|
correlationId: event.correlationId,
|
|
12838
12179
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -12856,7 +12197,7 @@ var Browser = class {
|
|
|
12856
12197
|
const docMap = new Map(resources.filter((doc) => doc !== null).map((doc) => [doc["@id"], doc]));
|
|
12857
12198
|
const referencedBy = references.map((ref) => {
|
|
12858
12199
|
const targetSource = getTargetSource2(ref.target);
|
|
12859
|
-
const targetSelector =
|
|
12200
|
+
const targetSelector = getTargetSelector2(ref.target);
|
|
12860
12201
|
const doc = docMap.get(targetSource);
|
|
12861
12202
|
return {
|
|
12862
12203
|
id: ref.id,
|
|
@@ -12864,7 +12205,7 @@ var Browser = class {
|
|
|
12864
12205
|
target: {
|
|
12865
12206
|
source: targetSource,
|
|
12866
12207
|
selector: {
|
|
12867
|
-
exact: targetSelector ?
|
|
12208
|
+
exact: targetSelector ? getExactText(targetSelector) : ""
|
|
12868
12209
|
}
|
|
12869
12210
|
}
|
|
12870
12211
|
};
|
|
@@ -12874,7 +12215,7 @@ var Browser = class {
|
|
|
12874
12215
|
response: { referencedBy }
|
|
12875
12216
|
});
|
|
12876
12217
|
} catch (error) {
|
|
12877
|
-
this.logger.error("Referenced-by query failed", { resourceId: event.resourceId, error });
|
|
12218
|
+
this.logger.error("Referenced-by query failed", { resourceId: event.resourceId, error: errField5(error) });
|
|
12878
12219
|
this.eventBus.get("browse:referenced-by-failed").next({
|
|
12879
12220
|
correlationId: event.correlationId,
|
|
12880
12221
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -12889,7 +12230,7 @@ var Browser = class {
|
|
|
12889
12230
|
response: { entityTypes }
|
|
12890
12231
|
});
|
|
12891
12232
|
} catch (error) {
|
|
12892
|
-
this.logger.error("Entity types read failed", { error });
|
|
12233
|
+
this.logger.error("Entity types read failed", { error: errField5(error) });
|
|
12893
12234
|
this.eventBus.get("browse:entity-types-failed").next({
|
|
12894
12235
|
correlationId: event.correlationId,
|
|
12895
12236
|
message: error instanceof Error ? error.message : String(error)
|
|
@@ -12902,8 +12243,8 @@ var Browser = class {
|
|
|
12902
12243
|
async handleBrowseDirectory(event) {
|
|
12903
12244
|
const { correlationId, path: reqPath, sort = "name" } = event;
|
|
12904
12245
|
const projectRoot = this.project.root;
|
|
12905
|
-
const resolved =
|
|
12906
|
-
if (!resolved.startsWith(projectRoot +
|
|
12246
|
+
const resolved = path2.resolve(projectRoot, reqPath);
|
|
12247
|
+
if (!resolved.startsWith(projectRoot + path2.sep) && resolved !== projectRoot) {
|
|
12907
12248
|
this.eventBus.get("browse:directory-failed").next({
|
|
12908
12249
|
correlationId,
|
|
12909
12250
|
path: reqPath,
|
|
@@ -12913,7 +12254,7 @@ var Browser = class {
|
|
|
12913
12254
|
}
|
|
12914
12255
|
let dirents;
|
|
12915
12256
|
try {
|
|
12916
|
-
dirents = await
|
|
12257
|
+
dirents = await fs3.readdir(resolved, { withFileTypes: true, encoding: "utf8" });
|
|
12917
12258
|
} catch (err) {
|
|
12918
12259
|
const msg = err.code === "ENOENT" ? "path not found" : String(err);
|
|
12919
12260
|
this.eventBus.get("browse:directory-failed").next({
|
|
@@ -12927,16 +12268,16 @@ var Browser = class {
|
|
|
12927
12268
|
const allViews = await this.views.getAll();
|
|
12928
12269
|
const prefix = `file://${resolved}`;
|
|
12929
12270
|
const viewsByUri = new Map(
|
|
12930
|
-
allViews.filter((v) => v.resource.storageUri?.startsWith(prefix + "/") || v.resource.storageUri?.startsWith(prefix +
|
|
12271
|
+
allViews.filter((v) => v.resource.storageUri?.startsWith(prefix + "/") || v.resource.storageUri?.startsWith(prefix + path2.sep)).map((v) => [v.resource.storageUri, v])
|
|
12931
12272
|
);
|
|
12932
12273
|
const entries = [];
|
|
12933
12274
|
for (const dirent of visible) {
|
|
12934
|
-
const entryPath =
|
|
12935
|
-
const relPath =
|
|
12275
|
+
const entryPath = path2.join(resolved, dirent.name);
|
|
12276
|
+
const relPath = path2.relative(projectRoot, entryPath);
|
|
12936
12277
|
if (dirent.isDirectory()) {
|
|
12937
12278
|
let mtime = (/* @__PURE__ */ new Date(0)).toISOString();
|
|
12938
12279
|
try {
|
|
12939
|
-
const stat = await
|
|
12280
|
+
const stat = await fs3.stat(entryPath);
|
|
12940
12281
|
mtime = stat.mtime.toISOString();
|
|
12941
12282
|
} catch {
|
|
12942
12283
|
}
|
|
@@ -12946,7 +12287,7 @@ var Browser = class {
|
|
|
12946
12287
|
let size = 0;
|
|
12947
12288
|
let mtime = (/* @__PURE__ */ new Date(0)).toISOString();
|
|
12948
12289
|
try {
|
|
12949
|
-
const stat = await
|
|
12290
|
+
const stat = await fs3.stat(entryPath);
|
|
12950
12291
|
size = stat.size;
|
|
12951
12292
|
mtime = stat.mtime.toISOString();
|
|
12952
12293
|
} catch {
|
|
@@ -13001,33 +12342,51 @@ var Browser = class {
|
|
|
13001
12342
|
}
|
|
13002
12343
|
};
|
|
13003
12344
|
|
|
12345
|
+
// src/event-enrichment.ts
|
|
12346
|
+
function eventAnnotationId(event) {
|
|
12347
|
+
switch (event.type) {
|
|
12348
|
+
case "mark:added":
|
|
12349
|
+
return event.payload.annotation.id;
|
|
12350
|
+
case "mark:body-updated":
|
|
12351
|
+
return event.payload.annotationId;
|
|
12352
|
+
case "mark:removed":
|
|
12353
|
+
return event.payload.annotationId;
|
|
12354
|
+
default:
|
|
12355
|
+
return null;
|
|
12356
|
+
}
|
|
12357
|
+
}
|
|
12358
|
+
async function readAnnotationFromView(kb, resourceId7, annotationId3) {
|
|
12359
|
+
const allAnnotations = await AnnotationContext.getAllAnnotations(resourceId7, kb);
|
|
12360
|
+
return allAnnotations.find((a) => a.id === annotationId3) ?? null;
|
|
12361
|
+
}
|
|
12362
|
+
|
|
13004
12363
|
// src/clone-token-manager.ts
|
|
13005
|
-
var
|
|
13006
|
-
var
|
|
12364
|
+
var import_rxjs7 = __toESM(require_cjs(), 1);
|
|
12365
|
+
var import_operators7 = __toESM(require_operators(), 1);
|
|
13007
12366
|
import { CREATION_METHODS as CREATION_METHODS2, cloneToken as makeCloneToken, resourceId as resourceId5, userId as makeUserId2 } from "@semiont/core";
|
|
13008
12367
|
import { getPrimaryRepresentation as getPrimaryRepresentation3, getResourceEntityTypes as getResourceEntityTypes6 } from "@semiont/api-client";
|
|
13009
12368
|
import { deriveStorageUri } from "@semiont/content";
|
|
13010
12369
|
|
|
13011
12370
|
// src/resource-operations.ts
|
|
13012
|
-
var
|
|
13013
|
-
var
|
|
13014
|
-
import { resourceId as
|
|
12371
|
+
var import_rxjs6 = __toESM(require_cjs(), 1);
|
|
12372
|
+
var import_operators6 = __toESM(require_operators(), 1);
|
|
12373
|
+
import { resourceId as makeResourceId3 } from "@semiont/core";
|
|
13015
12374
|
var ResourceOperations = class {
|
|
13016
12375
|
/**
|
|
13017
12376
|
* Create a new resource via EventBus → Stower
|
|
13018
12377
|
*/
|
|
13019
12378
|
static async createResource(input, userId2, eventBus) {
|
|
13020
|
-
const result$ = (0,
|
|
12379
|
+
const result$ = (0, import_rxjs6.race)(
|
|
13021
12380
|
eventBus.get("yield:create-ok").pipe(
|
|
13022
|
-
(0,
|
|
13023
|
-
(0,
|
|
12381
|
+
(0, import_operators6.take)(1),
|
|
12382
|
+
(0, import_operators6.map)((result) => ({ ok: true, result }))
|
|
13024
12383
|
),
|
|
13025
12384
|
eventBus.get("yield:create-failed").pipe(
|
|
13026
|
-
(0,
|
|
13027
|
-
(0,
|
|
12385
|
+
(0, import_operators6.take)(1),
|
|
12386
|
+
(0, import_operators6.map)((failure) => ({ ok: false, error: new Error(failure.message) }))
|
|
13028
12387
|
),
|
|
13029
|
-
(0,
|
|
13030
|
-
(0,
|
|
12388
|
+
(0, import_rxjs6.timer)(3e4).pipe(
|
|
12389
|
+
(0, import_operators6.map)(() => ({ ok: false, error: new Error("Resource creation timed out") }))
|
|
13031
12390
|
)
|
|
13032
12391
|
);
|
|
13033
12392
|
eventBus.get("yield:create").next({
|
|
@@ -13039,13 +12398,17 @@ var ResourceOperations = class {
|
|
|
13039
12398
|
userId: userId2,
|
|
13040
12399
|
language: input.language,
|
|
13041
12400
|
entityTypes: input.entityTypes,
|
|
13042
|
-
creationMethod: input.creationMethod
|
|
12401
|
+
creationMethod: input.creationMethod,
|
|
12402
|
+
generatedFrom: input.generatedFrom,
|
|
12403
|
+
generationPrompt: input.generationPrompt,
|
|
12404
|
+
generator: input.generator,
|
|
12405
|
+
isDraft: input.isDraft
|
|
13043
12406
|
});
|
|
13044
|
-
const outcome = await (0,
|
|
12407
|
+
const outcome = await (0, import_rxjs6.firstValueFrom)(result$);
|
|
13045
12408
|
if (!outcome.ok) {
|
|
13046
12409
|
throw outcome.error;
|
|
13047
12410
|
}
|
|
13048
|
-
return
|
|
12411
|
+
return makeResourceId3(outcome.result.resourceId);
|
|
13049
12412
|
}
|
|
13050
12413
|
/**
|
|
13051
12414
|
* Update resource metadata via EventBus → Stower
|
|
@@ -13083,13 +12446,13 @@ var CloneTokenManager = class {
|
|
|
13083
12446
|
this.logger.info("CloneTokenManager actor initialized");
|
|
13084
12447
|
const errorHandler = (err) => this.logger.error("CloneTokenManager pipeline error", { error: err });
|
|
13085
12448
|
const generateToken$ = this.eventBus.get("yield:clone-token-requested").pipe(
|
|
13086
|
-
(0,
|
|
12449
|
+
(0, import_operators7.mergeMap)((event) => (0, import_rxjs7.from)(this.handleGenerateToken(event)))
|
|
13087
12450
|
);
|
|
13088
12451
|
const getResource$ = this.eventBus.get("yield:clone-resource-requested").pipe(
|
|
13089
|
-
(0,
|
|
12452
|
+
(0, import_operators7.mergeMap)((event) => (0, import_rxjs7.from)(this.handleGetResource(event)))
|
|
13090
12453
|
);
|
|
13091
12454
|
const createResource$ = this.eventBus.get("yield:clone-create").pipe(
|
|
13092
|
-
(0,
|
|
12455
|
+
(0, import_operators7.mergeMap)((event) => (0, import_rxjs7.from)(this.handleCreateResource(event)))
|
|
13093
12456
|
);
|
|
13094
12457
|
this.subscriptions.push(
|
|
13095
12458
|
generateToken$.subscribe({ error: errorHandler }),
|
|
@@ -13266,8 +12629,8 @@ var CloneTokenManager = class {
|
|
|
13266
12629
|
};
|
|
13267
12630
|
|
|
13268
12631
|
// src/bootstrap/entity-types.ts
|
|
13269
|
-
var
|
|
13270
|
-
var
|
|
12632
|
+
var import_rxjs8 = __toESM(require_cjs(), 1);
|
|
12633
|
+
var import_operators8 = __toESM(require_operators(), 1);
|
|
13271
12634
|
import { DEFAULT_ENTITY_TYPES } from "@semiont/ontology";
|
|
13272
12635
|
import { userId, resourceId as resourceId6 } from "@semiont/core";
|
|
13273
12636
|
async function bootstrapEntityTypes(eventBus, eventStore, logger) {
|
|
@@ -13284,13 +12647,13 @@ async function bootstrapEntityTypes(eventBus, eventStore, logger) {
|
|
|
13284
12647
|
const SYSTEM_USER_ID = userId("00000000-0000-0000-0000-000000000000");
|
|
13285
12648
|
for (const entityType of missing) {
|
|
13286
12649
|
logger?.debug("Adding entity type via EventBus", { entityType });
|
|
13287
|
-
const result$ = (0,
|
|
13288
|
-
eventBus.get("mark:entity-type-added").pipe((0,
|
|
13289
|
-
eventBus.get("mark:entity-type-add-failed").pipe((0,
|
|
13290
|
-
(0,
|
|
12650
|
+
const result$ = (0, import_rxjs8.race)(
|
|
12651
|
+
eventBus.get("mark:entity-type-added").pipe((0, import_operators8.take)(1), (0, import_operators8.map)(() => ({ ok: true }))),
|
|
12652
|
+
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) }))),
|
|
12653
|
+
(0, import_rxjs8.timer)(1e4).pipe((0, import_operators8.map)(() => ({ ok: false, error: new Error(`Timeout adding entity type: ${entityType}`) })))
|
|
13291
12654
|
);
|
|
13292
12655
|
eventBus.get("mark:add-entity-type").next({ tag: entityType, userId: SYSTEM_USER_ID });
|
|
13293
|
-
const outcome = await (0,
|
|
12656
|
+
const outcome = await (0, import_rxjs8.firstValueFrom)(result$);
|
|
13294
12657
|
if (!outcome.ok) {
|
|
13295
12658
|
throw outcome.error;
|
|
13296
12659
|
}
|
|
@@ -13312,10 +12675,10 @@ async function stopKnowledgeSystem(ks) {
|
|
|
13312
12675
|
// src/service.ts
|
|
13313
12676
|
async function createJobQueue(project, eventBus, logger) {
|
|
13314
12677
|
const jobQueueLogger = logger.child({ component: "job-queue" });
|
|
13315
|
-
const jobQueue = new
|
|
12678
|
+
const jobQueue = new FsJobQueue(project, jobQueueLogger, eventBus);
|
|
13316
12679
|
await jobQueue.initialize();
|
|
13317
12680
|
const jobStatusSubscription = eventBus.get("job:status-requested").pipe(
|
|
13318
|
-
(0,
|
|
12681
|
+
(0, import_operators9.mergeMap)((event) => (0, import_rxjs9.from)((async () => {
|
|
13319
12682
|
try {
|
|
13320
12683
|
const job = await jobQueue.getJob(jobId(event.jobId));
|
|
13321
12684
|
if (!job) {
|
|
@@ -13374,13 +12737,15 @@ async function createKnowledgeSystemFromConfig(project, config, eventBus, logger
|
|
|
13374
12737
|
}
|
|
13375
12738
|
const kb = await createKnowledgeBase(eventStore, project, graphDb, eventBus, logger, {
|
|
13376
12739
|
vectorStore,
|
|
13377
|
-
embeddingProvider,
|
|
13378
|
-
chunkingConfig: embeddingConfig?.chunking ? {
|
|
13379
|
-
chunkSize: embeddingConfig.chunking.chunkSize ?? 512,
|
|
13380
|
-
overlap: embeddingConfig.chunking.overlap ?? 64
|
|
13381
|
-
} : void 0,
|
|
13382
12740
|
skipRebuild
|
|
13383
12741
|
});
|
|
12742
|
+
eventStore.setEnrichEvent(async (event, resourceId7) => {
|
|
12743
|
+
const annId = eventAnnotationId(event);
|
|
12744
|
+
if (annId === null) return event;
|
|
12745
|
+
const annotation = await readAnnotationFromView(kb, resourceId7, annId);
|
|
12746
|
+
if (annotation === null) return event;
|
|
12747
|
+
return { ...event, annotation };
|
|
12748
|
+
});
|
|
13384
12749
|
const stower = new Stower(kb, eventBus, logger.child({ component: "stower" }));
|
|
13385
12750
|
await stower.initialize();
|
|
13386
12751
|
await bootstrapEntityTypes(eventBus, eventStore, logger.child({ component: "entity-types-bootstrap" }));
|
|
@@ -13407,57 +12772,6 @@ async function createKnowledgeSystemFromConfig(project, config, eventBus, logger
|
|
|
13407
12772
|
const ks = { kb, stower, gatherer, matcher, browser, cloneTokenManager, stop: () => stopKnowledgeSystem(ks) };
|
|
13408
12773
|
return ks;
|
|
13409
12774
|
}
|
|
13410
|
-
function createContentFetcher(ks) {
|
|
13411
|
-
return async (resourceId7) => {
|
|
13412
|
-
const view = await ks.kb.views.get(resourceId7);
|
|
13413
|
-
if (!view?.resource.storageUri) return null;
|
|
13414
|
-
const buffer = await ks.kb.content.retrieve(view.resource.storageUri);
|
|
13415
|
-
if (!buffer) return null;
|
|
13416
|
-
return Readable.from([buffer]);
|
|
13417
|
-
};
|
|
13418
|
-
}
|
|
13419
|
-
function createWorkers(jobQueue, contentFetcher, contentStore, eventBus, config, logger) {
|
|
13420
|
-
const detection = (() => {
|
|
13421
|
-
const cfg = resolveWorkerInference(config, "reference-annotation");
|
|
13422
|
-
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" }));
|
|
13423
|
-
})();
|
|
13424
|
-
const generation = (() => {
|
|
13425
|
-
const cfg = resolveWorkerInference(config, "generation");
|
|
13426
|
-
return new GenerationWorker(jobQueue, createInferenceClient(cfg, logger.child({ component: "inference-client-generation" })), inferenceConfigToGenerator("Generation Worker", cfg), eventBus, contentStore, logger.child({ component: "generation-worker" }));
|
|
13427
|
-
})();
|
|
13428
|
-
const highlight = (() => {
|
|
13429
|
-
const cfg = resolveWorkerInference(config, "highlight-annotation");
|
|
13430
|
-
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" }));
|
|
13431
|
-
})();
|
|
13432
|
-
const assessment = (() => {
|
|
13433
|
-
const cfg = resolveWorkerInference(config, "assessment-annotation");
|
|
13434
|
-
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" }));
|
|
13435
|
-
})();
|
|
13436
|
-
const comment = (() => {
|
|
13437
|
-
const cfg = resolveWorkerInference(config, "comment-annotation");
|
|
13438
|
-
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" }));
|
|
13439
|
-
})();
|
|
13440
|
-
const tag = (() => {
|
|
13441
|
-
const cfg = resolveWorkerInference(config, "tag-annotation");
|
|
13442
|
-
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" }));
|
|
13443
|
-
})();
|
|
13444
|
-
return { detection, generation, highlight, assessment, comment, tag };
|
|
13445
|
-
}
|
|
13446
|
-
function startWorkers(workers, logger) {
|
|
13447
|
-
const entries = [
|
|
13448
|
-
["detection", "reference-detection-worker"],
|
|
13449
|
-
["generation", "generation-worker"],
|
|
13450
|
-
["highlight", "highlight-detection-worker"],
|
|
13451
|
-
["assessment", "assessment-detection-worker"],
|
|
13452
|
-
["comment", "comment-detection-worker"],
|
|
13453
|
-
["tag", "tag-detection-worker"]
|
|
13454
|
-
];
|
|
13455
|
-
for (const [key, component] of entries) {
|
|
13456
|
-
workers[key].start().catch((error) => {
|
|
13457
|
-
logger.child({ component }).error("Worker stopped unexpectedly", { error });
|
|
13458
|
-
});
|
|
13459
|
-
}
|
|
13460
|
-
}
|
|
13461
12775
|
async function startMakeMeaning(project, config, eventBus, logger, options) {
|
|
13462
12776
|
if (!config.services?.graph) {
|
|
13463
12777
|
throw new Error("services.graph is required for make-meaning service");
|
|
@@ -13465,16 +12779,11 @@ async function startMakeMeaning(project, config, eventBus, logger, options) {
|
|
|
13465
12779
|
const skipRebuild = options?.skipRebuild ?? process.env.SEMIONT_SKIP_REBUILD === "true";
|
|
13466
12780
|
const { jobQueue, jobStatusSubscription } = await createJobQueue(project, eventBus, logger);
|
|
13467
12781
|
const knowledgeSystem = await createKnowledgeSystemFromConfig(project, config, eventBus, logger, skipRebuild);
|
|
13468
|
-
const contentFetcher = createContentFetcher(knowledgeSystem);
|
|
13469
|
-
const workers = createWorkers(jobQueue, contentFetcher, knowledgeSystem.kb.content, eventBus, config, logger);
|
|
13470
|
-
startWorkers(workers, logger);
|
|
13471
12782
|
return {
|
|
13472
12783
|
knowledgeSystem,
|
|
13473
12784
|
jobQueue,
|
|
13474
|
-
workers,
|
|
13475
12785
|
stop: async () => {
|
|
13476
12786
|
logger.info("Stopping Make-Meaning service");
|
|
13477
|
-
await Promise.all(Object.values(workers).map((w) => w.stop()));
|
|
13478
12787
|
jobStatusSubscription.unsubscribe();
|
|
13479
12788
|
await knowledgeSystem.stop();
|
|
13480
12789
|
logger.info("Make-Meaning service stopped");
|
|
@@ -13487,7 +12796,7 @@ import { getExtensionForMimeType } from "@semiont/content";
|
|
|
13487
12796
|
|
|
13488
12797
|
// src/exchange/tar.ts
|
|
13489
12798
|
import { createGzip, createGunzip } from "zlib";
|
|
13490
|
-
import { Readable
|
|
12799
|
+
import { Readable, pipeline } from "stream";
|
|
13491
12800
|
import { promisify } from "util";
|
|
13492
12801
|
var pipelineAsync = promisify(pipeline);
|
|
13493
12802
|
var BLOCK_SIZE = 512;
|
|
@@ -13517,7 +12826,7 @@ function paddingBytes(size) {
|
|
|
13517
12826
|
}
|
|
13518
12827
|
async function writeTarGz(entries, output) {
|
|
13519
12828
|
const gzip = createGzip();
|
|
13520
|
-
const tarStream = new
|
|
12829
|
+
const tarStream = new Readable({ read() {
|
|
13521
12830
|
} });
|
|
13522
12831
|
const pipePromise = pipelineAsync(tarStream, gzip, output);
|
|
13523
12832
|
for await (const entry of entries) {
|
|
@@ -13673,8 +12982,8 @@ function collectContentRefs(streamData) {
|
|
|
13673
12982
|
}
|
|
13674
12983
|
|
|
13675
12984
|
// src/exchange/replay.ts
|
|
13676
|
-
var
|
|
13677
|
-
var
|
|
12985
|
+
var import_rxjs10 = __toESM(require_cjs(), 1);
|
|
12986
|
+
var import_operators10 = __toESM(require_operators(), 1);
|
|
13678
12987
|
import { deriveStorageUri as deriveStorageUri2 } from "@semiont/content";
|
|
13679
12988
|
var REPLAY_TIMEOUT_MS = 3e4;
|
|
13680
12989
|
async function replayEventStream(jsonl, eventBus, resolveBlob, contentStore, logger) {
|
|
@@ -13739,12 +13048,12 @@ async function replayEvent(event, eventBus, resolveBlob, contentStore, stats, lo
|
|
|
13739
13048
|
}
|
|
13740
13049
|
}
|
|
13741
13050
|
async function replayEntityTypeAdded(event, eventBus, logger) {
|
|
13742
|
-
const result$ = (0,
|
|
13743
|
-
eventBus.get("mark:entity-type-added").pipe((0,
|
|
13744
|
-
eventBus.get("mark:entity-type-add-failed").pipe((0,
|
|
13051
|
+
const result$ = (0, import_rxjs10.race)(
|
|
13052
|
+
eventBus.get("mark:entity-type-added").pipe((0, import_operators10.map)(() => "ok")),
|
|
13053
|
+
eventBus.get("mark:entity-type-add-failed").pipe((0, import_operators10.map)((e) => {
|
|
13745
13054
|
throw new Error(e.message);
|
|
13746
13055
|
})),
|
|
13747
|
-
(0,
|
|
13056
|
+
(0, import_rxjs10.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators10.map)(() => {
|
|
13748
13057
|
throw new Error("Timeout waiting for mark:entity-type-added");
|
|
13749
13058
|
}))
|
|
13750
13059
|
);
|
|
@@ -13752,7 +13061,7 @@ async function replayEntityTypeAdded(event, eventBus, logger) {
|
|
|
13752
13061
|
tag: event.payload.entityType,
|
|
13753
13062
|
userId: event.userId
|
|
13754
13063
|
});
|
|
13755
|
-
await (0,
|
|
13064
|
+
await (0, import_rxjs10.firstValueFrom)(result$);
|
|
13756
13065
|
logger?.debug("Replayed entitytype.added", { entityType: event.payload.entityType });
|
|
13757
13066
|
}
|
|
13758
13067
|
async function replayResourceCreated(event, eventBus, resolveBlob, contentStore, logger) {
|
|
@@ -13763,12 +13072,12 @@ async function replayResourceCreated(event, eventBus, resolveBlob, contentStore,
|
|
|
13763
13072
|
}
|
|
13764
13073
|
const resolvedUri = payload.storageUri || deriveStorageUri2(payload.name, payload.format);
|
|
13765
13074
|
const stored = await contentStore.store(blob, resolvedUri);
|
|
13766
|
-
const result$ = (0,
|
|
13767
|
-
eventBus.get("yield:create-ok").pipe((0,
|
|
13768
|
-
eventBus.get("yield:create-failed").pipe((0,
|
|
13075
|
+
const result$ = (0, import_rxjs10.race)(
|
|
13076
|
+
eventBus.get("yield:create-ok").pipe((0, import_operators10.map)((r) => r)),
|
|
13077
|
+
eventBus.get("yield:create-failed").pipe((0, import_operators10.map)((e) => {
|
|
13769
13078
|
throw new Error(e.message);
|
|
13770
13079
|
})),
|
|
13771
|
-
(0,
|
|
13080
|
+
(0, import_rxjs10.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators10.map)(() => {
|
|
13772
13081
|
throw new Error("Timeout waiting for yield:create-ok");
|
|
13773
13082
|
}))
|
|
13774
13083
|
);
|
|
@@ -13786,16 +13095,16 @@ async function replayResourceCreated(event, eventBus, resolveBlob, contentStore,
|
|
|
13786
13095
|
generatedFrom: payload.generatedFrom,
|
|
13787
13096
|
generationPrompt: payload.generationPrompt
|
|
13788
13097
|
});
|
|
13789
|
-
await (0,
|
|
13098
|
+
await (0, import_rxjs10.firstValueFrom)(result$);
|
|
13790
13099
|
logger?.debug("Replayed resource.created", { name: payload.name });
|
|
13791
13100
|
}
|
|
13792
13101
|
async function replayAnnotationAdded(event, eventBus, logger) {
|
|
13793
|
-
const result$ = (0,
|
|
13794
|
-
eventBus.get("mark:create-ok").pipe((0,
|
|
13795
|
-
eventBus.get("mark:create-failed").pipe((0,
|
|
13102
|
+
const result$ = (0, import_rxjs10.race)(
|
|
13103
|
+
eventBus.get("mark:create-ok").pipe((0, import_operators10.map)(() => "ok")),
|
|
13104
|
+
eventBus.get("mark:create-failed").pipe((0, import_operators10.map)((e) => {
|
|
13796
13105
|
throw new Error(e.message);
|
|
13797
13106
|
})),
|
|
13798
|
-
(0,
|
|
13107
|
+
(0, import_rxjs10.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators10.map)(() => {
|
|
13799
13108
|
throw new Error("Timeout waiting for mark:create-ok");
|
|
13800
13109
|
}))
|
|
13801
13110
|
);
|
|
@@ -13804,16 +13113,16 @@ async function replayAnnotationAdded(event, eventBus, logger) {
|
|
|
13804
13113
|
userId: event.userId,
|
|
13805
13114
|
resourceId: event.resourceId
|
|
13806
13115
|
});
|
|
13807
|
-
await (0,
|
|
13116
|
+
await (0, import_rxjs10.firstValueFrom)(result$);
|
|
13808
13117
|
logger?.debug("Replayed annotation.added", { annotationId: event.payload.annotation.id });
|
|
13809
13118
|
}
|
|
13810
13119
|
async function replayAnnotationBodyUpdated(event, eventBus, logger) {
|
|
13811
|
-
const result$ = (0,
|
|
13812
|
-
eventBus.get("mark:body-updated").pipe((0,
|
|
13813
|
-
eventBus.get("mark:body-update-failed").pipe((0,
|
|
13120
|
+
const result$ = (0, import_rxjs10.race)(
|
|
13121
|
+
eventBus.get("mark:body-updated").pipe((0, import_operators10.map)(() => "ok")),
|
|
13122
|
+
eventBus.get("mark:body-update-failed").pipe((0, import_operators10.map)((e) => {
|
|
13814
13123
|
throw new Error(e.message);
|
|
13815
13124
|
})),
|
|
13816
|
-
(0,
|
|
13125
|
+
(0, import_rxjs10.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators10.map)(() => {
|
|
13817
13126
|
throw new Error("Timeout waiting for mark:body-updated");
|
|
13818
13127
|
}))
|
|
13819
13128
|
);
|
|
@@ -13823,16 +13132,16 @@ async function replayAnnotationBodyUpdated(event, eventBus, logger) {
|
|
|
13823
13132
|
resourceId: event.resourceId,
|
|
13824
13133
|
operations: event.payload.operations
|
|
13825
13134
|
});
|
|
13826
|
-
await (0,
|
|
13135
|
+
await (0, import_rxjs10.firstValueFrom)(result$);
|
|
13827
13136
|
logger?.debug("Replayed annotation.body.updated", { annotationId: event.payload.annotationId });
|
|
13828
13137
|
}
|
|
13829
13138
|
async function replayAnnotationRemoved(event, eventBus, logger) {
|
|
13830
|
-
const result$ = (0,
|
|
13831
|
-
eventBus.get("mark:delete-ok").pipe((0,
|
|
13832
|
-
eventBus.get("mark:delete-failed").pipe((0,
|
|
13139
|
+
const result$ = (0, import_rxjs10.race)(
|
|
13140
|
+
eventBus.get("mark:delete-ok").pipe((0, import_operators10.map)(() => "ok")),
|
|
13141
|
+
eventBus.get("mark:delete-failed").pipe((0, import_operators10.map)((e) => {
|
|
13833
13142
|
throw new Error(e.message);
|
|
13834
13143
|
})),
|
|
13835
|
-
(0,
|
|
13144
|
+
(0, import_rxjs10.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators10.map)(() => {
|
|
13836
13145
|
throw new Error("Timeout waiting for mark:delete-ok");
|
|
13837
13146
|
}))
|
|
13838
13147
|
);
|
|
@@ -13841,7 +13150,7 @@ async function replayAnnotationRemoved(event, eventBus, logger) {
|
|
|
13841
13150
|
userId: event.userId,
|
|
13842
13151
|
resourceId: event.resourceId
|
|
13843
13152
|
});
|
|
13844
|
-
await (0,
|
|
13153
|
+
await (0, import_rxjs10.firstValueFrom)(result$);
|
|
13845
13154
|
logger?.debug("Replayed annotation.removed", { annotationId: event.payload.annotationId });
|
|
13846
13155
|
}
|
|
13847
13156
|
async function replayResourceArchived(event, eventBus, logger) {
|
|
@@ -14131,9 +13440,9 @@ function collectContentRefsFromResource(resource, refs) {
|
|
|
14131
13440
|
}
|
|
14132
13441
|
|
|
14133
13442
|
// src/exchange/linked-data-importer.ts
|
|
14134
|
-
var
|
|
14135
|
-
var
|
|
14136
|
-
import { resourceId as
|
|
13443
|
+
var import_rxjs11 = __toESM(require_cjs(), 1);
|
|
13444
|
+
var import_operators11 = __toESM(require_operators(), 1);
|
|
13445
|
+
import { resourceId as makeResourceId4 } from "@semiont/core";
|
|
14137
13446
|
import { deriveStorageUri as deriveStorageUri3 } from "@semiont/content";
|
|
14138
13447
|
var IMPORT_TIMEOUT_MS = 3e4;
|
|
14139
13448
|
function stripUriToId(uri) {
|
|
@@ -14236,12 +13545,12 @@ async function importLinkedData(archive, options) {
|
|
|
14236
13545
|
};
|
|
14237
13546
|
}
|
|
14238
13547
|
async function addEntityType(entityType, userId2, eventBus, logger) {
|
|
14239
|
-
const result$ = (0,
|
|
14240
|
-
eventBus.get("mark:entity-type-added").pipe((0,
|
|
14241
|
-
eventBus.get("mark:entity-type-add-failed").pipe((0,
|
|
13548
|
+
const result$ = (0, import_rxjs11.race)(
|
|
13549
|
+
eventBus.get("mark:entity-type-added").pipe((0, import_operators11.map)(() => "ok")),
|
|
13550
|
+
eventBus.get("mark:entity-type-add-failed").pipe((0, import_operators11.map)((e) => {
|
|
14242
13551
|
throw new Error(e.message);
|
|
14243
13552
|
})),
|
|
14244
|
-
(0,
|
|
13553
|
+
(0, import_rxjs11.timer)(IMPORT_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
|
|
14245
13554
|
throw new Error("Timeout waiting for mark:entity-type-added");
|
|
14246
13555
|
}))
|
|
14247
13556
|
);
|
|
@@ -14249,7 +13558,7 @@ async function addEntityType(entityType, userId2, eventBus, logger) {
|
|
|
14249
13558
|
tag: entityType,
|
|
14250
13559
|
userId: userId2
|
|
14251
13560
|
});
|
|
14252
|
-
await (0,
|
|
13561
|
+
await (0, import_rxjs11.firstValueFrom)(result$);
|
|
14253
13562
|
logger?.debug("Added entity type", { entityType });
|
|
14254
13563
|
}
|
|
14255
13564
|
async function importResource(doc, userId2, eventBus, contentStore, resolveBlob, logger) {
|
|
@@ -14276,12 +13585,12 @@ async function importResource(doc, userId2, eventBus, contentStore, resolveBlob,
|
|
|
14276
13585
|
}
|
|
14277
13586
|
const resolvedUri = deriveStorageUri3(name, format);
|
|
14278
13587
|
const stored = await contentStore.store(blob, resolvedUri);
|
|
14279
|
-
const createResult$ = (0,
|
|
14280
|
-
eventBus.get("yield:create-ok").pipe((0,
|
|
14281
|
-
eventBus.get("yield:create-failed").pipe((0,
|
|
13588
|
+
const createResult$ = (0, import_rxjs11.race)(
|
|
13589
|
+
eventBus.get("yield:create-ok").pipe((0, import_operators11.map)((r) => r)),
|
|
13590
|
+
eventBus.get("yield:create-failed").pipe((0, import_operators11.map)((e) => {
|
|
14282
13591
|
throw new Error(e.message);
|
|
14283
13592
|
})),
|
|
14284
|
-
(0,
|
|
13593
|
+
(0, import_rxjs11.timer)(IMPORT_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
|
|
14285
13594
|
throw new Error("Timeout waiting for yield:create-ok");
|
|
14286
13595
|
}))
|
|
14287
13596
|
);
|
|
@@ -14296,8 +13605,8 @@ async function importResource(doc, userId2, eventBus, contentStore, resolveBlob,
|
|
|
14296
13605
|
entityTypes: entityTypes ?? [],
|
|
14297
13606
|
creationMethod
|
|
14298
13607
|
});
|
|
14299
|
-
const created = await (0,
|
|
14300
|
-
const resourceId7 =
|
|
13608
|
+
const created = await (0, import_rxjs11.firstValueFrom)(createResult$);
|
|
13609
|
+
const resourceId7 = makeResourceId4(created.resourceId);
|
|
14301
13610
|
logger?.debug("Created resource from JSON-LD", { name, resourceId: resourceId7 });
|
|
14302
13611
|
let annotationsCreated = 0;
|
|
14303
13612
|
if (annotations && annotations.length > 0) {
|
|
@@ -14309,12 +13618,12 @@ async function importResource(doc, userId2, eventBus, contentStore, resolveBlob,
|
|
|
14309
13618
|
return { annotationsCreated };
|
|
14310
13619
|
}
|
|
14311
13620
|
async function createAnnotation(annotation, resourceId7, userId2, eventBus, logger) {
|
|
14312
|
-
const result$ = (0,
|
|
14313
|
-
eventBus.get("mark:create-ok").pipe((0,
|
|
14314
|
-
eventBus.get("mark:create-failed").pipe((0,
|
|
13621
|
+
const result$ = (0, import_rxjs11.race)(
|
|
13622
|
+
eventBus.get("mark:create-ok").pipe((0, import_operators11.map)(() => "ok")),
|
|
13623
|
+
eventBus.get("mark:create-failed").pipe((0, import_operators11.map)((e) => {
|
|
14315
13624
|
throw new Error(e.message);
|
|
14316
13625
|
})),
|
|
14317
|
-
(0,
|
|
13626
|
+
(0, import_rxjs11.timer)(IMPORT_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
|
|
14318
13627
|
throw new Error("Timeout waiting for mark:create-ok");
|
|
14319
13628
|
}))
|
|
14320
13629
|
);
|
|
@@ -14323,7 +13632,7 @@ async function createAnnotation(annotation, resourceId7, userId2, eventBus, logg
|
|
|
14323
13632
|
userId: userId2,
|
|
14324
13633
|
resourceId: resourceId7
|
|
14325
13634
|
});
|
|
14326
|
-
await (0,
|
|
13635
|
+
await (0, import_rxjs11.firstValueFrom)(result$);
|
|
14327
13636
|
logger?.debug("Created annotation", { annotationId: annotation.id });
|
|
14328
13637
|
}
|
|
14329
13638
|
|
|
@@ -14334,14 +13643,14 @@ import {
|
|
|
14334
13643
|
} from "@semiont/core";
|
|
14335
13644
|
|
|
14336
13645
|
// src/annotation-operations.ts
|
|
14337
|
-
import { annotationId as annotationId2, resourceId as
|
|
13646
|
+
import { annotationId as annotationId2, resourceId as makeResourceId5, assembleAnnotation as assembleAnnotation2, applyBodyOperations as applyBodyOperations2 } from "@semiont/core";
|
|
14338
13647
|
var AnnotationOperations = class {
|
|
14339
13648
|
/**
|
|
14340
13649
|
* Create a new annotation via EventBus → Stower
|
|
14341
13650
|
*/
|
|
14342
13651
|
static async createAnnotation(request, userId2, creator, eventBus) {
|
|
14343
13652
|
const { annotation } = assembleAnnotation2(request, creator);
|
|
14344
|
-
const resId =
|
|
13653
|
+
const resId = makeResourceId5(request.target.source);
|
|
14345
13654
|
eventBus.get("mark:create").next({
|
|
14346
13655
|
annotation,
|
|
14347
13656
|
userId: userId2,
|
|
@@ -14353,7 +13662,7 @@ var AnnotationOperations = class {
|
|
|
14353
13662
|
* Update annotation body via EventBus → Stower
|
|
14354
13663
|
*/
|
|
14355
13664
|
static async updateAnnotationBody(id, request, userId2, eventBus, kb) {
|
|
14356
|
-
const resId =
|
|
13665
|
+
const resId = makeResourceId5(request.resourceId);
|
|
14357
13666
|
const annotation = await AnnotationContext.getAnnotation(
|
|
14358
13667
|
annotationId2(id),
|
|
14359
13668
|
resId,
|
|
@@ -14380,7 +13689,7 @@ var AnnotationOperations = class {
|
|
|
14380
13689
|
* Delete an annotation via EventBus → Stower
|
|
14381
13690
|
*/
|
|
14382
13691
|
static async deleteAnnotation(id, resourceIdStr, userId2, eventBus, kb, logger) {
|
|
14383
|
-
const resId =
|
|
13692
|
+
const resId = makeResourceId5(resourceIdStr);
|
|
14384
13693
|
const projection = await AnnotationContext.getResourceAnnotations(resId, kb);
|
|
14385
13694
|
const annotation = projection.annotations.find((a) => a.id === id);
|
|
14386
13695
|
if (!annotation) {
|
|
@@ -14413,7 +13722,6 @@ export {
|
|
|
14413
13722
|
PACKAGE_NAME,
|
|
14414
13723
|
ResourceContext,
|
|
14415
13724
|
ResourceOperations,
|
|
14416
|
-
Smelter,
|
|
14417
13725
|
Stower,
|
|
14418
13726
|
VERSION,
|
|
14419
13727
|
applyBodyOperations,
|