@semiont/make-meaning 0.5.10 → 0.5.12

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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { FsJobQueue } from '@semiont/jobs';
2
2
  import { FilesystemViewStorage, resolveStorageUri, EventQuery, createEventStore } from '@semiont/event-sourcing';
3
- import { getPrimaryRepresentation, decodeRepresentation, getResourceEntityTypes, getResourceId, getTargetSource, resourceId, getBodySource, getTargetSelector, deriveViews, getTextPositionSelector, annotationId, errField, userId, generateUuid, getExactText, busRequest, cloneToken, baseMediaType, isSupportedMediaType, capabilitiesOf, didToAgent, assembleAnnotation, jobId, entityType, baseUrl, busLog, BRIDGED_CHANNELS, burstBuffer, textExtractionOf, getPrimaryMediaType, extensionForMediaType, applyBodyOperations, findBodyItem } from '@semiont/core';
3
+ import { getPrimaryRepresentation, decodeRepresentation, getResourceEntityTypes, getResourceId, getTargetSource, resourceId, getBodySource, getTargetSelector, deriveViews, getTextPositionSelector, annotationId, errField, userId, generateUuid, getExactText, busRequest, cloneToken, baseMediaType, isSupportedMediaType, capabilitiesOf, didToAgent, assembleAnnotation, jobId, entityType, baseUrl, busLog, BRIDGED_CHANNELS, burstBuffer, textExtractionOf, getPrimaryMediaType, extensionForMediaType, applyBodyOperations, softwareToAgent } from '@semiont/core';
4
4
  import { withActorSpan, recordBusEmit, withSpan, SpanKind, registerJobQueueProvider, registerVectorIndexSizeProvider } from '@semiont/observability';
5
5
  import { createInferenceClient } from '@semiont/inference';
6
6
  import { getGraphDatabase } from '@semiont/graph';
@@ -26,11 +26,11 @@ var __commonJS = (cb, mod) => function __require() {
26
26
  throw mod = 0, e;
27
27
  }
28
28
  };
29
- var __copyProps = (to, from9, except, desc) => {
30
- if (from9 && typeof from9 === "object" || typeof from9 === "function") {
31
- for (let key of __getOwnPropNames(from9))
29
+ var __copyProps = (to, from8, except, desc) => {
30
+ if (from8 && typeof from8 === "object" || typeof from8 === "function") {
31
+ for (let key of __getOwnPropNames(from8))
32
32
  if (!__hasOwnProp.call(to, key) && key !== except)
33
- __defProp(to, key, { get: () => from9[key], enumerable: !(desc = __getOwnPropDesc(from9, key)) || desc.enumerable });
33
+ __defProp(to, key, { get: () => from8[key], enumerable: !(desc = __getOwnPropDesc(from8, key)) || desc.enumerable });
34
34
  }
35
35
  return to;
36
36
  };
@@ -139,9 +139,9 @@ var require_Subscription = __commonJS({
139
139
  }
140
140
  return ar;
141
141
  };
142
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
143
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
144
- to[j] = from9[i];
142
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
143
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
144
+ to[j] = from8[i];
145
145
  return to;
146
146
  };
147
147
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -149,14 +149,14 @@ var require_Subscription = __commonJS({
149
149
  var isFunction_1 = require_isFunction();
150
150
  var UnsubscriptionError_1 = require_UnsubscriptionError();
151
151
  var arrRemove_1 = require_arrRemove();
152
- var Subscription8 = (function() {
153
- function Subscription9(initialTeardown) {
152
+ var Subscription7 = (function() {
153
+ function Subscription8(initialTeardown) {
154
154
  this.initialTeardown = initialTeardown;
155
155
  this.closed = false;
156
156
  this._parentage = null;
157
157
  this._finalizers = null;
158
158
  }
159
- Subscription9.prototype.unsubscribe = function() {
159
+ Subscription8.prototype.unsubscribe = function() {
160
160
  var e_1, _a, e_2, _b;
161
161
  var errors;
162
162
  if (!this.closed) {
@@ -223,13 +223,13 @@ var require_Subscription = __commonJS({
223
223
  }
224
224
  }
225
225
  };
226
- Subscription9.prototype.add = function(teardown) {
226
+ Subscription8.prototype.add = function(teardown) {
227
227
  var _a;
228
228
  if (teardown && teardown !== this) {
229
229
  if (this.closed) {
230
230
  execFinalizer(teardown);
231
231
  } else {
232
- if (teardown instanceof Subscription9) {
232
+ if (teardown instanceof Subscription8) {
233
233
  if (teardown.closed || teardown._hasParent(this)) {
234
234
  return;
235
235
  }
@@ -239,15 +239,15 @@ var require_Subscription = __commonJS({
239
239
  }
240
240
  }
241
241
  };
242
- Subscription9.prototype._hasParent = function(parent) {
242
+ Subscription8.prototype._hasParent = function(parent) {
243
243
  var _parentage = this._parentage;
244
244
  return _parentage === parent || Array.isArray(_parentage) && _parentage.includes(parent);
245
245
  };
246
- Subscription9.prototype._addParent = function(parent) {
246
+ Subscription8.prototype._addParent = function(parent) {
247
247
  var _parentage = this._parentage;
248
248
  this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
249
249
  };
250
- Subscription9.prototype._removeParent = function(parent) {
250
+ Subscription8.prototype._removeParent = function(parent) {
251
251
  var _parentage = this._parentage;
252
252
  if (_parentage === parent) {
253
253
  this._parentage = null;
@@ -255,24 +255,24 @@ var require_Subscription = __commonJS({
255
255
  arrRemove_1.arrRemove(_parentage, parent);
256
256
  }
257
257
  };
258
- Subscription9.prototype.remove = function(teardown) {
258
+ Subscription8.prototype.remove = function(teardown) {
259
259
  var _finalizers = this._finalizers;
260
260
  _finalizers && arrRemove_1.arrRemove(_finalizers, teardown);
261
- if (teardown instanceof Subscription9) {
261
+ if (teardown instanceof Subscription8) {
262
262
  teardown._removeParent(this);
263
263
  }
264
264
  };
265
- Subscription9.EMPTY = (function() {
266
- var empty = new Subscription9();
265
+ Subscription8.EMPTY = (function() {
266
+ var empty = new Subscription8();
267
267
  empty.closed = true;
268
268
  return empty;
269
269
  })();
270
- return Subscription9;
270
+ return Subscription8;
271
271
  })();
272
- exports.Subscription = Subscription8;
273
- exports.EMPTY_SUBSCRIPTION = Subscription8.EMPTY;
272
+ exports.Subscription = Subscription7;
273
+ exports.EMPTY_SUBSCRIPTION = Subscription7.EMPTY;
274
274
  function isSubscription(value) {
275
- return value instanceof Subscription8 || value && "closed" in value && isFunction_1.isFunction(value.remove) && isFunction_1.isFunction(value.add) && isFunction_1.isFunction(value.unsubscribe);
275
+ return value instanceof Subscription7 || value && "closed" in value && isFunction_1.isFunction(value.remove) && isFunction_1.isFunction(value.add) && isFunction_1.isFunction(value.unsubscribe);
276
276
  }
277
277
  exports.isSubscription = isSubscription;
278
278
  function execFinalizer(finalizer) {
@@ -320,9 +320,9 @@ var require_timeoutProvider = __commonJS({
320
320
  }
321
321
  return ar;
322
322
  };
323
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
324
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
325
- to[j] = from9[i];
323
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
324
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
325
+ to[j] = from8[i];
326
326
  return to;
327
327
  };
328
328
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1065,9 +1065,9 @@ var require_animationFrameProvider = __commonJS({
1065
1065
  }
1066
1066
  return ar;
1067
1067
  };
1068
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
1069
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
1070
- to[j] = from9[i];
1068
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
1069
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
1070
+ to[j] = from8[i];
1071
1071
  return to;
1072
1072
  };
1073
1073
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1209,9 +1209,9 @@ var require_Subject = __commonJS({
1209
1209
  var ObjectUnsubscribedError_1 = require_ObjectUnsubscribedError();
1210
1210
  var arrRemove_1 = require_arrRemove();
1211
1211
  var errorContext_1 = require_errorContext();
1212
- var Subject4 = (function(_super) {
1213
- __extends(Subject5, _super);
1214
- function Subject5() {
1212
+ var Subject3 = (function(_super) {
1213
+ __extends(Subject4, _super);
1214
+ function Subject4() {
1215
1215
  var _this = _super.call(this) || this;
1216
1216
  _this.closed = false;
1217
1217
  _this.currentObservers = null;
@@ -1221,17 +1221,17 @@ var require_Subject = __commonJS({
1221
1221
  _this.thrownError = null;
1222
1222
  return _this;
1223
1223
  }
1224
- Subject5.prototype.lift = function(operator) {
1224
+ Subject4.prototype.lift = function(operator) {
1225
1225
  var subject = new AnonymousSubject(this, this);
1226
1226
  subject.operator = operator;
1227
1227
  return subject;
1228
1228
  };
1229
- Subject5.prototype._throwIfClosed = function() {
1229
+ Subject4.prototype._throwIfClosed = function() {
1230
1230
  if (this.closed) {
1231
1231
  throw new ObjectUnsubscribedError_1.ObjectUnsubscribedError();
1232
1232
  }
1233
1233
  };
1234
- Subject5.prototype.next = function(value) {
1234
+ Subject4.prototype.next = function(value) {
1235
1235
  var _this = this;
1236
1236
  errorContext_1.errorContext(function() {
1237
1237
  var e_1, _a;
@@ -1257,7 +1257,7 @@ var require_Subject = __commonJS({
1257
1257
  }
1258
1258
  });
1259
1259
  };
1260
- Subject5.prototype.error = function(err) {
1260
+ Subject4.prototype.error = function(err) {
1261
1261
  var _this = this;
1262
1262
  errorContext_1.errorContext(function() {
1263
1263
  _this._throwIfClosed();
@@ -1271,7 +1271,7 @@ var require_Subject = __commonJS({
1271
1271
  }
1272
1272
  });
1273
1273
  };
1274
- Subject5.prototype.complete = function() {
1274
+ Subject4.prototype.complete = function() {
1275
1275
  var _this = this;
1276
1276
  errorContext_1.errorContext(function() {
1277
1277
  _this._throwIfClosed();
@@ -1284,11 +1284,11 @@ var require_Subject = __commonJS({
1284
1284
  }
1285
1285
  });
1286
1286
  };
1287
- Subject5.prototype.unsubscribe = function() {
1287
+ Subject4.prototype.unsubscribe = function() {
1288
1288
  this.isStopped = this.closed = true;
1289
1289
  this.observers = this.currentObservers = null;
1290
1290
  };
1291
- Object.defineProperty(Subject5.prototype, "observed", {
1291
+ Object.defineProperty(Subject4.prototype, "observed", {
1292
1292
  get: function() {
1293
1293
  var _a;
1294
1294
  return ((_a = this.observers) === null || _a === void 0 ? void 0 : _a.length) > 0;
@@ -1296,16 +1296,16 @@ var require_Subject = __commonJS({
1296
1296
  enumerable: false,
1297
1297
  configurable: true
1298
1298
  });
1299
- Subject5.prototype._trySubscribe = function(subscriber) {
1299
+ Subject4.prototype._trySubscribe = function(subscriber) {
1300
1300
  this._throwIfClosed();
1301
1301
  return _super.prototype._trySubscribe.call(this, subscriber);
1302
1302
  };
1303
- Subject5.prototype._subscribe = function(subscriber) {
1303
+ Subject4.prototype._subscribe = function(subscriber) {
1304
1304
  this._throwIfClosed();
1305
1305
  this._checkFinalizedStatuses(subscriber);
1306
1306
  return this._innerSubscribe(subscriber);
1307
1307
  };
1308
- Subject5.prototype._innerSubscribe = function(subscriber) {
1308
+ Subject4.prototype._innerSubscribe = function(subscriber) {
1309
1309
  var _this = this;
1310
1310
  var _a = this, hasError = _a.hasError, isStopped = _a.isStopped, observers = _a.observers;
1311
1311
  if (hasError || isStopped) {
@@ -1318,7 +1318,7 @@ var require_Subject = __commonJS({
1318
1318
  arrRemove_1.arrRemove(observers, subscriber);
1319
1319
  });
1320
1320
  };
1321
- Subject5.prototype._checkFinalizedStatuses = function(subscriber) {
1321
+ Subject4.prototype._checkFinalizedStatuses = function(subscriber) {
1322
1322
  var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, isStopped = _a.isStopped;
1323
1323
  if (hasError) {
1324
1324
  subscriber.error(thrownError);
@@ -1326,17 +1326,17 @@ var require_Subject = __commonJS({
1326
1326
  subscriber.complete();
1327
1327
  }
1328
1328
  };
1329
- Subject5.prototype.asObservable = function() {
1329
+ Subject4.prototype.asObservable = function() {
1330
1330
  var observable = new Observable_1.Observable();
1331
1331
  observable.source = this;
1332
1332
  return observable;
1333
1333
  };
1334
- Subject5.create = function(destination, source) {
1334
+ Subject4.create = function(destination, source) {
1335
1335
  return new AnonymousSubject(destination, source);
1336
1336
  };
1337
- return Subject5;
1337
+ return Subject4;
1338
1338
  })(Observable_1.Observable);
1339
- exports.Subject = Subject4;
1339
+ exports.Subject = Subject3;
1340
1340
  var AnonymousSubject = (function(_super) {
1341
1341
  __extends(AnonymousSubject2, _super);
1342
1342
  function AnonymousSubject2(destination, source) {
@@ -1362,7 +1362,7 @@ var require_Subject = __commonJS({
1362
1362
  return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : Subscription_1.EMPTY_SUBSCRIPTION;
1363
1363
  };
1364
1364
  return AnonymousSubject2;
1365
- })(Subject4);
1365
+ })(Subject3);
1366
1366
  exports.AnonymousSubject = AnonymousSubject;
1367
1367
  }
1368
1368
  });
@@ -1653,9 +1653,9 @@ var require_intervalProvider = __commonJS({
1653
1653
  }
1654
1654
  return ar;
1655
1655
  };
1656
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
1657
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
1658
- to[j] = from9[i];
1656
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
1657
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
1658
+ to[j] = from8[i];
1659
1659
  return to;
1660
1660
  };
1661
1661
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1859,9 +1859,9 @@ var require_immediateProvider = __commonJS({
1859
1859
  }
1860
1860
  return ar;
1861
1861
  };
1862
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
1863
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
1864
- to[j] = from9[i];
1862
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
1863
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
1864
+ to[j] = from8[i];
1865
1865
  return to;
1866
1866
  };
1867
1867
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -3383,10 +3383,10 @@ var require_from = __commonJS({
3383
3383
  exports.from = void 0;
3384
3384
  var scheduled_1 = require_scheduled();
3385
3385
  var innerFrom_1 = require_innerFrom();
3386
- function from9(input, scheduler) {
3386
+ function from8(input, scheduler) {
3387
3387
  return scheduler ? scheduled_1.scheduled(input, scheduler) : innerFrom_1.innerFrom(input);
3388
3388
  }
3389
- exports.from = from9;
3389
+ exports.from = from8;
3390
3390
  }
3391
3391
  });
3392
3392
 
@@ -3759,9 +3759,9 @@ var require_mapOneOrManyArgs = __commonJS({
3759
3759
  }
3760
3760
  return ar;
3761
3761
  };
3762
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
3763
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
3764
- to[j] = from9[i];
3762
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
3763
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
3764
+ to[j] = from8[i];
3765
3765
  return to;
3766
3766
  };
3767
3767
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -3800,9 +3800,9 @@ var require_bindCallbackInternals = __commonJS({
3800
3800
  }
3801
3801
  return ar;
3802
3802
  };
3803
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
3804
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
3805
- to[j] = from9[i];
3803
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
3804
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
3805
+ to[j] = from8[i];
3806
3806
  return to;
3807
3807
  };
3808
3808
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -4115,12 +4115,12 @@ var require_mergeMap = __commonJS({
4115
4115
  var lift_1 = require_lift();
4116
4116
  var mergeInternals_1 = require_mergeInternals();
4117
4117
  var isFunction_1 = require_isFunction();
4118
- function mergeMap7(project, resultSelector, concurrent) {
4118
+ function mergeMap6(project, resultSelector, concurrent) {
4119
4119
  if (concurrent === void 0) {
4120
4120
  concurrent = Infinity;
4121
4121
  }
4122
4122
  if (isFunction_1.isFunction(resultSelector)) {
4123
- return mergeMap7(function(a, i) {
4123
+ return mergeMap6(function(a, i) {
4124
4124
  return map_1.map(function(b, ii) {
4125
4125
  return resultSelector(a, b, i, ii);
4126
4126
  })(innerFrom_1.innerFrom(project(a, i)));
@@ -4132,7 +4132,7 @@ var require_mergeMap = __commonJS({
4132
4132
  return mergeInternals_1.mergeInternals(source, subscriber, project, concurrent);
4133
4133
  });
4134
4134
  }
4135
- exports.mergeMap = mergeMap7;
4135
+ exports.mergeMap = mergeMap6;
4136
4136
  }
4137
4137
  });
4138
4138
 
@@ -4903,9 +4903,9 @@ var require_zip = __commonJS({
4903
4903
  }
4904
4904
  return ar;
4905
4905
  };
4906
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
4907
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
4908
- to[j] = from9[i];
4906
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
4907
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
4908
+ to[j] = from8[i];
4909
4909
  return to;
4910
4910
  };
4911
4911
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -5517,9 +5517,9 @@ var require_combineLatest2 = __commonJS({
5517
5517
  }
5518
5518
  return ar;
5519
5519
  };
5520
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
5521
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
5522
- to[j] = from9[i];
5520
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
5521
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
5522
+ to[j] = from8[i];
5523
5523
  return to;
5524
5524
  };
5525
5525
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -5564,9 +5564,9 @@ var require_combineLatestWith = __commonJS({
5564
5564
  }
5565
5565
  return ar;
5566
5566
  };
5567
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
5568
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
5569
- to[j] = from9[i];
5567
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
5568
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
5569
+ to[j] = from8[i];
5570
5570
  return to;
5571
5571
  };
5572
5572
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -5590,10 +5590,10 @@ var require_concatMap = __commonJS({
5590
5590
  exports.concatMap = void 0;
5591
5591
  var mergeMap_1 = require_mergeMap();
5592
5592
  var isFunction_1 = require_isFunction();
5593
- function concatMap6(project, resultSelector) {
5593
+ function concatMap5(project, resultSelector) {
5594
5594
  return isFunction_1.isFunction(resultSelector) ? mergeMap_1.mergeMap(project, resultSelector, 1) : mergeMap_1.mergeMap(project, 1);
5595
5595
  }
5596
- exports.concatMap = concatMap6;
5596
+ exports.concatMap = concatMap5;
5597
5597
  }
5598
5598
  });
5599
5599
 
@@ -5635,9 +5635,9 @@ var require_concat2 = __commonJS({
5635
5635
  }
5636
5636
  return ar;
5637
5637
  };
5638
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
5639
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
5640
- to[j] = from9[i];
5638
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
5639
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
5640
+ to[j] = from8[i];
5641
5641
  return to;
5642
5642
  };
5643
5643
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -5680,9 +5680,9 @@ var require_concatWith = __commonJS({
5680
5680
  }
5681
5681
  return ar;
5682
5682
  };
5683
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
5684
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
5685
- to[j] = from9[i];
5683
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
5684
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
5685
+ to[j] = from8[i];
5686
5686
  return to;
5687
5687
  };
5688
5688
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -6155,9 +6155,9 @@ var require_endWith = __commonJS({
6155
6155
  }
6156
6156
  return ar;
6157
6157
  };
6158
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
6159
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
6160
- to[j] = from9[i];
6158
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
6159
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
6160
+ to[j] = from8[i];
6161
6161
  return to;
6162
6162
  };
6163
6163
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -6386,7 +6386,7 @@ var require_groupBy = __commonJS({
6386
6386
  var Subject_1 = require_Subject();
6387
6387
  var lift_1 = require_lift();
6388
6388
  var OperatorSubscriber_1 = require_OperatorSubscriber();
6389
- function groupBy4(keySelector, elementOrOptions, duration, connector) {
6389
+ function groupBy3(keySelector, elementOrOptions, duration, connector) {
6390
6390
  return lift_1.operate(function(source, subscriber) {
6391
6391
  var element;
6392
6392
  if (!elementOrOptions || typeof elementOrOptions === "function") {
@@ -6453,7 +6453,7 @@ var require_groupBy = __commonJS({
6453
6453
  }
6454
6454
  });
6455
6455
  }
6456
- exports.groupBy = groupBy4;
6456
+ exports.groupBy = groupBy3;
6457
6457
  }
6458
6458
  });
6459
6459
 
@@ -6683,9 +6683,9 @@ var require_merge2 = __commonJS({
6683
6683
  }
6684
6684
  return ar;
6685
6685
  };
6686
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
6687
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
6688
- to[j] = from9[i];
6686
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
6687
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
6688
+ to[j] = from8[i];
6689
6689
  return to;
6690
6690
  };
6691
6691
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -6729,9 +6729,9 @@ var require_mergeWith = __commonJS({
6729
6729
  }
6730
6730
  return ar;
6731
6731
  };
6732
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
6733
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
6734
- to[j] = from9[i];
6732
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
6733
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
6734
+ to[j] = from8[i];
6735
6735
  return to;
6736
6736
  };
6737
6737
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -6811,9 +6811,9 @@ var require_onErrorResumeNextWith = __commonJS({
6811
6811
  }
6812
6812
  return ar;
6813
6813
  };
6814
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
6815
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
6816
- to[j] = from9[i];
6814
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
6815
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
6816
+ to[j] = from8[i];
6817
6817
  return to;
6818
6818
  };
6819
6819
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -6988,9 +6988,9 @@ var require_raceWith = __commonJS({
6988
6988
  }
6989
6989
  return ar;
6990
6990
  };
6991
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
6992
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
6993
- to[j] = from9[i];
6991
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
6992
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
6993
+ to[j] = from8[i];
6994
6994
  return to;
6995
6995
  };
6996
6996
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -7377,9 +7377,9 @@ var require_share = __commonJS({
7377
7377
  }
7378
7378
  return ar;
7379
7379
  };
7380
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
7381
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
7382
- to[j] = from9[i];
7380
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
7381
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
7382
+ to[j] = from8[i];
7383
7383
  return to;
7384
7384
  };
7385
7385
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -8352,9 +8352,9 @@ var require_withLatestFrom = __commonJS({
8352
8352
  }
8353
8353
  return ar;
8354
8354
  };
8355
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
8356
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
8357
- to[j] = from9[i];
8355
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
8356
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
8357
+ to[j] = from8[i];
8358
8358
  return to;
8359
8359
  };
8360
8360
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -8436,9 +8436,9 @@ var require_zip2 = __commonJS({
8436
8436
  }
8437
8437
  return ar;
8438
8438
  };
8439
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
8440
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
8441
- to[j] = from9[i];
8439
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
8440
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
8441
+ to[j] = from8[i];
8442
8442
  return to;
8443
8443
  };
8444
8444
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -8478,9 +8478,9 @@ var require_zipWith = __commonJS({
8478
8478
  }
8479
8479
  return ar;
8480
8480
  };
8481
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
8482
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
8483
- to[j] = from9[i];
8481
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
8482
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
8483
+ to[j] = from8[i];
8484
8484
  return to;
8485
8485
  };
8486
8486
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -9243,9 +9243,9 @@ var require_race2 = __commonJS({
9243
9243
  }
9244
9244
  return ar;
9245
9245
  };
9246
- var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
9247
- for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
9248
- to[j] = from9[i];
9246
+ var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
9247
+ for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
9248
+ to[j] = from8[i];
9249
9249
  return to;
9250
9250
  };
9251
9251
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -9733,427 +9733,154 @@ function resolveActorInference(config, actor) {
9733
9733
  `No inference config found for actor '${actor}'. Set actors.${actor}.inference in your config.`
9734
9734
  );
9735
9735
  }
9736
+ function resolveWorkerInference(config, workerType) {
9737
+ const specific = config.workers?.[workerType];
9738
+ if (specific) return specific;
9739
+ const defaultWorker = config.workers?.default;
9740
+ if (defaultWorker) return defaultWorker;
9741
+ throw new Error(
9742
+ `No inference config found for worker '${workerType}'. Set workers.${workerType}.inference or workers.default.inference in your config.`
9743
+ );
9744
+ }
9736
9745
 
9737
9746
  // src/service.ts
9738
- var import_rxjs7 = __toESM(require_cjs());
9739
- var import_operators7 = __toESM(require_operators());
9740
-
9741
- // src/graph/consumer.ts
9742
- var import_rxjs = __toESM(require_cjs());
9743
- var import_operators = __toESM(require_operators());
9744
-
9745
- // src/batch-utils.ts
9746
- function partitionByType(events) {
9747
- const runs = [];
9748
- let currentRun = [];
9749
- for (const event of events) {
9750
- if (currentRun.length > 0 && currentRun[0].type !== event.type) {
9751
- runs.push(currentRun);
9752
- currentRun = [];
9753
- }
9754
- currentRun.push(event);
9755
- }
9756
- if (currentRun.length > 0) runs.push(currentRun);
9757
- return runs;
9758
- }
9747
+ var import_rxjs6 = __toESM(require_cjs());
9748
+ var import_operators6 = __toESM(require_operators());
9759
9749
 
9760
- // src/graph/consumer.ts
9761
- var GraphDBConsumer = class _GraphDBConsumer {
9762
- constructor(eventStore, graphDb, coreEventBus, logger) {
9763
- this.eventStore = eventStore;
9764
- this.graphDb = graphDb;
9765
- this.coreEventBus = coreEventBus;
9766
- this.logger = logger;
9767
- }
9768
- eventStore;
9769
- graphDb;
9770
- coreEventBus;
9771
- // Event types that produce GraphDB mutations — filter everything else
9772
- static GRAPH_RELEVANT_EVENTS = /* @__PURE__ */ new Set([
9773
- "yield:created",
9774
- "mark:archived",
9775
- "mark:unarchived",
9776
- "mark:added",
9777
- "mark:removed",
9778
- "mark:body-updated",
9779
- "mark:entity-tag-added",
9780
- "mark:entity-tag-removed",
9781
- "frame:entity-type-added"
9782
- ]);
9783
- // Burst buffer thresholds — see class doc and BATCH-GRAPH-CONSUMER-RX.md
9784
- static BURST_WINDOW_MS = 50;
9785
- static MAX_BATCH_SIZE = 500;
9786
- static IDLE_TIMEOUT_MS = 200;
9787
- _globalSubscriptions = [];
9788
- eventSubject = new import_rxjs.Subject();
9789
- pipelineSubscription = null;
9790
- lastProcessed = /* @__PURE__ */ new Map();
9791
- logger;
9792
- async initialize() {
9793
- this.logger.info("GraphDB consumer initialized");
9794
- await this.subscribeToGlobalEvents();
9750
+ // src/weave-progress.ts
9751
+ var WeaveProgressTimeout = class extends Error {
9752
+ constructor(resourceId10, sequenceNumber, timeoutMs) {
9753
+ super(`weave:applied parity not reached for ${resourceId10} (seq ${sequenceNumber}) within ${timeoutMs}ms`);
9754
+ this.name = "WeaveProgressTimeout";
9795
9755
  }
9796
- /**
9797
- * Subscribe globally to ALL events, pre-filter to graph-relevant types,
9798
- * and wire through the RxJS burst-buffered pipeline.
9799
- */
9800
- async subscribeToGlobalEvents() {
9801
- for (const eventType of _GraphDBConsumer.GRAPH_RELEVANT_EVENTS) {
9802
- this._globalSubscriptions.push(
9803
- this.coreEventBus.getDomainEvent(eventType).subscribe(
9804
- (storedEvent) => this.eventSubject.next(storedEvent)
9805
- )
9806
- );
9807
- }
9808
- this.pipelineSubscription = this.eventSubject.pipe(
9809
- // Split into one inner Observable per resource (system events grouped under '__system__')
9810
- (0, import_operators.groupBy)((se) => se.resourceId ?? "__system__"),
9811
- (0, import_operators.mergeMap)((group) => {
9812
- if (group.key === "__system__") {
9813
- return group.pipe(
9814
- (0, import_operators.concatMap)((se) => (0, import_rxjs.from)(this.safeApplyEvent(se)))
9815
- );
9816
- }
9817
- return group.pipe(
9818
- burstBuffer({
9819
- burstWindowMs: _GraphDBConsumer.BURST_WINDOW_MS,
9820
- maxBatchSize: _GraphDBConsumer.MAX_BATCH_SIZE,
9821
- idleTimeoutMs: _GraphDBConsumer.IDLE_TIMEOUT_MS
9822
- }),
9823
- (0, import_operators.concatMap)((eventOrBatch) => {
9824
- if (Array.isArray(eventOrBatch)) {
9825
- return (0, import_rxjs.from)(this.processBatch(eventOrBatch));
9826
- }
9827
- return (0, import_rxjs.from)(this.safeApplyEvent(eventOrBatch).then(() => {
9828
- this.lastProcessed.set(
9829
- eventOrBatch.resourceId,
9830
- eventOrBatch.metadata.sequenceNumber
9831
- );
9832
- }));
9833
- })
9834
- );
9835
- })
9836
- ).subscribe({
9837
- error: (err) => {
9838
- this.logger.error("GraphDB consumer pipeline error", { error: err });
9839
- }
9840
- });
9841
- this.logger.info("Subscribed to global events with burst-buffered pipeline");
9842
- }
9843
- /**
9844
- * Wrap applyEventToGraph in try/catch so one failed event doesn't kill the pipeline.
9845
- */
9846
- async safeApplyEvent(storedEvent) {
9847
- await new Promise((resolve2) => setTimeout(resolve2, 0));
9848
- try {
9849
- await this.applyEventToGraph(storedEvent);
9850
- } catch (error) {
9851
- this.logger.error("Failed to apply event to graph", {
9852
- eventType: storedEvent.type,
9853
- resourceId: storedEvent.resourceId,
9854
- error: errField(error)
9855
- });
9856
- }
9857
- }
9858
- ensureInitialized() {
9859
- return this.graphDb;
9860
- }
9861
- /**
9862
- * Stop the consumer, flush remaining buffered events, and unsubscribe.
9863
- */
9864
- async stop() {
9865
- this.logger.info("Stopping GraphDB consumer");
9866
- for (const sub of this._globalSubscriptions) sub.unsubscribe();
9867
- this._globalSubscriptions = [];
9868
- this.eventSubject.complete();
9869
- if (this.pipelineSubscription) {
9870
- this.pipelineSubscription.unsubscribe();
9871
- this.pipelineSubscription = null;
9872
- }
9873
- this.eventSubject = new import_rxjs.Subject();
9874
- this.logger.info("GraphDB consumer stopped");
9875
- }
9876
- /**
9877
- * Process a batch of events for the same resource.
9878
- * Partitions into consecutive same-type runs for batch optimization.
9879
- */
9880
- async processBatch(events) {
9881
- const runs = partitionByType(events);
9882
- for (const run of runs) {
9883
- try {
9884
- if (run.length === 1) {
9885
- await this.applyEventToGraph(run[0]);
9886
- } else {
9887
- await this.applyBatchByType(run);
9888
- }
9889
- } catch (error) {
9890
- this.logger.error("Failed to process batch run", {
9891
- eventType: run[0].type,
9892
- runSize: run.length,
9893
- error: errField(error)
9894
- });
9895
- }
9896
- const last = run[run.length - 1];
9897
- if (last.resourceId) {
9898
- this.lastProcessed.set(last.resourceId, last.metadata.sequenceNumber);
9899
- }
9900
- }
9901
- this.logger.debug("Processed batch", {
9902
- resourceId: events[0]?.resourceId,
9903
- batchSize: events.length
9904
- });
9905
- }
9906
- /**
9907
- * Batch-optimized processing for consecutive events of the same type.
9908
- * Uses batch graph methods where available, falls back to sequential.
9909
- */
9910
- async applyBatchByType(events) {
9911
- const graphDb = this.ensureInitialized();
9912
- const type = events[0].type;
9913
- switch (type) {
9914
- case "yield:created": {
9915
- const resources = events.map((e) => this.buildResourceDescriptor(e));
9916
- await graphDb.batchCreateResources(resources);
9917
- this.logger.info("Batch created resources in graph", { count: events.length });
9918
- break;
9919
- }
9920
- case "mark:added": {
9921
- const inputs = events.map((e) => {
9922
- const event = e;
9923
- return {
9924
- ...event.payload.annotation,
9925
- creator: didToAgent(event.userId)
9926
- };
9927
- });
9928
- await graphDb.createAnnotations(inputs);
9929
- this.logger.info("Batch created annotations in graph", { count: events.length });
9930
- break;
9756
+ };
9757
+ var APPLIED_TTL_MS = 5 * 6e4;
9758
+ var SWEEP_INTERVAL_MS = 6e4;
9759
+ function createWeaveProgress(eventBus) {
9760
+ const applied = /* @__PURE__ */ new Map();
9761
+ const waiters = /* @__PURE__ */ new Set();
9762
+ let disposed = false;
9763
+ let lastSweep = Date.now();
9764
+ const subscription = eventBus.get("weave:applied").subscribe(({ resourceId: resourceId10, sequenceNumber }) => {
9765
+ const now = Date.now();
9766
+ if (now - lastSweep >= SWEEP_INTERVAL_MS) {
9767
+ lastSweep = now;
9768
+ for (const [rid, entry] of applied) {
9769
+ if (now - entry.at >= APPLIED_TTL_MS) applied.delete(rid);
9770
+ }
9771
+ }
9772
+ const current = applied.get(resourceId10);
9773
+ if (current !== void 0 && current.seq >= sequenceNumber) return;
9774
+ applied.set(resourceId10, { seq: sequenceNumber, at: now });
9775
+ for (const waiter of waiters) {
9776
+ if (waiter.resourceId === resourceId10 && sequenceNumber >= waiter.sequenceNumber) {
9777
+ clearTimeout(waiter.timer);
9778
+ waiters.delete(waiter);
9779
+ waiter.resolve();
9931
9780
  }
9932
- default:
9933
- for (const event of events) {
9934
- await this.applyEventToGraph(event);
9935
- }
9936
- }
9937
- }
9938
- /**
9939
- * Build a ResourceDescriptor from a resource.created event.
9940
- * Extracted for reuse by both applyEventToGraph and applyBatchByType.
9941
- */
9942
- buildResourceDescriptor(storedEvent) {
9943
- const event = storedEvent;
9944
- if (event.type !== "yield:created") {
9945
- throw new Error("Expected resource.created event");
9946
9781
  }
9947
- if (!event.resourceId) {
9948
- throw new Error("yield:created requires resourceId");
9949
- }
9950
- return {
9951
- "@context": "https://schema.org/",
9952
- "@id": event.resourceId,
9953
- name: event.payload.name,
9954
- entityTypes: event.payload.entityTypes || [],
9955
- representations: [{
9956
- mediaType: event.payload.format,
9957
- checksum: event.payload.contentChecksum,
9958
- rel: "original"
9959
- }],
9960
- archived: false,
9961
- dateCreated: (/* @__PURE__ */ new Date()).toISOString(),
9962
- wasAttributedTo: didToAgent(event.userId),
9963
- ...event.payload.storageUri ? { storageUri: event.payload.storageUri } : {}
9964
- };
9965
- }
9966
- /**
9967
- * Apply a single event to GraphDB.
9968
- */
9969
- async applyEventToGraph(storedEvent) {
9970
- const graphDb = this.ensureInitialized();
9971
- const event = storedEvent;
9972
- this.logger.debug("Applying event to GraphDB", {
9973
- eventType: event.type,
9974
- sequenceNumber: storedEvent.metadata.sequenceNumber
9975
- });
9976
- switch (event.type) {
9977
- case "yield:created": {
9978
- const resource = this.buildResourceDescriptor(storedEvent);
9979
- this.logger.debug("Creating resource in graph", { resourceUri: resource["@id"] });
9980
- await graphDb.createResource(resource);
9981
- this.logger.info("Resource created in graph", { resourceUri: resource["@id"] });
9982
- break;
9782
+ });
9783
+ return {
9784
+ appliedUpTo: (resourceId10) => applied.get(resourceId10)?.seq,
9785
+ whenApplied: (resourceId10, sequenceNumber, timeoutMs) => {
9786
+ if (disposed) return Promise.resolve();
9787
+ const current = applied.get(resourceId10)?.seq;
9788
+ if (current !== void 0 && current >= sequenceNumber) return Promise.resolve();
9789
+ return new Promise((resolve2, reject) => {
9790
+ const waiter = {
9791
+ resourceId: resourceId10,
9792
+ sequenceNumber,
9793
+ resolve: resolve2,
9794
+ timer: setTimeout(() => {
9795
+ waiters.delete(waiter);
9796
+ reject(new WeaveProgressTimeout(resourceId10, sequenceNumber, timeoutMs));
9797
+ }, timeoutMs)
9798
+ };
9799
+ waiters.add(waiter);
9800
+ });
9801
+ },
9802
+ dispose: () => {
9803
+ if (disposed) return;
9804
+ disposed = true;
9805
+ subscription.unsubscribe();
9806
+ for (const waiter of waiters) {
9807
+ clearTimeout(waiter.timer);
9808
+ waiter.resolve();
9983
9809
  }
9984
- case "mark:archived":
9985
- if (!event.resourceId) throw new Error("mark:archived requires resourceId");
9986
- await graphDb.updateResource(resourceId(event.resourceId), {
9987
- archived: true
9988
- });
9989
- break;
9990
- case "mark:unarchived":
9991
- if (!event.resourceId) throw new Error("mark:unarchived requires resourceId");
9992
- await graphDb.updateResource(resourceId(event.resourceId), {
9993
- archived: false
9994
- });
9995
- break;
9996
- case "mark:added":
9997
- this.logger.debug("Processing annotation.added event", {
9998
- annotationId: event.payload.annotation.id
9999
- });
10000
- await graphDb.createAnnotation({
10001
- ...event.payload.annotation,
10002
- creator: didToAgent(event.userId)
10003
- });
10004
- this.logger.info("Annotation created in graph", {
10005
- annotationId: event.payload.annotation.id
10006
- });
10007
- break;
10008
- case "mark:removed":
10009
- await graphDb.deleteAnnotation(annotationId(event.payload.annotationId));
10010
- break;
10011
- case "mark:body-updated":
10012
- this.logger.debug("Processing annotation.body.updated event", {
10013
- annotationId: event.payload.annotationId,
10014
- payload: event.payload
10015
- });
10016
- try {
10017
- const annId = annotationId(event.payload.annotationId);
10018
- const currentAnnotation = await graphDb.getAnnotation(annId);
10019
- if (currentAnnotation) {
10020
- let bodyArray = Array.isArray(currentAnnotation.body) ? [...currentAnnotation.body] : currentAnnotation.body ? [currentAnnotation.body] : [];
10021
- for (const op of event.payload.operations) {
10022
- if (op.op === "add") {
10023
- const exists = findBodyItem(bodyArray, op.item) !== -1;
10024
- if (!exists) {
10025
- bodyArray.push(op.item);
10026
- }
10027
- } else if (op.op === "remove") {
10028
- const index = findBodyItem(bodyArray, op.item);
10029
- if (index !== -1) {
10030
- bodyArray.splice(index, 1);
10031
- }
10032
- } else if (op.op === "replace") {
10033
- const index = findBodyItem(bodyArray, op.oldItem);
10034
- if (index !== -1) {
10035
- bodyArray[index] = op.newItem;
10036
- }
10037
- }
10038
- }
10039
- await graphDb.updateAnnotation(annId, {
10040
- body: bodyArray
10041
- });
10042
- this.logger.info("updateAnnotation completed successfully");
10043
- } else {
10044
- this.logger.warn("Annotation not found in graph, skipping update");
10045
- }
10046
- } catch (error) {
10047
- this.logger.error("Error in annotation.body.updated handler", {
10048
- annotationId: event.payload.annotationId,
10049
- error: errField(error)
10050
- });
10051
- }
10052
- break;
10053
- case "mark:entity-tag-added":
10054
- if (!event.resourceId) throw new Error("mark:entity-tag-added requires resourceId");
10055
- {
10056
- const rid = resourceId(event.resourceId);
10057
- const doc = await graphDb.getResource(rid);
10058
- if (doc) {
10059
- await graphDb.updateResource(rid, {
10060
- entityTypes: [...doc.entityTypes || [], event.payload.entityType]
10061
- });
10062
- }
10063
- }
10064
- break;
10065
- case "mark:entity-tag-removed":
10066
- if (!event.resourceId) throw new Error("mark:entity-tag-removed requires resourceId");
10067
- {
10068
- const rid = resourceId(event.resourceId);
10069
- const doc = await graphDb.getResource(rid);
10070
- if (doc) {
10071
- await graphDb.updateResource(rid, {
10072
- entityTypes: (doc.entityTypes || []).filter((t) => t !== event.payload.entityType)
10073
- });
10074
- }
10075
- }
10076
- break;
10077
- case "frame:entity-type-added":
10078
- await graphDb.addEntityType(event.payload.entityType);
10079
- break;
10080
- default:
10081
- this.logger.warn("Unknown event type", { eventType: event.type });
9810
+ waiters.clear();
9811
+ applied.clear();
10082
9812
  }
9813
+ };
9814
+ }
9815
+
9816
+ // src/smelt-progress.ts
9817
+ var SmeltProgressTimeout = class extends Error {
9818
+ constructor(resourceId10, contentChecksum, timeoutMs) {
9819
+ super(`smelt:settled not observed for ${resourceId10} (checksum ${contentChecksum.slice(0, 12)}\u2026) within ${timeoutMs}ms`);
9820
+ this.name = "SmeltProgressTimeout";
10083
9821
  }
10084
- /**
10085
- * Rebuild entire resource from events.
10086
- * Bypasses the live pipeline — reads directly from event store.
10087
- */
10088
- async rebuildResource(resourceId10) {
10089
- const graphDb = this.ensureInitialized();
10090
- this.logger.info("Rebuilding resource from events", { resourceId: resourceId10 });
10091
- try {
10092
- await graphDb.deleteResource(resourceId10);
10093
- } catch (error) {
10094
- this.logger.debug("No existing resource to delete", { resourceId: resourceId10 });
10095
- }
10096
- const query = new EventQuery(this.eventStore.log.storage);
10097
- const events = await query.getResourceEvents(resourceId10);
10098
- for (const storedEvent of events) {
10099
- await this.safeApplyEvent(storedEvent);
10100
- }
10101
- this.logger.info("Resource rebuild complete", { resourceId: resourceId10, eventCount: events.length });
10102
- }
10103
- /**
10104
- * Rebuild entire GraphDB from all events.
10105
- * Uses two-pass approach to ensure all resources exist before creating REFERENCES edges.
10106
- * Bypasses the live pipeline — reads directly from event store.
10107
- */
10108
- async rebuildAll() {
10109
- const graphDb = this.ensureInitialized();
10110
- this.logger.info("Rebuilding entire GraphDB from events");
10111
- this.logger.info("Using two-pass approach: nodes first, then edges");
10112
- await graphDb.clearDatabase();
10113
- const query = new EventQuery(this.eventStore.log.storage);
10114
- const allResourceIds = await this.eventStore.log.getAllResourceIds();
10115
- this.logger.info("Found resources to rebuild", { count: allResourceIds.length });
10116
- this.logger.info("PASS 1: Creating all nodes (resources + annotations)");
10117
- for (const resourceId10 of allResourceIds) {
10118
- const events = await query.getResourceEvents(resourceId(resourceId10));
10119
- for (const storedEvent of events) {
10120
- if (storedEvent.type === "mark:body-updated") {
10121
- continue;
10122
- }
10123
- await this.safeApplyEvent(storedEvent);
9822
+ };
9823
+ var SETTLED_TTL_MS = 5 * 6e4;
9824
+ var SWEEP_INTERVAL_MS2 = 6e4;
9825
+ function createSmeltProgress(eventBus) {
9826
+ const settled = /* @__PURE__ */ new Map();
9827
+ const waiters = /* @__PURE__ */ new Set();
9828
+ let disposed = false;
9829
+ let lastSweep = Date.now();
9830
+ const subscription = eventBus.get("smelt:settled").subscribe(({ resourceId: resourceId10, contentChecksum, outcome }) => {
9831
+ const now = Date.now();
9832
+ if (now - lastSweep >= SWEEP_INTERVAL_MS2) {
9833
+ lastSweep = now;
9834
+ for (const [rid, entry] of settled) {
9835
+ if (now - entry.at >= SETTLED_TTL_MS) settled.delete(rid);
9836
+ }
9837
+ }
9838
+ settled.set(resourceId10, { contentChecksum, outcome, at: now });
9839
+ for (const waiter of waiters) {
9840
+ if (waiter.resourceId === resourceId10 && waiter.contentChecksum === contentChecksum) {
9841
+ clearTimeout(waiter.timer);
9842
+ waiters.delete(waiter);
9843
+ waiter.resolve(outcome);
10124
9844
  }
10125
9845
  }
10126
- this.logger.info("Pass 1 complete - all nodes created");
10127
- this.logger.info("PASS 2: Creating all REFERENCES edges");
10128
- for (const resourceId10 of allResourceIds) {
10129
- const events = await query.getResourceEvents(resourceId(resourceId10));
10130
- for (const storedEvent of events) {
10131
- if (storedEvent.type === "mark:body-updated") {
10132
- await this.safeApplyEvent(storedEvent);
10133
- }
9846
+ });
9847
+ return {
9848
+ settledAt: (resourceId10) => {
9849
+ const entry = settled.get(resourceId10);
9850
+ return entry ? { contentChecksum: entry.contentChecksum, outcome: entry.outcome } : void 0;
9851
+ },
9852
+ whenSettled: (resourceId10, contentChecksum, timeoutMs) => {
9853
+ if (disposed) return Promise.resolve("inert");
9854
+ const current = settled.get(resourceId10);
9855
+ if (current && current.contentChecksum === contentChecksum) {
9856
+ return Promise.resolve(current.outcome);
9857
+ }
9858
+ return new Promise((resolve2, reject) => {
9859
+ const waiter = {
9860
+ resourceId: resourceId10,
9861
+ contentChecksum,
9862
+ resolve: resolve2,
9863
+ timer: setTimeout(() => {
9864
+ waiters.delete(waiter);
9865
+ reject(new SmeltProgressTimeout(resourceId10, contentChecksum, timeoutMs));
9866
+ }, timeoutMs)
9867
+ };
9868
+ waiters.add(waiter);
9869
+ });
9870
+ },
9871
+ dispose: () => {
9872
+ if (disposed) return;
9873
+ disposed = true;
9874
+ subscription.unsubscribe();
9875
+ for (const waiter of waiters) {
9876
+ clearTimeout(waiter.timer);
9877
+ waiter.resolve("inert");
10134
9878
  }
9879
+ waiters.clear();
9880
+ settled.clear();
10135
9881
  }
10136
- this.logger.info("Pass 2 complete - all edges created");
10137
- this.logger.info("Rebuild complete");
10138
- }
10139
- /**
10140
- * Get consumer health metrics.
10141
- */
10142
- getHealthMetrics() {
10143
- return {
10144
- subscriptions: this._globalSubscriptions.length,
10145
- lastProcessed: Object.fromEntries(this.lastProcessed),
10146
- pipelineActive: !!this.pipelineSubscription
10147
- };
10148
- }
10149
- /**
10150
- * Shutdown consumer.
10151
- */
10152
- async shutdown() {
10153
- await this.stop();
10154
- this.logger.info("GraphDB consumer shut down");
10155
- }
10156
- };
9882
+ };
9883
+ }
10157
9884
 
10158
9885
  // src/knowledge-base.ts
10159
9886
  async function createKnowledgeBase(eventStore, project, graphDb, eventBus, logger, options) {
@@ -10162,23 +9889,18 @@ async function createKnowledgeBase(eventStore, project, graphDb, eventBus, logge
10162
9889
  project,
10163
9890
  logger.child({ component: "working-tree-store" })
10164
9891
  );
10165
- const graphConsumer = new GraphDBConsumer(
10166
- eventStore,
10167
- graphDb,
10168
- eventBus,
10169
- logger.child({ component: "graph-consumer" })
10170
- );
10171
- await graphConsumer.initialize();
9892
+ const weaveProgress = createWeaveProgress(eventBus);
9893
+ const smeltProgress = createSmeltProgress(eventBus);
10172
9894
  if (!options?.skipRebuild) {
10173
9895
  await eventStore.views.rebuildAll(eventStore.log);
10174
- await graphConsumer.rebuildAll();
10175
9896
  }
10176
9897
  const kb = {
10177
9898
  eventStore,
10178
9899
  views,
10179
9900
  content,
10180
9901
  graph: graphDb,
10181
- graphConsumer,
9902
+ weaveProgress,
9903
+ smeltProgress,
10182
9904
  projectionsDir: project.projectionsDir
10183
9905
  };
10184
9906
  if (options?.vectorStore) {
@@ -10188,8 +9910,8 @@ async function createKnowledgeBase(eventStore, project, graphDb, eventBus, logge
10188
9910
  }
10189
9911
 
10190
9912
  // src/gatherer.ts
10191
- var import_rxjs2 = __toESM(require_cjs());
10192
- var import_operators2 = __toESM(require_operators());
9913
+ var import_rxjs = __toESM(require_cjs());
9914
+ var import_operators = __toESM(require_operators());
10193
9915
 
10194
9916
  // src/generation/resource-generation.ts
10195
9917
  async function generateResourceSummary(resourceName, content, entityTypes, client) {
@@ -10292,7 +10014,21 @@ var ResourceContext = class _ResourceContext {
10292
10014
  return void 0;
10293
10015
  }
10294
10016
  };
10295
- var GraphContext = class {
10017
+ var GraphContext = class _GraphContext {
10018
+ /**
10019
+ * Backoff schedule for the projection-lag grace in `buildKnowledgeGraph`
10020
+ * (GRAPH-PROJECTION-SYNC P1). Total wait is bounded at 375 ms — the Weaver
10021
+ * applies in tens of milliseconds when merely lagging; anything slower is
10022
+ * treated as a real miss.
10023
+ */
10024
+ static PROJECTION_LAG_BACKOFF_MS = [25, 50, 100, 200];
10025
+ /**
10026
+ * Bounded wait for the applied-offset barrier (GRAPH-PROJECTION-SYNC P2).
10027
+ * The Weaver applies in tens of milliseconds when merely lagging; a
10028
+ * barrier that hasn't woken in 500 ms means signals have stalled and the
10029
+ * poll floor above owns the remainder.
10030
+ */
10031
+ static PROJECTION_BARRIER_TIMEOUT_MS = 500;
10296
10032
  /**
10297
10033
  * Get all resources referencing this resource (backlinks)
10298
10034
  * Requires graph traversal - must use graph database
@@ -10336,7 +10072,30 @@ var GraphContext = class {
10336
10072
  * so siblingEntityTypes = union of those nodes' entityTypes
10337
10073
  */
10338
10074
  static async buildKnowledgeGraph(resourceId10, kb) {
10339
- const mainDoc = await kb.graph.getResource(resourceId10);
10075
+ let mainDoc = await kb.graph.getResource(resourceId10);
10076
+ if (!mainDoc) {
10077
+ const view = await kb.views.get(resourceId10);
10078
+ if (view) {
10079
+ if (view.lastSequence !== void 0) {
10080
+ try {
10081
+ await kb.weaveProgress.whenApplied(
10082
+ String(resourceId10),
10083
+ view.lastSequence,
10084
+ _GraphContext.PROJECTION_BARRIER_TIMEOUT_MS
10085
+ );
10086
+ mainDoc = await kb.graph.getResource(resourceId10);
10087
+ } catch {
10088
+ }
10089
+ }
10090
+ if (!mainDoc) {
10091
+ for (const delayMs of _GraphContext.PROJECTION_LAG_BACKOFF_MS) {
10092
+ await new Promise((resolve2) => setTimeout(resolve2, delayMs));
10093
+ mainDoc = await kb.graph.getResource(resourceId10);
10094
+ if (mainDoc) break;
10095
+ }
10096
+ }
10097
+ }
10098
+ }
10340
10099
  if (!mainDoc) {
10341
10100
  throw new Error("Resource not found");
10342
10101
  }
@@ -10802,12 +10561,13 @@ Entity types: ${entityTypes.join(", ")}`;
10802
10561
  return inferenceClient.generateText(summaryPrompt, 500, 0.5);
10803
10562
  }
10804
10563
  };
10564
+ var SMELT_SETTLE_TIMEOUT_MS = 15e3;
10805
10565
  var LLMContext = class {
10806
10566
  /**
10807
10567
  * Get comprehensive LLM context for a resource
10808
10568
  * Includes: main resource, related resources, annotations, graph, content, summary, references
10809
10569
  */
10810
- static async getResourceContext(resourceId10, options, kb, inferenceClient) {
10570
+ static async getResourceContext(resourceId10, options, kb, inferenceClient, logger) {
10811
10571
  const mainDoc = await ResourceContext.getResourceMetadata(resourceId10, kb);
10812
10572
  if (!mainDoc) {
10813
10573
  throw new Error("Resource not found");
@@ -10847,13 +10607,33 @@ var LLMContext = class {
10847
10607
  if (mainContent) content.main = mainContent;
10848
10608
  if (options.includeContent) content.related = relatedContent;
10849
10609
  let semanticContext;
10850
- if (kb.vectors) {
10610
+ const vectors = kb.vectors;
10611
+ if (vectors) {
10851
10612
  const excludeEntityTypes = options.excludeEntityTypes ?? [];
10852
- const matches = await kb.vectors.searchByResource(resourceId10, {
10613
+ const search = () => vectors.searchByResource(resourceId10, {
10853
10614
  limit: options.maxResources,
10854
10615
  scoreThreshold: 0.5,
10855
10616
  ...excludeEntityTypes.length ? { filter: { excludeEntityTypes } } : {}
10856
10617
  });
10618
+ let matches = await search();
10619
+ if (matches.length === 0) {
10620
+ const contentChecksum = getPrimaryRepresentation(mainDoc)?.checksum;
10621
+ if (contentChecksum) {
10622
+ try {
10623
+ const outcome = await kb.smeltProgress.whenSettled(resourceIdStr, contentChecksum, SMELT_SETTLE_TIMEOUT_MS);
10624
+ if (outcome === "indexed") {
10625
+ matches = await search();
10626
+ }
10627
+ } catch (error) {
10628
+ if (!(error instanceof SmeltProgressTimeout)) throw error;
10629
+ logger.warn("[gather DEGRADED] semanticContext absent \u2014 the vector projection did not settle within the barrier", {
10630
+ resourceId: resourceIdStr,
10631
+ contentChecksum,
10632
+ timeoutMs: SMELT_SETTLE_TIMEOUT_MS
10633
+ });
10634
+ }
10635
+ }
10636
+ }
10857
10637
  if (matches.length > 0) {
10858
10638
  semanticContext = {
10859
10639
  similar: matches.map((m) => ({
@@ -10904,21 +10684,21 @@ var Gatherer = class {
10904
10684
  this.logger.info("Gatherer actor initialized");
10905
10685
  const errorHandler = (err) => this.logger.error("Gatherer pipeline error", { error: err });
10906
10686
  const annotationGather$ = this.eventBus.get("gather:requested").pipe(
10907
- (0, import_operators2.groupBy)((event) => event.resourceId),
10908
- (0, import_operators2.mergeMap)(
10687
+ (0, import_operators.groupBy)((event) => event.resourceId),
10688
+ (0, import_operators.mergeMap)(
10909
10689
  (group$) => group$.pipe(
10910
- (0, import_operators2.concatMap)(
10911
- (event) => (0, import_rxjs2.from)(withActorSpan("gatherer", "gather:requested", () => this.handleAnnotationGather(event)))
10690
+ (0, import_operators.concatMap)(
10691
+ (event) => (0, import_rxjs.from)(withActorSpan("gatherer", "gather:requested", () => this.handleAnnotationGather(event)))
10912
10692
  )
10913
10693
  )
10914
10694
  )
10915
10695
  );
10916
10696
  const resourceGather$ = this.eventBus.get("gather:resource-requested").pipe(
10917
- (0, import_operators2.groupBy)((event) => event.resourceId),
10918
- (0, import_operators2.mergeMap)(
10697
+ (0, import_operators.groupBy)((event) => event.resourceId),
10698
+ (0, import_operators.mergeMap)(
10919
10699
  (group$) => group$.pipe(
10920
- (0, import_operators2.concatMap)(
10921
- (event) => (0, import_rxjs2.from)(withActorSpan("gatherer", "gather:resource-requested", () => this.handleResourceGather(event)))
10700
+ (0, import_operators.concatMap)(
10701
+ (event) => (0, import_rxjs.from)(withActorSpan("gatherer", "gather:resource-requested", () => this.handleResourceGather(event)))
10922
10702
  )
10923
10703
  )
10924
10704
  )
@@ -10972,7 +10752,8 @@ var Gatherer = class {
10972
10752
  resourceId(event.resourceId),
10973
10753
  event.options,
10974
10754
  this.kb,
10975
- this.inferenceClient
10755
+ this.inferenceClient,
10756
+ this.logger
10976
10757
  );
10977
10758
  this.eventBus.get("gather:resource-complete").next({
10978
10759
  correlationId: event.correlationId,
@@ -11009,8 +10790,19 @@ var Gatherer = class {
11009
10790
  };
11010
10791
 
11011
10792
  // src/matcher.ts
11012
- var import_rxjs3 = __toESM(require_cjs());
11013
- var import_operators3 = __toESM(require_operators());
10793
+ var import_rxjs2 = __toESM(require_cjs());
10794
+ var import_operators2 = __toESM(require_operators());
10795
+
10796
+ // src/graph-read-grace.ts
10797
+ async function resourceWithViewGrace(kb, rid) {
10798
+ const fromGraph = await kb.graph.getResource(rid).catch(() => null);
10799
+ if (fromGraph) return { resource: fromGraph, laggedBehindView: false };
10800
+ const view = await kb.views.get(rid);
10801
+ if (view) return { resource: view.resource, laggedBehindView: true };
10802
+ return { resource: null, laggedBehindView: false };
10803
+ }
10804
+
10805
+ // src/matcher.ts
11014
10806
  var Matcher = class {
11015
10807
  constructor(kb, eventBus, logger, inferenceClient, embeddingProvider) {
11016
10808
  this.kb = kb;
@@ -11029,8 +10821,8 @@ var Matcher = class {
11029
10821
  this.logger.info("Matcher actor initialized");
11030
10822
  const errorHandler = (err) => this.logger.error("Matcher pipeline error", { error: err });
11031
10823
  const search$ = this.eventBus.get("match:search-requested").pipe(
11032
- (0, import_operators3.concatMap)(
11033
- (event) => (0, import_rxjs3.from)(withActorSpan("matcher", "match:search-requested", () => this.handleSearch(event)))
10824
+ (0, import_operators2.concatMap)(
10825
+ (event) => (0, import_rxjs2.from)(withActorSpan("matcher", "match:search-requested", () => this.handleSearch(event)))
11034
10826
  )
11035
10827
  );
11036
10828
  this.subscriptions.push(
@@ -11104,11 +10896,14 @@ var Matcher = class {
11104
10896
  // 4. Semantic match — vector similarity search (if vectors configured)
11105
10897
  this.searchVectors(searchTerm)
11106
10898
  ]);
11107
- const neighborResources = await Promise.all(
11108
- connections.map(
11109
- (conn) => this.kb.graph.getResource(resourceId(conn.resourceId)).catch(() => null)
11110
- )
10899
+ const neighborResolved = await Promise.all(
10900
+ connections.map((conn) => resourceWithViewGrace(this.kb, resourceId(conn.resourceId)))
11111
10901
  );
10902
+ const laggedNeighbors = neighborResolved.filter((r) => r.laggedBehindView).length;
10903
+ if (laggedNeighbors > 0) {
10904
+ this.logger.info("[graph lag] neighborhood candidates hydrated from view", { count: laggedNeighbors });
10905
+ }
10906
+ const neighborResources = neighborResolved.map((r) => r.resource);
11112
10907
  const candidateMap = /* @__PURE__ */ new Map();
11113
10908
  const addCandidate = (resource, source) => {
11114
10909
  const id = getResourceId(resource);
@@ -11126,11 +10921,16 @@ var Matcher = class {
11126
10921
  if (r) addCandidate(r, "neighborhood");
11127
10922
  }
11128
10923
  const semanticScores = /* @__PURE__ */ new Map();
10924
+ let laggedSemantic = 0;
11129
10925
  for (const sm of semanticMatches) {
11130
10926
  semanticScores.set(sm.resourceId, sm.score);
11131
- const resource = await this.kb.graph.getResource(resourceId(sm.resourceId)).catch(() => null);
10927
+ const { resource, laggedBehindView } = await resourceWithViewGrace(this.kb, resourceId(sm.resourceId));
10928
+ if (laggedBehindView) laggedSemantic++;
11132
10929
  if (resource) addCandidate(resource, "semantic");
11133
10930
  }
10931
+ if (laggedSemantic > 0) {
10932
+ this.logger.info("[graph lag] semantic candidates hydrated from view", { count: laggedSemantic });
10933
+ }
11134
10934
  this.logger.debug("Candidate retrieval", {
11135
10935
  nameMatches: nameMatches.length,
11136
10936
  entityTypeMatches: entityTypeMatches.length,
@@ -11343,26 +11143,71 @@ For each candidate, output a line with the number and score, like:
11343
11143
  };
11344
11144
 
11345
11145
  // src/stower.ts
11346
- var import_rxjs4 = __toESM(require_cjs());
11347
- var import_operators4 = __toESM(require_operators());
11146
+ var import_rxjs3 = __toESM(require_cjs());
11147
+ var import_operators3 = __toESM(require_operators());
11148
+ async function readEntityTypesProjection(project) {
11149
+ const entityTypesPath = path3.join(
11150
+ project.stateDir,
11151
+ "projections",
11152
+ "__system__",
11153
+ "entitytypes.json"
11154
+ );
11155
+ try {
11156
+ const content = await promises.readFile(entityTypesPath, "utf-8");
11157
+ const projection = JSON.parse(content);
11158
+ return projection.entityTypes || [];
11159
+ } catch (error) {
11160
+ if (error.code === "ENOENT") {
11161
+ return [];
11162
+ }
11163
+ throw error;
11164
+ }
11165
+ }
11166
+
11167
+ // src/views/projection-validators.ts
11168
+ function resolveTagSchema(tagSchemas, schemaId) {
11169
+ if (typeof schemaId !== "string" || !schemaId) {
11170
+ return { error: "tag-annotation requires schemaId" };
11171
+ }
11172
+ const schema = tagSchemas.find((s) => s.id === schemaId);
11173
+ if (!schema) {
11174
+ return { error: `Tag schema not registered: ${schemaId}` };
11175
+ }
11176
+ return { schema };
11177
+ }
11178
+ function validateEntityTypes(registered, requested) {
11179
+ if (!requested || requested.length === 0) {
11180
+ return { ok: true };
11181
+ }
11182
+ const set = new Set(registered);
11183
+ const unknown = requested.filter((t) => !set.has(t));
11184
+ return unknown.length > 0 ? { ok: false, unknown } : { ok: true };
11185
+ }
11186
+ function entityTypesNotRegisteredMessage(unknown) {
11187
+ return `Entity type not registered: ${unknown.join(", ")}`;
11188
+ }
11189
+
11190
+ // src/stower.ts
11348
11191
  var Stower = class {
11349
- constructor(kb, eventBus, logger) {
11192
+ constructor(kb, eventBus, project, logger) {
11350
11193
  this.kb = kb;
11351
11194
  this.eventBus = eventBus;
11195
+ this.project = project;
11352
11196
  this.logger = logger;
11353
11197
  }
11354
11198
  kb;
11355
11199
  eventBus;
11200
+ project;
11356
11201
  subscription = null;
11357
11202
  logger;
11358
11203
  async initialize() {
11359
11204
  this.logger.info("Stower actor initialized");
11360
11205
  const pipe = (event, handler) => this.eventBus.get(event).pipe(
11361
- (0, import_operators4.concatMap)(
11362
- (e) => (0, import_rxjs4.from)(withActorSpan("stower", event, () => handler(e)))
11206
+ (0, import_operators3.concatMap)(
11207
+ (e) => (0, import_rxjs3.from)(withActorSpan("stower", event, () => handler(e)))
11363
11208
  )
11364
11209
  );
11365
- this.subscription = (0, import_rxjs4.merge)(
11210
+ this.subscription = (0, import_rxjs3.merge)(
11366
11211
  pipe("yield:create", (e) => this.handleYieldCreate(e)),
11367
11212
  pipe("yield:update", (e) => this.handleYieldUpdate(e)),
11368
11213
  pipe("yield:mv", (e) => this.handleYieldMv(e)),
@@ -11688,22 +11533,38 @@ var Stower = class {
11688
11533
  const uid = userId(event._userId);
11689
11534
  const added = event.updatedEntityTypes.filter((et) => !event.currentEntityTypes.includes(et));
11690
11535
  const removed = event.currentEntityTypes.filter((et) => !event.updatedEntityTypes.includes(et));
11691
- for (const entityType2 of added) {
11692
- await this.kb.eventStore.appendEvent({
11693
- type: "mark:entity-tag-added",
11694
- resourceId: resourceId(event.resourceId),
11695
- userId: uid,
11696
- version: 1,
11697
- payload: { entityType: entityType2 }
11698
- });
11699
- }
11700
- for (const entityType2 of removed) {
11701
- await this.kb.eventStore.appendEvent({
11702
- type: "mark:entity-tag-removed",
11703
- resourceId: resourceId(event.resourceId),
11704
- userId: uid,
11705
- version: 1,
11706
- payload: { entityType: entityType2 }
11536
+ try {
11537
+ if (added.length > 0) {
11538
+ const registered = await readEntityTypesProjection(this.project);
11539
+ const result = validateEntityTypes(registered, added);
11540
+ if (!result.ok) {
11541
+ throw new Error(entityTypesNotRegisteredMessage(result.unknown));
11542
+ }
11543
+ }
11544
+ for (const entityType2 of added) {
11545
+ await this.kb.eventStore.appendEvent({
11546
+ type: "mark:entity-tag-added",
11547
+ resourceId: resourceId(event.resourceId),
11548
+ userId: uid,
11549
+ version: 1,
11550
+ payload: { entityType: entityType2 }
11551
+ });
11552
+ }
11553
+ for (const entityType2 of removed) {
11554
+ await this.kb.eventStore.appendEvent({
11555
+ type: "mark:entity-tag-removed",
11556
+ resourceId: resourceId(event.resourceId),
11557
+ userId: uid,
11558
+ version: 1,
11559
+ payload: { entityType: entityType2 }
11560
+ });
11561
+ }
11562
+ this.eventBus.get("mark:update-entity-types-ok").next({ correlationId: event.correlationId });
11563
+ } catch (error) {
11564
+ this.logger.error("Failed to update entity types", { error: errField(error) });
11565
+ this.eventBus.get("mark:update-entity-types-failed").next({
11566
+ correlationId: event.correlationId,
11567
+ message: error instanceof Error ? error.message : String(error)
11707
11568
  });
11708
11569
  }
11709
11570
  }
@@ -11765,26 +11626,8 @@ var Stower = class {
11765
11626
  };
11766
11627
 
11767
11628
  // src/browser.ts
11768
- var import_rxjs5 = __toESM(require_cjs());
11769
- var import_operators5 = __toESM(require_operators());
11770
- async function readEntityTypesProjection(project) {
11771
- const entityTypesPath = path3.join(
11772
- project.stateDir,
11773
- "projections",
11774
- "__system__",
11775
- "entitytypes.json"
11776
- );
11777
- try {
11778
- const content = await promises.readFile(entityTypesPath, "utf-8");
11779
- const projection = JSON.parse(content);
11780
- return projection.entityTypes || [];
11781
- } catch (error) {
11782
- if (error.code === "ENOENT") {
11783
- return [];
11784
- }
11785
- throw error;
11786
- }
11787
- }
11629
+ var import_rxjs4 = __toESM(require_cjs());
11630
+ var import_operators4 = __toESM(require_operators());
11788
11631
  async function readTagSchemasProjection(project) {
11789
11632
  const tagSchemasPath = path3.join(
11790
11633
  project.stateDir,
@@ -11815,28 +11658,74 @@ async function assembleResourceGraph(kb, resourceId10) {
11815
11658
  });
11816
11659
  return { resource: stored.resource, annotations, entityReferences };
11817
11660
  }
11661
+ var JOB_TYPES = [
11662
+ "reference-annotation",
11663
+ "highlight-annotation",
11664
+ "assessment-annotation",
11665
+ "comment-annotation",
11666
+ "tag-annotation",
11667
+ "generation"
11668
+ ];
11669
+ function deriveAgentRoster(config) {
11670
+ const domain = config.site?.domain;
11671
+ if (!domain) {
11672
+ throw new Error(
11673
+ "site.domain is required to mint agent DIDs \u2014 the directory must use the same canonical domain /api/tokens/agent mints worker DIDs from (no topology fallback)"
11674
+ );
11675
+ }
11676
+ const roster = /* @__PURE__ */ new Map();
11677
+ const admit = (inference, jobType) => {
11678
+ const key = `${inference.type}\0${inference.model}`;
11679
+ let entry = roster.get(key);
11680
+ if (!entry) {
11681
+ entry = {
11682
+ agent: softwareToAgent({ domain, provider: inference.type, model: inference.model }),
11683
+ servesJobTypes: []
11684
+ };
11685
+ roster.set(key, entry);
11686
+ }
11687
+ if (jobType) entry.servesJobTypes.push(jobType);
11688
+ };
11689
+ for (const jobType of JOB_TYPES) {
11690
+ try {
11691
+ admit(resolveWorkerInference(config, jobType), jobType);
11692
+ } catch {
11693
+ }
11694
+ }
11695
+ for (const actor of ["gatherer", "matcher"]) {
11696
+ try {
11697
+ admit(resolveActorInference(config, actor));
11698
+ } catch {
11699
+ }
11700
+ }
11701
+ return [...roster.values()].map(
11702
+ ({ agent, servesJobTypes }) => servesJobTypes.length ? { agent, servesJobTypes } : { agent }
11703
+ );
11704
+ }
11818
11705
 
11819
11706
  // src/browser.ts
11820
11707
  var Browser = class {
11821
- constructor(views, kb, eventBus, project, logger) {
11708
+ constructor(views, kb, eventBus, project, config, logger) {
11822
11709
  this.views = views;
11823
11710
  this.kb = kb;
11824
11711
  this.eventBus = eventBus;
11825
11712
  this.project = project;
11713
+ this.config = config;
11826
11714
  this.logger = logger;
11827
11715
  }
11828
11716
  views;
11829
11717
  kb;
11830
11718
  eventBus;
11831
11719
  project;
11720
+ config;
11832
11721
  subscriptions = [];
11833
11722
  logger;
11834
11723
  async initialize() {
11835
11724
  this.logger.info("Browser actor initialized");
11836
11725
  const errorHandler = (err) => this.logger.error("Browser pipeline error", { error: err });
11837
11726
  const pipe = (name, handler) => this.eventBus.get(name).pipe(
11838
- (0, import_operators5.mergeMap)(
11839
- (event) => (0, import_rxjs5.from)(withActorSpan("browser", name, () => handler(event))).pipe(
11727
+ (0, import_operators4.mergeMap)(
11728
+ (event) => (0, import_rxjs4.from)(withActorSpan("browser", name, () => handler(event))).pipe(
11840
11729
  // Isolate per-event failures: a single handler throw must NOT tear down the
11841
11730
  // channel subscription for every future request — that's the browse:entity-types
11842
11731
  // wedge (.plans/bugs/browse-entity-types-never-responds.md). Handlers emit their
@@ -11844,9 +11733,9 @@ var Browser = class {
11844
11733
  // handler's try/catch — the channel survives, the offending request is logged.
11845
11734
  // (A per-channel *-failed can't be emitted from this generic helper without the
11846
11735
  // request→failure mapping — that's the Tier 1 operations registry.)
11847
- (0, import_operators5.catchError)((error) => {
11736
+ (0, import_operators4.catchError)((error) => {
11848
11737
  this.logger.error(`browse handler threw on ${name}`, { error: errField(error) });
11849
- return import_rxjs5.EMPTY;
11738
+ return import_rxjs4.EMPTY;
11850
11739
  })
11851
11740
  )
11852
11741
  )
@@ -11861,6 +11750,7 @@ var Browser = class {
11861
11750
  pipe("browse:referenced-by-requested", (e) => this.handleReferencedBy(e)).subscribe({ error: errorHandler }),
11862
11751
  pipe("browse:entity-types-requested", (e) => this.handleEntityTypes(e)).subscribe({ error: errorHandler }),
11863
11752
  pipe("browse:tag-schemas-requested", (e) => this.handleTagSchemas(e)).subscribe({ error: errorHandler }),
11753
+ pipe("browse:agents-requested", (e) => this.handleBrowseAgents(e)).subscribe({ error: errorHandler }),
11864
11754
  pipe("browse:directory-requested", (e) => this.handleBrowseDirectory(e)).subscribe({ error: errorHandler })
11865
11755
  );
11866
11756
  }
@@ -12045,13 +11935,19 @@ var Browser = class {
12045
11935
  });
12046
11936
  const references = await this.kb.graph.getResourceReferencedBy(resourceId(event.resourceId), event.motivation);
12047
11937
  const sourceIds = [...new Set(references.map((ref) => getTargetSource(ref.target)))];
12048
- const resources = await Promise.all(sourceIds.map((id) => this.kb.graph.getResource(resourceId(id))));
11938
+ const resolved = await Promise.all(
11939
+ sourceIds.map((id) => resourceWithViewGrace(this.kb, resourceId(id)))
11940
+ );
11941
+ const docMap = new Map(
11942
+ resolved.filter((r) => r.resource !== null).map((r) => [r.resource["@id"], r.resource])
11943
+ );
12049
11944
  for (let i = 0; i < sourceIds.length; i++) {
12050
- if (resources[i] === null) {
12051
- this.logger.warn("Referenced resource not found in graph", { resourceId: sourceIds[i] });
11945
+ if (resolved[i].laggedBehindView) {
11946
+ this.logger.info("[graph lag] citer hydrated from view", { resourceId: sourceIds[i] });
11947
+ } else if (resolved[i].resource === null) {
11948
+ this.logger.warn("Referenced resource not found in graph or view", { resourceId: sourceIds[i] });
12052
11949
  }
12053
11950
  }
12054
- const docMap = new Map(resources.filter((doc) => doc !== null).map((doc) => [doc["@id"], doc]));
12055
11951
  const referencedBy = references.map((ref) => {
12056
11952
  const targetSource = getTargetSource(ref.target);
12057
11953
  const targetSelector = getTargetSelector(ref.target);
@@ -12109,6 +12005,21 @@ var Browser = class {
12109
12005
  });
12110
12006
  }
12111
12007
  }
12008
+ async handleBrowseAgents(event) {
12009
+ try {
12010
+ const agents = deriveAgentRoster(this.config);
12011
+ this.eventBus.get("browse:agents-result").next({
12012
+ correlationId: event.correlationId,
12013
+ response: { agents }
12014
+ });
12015
+ } catch (error) {
12016
+ this.logger.error("Agent roster derivation failed", { error: errField(error) });
12017
+ this.eventBus.get("browse:agents-failed").next({
12018
+ correlationId: event.correlationId,
12019
+ message: error instanceof Error ? error.message : String(error)
12020
+ });
12021
+ }
12022
+ }
12112
12023
  // ========================================================================
12113
12024
  // Filesystem read handler
12114
12025
  // ========================================================================
@@ -12233,8 +12144,8 @@ async function readAnnotationFromView(kb, resourceId10, annotationId5) {
12233
12144
  }
12234
12145
 
12235
12146
  // src/clone-token-manager.ts
12236
- var import_rxjs6 = __toESM(require_cjs());
12237
- var import_operators6 = __toESM(require_operators());
12147
+ var import_rxjs5 = __toESM(require_cjs());
12148
+ var import_operators5 = __toESM(require_operators());
12238
12149
 
12239
12150
  // src/bus-request-local.ts
12240
12151
  function asBusRequestPrimitive(eventBus) {
@@ -12294,13 +12205,13 @@ var CloneTokenManager = class {
12294
12205
  this.logger.info("CloneTokenManager actor initialized");
12295
12206
  const errorHandler = (err) => this.logger.error("CloneTokenManager pipeline error", { error: err });
12296
12207
  const generateToken$ = this.eventBus.get("yield:clone-token-requested").pipe(
12297
- (0, import_operators6.mergeMap)((event) => (0, import_rxjs6.from)(this.handleGenerateToken(event)))
12208
+ (0, import_operators5.mergeMap)((event) => (0, import_rxjs5.from)(this.handleGenerateToken(event)))
12298
12209
  );
12299
12210
  const getResource$ = this.eventBus.get("yield:clone-resource-requested").pipe(
12300
- (0, import_operators6.mergeMap)((event) => (0, import_rxjs6.from)(this.handleGetResource(event)))
12211
+ (0, import_operators5.mergeMap)((event) => (0, import_rxjs5.from)(this.handleGetResource(event)))
12301
12212
  );
12302
12213
  const createResource$ = this.eventBus.get("yield:clone-create").pipe(
12303
- (0, import_operators6.mergeMap)((event) => (0, import_rxjs6.from)(this.handleCreateResource(event)))
12214
+ (0, import_operators5.mergeMap)((event) => (0, import_rxjs5.from)(this.handleCreateResource(event)))
12304
12215
  );
12305
12216
  this.subscriptions.push(
12306
12217
  generateToken$.subscribe({ error: errorHandler }),
@@ -12505,7 +12416,7 @@ async function stopKnowledgeSystem(ks) {
12505
12416
  await ks.browser.stop();
12506
12417
  await ks.cloneTokenManager.stop();
12507
12418
  await ks.stower.stop();
12508
- await ks.kb.graphConsumer.stop();
12419
+ ks.kb.weaveProgress.dispose();
12509
12420
  await ks.kb.graph.disconnect();
12510
12421
  }
12511
12422
  function registerAnnotationAssemblyHandler(eventBus, parentLogger) {
@@ -12669,31 +12580,6 @@ function registerBindUpdateBodyHandler(eventBus, parentLogger) {
12669
12580
  logger.warn("Bind body-update failed after forwarding", { correlationId: cid, message });
12670
12581
  });
12671
12582
  }
12672
-
12673
- // src/views/projection-validators.ts
12674
- function resolveTagSchema(tagSchemas, schemaId) {
12675
- if (typeof schemaId !== "string" || !schemaId) {
12676
- return { error: "tag-annotation requires schemaId" };
12677
- }
12678
- const schema = tagSchemas.find((s) => s.id === schemaId);
12679
- if (!schema) {
12680
- return { error: `Tag schema not registered: ${schemaId}` };
12681
- }
12682
- return { schema };
12683
- }
12684
- function validateEntityTypes(registered, requested) {
12685
- if (!requested || requested.length === 0) {
12686
- return { ok: true };
12687
- }
12688
- const set = new Set(registered);
12689
- const unknown = requested.filter((t) => !set.has(t));
12690
- return unknown.length > 0 ? { ok: false, unknown } : { ok: true };
12691
- }
12692
- function entityTypesNotRegisteredMessage(unknown) {
12693
- return `Entity type not registered: ${unknown.join(", ")}`;
12694
- }
12695
-
12696
- // src/handlers/job-commands.ts
12697
12583
  function parseDidUser(did) {
12698
12584
  const parts = did.split(":");
12699
12585
  const usersIdx = parts.indexOf("users");
@@ -12874,7 +12760,7 @@ async function createJobQueue(project, eventBus, logger) {
12874
12760
  await jobQueue.initialize();
12875
12761
  registerJobQueueProvider(() => jobQueue.getStats());
12876
12762
  const jobStatusSubscription = eventBus.get("job:status-requested").pipe(
12877
- (0, import_operators7.mergeMap)((event) => (0, import_rxjs7.from)((async () => {
12763
+ (0, import_operators6.mergeMap)((event) => (0, import_rxjs6.from)((async () => {
12878
12764
  try {
12879
12765
  const job = await jobQueue.getJob(jobId(event.jobId));
12880
12766
  if (!job) {
@@ -12944,7 +12830,7 @@ async function createKnowledgeSystemFromConfig(project, config, eventBus, logger
12944
12830
  if (annotation === null) return event;
12945
12831
  return { ...event, annotation };
12946
12832
  });
12947
- const stower = new Stower(kb, eventBus, logger.child({ component: "stower" }));
12833
+ const stower = new Stower(kb, eventBus, project, logger.child({ component: "stower" }));
12948
12834
  await stower.initialize();
12949
12835
  await bootstrapEntityTypes(eventBus, eventStore, logger.child({ component: "entity-types-bootstrap" }));
12950
12836
  const gatherer = new Gatherer(
@@ -12963,7 +12849,7 @@ async function createKnowledgeSystemFromConfig(project, config, eventBus, logger
12963
12849
  embeddingProvider
12964
12850
  );
12965
12851
  await matcher.initialize();
12966
- const browser = new Browser(kb.views, kb, eventBus, project, logger.child({ component: "browser" }));
12852
+ const browser = new Browser(kb.views, kb, eventBus, project, config, logger.child({ component: "browser" }));
12967
12853
  await browser.initialize();
12968
12854
  const cloneTokenManager = new CloneTokenManager(kb, eventBus, logger.child({ component: "clone-token-manager" }));
12969
12855
  await cloneTokenManager.initialize();
@@ -12991,11 +12877,11 @@ async function startMakeMeaning(project, config, eventBus, logger, options) {
12991
12877
  }
12992
12878
 
12993
12879
  // src/local-transport.ts
12994
- var import_rxjs8 = __toESM(require_cjs());
12880
+ var import_rxjs7 = __toESM(require_cjs());
12995
12881
  var LocalTransport = class {
12996
12882
  baseUrl;
12997
12883
  state$;
12998
- errorsSubject = new import_rxjs8.Subject();
12884
+ errorsSubject = new import_rxjs7.Subject();
12999
12885
  /**
13000
12886
  * Stream of `SemiontError` instances surfaced from transport-mediated
13001
12887
  * round-trips (typed-wire methods on this transport that fail). The
@@ -13016,7 +12902,7 @@ var LocalTransport = class {
13016
12902
  this.bus = cfg.eventBus;
13017
12903
  this.userId = cfg.userId;
13018
12904
  this.baseUrl = cfg.baseUrl ?? baseUrl("local://in-process");
13019
- this.state$ = new import_rxjs8.BehaviorSubject("open");
12905
+ this.state$ = new import_rxjs7.BehaviorSubject("open");
13020
12906
  }
13021
12907
  // ── Bus primitives ──────────────────────────────────────────────────────
13022
12908
  async emit(channel, payload, resourceScope) {
@@ -13149,10 +13035,39 @@ var LocalContentTransport = class {
13149
13035
  };
13150
13036
 
13151
13037
  // src/smelter.ts
13152
- var import_rxjs9 = __toESM(require_cjs());
13153
- var import_operators8 = __toESM(require_operators());
13038
+ var import_rxjs8 = __toESM(require_cjs());
13039
+ var import_operators7 = __toESM(require_operators());
13040
+
13041
+ // src/batch-utils.ts
13042
+ function partitionByType(events) {
13043
+ const runs = [];
13044
+ let currentRun = [];
13045
+ for (const event of events) {
13046
+ if (currentRun.length > 0 && currentRun[0].type !== event.type) {
13047
+ runs.push(currentRun);
13048
+ currentRun = [];
13049
+ }
13050
+ currentRun.push(event);
13051
+ }
13052
+ if (currentRun.length > 0) runs.push(currentRun);
13053
+ return runs;
13054
+ }
13055
+
13056
+ // src/smelter.ts
13057
+ function sameStringSet(a, b) {
13058
+ if (a.length !== b.length) return false;
13059
+ const set = new Set(a);
13060
+ return b.every((t) => set.has(t));
13061
+ }
13062
+ var WORK_ITEM_TYPES = /* @__PURE__ */ new Set([
13063
+ "smelt:embed",
13064
+ "smelt:restamp",
13065
+ "smelt:purge",
13066
+ "smelt:embed-annotation",
13067
+ "smelt:purge-annotation"
13068
+ ]);
13154
13069
  function isWorkItem(input) {
13155
- return input.type.startsWith("smelt:");
13070
+ return WORK_ITEM_TYPES.has(input.type);
13156
13071
  }
13157
13072
  var Smelter = class _Smelter {
13158
13073
  constructor(events$, vectorStore, embeddingProvider, content, bus, chunkingConfig, timing, logger) {
@@ -13176,7 +13091,7 @@ var Smelter = class _Smelter {
13176
13091
  static RECONCILE_PAGE_SIZE = 200;
13177
13092
  /** Bound on concurrently in-flight reconcile work — a cold rebuild must not fan out unbounded embedding calls. */
13178
13093
  static RECONCILE_WAVE = 8;
13179
- eventSubject = new import_rxjs9.Subject();
13094
+ eventSubject = new import_rxjs8.Subject();
13180
13095
  sourceSubscription = null;
13181
13096
  pipelineSubscription = null;
13182
13097
  _eventsProcessed = 0;
@@ -13191,23 +13106,23 @@ var Smelter = class _Smelter {
13191
13106
  }
13192
13107
  initialize() {
13193
13108
  this.pipelineSubscription = this.eventSubject.pipe(
13194
- (0, import_operators8.groupBy)((e) => e.resourceId ?? "__unknown__"),
13195
- (0, import_operators8.mergeMap)(
13109
+ (0, import_operators7.groupBy)((e) => e.resourceId ?? "__unknown__"),
13110
+ (0, import_operators7.mergeMap)(
13196
13111
  (group) => group.pipe(
13197
13112
  burstBuffer({
13198
13113
  burstWindowMs: this.timing.burstWindowMs,
13199
13114
  maxBatchSize: this.timing.maxBatchSize,
13200
13115
  idleTimeoutMs: this.timing.idleTimeoutMs
13201
13116
  }),
13202
- (0, import_operators8.concatMap)((inputOrBatch) => {
13117
+ (0, import_operators7.concatMap)((inputOrBatch) => {
13203
13118
  if (Array.isArray(inputOrBatch)) {
13204
- return (0, import_rxjs9.from)(
13119
+ return (0, import_rxjs8.from)(
13205
13120
  withActorSpan("smelter", "batch", async () => {
13206
13121
  this._eventsProcessed += await this.processBatch(inputOrBatch);
13207
13122
  }, { "batch.size": inputOrBatch.length })
13208
13123
  );
13209
13124
  }
13210
- return (0, import_rxjs9.from)(
13125
+ return (0, import_rxjs8.from)(
13211
13126
  withActorSpan("smelter", inputOrBatch.type, async () => {
13212
13127
  const ok = await this.safeProcessEvent(inputOrBatch);
13213
13128
  if (isWorkItem(inputOrBatch)) this.noteWorkDone(1);
@@ -13316,16 +13231,26 @@ var Smelter = class _Smelter {
13316
13231
  case "mark:archived":
13317
13232
  await this.handleResourceArchived(event);
13318
13233
  break;
13234
+ case "mark:unarchived":
13235
+ await this.handleResourceUnarchived(event);
13236
+ break;
13319
13237
  case "mark:added":
13320
13238
  await this.handleAnnotationAdded(event);
13321
13239
  break;
13322
13240
  case "mark:removed":
13323
13241
  await this.handleAnnotationRemoved(event);
13324
13242
  break;
13243
+ case "mark:entity-tag-added":
13244
+ case "mark:entity-tag-removed":
13245
+ await this.restampResource(event);
13246
+ break;
13325
13247
  // Reconcile work items — same handlers, distinct provenance.
13326
13248
  case "smelt:embed":
13327
13249
  await this.embedResource(event, "Reconcile-indexed resource");
13328
13250
  break;
13251
+ case "smelt:restamp":
13252
+ await this.restampResource(event);
13253
+ break;
13329
13254
  case "smelt:purge":
13330
13255
  await this.handleResourcePurge(event);
13331
13256
  break;
@@ -13337,6 +13262,21 @@ var Smelter = class _Smelter {
13337
13262
  break;
13338
13263
  }
13339
13264
  }
13265
+ /**
13266
+ * Payload-only stamp refresh: re-read the resource's CURRENT entity types
13267
+ * (one code path — `resolveEntityTypes` — so any prior drift self-corrects
13268
+ * on first touch) and rewrite the stamp on its existing points. Never calls
13269
+ * the embedding provider (S13): content is unchanged by definition on every
13270
+ * path that lands here. A resource with no points is a no-op — the stamp
13271
+ * rides the next embed.
13272
+ */
13273
+ async restampResource(event) {
13274
+ const rid = event.resourceId;
13275
+ if (!rid) return;
13276
+ const entityTypes = await this.resolveEntityTypes(rid);
13277
+ await this.vectorStore.updateResourceEntityTypes(resourceId(rid), entityTypes);
13278
+ this.logger.info("Restamped resource entity types", { resourceId: rid, entityTypes });
13279
+ }
13340
13280
  async handleResourcePurge(event) {
13341
13281
  const rid = event.resourceId;
13342
13282
  if (!rid) return;
@@ -13354,16 +13294,30 @@ var Smelter = class _Smelter {
13354
13294
  async fetchEmbeddableText(resourceId10) {
13355
13295
  try {
13356
13296
  const { data, contentType } = await this.content.getBinary(resourceId(resourceId10));
13297
+ const bytes = Buffer.from(data);
13298
+ const checksum = calculateChecksum(bytes);
13357
13299
  if (textExtractionOf(contentType) !== "decode") {
13358
13300
  this.logger.debug("Skipping resource that does not decode as text", { resourceId: resourceId10, contentType });
13359
- return null;
13301
+ return { kind: "skipped", checksum };
13360
13302
  }
13361
- const bytes = Buffer.from(data);
13362
13303
  const text = decodeRepresentation(bytes, contentType);
13363
- return text.trim() ? { text, checksum: calculateChecksum(bytes) } : null;
13304
+ return text.trim() ? { kind: "text", text, checksum } : { kind: "skipped", checksum };
13364
13305
  } catch (error) {
13365
13306
  this.logger.warn("Content unavailable for embedding", { resourceId: resourceId10, error: errField(error) });
13366
- return null;
13307
+ return { kind: "unavailable" };
13308
+ }
13309
+ }
13310
+ /**
13311
+ * The Smelter's single outbound signal (SMELTER-AXIOMS D3 as amended by
13312
+ * SMELTER-INDEX-SYNC): a per-resource decision report for the barrier
13313
+ * fold. Best-effort — waiters degrade to their bounded timeout; a signal
13314
+ * failure must never fail the embed.
13315
+ */
13316
+ async emitSettled(resourceId10, contentChecksum, outcome) {
13317
+ try {
13318
+ await this.bus.emit("smelt:settled", { resourceId: resourceId10, contentChecksum, outcome });
13319
+ } catch (error) {
13320
+ this.logger.warn("Failed to emit smelt:settled", { resourceId: resourceId10, outcome, error: errField(error) });
13367
13321
  }
13368
13322
  }
13369
13323
  /**
@@ -13387,9 +13341,16 @@ var Smelter = class _Smelter {
13387
13341
  const rid = event.resourceId;
13388
13342
  if (!rid) return;
13389
13343
  const fetched = await this.fetchEmbeddableText(rid);
13390
- if (!fetched) return;
13344
+ if (fetched.kind === "unavailable") return;
13345
+ if (fetched.kind === "skipped") {
13346
+ await this.emitSettled(rid, fetched.checksum, "skipped");
13347
+ return;
13348
+ }
13391
13349
  const chunks = chunkText(fetched.text, this.chunkingConfig);
13392
- if (chunks.length === 0) return;
13350
+ if (chunks.length === 0) {
13351
+ await this.emitSettled(rid, fetched.checksum, "skipped");
13352
+ return;
13353
+ }
13393
13354
  const entityTypes = await this.resolveEntityTypes(rid);
13394
13355
  const embeddings = await this.embeddingProvider.embedBatch(chunks);
13395
13356
  const embeddingChunks = chunks.map((t, i) => ({
@@ -13398,6 +13359,7 @@ var Smelter = class _Smelter {
13398
13359
  embedding: embeddings[i]
13399
13360
  }));
13400
13361
  await this.vectorStore.upsertResourceVectors(resourceId(rid), embeddingChunks, fetched.checksum, entityTypes);
13362
+ await this.emitSettled(rid, fetched.checksum, "indexed");
13401
13363
  this.logger.info(logMessage, { resourceId: rid, chunks: chunks.length });
13402
13364
  }
13403
13365
  async handleResourceArchived(event) {
@@ -13407,11 +13369,34 @@ var Smelter = class _Smelter {
13407
13369
  await this.vectorStore.deleteAnnotationVectorsForResource(resourceId(rid));
13408
13370
  this.logger.info("Deleted vectors for archived resource", { resourceId: rid });
13409
13371
  }
13372
+ /**
13373
+ * Restore what `handleResourceArchived` deleted, from CURRENT state: the
13374
+ * resource's vectors (media-gated, full-replace) and its current exact-text
13375
+ * annotations — the same catalog read `reconcile()` uses, so the live path
13376
+ * and a restart agree (bugs/smelter-misses-unarchive.md).
13377
+ */
13378
+ async handleResourceUnarchived(event) {
13379
+ const rid = event.resourceId;
13380
+ if (!rid) return;
13381
+ await this.embedResource(event, "Re-embedded unarchived resource");
13382
+ const { annotations } = await busRequest(
13383
+ this.bus,
13384
+ "browse:annotations-requested",
13385
+ { resourceId: rid }
13386
+ );
13387
+ for (const annotation of annotations) {
13388
+ await this.indexAnnotation(rid, annotation);
13389
+ }
13390
+ }
13410
13391
  async handleAnnotationAdded(event) {
13411
13392
  const annotation = event.payload.annotation;
13412
13393
  if (!annotation?.id) return;
13413
13394
  const rid = event.resourceId;
13414
13395
  if (!rid) return;
13396
+ await this.indexAnnotation(rid, annotation);
13397
+ }
13398
+ async indexAnnotation(rid, annotation) {
13399
+ if (!annotation.id) return;
13415
13400
  const selector = getTargetSelector(annotation.target);
13416
13401
  const exactText = getExactText(selector);
13417
13402
  if (!exactText?.trim()) return;
@@ -13445,9 +13430,16 @@ var Smelter = class _Smelter {
13445
13430
  const rid = event.resourceId;
13446
13431
  if (!rid) continue;
13447
13432
  const fetched = await this.fetchEmbeddableText(rid);
13448
- if (!fetched) continue;
13433
+ if (fetched.kind === "unavailable") continue;
13434
+ if (fetched.kind === "skipped") {
13435
+ await this.emitSettled(rid, fetched.checksum, "skipped");
13436
+ continue;
13437
+ }
13449
13438
  const chunks = chunkText(fetched.text, this.chunkingConfig);
13450
- if (chunks.length === 0) continue;
13439
+ if (chunks.length === 0) {
13440
+ await this.emitSettled(rid, fetched.checksum, "skipped");
13441
+ continue;
13442
+ }
13451
13443
  const entityTypes = await this.resolveEntityTypes(rid);
13452
13444
  resourceData.push({ rid: resourceId(rid), chunks, checksum: fetched.checksum, entityTypes });
13453
13445
  allChunks.push(...chunks);
@@ -13462,6 +13454,7 @@ var Smelter = class _Smelter {
13462
13454
  embedding: allEmbeddings[offset + i]
13463
13455
  }));
13464
13456
  await this.vectorStore.upsertResourceVectors(rid, embeddingChunks, checksum, entityTypes);
13457
+ await this.emitSettled(String(rid), checksum, "indexed");
13465
13458
  this.logger.info("Batch-indexed resource", { resourceId: String(rid), chunks: chunks.length });
13466
13459
  offset += chunks.length;
13467
13460
  }
@@ -13534,7 +13527,7 @@ var Smelter = class _Smelter {
13534
13527
  this._reconcileState = { phase: "running" };
13535
13528
  try {
13536
13529
  const [indexedResources, indexedAnnotations] = await Promise.all([
13537
- this.vectorStore.listResourceChecksums(),
13530
+ this.vectorStore.listResourceStamps(),
13538
13531
  this.vectorStore.listAnnotationIds()
13539
13532
  ]);
13540
13533
  const resources = await this.listAllResources();
@@ -13547,18 +13540,24 @@ var Smelter = class _Smelter {
13547
13540
  for (const resource of resources) {
13548
13541
  const mediaType = getPrimaryMediaType(resource);
13549
13542
  if (resource["@id"] && mediaType && textExtractionOf(mediaType) === "decode") {
13550
- embeddable.set(resource["@id"], getPrimaryRepresentation(resource)?.checksum);
13543
+ embeddable.set(resource["@id"], {
13544
+ checksum: getPrimaryRepresentation(resource)?.checksum,
13545
+ entityTypes: getResourceEntityTypes(resource)
13546
+ });
13551
13547
  }
13552
13548
  }
13553
13549
  const work = [];
13554
13550
  for (const rid of indexedResources.keys()) {
13555
13551
  if (!embeddable.has(rid)) work.push({ type: "smelt:purge", resourceId: rid, payload: {} });
13556
13552
  }
13557
- for (const [rid, catalogChecksum] of embeddable) {
13558
- if (!indexedResources.has(rid)) {
13553
+ for (const [rid, catalog] of embeddable) {
13554
+ const indexed = indexedResources.get(rid);
13555
+ if (!indexed) {
13559
13556
  work.push({ type: "smelt:embed", resourceId: rid, payload: {} });
13560
- } else if (catalogChecksum !== void 0 && indexedResources.get(rid) !== catalogChecksum) {
13557
+ } else if (catalog.checksum !== void 0 && indexed.contentChecksum !== catalog.checksum) {
13561
13558
  work.push({ type: "smelt:embed", resourceId: rid, payload: {} });
13559
+ } else if (!sameStringSet(indexed.entityTypes, catalog.entityTypes)) {
13560
+ work.push({ type: "smelt:restamp", resourceId: rid, payload: {} });
13562
13561
  }
13563
13562
  }
13564
13563
  const liveAnnotationIds = /* @__PURE__ */ new Set();
@@ -13587,6 +13586,7 @@ var Smelter = class _Smelter {
13587
13586
  await this.drain(work);
13588
13587
  const summary = {
13589
13588
  resourcesEmbedded: work.filter((w) => w.type === "smelt:embed").length,
13589
+ resourcesRestamped: work.filter((w) => w.type === "smelt:restamp").length,
13590
13590
  resourceVectorsDeleted: work.filter((w) => w.type === "smelt:purge").length,
13591
13591
  annotationsEmbedded: work.filter((w) => w.type === "smelt:embed-annotation").length,
13592
13592
  annotationVectorsDeleted: work.filter((w) => w.type === "smelt:purge-annotation").length
@@ -13635,23 +13635,26 @@ var Smelter = class _Smelter {
13635
13635
  };
13636
13636
 
13637
13637
  // src/smelter-actor-state-unit.ts
13638
- var import_rxjs10 = __toESM(require_cjs());
13639
- var import_operators9 = __toESM(require_operators());
13638
+ var import_rxjs9 = __toESM(require_cjs());
13639
+ var import_operators8 = __toESM(require_operators());
13640
13640
  var SMELTER_CHANNELS = [
13641
13641
  "yield:created",
13642
13642
  "yield:updated",
13643
13643
  "yield:representation-added",
13644
13644
  "mark:archived",
13645
+ "mark:unarchived",
13645
13646
  "mark:added",
13646
- "mark:removed"
13647
+ "mark:removed",
13648
+ "mark:entity-tag-added",
13649
+ "mark:entity-tag-removed"
13647
13650
  ];
13648
13651
  function createSmelterActorStateUnit(options) {
13649
13652
  const { bus } = options;
13650
13653
  let started = false;
13651
- const events$ = (0, import_rxjs10.merge)(
13654
+ const events$ = (0, import_rxjs9.merge)(
13652
13655
  ...SMELTER_CHANNELS.map(
13653
13656
  (channel) => bus.on$(channel).pipe(
13654
- (0, import_operators9.map)((payload) => ({
13657
+ (0, import_operators8.map)((payload) => ({
13655
13658
  type: channel,
13656
13659
  resourceId: payload.resourceId,
13657
13660
  payload
@@ -13855,27 +13858,27 @@ function collectContentRefs(streamData) {
13855
13858
  }
13856
13859
 
13857
13860
  // src/exchange/await-reply.ts
13858
- var import_rxjs11 = __toESM(require_cjs());
13859
- var import_operators10 = __toESM(require_operators());
13861
+ var import_rxjs10 = __toESM(require_cjs());
13862
+ var import_operators9 = __toESM(require_operators());
13860
13863
  function awaitReply(eventBus, command, payload, okChannel, failedChannel, timeoutMs) {
13861
- const result$ = (0, import_rxjs11.race)(
13862
- eventBus.get(okChannel).pipe((0, import_operators10.map)(() => void 0)),
13864
+ const result$ = (0, import_rxjs10.race)(
13865
+ eventBus.get(okChannel).pipe((0, import_operators9.map)(() => void 0)),
13863
13866
  eventBus.get(failedChannel).pipe(
13864
- (0, import_operators10.map)((e) => {
13867
+ (0, import_operators9.map)((e) => {
13865
13868
  throw new Error(e.message ?? `${command} failed`);
13866
13869
  })
13867
13870
  ),
13868
- (0, import_rxjs11.timer)(timeoutMs).pipe(
13869
- (0, import_operators10.map)(() => {
13871
+ (0, import_rxjs10.timer)(timeoutMs).pipe(
13872
+ (0, import_operators9.map)(() => {
13870
13873
  throw new Error(`Timeout waiting for ${okChannel}`);
13871
13874
  })
13872
13875
  )
13873
13876
  );
13874
13877
  eventBus.get(command).next(payload);
13875
- return (0, import_rxjs11.firstValueFrom)(result$);
13878
+ return (0, import_rxjs10.firstValueFrom)(result$);
13876
13879
  }
13877
13880
  var REPLAY_TIMEOUT_MS = 3e4;
13878
- async function replayEventStream(jsonl, eventBus, resolveBlob, contentStore, logger) {
13881
+ async function replayEventStream(jsonl, eventBus, eventStore, resolveBlob, contentStore, logger) {
13879
13882
  const lines = jsonl.trim().split("\n").filter((l) => l.length > 0);
13880
13883
  const storedEvents = lines.map((line) => JSON.parse(line));
13881
13884
  const stats = {
@@ -13885,12 +13888,12 @@ async function replayEventStream(jsonl, eventBus, resolveBlob, contentStore, log
13885
13888
  entityTypesAdded: 0
13886
13889
  };
13887
13890
  for (const stored of storedEvents) {
13888
- await replayEvent(stored, eventBus, resolveBlob, contentStore, stats, logger);
13891
+ await replayEvent(stored, eventBus, eventStore, resolveBlob, contentStore, stats, logger);
13889
13892
  stats.eventsReplayed++;
13890
13893
  }
13891
13894
  return { stats };
13892
13895
  }
13893
- async function replayEvent(event, eventBus, resolveBlob, contentStore, stats, logger) {
13896
+ async function replayEvent(event, eventBus, eventStore, resolveBlob, contentStore, stats, logger) {
13894
13897
  switch (event.type) {
13895
13898
  case "frame:entity-type-added":
13896
13899
  await replayEntityTypeAdded(event, eventBus, logger);
@@ -13918,7 +13921,7 @@ async function replayEvent(event, eventBus, resolveBlob, contentStore, stats, lo
13918
13921
  break;
13919
13922
  case "mark:entity-tag-added":
13920
13923
  case "mark:entity-tag-removed":
13921
- await replayEntityTagChange(event, eventBus, logger);
13924
+ await replayEntityTagChange(event, eventStore, logger);
13922
13925
  break;
13923
13926
  // Job events are transient — skip during replay
13924
13927
  case "job:started":
@@ -14034,25 +14037,18 @@ async function replayResourceUnarchived(event, eventBus, logger) {
14034
14037
  });
14035
14038
  logger?.debug("Replayed resource.unarchived", { resourceId: event.resourceId });
14036
14039
  }
14037
- async function replayEntityTagChange(event, eventBus, logger) {
14038
- const resourceId10 = event.resourceId;
14039
- const entityType2 = event.payload.entityType;
14040
+ async function replayEntityTagChange(event, eventStore, logger) {
14041
+ const base = {
14042
+ resourceId: event.resourceId,
14043
+ userId: event.userId,
14044
+ version: event.version
14045
+ };
14040
14046
  if (event.type === "mark:entity-tag-added") {
14041
- eventBus.get("mark:update-entity-types").next({
14042
- resourceId: resourceId10,
14043
- _userId: event.userId,
14044
- currentEntityTypes: [],
14045
- updatedEntityTypes: [entityType2]
14046
- });
14047
+ await eventStore.appendEvent({ ...base, type: "mark:entity-tag-added", payload: event.payload });
14047
14048
  } else {
14048
- eventBus.get("mark:update-entity-types").next({
14049
- resourceId: resourceId10,
14050
- _userId: event.userId,
14051
- currentEntityTypes: [entityType2],
14052
- updatedEntityTypes: []
14053
- });
14049
+ await eventStore.appendEvent({ ...base, type: "mark:entity-tag-removed", payload: event.payload });
14054
14050
  }
14055
- logger?.debug("Replayed entity tag change", { type: event.type, entityType: entityType2 });
14051
+ logger?.debug("Replayed entity tag change", { type: event.type, entityType: event.payload.entityType });
14056
14052
  }
14057
14053
 
14058
14054
  // src/exchange/backup-importer.ts
@@ -14071,7 +14067,7 @@ function buildBlobResolver(entries) {
14071
14067
  };
14072
14068
  }
14073
14069
  async function importBackup(archive, options) {
14074
- const { eventBus, contentStore, logger } = options;
14070
+ const { eventBus, eventStore, contentStore, logger } = options;
14075
14071
  const entries = /* @__PURE__ */ new Map();
14076
14072
  for await (const entry of readTarGz(archive)) {
14077
14073
  entries.set(entry.name, entry.data);
@@ -14099,6 +14095,7 @@ async function importBackup(archive, options) {
14099
14095
  const result = await replayEventStream(
14100
14096
  systemData.toString("utf8"),
14101
14097
  eventBus,
14098
+ eventStore,
14102
14099
  resolveBlob,
14103
14100
  contentStore,
14104
14101
  logger
@@ -14115,6 +14112,7 @@ async function importBackup(archive, options) {
14115
14112
  const result = await replayEventStream(
14116
14113
  eventData.toString("utf8"),
14117
14114
  eventBus,
14115
+ eventStore,
14118
14116
  resolveBlob,
14119
14117
  contentStore,
14120
14118
  logger
@@ -14535,6 +14533,6 @@ var AnnotationOperations = class {
14535
14533
  }
14536
14534
  };
14537
14535
 
14538
- export { AnnotationContext, AnnotationOperations, BACKUP_FORMAT, Browser, CloneTokenManager, FORMAT_VERSION, Gatherer, GraphContext, LLMContext, LocalContentTransport, LocalTransport, Matcher, ResourceContext, ResourceOperations, Smelter, Stower, bootstrapEntityTypes, createKnowledgeBase, createSmelterActorStateUnit, exportBackup, exportLinkedData, generateReferenceSuggestions, generateResourceSummary, importBackup, importLinkedData, isBackupManifest, readEntityTypesProjection, registerAnnotationAssemblyHandler, registerAnnotationLookupHandlers, registerBindUpdateBodyHandler, registerBusHandlers, registerJobCommandHandlers, startMakeMeaning, stopKnowledgeSystem, validateManifestVersion };
14536
+ export { AnnotationContext, AnnotationOperations, BACKUP_FORMAT, Browser, CloneTokenManager, FORMAT_VERSION, Gatherer, GraphContext, LLMContext, LocalContentTransport, LocalTransport, Matcher, ResourceContext, ResourceOperations, Smelter, Stower, asBusRequestPrimitive, bootstrapEntityTypes, createKnowledgeBase, createSmelterActorStateUnit, exportBackup, exportLinkedData, generateReferenceSuggestions, generateResourceSummary, importBackup, importLinkedData, isBackupManifest, readEntityTypesProjection, registerAnnotationAssemblyHandler, registerAnnotationLookupHandlers, registerBindUpdateBodyHandler, registerBusHandlers, registerJobCommandHandlers, startMakeMeaning, stopKnowledgeSystem, validateManifestVersion };
14539
14537
  //# sourceMappingURL=index.js.map
14540
14538
  //# sourceMappingURL=index.js.map