@semiont/make-meaning 0.5.6 → 0.5.8

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,14 +1,15 @@
1
1
  import { FsJobQueue } from '@semiont/jobs';
2
2
  import { FilesystemViewStorage, resolveStorageUri, EventQuery, createEventStore } from '@semiont/event-sourcing';
3
- import { getPrimaryRepresentation, decodeRepresentation, getTargetSource, getBodySource, resourceId, getTargetSelector, getResourceEntityTypes, getResourceId, getTextPositionSelector, annotationId, errField, userId, generateUuid, getExactText, cloneToken, didToAgent, assembleAnnotation, jobId, entityType, baseUrl, busLog, BRIDGED_CHANNELS, applyBodyOperations, burstBuffer, findBodyItem } from '@semiont/core';
4
- export { applyBodyOperations, assembleAnnotation } from '@semiont/core';
5
- import { withActorSpan, recordBusEmit, withSpan, SpanKind, registerJobQueueProvider } from '@semiont/observability';
3
+ import { getPrimaryRepresentation, decodeRepresentation, getTargetSource, getBodySource, resourceId, getTargetSelector, getResourceEntityTypes, getResourceId, getTextPositionSelector, annotationId, errField, userId, generateUuid, getExactText, cloneToken, baseMediaType, isSupportedMediaType, capabilitiesOf, didToAgent, assembleAnnotation, jobId, entityType, baseUrl, busLog, BRIDGED_CHANNELS, burstBuffer, textExtractionOf, getPrimaryMediaType, extensionForMediaType, applyBodyOperations, findBodyItem } from '@semiont/core';
4
+ import { withActorSpan, recordBusEmit, withSpan, SpanKind, registerJobQueueProvider, registerVectorIndexSizeProvider } from '@semiont/observability';
6
5
  import { createInferenceClient } from '@semiont/inference';
7
6
  import { getGraphDatabase } from '@semiont/graph';
8
- import { WorkingTreeStore, deriveStorageUri, getExtensionForMimeType } from '@semiont/content';
7
+ import { WorkingTreeStore, deriveStorageUri, calculateChecksum } from '@semiont/content';
9
8
  import { getEntityTypes, DEFAULT_ENTITY_TYPES } from '@semiont/ontology';
10
9
  import { promises } from 'fs';
11
10
  import * as path3 from 'path';
11
+ import { chunkText } from '@semiont/vectors';
12
+ import { busRequest } from '@semiont/sdk';
12
13
  import { createGzip, createGunzip } from 'zlib';
13
14
  import { pipeline, Readable } from 'stream';
14
15
  import { promisify } from 'util';
@@ -20,13 +21,17 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
20
21
  var __getProtoOf = Object.getPrototypeOf;
21
22
  var __hasOwnProp = Object.prototype.hasOwnProperty;
22
23
  var __commonJS = (cb, mod) => function __require() {
23
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
24
+ try {
25
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
26
+ } catch (e) {
27
+ throw mod = 0, e;
28
+ }
24
29
  };
25
- var __copyProps = (to, from8, except, desc) => {
26
- if (from8 && typeof from8 === "object" || typeof from8 === "function") {
27
- for (let key of __getOwnPropNames(from8))
30
+ var __copyProps = (to, from9, except, desc) => {
31
+ if (from9 && typeof from9 === "object" || typeof from9 === "function") {
32
+ for (let key of __getOwnPropNames(from9))
28
33
  if (!__hasOwnProp.call(to, key) && key !== except)
29
- __defProp(to, key, { get: () => from8[key], enumerable: !(desc = __getOwnPropDesc(from8, key)) || desc.enumerable });
34
+ __defProp(to, key, { get: () => from9[key], enumerable: !(desc = __getOwnPropDesc(from9, key)) || desc.enumerable });
30
35
  }
31
36
  return to;
32
37
  };
@@ -135,9 +140,9 @@ var require_Subscription = __commonJS({
135
140
  }
136
141
  return ar;
137
142
  };
138
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
139
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
140
- to[j] = from8[i];
143
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
144
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
145
+ to[j] = from9[i];
141
146
  return to;
142
147
  };
143
148
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -145,14 +150,14 @@ var require_Subscription = __commonJS({
145
150
  var isFunction_1 = require_isFunction();
146
151
  var UnsubscriptionError_1 = require_UnsubscriptionError();
147
152
  var arrRemove_1 = require_arrRemove();
148
- var Subscription7 = (function() {
149
- function Subscription8(initialTeardown) {
153
+ var Subscription8 = (function() {
154
+ function Subscription9(initialTeardown) {
150
155
  this.initialTeardown = initialTeardown;
151
156
  this.closed = false;
152
157
  this._parentage = null;
153
158
  this._finalizers = null;
154
159
  }
155
- Subscription8.prototype.unsubscribe = function() {
160
+ Subscription9.prototype.unsubscribe = function() {
156
161
  var e_1, _a, e_2, _b;
157
162
  var errors;
158
163
  if (!this.closed) {
@@ -219,13 +224,13 @@ var require_Subscription = __commonJS({
219
224
  }
220
225
  }
221
226
  };
222
- Subscription8.prototype.add = function(teardown) {
227
+ Subscription9.prototype.add = function(teardown) {
223
228
  var _a;
224
229
  if (teardown && teardown !== this) {
225
230
  if (this.closed) {
226
231
  execFinalizer(teardown);
227
232
  } else {
228
- if (teardown instanceof Subscription8) {
233
+ if (teardown instanceof Subscription9) {
229
234
  if (teardown.closed || teardown._hasParent(this)) {
230
235
  return;
231
236
  }
@@ -235,15 +240,15 @@ var require_Subscription = __commonJS({
235
240
  }
236
241
  }
237
242
  };
238
- Subscription8.prototype._hasParent = function(parent) {
243
+ Subscription9.prototype._hasParent = function(parent) {
239
244
  var _parentage = this._parentage;
240
245
  return _parentage === parent || Array.isArray(_parentage) && _parentage.includes(parent);
241
246
  };
242
- Subscription8.prototype._addParent = function(parent) {
247
+ Subscription9.prototype._addParent = function(parent) {
243
248
  var _parentage = this._parentage;
244
249
  this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
245
250
  };
246
- Subscription8.prototype._removeParent = function(parent) {
251
+ Subscription9.prototype._removeParent = function(parent) {
247
252
  var _parentage = this._parentage;
248
253
  if (_parentage === parent) {
249
254
  this._parentage = null;
@@ -251,24 +256,24 @@ var require_Subscription = __commonJS({
251
256
  arrRemove_1.arrRemove(_parentage, parent);
252
257
  }
253
258
  };
254
- Subscription8.prototype.remove = function(teardown) {
259
+ Subscription9.prototype.remove = function(teardown) {
255
260
  var _finalizers = this._finalizers;
256
261
  _finalizers && arrRemove_1.arrRemove(_finalizers, teardown);
257
- if (teardown instanceof Subscription8) {
262
+ if (teardown instanceof Subscription9) {
258
263
  teardown._removeParent(this);
259
264
  }
260
265
  };
261
- Subscription8.EMPTY = (function() {
262
- var empty = new Subscription8();
266
+ Subscription9.EMPTY = (function() {
267
+ var empty = new Subscription9();
263
268
  empty.closed = true;
264
269
  return empty;
265
270
  })();
266
- return Subscription8;
271
+ return Subscription9;
267
272
  })();
268
- exports.Subscription = Subscription7;
269
- exports.EMPTY_SUBSCRIPTION = Subscription7.EMPTY;
273
+ exports.Subscription = Subscription8;
274
+ exports.EMPTY_SUBSCRIPTION = Subscription8.EMPTY;
270
275
  function isSubscription(value) {
271
- return value instanceof Subscription7 || value && "closed" in value && isFunction_1.isFunction(value.remove) && isFunction_1.isFunction(value.add) && isFunction_1.isFunction(value.unsubscribe);
276
+ return value instanceof Subscription8 || value && "closed" in value && isFunction_1.isFunction(value.remove) && isFunction_1.isFunction(value.add) && isFunction_1.isFunction(value.unsubscribe);
272
277
  }
273
278
  exports.isSubscription = isSubscription;
274
279
  function execFinalizer(finalizer) {
@@ -316,9 +321,9 @@ var require_timeoutProvider = __commonJS({
316
321
  }
317
322
  return ar;
318
323
  };
319
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
320
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
321
- to[j] = from8[i];
324
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
325
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
326
+ to[j] = from9[i];
322
327
  return to;
323
328
  };
324
329
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -705,19 +710,19 @@ var require_Observable = __commonJS({
705
710
  var config_1 = require_config();
706
711
  var isFunction_1 = require_isFunction();
707
712
  var errorContext_1 = require_errorContext();
708
- var Observable2 = (function() {
709
- function Observable3(subscribe) {
713
+ var Observable3 = (function() {
714
+ function Observable4(subscribe) {
710
715
  if (subscribe) {
711
716
  this._subscribe = subscribe;
712
717
  }
713
718
  }
714
- Observable3.prototype.lift = function(operator) {
715
- var observable = new Observable3();
719
+ Observable4.prototype.lift = function(operator) {
720
+ var observable = new Observable4();
716
721
  observable.source = this;
717
722
  observable.operator = operator;
718
723
  return observable;
719
724
  };
720
- Observable3.prototype.subscribe = function(observerOrNext, error, complete) {
725
+ Observable4.prototype.subscribe = function(observerOrNext, error, complete) {
721
726
  var _this = this;
722
727
  var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new Subscriber_1.SafeSubscriber(observerOrNext, error, complete);
723
728
  errorContext_1.errorContext(function() {
@@ -726,14 +731,14 @@ var require_Observable = __commonJS({
726
731
  });
727
732
  return subscriber;
728
733
  };
729
- Observable3.prototype._trySubscribe = function(sink) {
734
+ Observable4.prototype._trySubscribe = function(sink) {
730
735
  try {
731
736
  return this._subscribe(sink);
732
737
  } catch (err) {
733
738
  sink.error(err);
734
739
  }
735
740
  };
736
- Observable3.prototype.forEach = function(next, promiseCtor) {
741
+ Observable4.prototype.forEach = function(next, promiseCtor) {
737
742
  var _this = this;
738
743
  promiseCtor = getPromiseCtor(promiseCtor);
739
744
  return new promiseCtor(function(resolve2, reject) {
@@ -752,21 +757,21 @@ var require_Observable = __commonJS({
752
757
  _this.subscribe(subscriber);
753
758
  });
754
759
  };
755
- Observable3.prototype._subscribe = function(subscriber) {
760
+ Observable4.prototype._subscribe = function(subscriber) {
756
761
  var _a;
757
762
  return (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber);
758
763
  };
759
- Observable3.prototype[observable_1.observable] = function() {
764
+ Observable4.prototype[observable_1.observable] = function() {
760
765
  return this;
761
766
  };
762
- Observable3.prototype.pipe = function() {
767
+ Observable4.prototype.pipe = function() {
763
768
  var operations = [];
764
769
  for (var _i = 0; _i < arguments.length; _i++) {
765
770
  operations[_i] = arguments[_i];
766
771
  }
767
772
  return pipe_1.pipeFromArray(operations)(this);
768
773
  };
769
- Observable3.prototype.toPromise = function(promiseCtor) {
774
+ Observable4.prototype.toPromise = function(promiseCtor) {
770
775
  var _this = this;
771
776
  promiseCtor = getPromiseCtor(promiseCtor);
772
777
  return new promiseCtor(function(resolve2, reject) {
@@ -780,12 +785,12 @@ var require_Observable = __commonJS({
780
785
  });
781
786
  });
782
787
  };
783
- Observable3.create = function(subscribe) {
784
- return new Observable3(subscribe);
788
+ Observable4.create = function(subscribe) {
789
+ return new Observable4(subscribe);
785
790
  };
786
- return Observable3;
791
+ return Observable4;
787
792
  })();
788
- exports.Observable = Observable2;
793
+ exports.Observable = Observable3;
789
794
  function getPromiseCtor(promiseCtor) {
790
795
  var _a;
791
796
  return (_a = promiseCtor !== null && promiseCtor !== void 0 ? promiseCtor : config_1.config.Promise) !== null && _a !== void 0 ? _a : Promise;
@@ -1061,9 +1066,9 @@ var require_animationFrameProvider = __commonJS({
1061
1066
  }
1062
1067
  return ar;
1063
1068
  };
1064
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
1065
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
1066
- to[j] = from8[i];
1069
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
1070
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
1071
+ to[j] = from9[i];
1067
1072
  return to;
1068
1073
  };
1069
1074
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1205,9 +1210,9 @@ var require_Subject = __commonJS({
1205
1210
  var ObjectUnsubscribedError_1 = require_ObjectUnsubscribedError();
1206
1211
  var arrRemove_1 = require_arrRemove();
1207
1212
  var errorContext_1 = require_errorContext();
1208
- var Subject3 = (function(_super) {
1209
- __extends(Subject4, _super);
1210
- function Subject4() {
1213
+ var Subject4 = (function(_super) {
1214
+ __extends(Subject5, _super);
1215
+ function Subject5() {
1211
1216
  var _this = _super.call(this) || this;
1212
1217
  _this.closed = false;
1213
1218
  _this.currentObservers = null;
@@ -1217,17 +1222,17 @@ var require_Subject = __commonJS({
1217
1222
  _this.thrownError = null;
1218
1223
  return _this;
1219
1224
  }
1220
- Subject4.prototype.lift = function(operator) {
1225
+ Subject5.prototype.lift = function(operator) {
1221
1226
  var subject = new AnonymousSubject(this, this);
1222
1227
  subject.operator = operator;
1223
1228
  return subject;
1224
1229
  };
1225
- Subject4.prototype._throwIfClosed = function() {
1230
+ Subject5.prototype._throwIfClosed = function() {
1226
1231
  if (this.closed) {
1227
1232
  throw new ObjectUnsubscribedError_1.ObjectUnsubscribedError();
1228
1233
  }
1229
1234
  };
1230
- Subject4.prototype.next = function(value) {
1235
+ Subject5.prototype.next = function(value) {
1231
1236
  var _this = this;
1232
1237
  errorContext_1.errorContext(function() {
1233
1238
  var e_1, _a;
@@ -1253,7 +1258,7 @@ var require_Subject = __commonJS({
1253
1258
  }
1254
1259
  });
1255
1260
  };
1256
- Subject4.prototype.error = function(err) {
1261
+ Subject5.prototype.error = function(err) {
1257
1262
  var _this = this;
1258
1263
  errorContext_1.errorContext(function() {
1259
1264
  _this._throwIfClosed();
@@ -1267,7 +1272,7 @@ var require_Subject = __commonJS({
1267
1272
  }
1268
1273
  });
1269
1274
  };
1270
- Subject4.prototype.complete = function() {
1275
+ Subject5.prototype.complete = function() {
1271
1276
  var _this = this;
1272
1277
  errorContext_1.errorContext(function() {
1273
1278
  _this._throwIfClosed();
@@ -1280,11 +1285,11 @@ var require_Subject = __commonJS({
1280
1285
  }
1281
1286
  });
1282
1287
  };
1283
- Subject4.prototype.unsubscribe = function() {
1288
+ Subject5.prototype.unsubscribe = function() {
1284
1289
  this.isStopped = this.closed = true;
1285
1290
  this.observers = this.currentObservers = null;
1286
1291
  };
1287
- Object.defineProperty(Subject4.prototype, "observed", {
1292
+ Object.defineProperty(Subject5.prototype, "observed", {
1288
1293
  get: function() {
1289
1294
  var _a;
1290
1295
  return ((_a = this.observers) === null || _a === void 0 ? void 0 : _a.length) > 0;
@@ -1292,16 +1297,16 @@ var require_Subject = __commonJS({
1292
1297
  enumerable: false,
1293
1298
  configurable: true
1294
1299
  });
1295
- Subject4.prototype._trySubscribe = function(subscriber) {
1300
+ Subject5.prototype._trySubscribe = function(subscriber) {
1296
1301
  this._throwIfClosed();
1297
1302
  return _super.prototype._trySubscribe.call(this, subscriber);
1298
1303
  };
1299
- Subject4.prototype._subscribe = function(subscriber) {
1304
+ Subject5.prototype._subscribe = function(subscriber) {
1300
1305
  this._throwIfClosed();
1301
1306
  this._checkFinalizedStatuses(subscriber);
1302
1307
  return this._innerSubscribe(subscriber);
1303
1308
  };
1304
- Subject4.prototype._innerSubscribe = function(subscriber) {
1309
+ Subject5.prototype._innerSubscribe = function(subscriber) {
1305
1310
  var _this = this;
1306
1311
  var _a = this, hasError = _a.hasError, isStopped = _a.isStopped, observers = _a.observers;
1307
1312
  if (hasError || isStopped) {
@@ -1314,7 +1319,7 @@ var require_Subject = __commonJS({
1314
1319
  arrRemove_1.arrRemove(observers, subscriber);
1315
1320
  });
1316
1321
  };
1317
- Subject4.prototype._checkFinalizedStatuses = function(subscriber) {
1322
+ Subject5.prototype._checkFinalizedStatuses = function(subscriber) {
1318
1323
  var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, isStopped = _a.isStopped;
1319
1324
  if (hasError) {
1320
1325
  subscriber.error(thrownError);
@@ -1322,17 +1327,17 @@ var require_Subject = __commonJS({
1322
1327
  subscriber.complete();
1323
1328
  }
1324
1329
  };
1325
- Subject4.prototype.asObservable = function() {
1330
+ Subject5.prototype.asObservable = function() {
1326
1331
  var observable = new Observable_1.Observable();
1327
1332
  observable.source = this;
1328
1333
  return observable;
1329
1334
  };
1330
- Subject4.create = function(destination, source) {
1335
+ Subject5.create = function(destination, source) {
1331
1336
  return new AnonymousSubject(destination, source);
1332
1337
  };
1333
- return Subject4;
1338
+ return Subject5;
1334
1339
  })(Observable_1.Observable);
1335
- exports.Subject = Subject3;
1340
+ exports.Subject = Subject4;
1336
1341
  var AnonymousSubject = (function(_super) {
1337
1342
  __extends(AnonymousSubject2, _super);
1338
1343
  function AnonymousSubject2(destination, source) {
@@ -1358,7 +1363,7 @@ var require_Subject = __commonJS({
1358
1363
  return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : Subscription_1.EMPTY_SUBSCRIPTION;
1359
1364
  };
1360
1365
  return AnonymousSubject2;
1361
- })(Subject3);
1366
+ })(Subject4);
1362
1367
  exports.AnonymousSubject = AnonymousSubject;
1363
1368
  }
1364
1369
  });
@@ -1649,9 +1654,9 @@ var require_intervalProvider = __commonJS({
1649
1654
  }
1650
1655
  return ar;
1651
1656
  };
1652
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
1653
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
1654
- to[j] = from8[i];
1657
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
1658
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
1659
+ to[j] = from9[i];
1655
1660
  return to;
1656
1661
  };
1657
1662
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1855,9 +1860,9 @@ var require_immediateProvider = __commonJS({
1855
1860
  }
1856
1861
  return ar;
1857
1862
  };
1858
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
1859
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
1860
- to[j] = from8[i];
1863
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
1864
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
1865
+ to[j] = from9[i];
1861
1866
  return to;
1862
1867
  };
1863
1868
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -3379,10 +3384,10 @@ var require_from = __commonJS({
3379
3384
  exports.from = void 0;
3380
3385
  var scheduled_1 = require_scheduled();
3381
3386
  var innerFrom_1 = require_innerFrom();
3382
- function from8(input, scheduler) {
3387
+ function from9(input, scheduler) {
3383
3388
  return scheduler ? scheduled_1.scheduled(input, scheduler) : innerFrom_1.innerFrom(input);
3384
3389
  }
3385
- exports.from = from8;
3390
+ exports.from = from9;
3386
3391
  }
3387
3392
  });
3388
3393
 
@@ -3755,9 +3760,9 @@ var require_mapOneOrManyArgs = __commonJS({
3755
3760
  }
3756
3761
  return ar;
3757
3762
  };
3758
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
3759
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
3760
- to[j] = from8[i];
3763
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
3764
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
3765
+ to[j] = from9[i];
3761
3766
  return to;
3762
3767
  };
3763
3768
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -3796,9 +3801,9 @@ var require_bindCallbackInternals = __commonJS({
3796
3801
  }
3797
3802
  return ar;
3798
3803
  };
3799
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
3800
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
3801
- to[j] = from8[i];
3804
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
3805
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
3806
+ to[j] = from9[i];
3802
3807
  return to;
3803
3808
  };
3804
3809
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -4111,12 +4116,12 @@ var require_mergeMap = __commonJS({
4111
4116
  var lift_1 = require_lift();
4112
4117
  var mergeInternals_1 = require_mergeInternals();
4113
4118
  var isFunction_1 = require_isFunction();
4114
- function mergeMap6(project, resultSelector, concurrent) {
4119
+ function mergeMap7(project, resultSelector, concurrent) {
4115
4120
  if (concurrent === void 0) {
4116
4121
  concurrent = Infinity;
4117
4122
  }
4118
4123
  if (isFunction_1.isFunction(resultSelector)) {
4119
- return mergeMap6(function(a, i) {
4124
+ return mergeMap7(function(a, i) {
4120
4125
  return map_1.map(function(b, ii) {
4121
4126
  return resultSelector(a, b, i, ii);
4122
4127
  })(innerFrom_1.innerFrom(project(a, i)));
@@ -4128,7 +4133,7 @@ var require_mergeMap = __commonJS({
4128
4133
  return mergeInternals_1.mergeInternals(source, subscriber, project, concurrent);
4129
4134
  });
4130
4135
  }
4131
- exports.mergeMap = mergeMap6;
4136
+ exports.mergeMap = mergeMap7;
4132
4137
  }
4133
4138
  });
4134
4139
 
@@ -4899,9 +4904,9 @@ var require_zip = __commonJS({
4899
4904
  }
4900
4905
  return ar;
4901
4906
  };
4902
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
4903
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
4904
- to[j] = from8[i];
4907
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
4908
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
4909
+ to[j] = from9[i];
4905
4910
  return to;
4906
4911
  };
4907
4912
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -5513,9 +5518,9 @@ var require_combineLatest2 = __commonJS({
5513
5518
  }
5514
5519
  return ar;
5515
5520
  };
5516
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
5517
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
5518
- to[j] = from8[i];
5521
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
5522
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
5523
+ to[j] = from9[i];
5519
5524
  return to;
5520
5525
  };
5521
5526
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -5560,9 +5565,9 @@ var require_combineLatestWith = __commonJS({
5560
5565
  }
5561
5566
  return ar;
5562
5567
  };
5563
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
5564
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
5565
- to[j] = from8[i];
5568
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
5569
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
5570
+ to[j] = from9[i];
5566
5571
  return to;
5567
5572
  };
5568
5573
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -5586,10 +5591,10 @@ var require_concatMap = __commonJS({
5586
5591
  exports.concatMap = void 0;
5587
5592
  var mergeMap_1 = require_mergeMap();
5588
5593
  var isFunction_1 = require_isFunction();
5589
- function concatMap5(project, resultSelector) {
5594
+ function concatMap6(project, resultSelector) {
5590
5595
  return isFunction_1.isFunction(resultSelector) ? mergeMap_1.mergeMap(project, resultSelector, 1) : mergeMap_1.mergeMap(project, 1);
5591
5596
  }
5592
- exports.concatMap = concatMap5;
5597
+ exports.concatMap = concatMap6;
5593
5598
  }
5594
5599
  });
5595
5600
 
@@ -5631,9 +5636,9 @@ var require_concat2 = __commonJS({
5631
5636
  }
5632
5637
  return ar;
5633
5638
  };
5634
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
5635
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
5636
- to[j] = from8[i];
5639
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
5640
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
5641
+ to[j] = from9[i];
5637
5642
  return to;
5638
5643
  };
5639
5644
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -5676,9 +5681,9 @@ var require_concatWith = __commonJS({
5676
5681
  }
5677
5682
  return ar;
5678
5683
  };
5679
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
5680
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
5681
- to[j] = from8[i];
5684
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
5685
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
5686
+ to[j] = from9[i];
5682
5687
  return to;
5683
5688
  };
5684
5689
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -6151,9 +6156,9 @@ var require_endWith = __commonJS({
6151
6156
  }
6152
6157
  return ar;
6153
6158
  };
6154
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
6155
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
6156
- to[j] = from8[i];
6159
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
6160
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
6161
+ to[j] = from9[i];
6157
6162
  return to;
6158
6163
  };
6159
6164
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -6382,7 +6387,7 @@ var require_groupBy = __commonJS({
6382
6387
  var Subject_1 = require_Subject();
6383
6388
  var lift_1 = require_lift();
6384
6389
  var OperatorSubscriber_1 = require_OperatorSubscriber();
6385
- function groupBy3(keySelector, elementOrOptions, duration, connector) {
6390
+ function groupBy4(keySelector, elementOrOptions, duration, connector) {
6386
6391
  return lift_1.operate(function(source, subscriber) {
6387
6392
  var element;
6388
6393
  if (!elementOrOptions || typeof elementOrOptions === "function") {
@@ -6449,7 +6454,7 @@ var require_groupBy = __commonJS({
6449
6454
  }
6450
6455
  });
6451
6456
  }
6452
- exports.groupBy = groupBy3;
6457
+ exports.groupBy = groupBy4;
6453
6458
  }
6454
6459
  });
6455
6460
 
@@ -6679,9 +6684,9 @@ var require_merge2 = __commonJS({
6679
6684
  }
6680
6685
  return ar;
6681
6686
  };
6682
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
6683
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
6684
- to[j] = from8[i];
6687
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
6688
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
6689
+ to[j] = from9[i];
6685
6690
  return to;
6686
6691
  };
6687
6692
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -6725,9 +6730,9 @@ var require_mergeWith = __commonJS({
6725
6730
  }
6726
6731
  return ar;
6727
6732
  };
6728
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
6729
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
6730
- to[j] = from8[i];
6733
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
6734
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
6735
+ to[j] = from9[i];
6731
6736
  return to;
6732
6737
  };
6733
6738
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -6807,9 +6812,9 @@ var require_onErrorResumeNextWith = __commonJS({
6807
6812
  }
6808
6813
  return ar;
6809
6814
  };
6810
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
6811
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
6812
- to[j] = from8[i];
6815
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
6816
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
6817
+ to[j] = from9[i];
6813
6818
  return to;
6814
6819
  };
6815
6820
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -6984,9 +6989,9 @@ var require_raceWith = __commonJS({
6984
6989
  }
6985
6990
  return ar;
6986
6991
  };
6987
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
6988
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
6989
- to[j] = from8[i];
6992
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
6993
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
6994
+ to[j] = from9[i];
6990
6995
  return to;
6991
6996
  };
6992
6997
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -7373,9 +7378,9 @@ var require_share = __commonJS({
7373
7378
  }
7374
7379
  return ar;
7375
7380
  };
7376
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
7377
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
7378
- to[j] = from8[i];
7381
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
7382
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
7383
+ to[j] = from9[i];
7379
7384
  return to;
7380
7385
  };
7381
7386
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -8348,9 +8353,9 @@ var require_withLatestFrom = __commonJS({
8348
8353
  }
8349
8354
  return ar;
8350
8355
  };
8351
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
8352
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
8353
- to[j] = from8[i];
8356
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
8357
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
8358
+ to[j] = from9[i];
8354
8359
  return to;
8355
8360
  };
8356
8361
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -8432,9 +8437,9 @@ var require_zip2 = __commonJS({
8432
8437
  }
8433
8438
  return ar;
8434
8439
  };
8435
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
8436
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
8437
- to[j] = from8[i];
8440
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
8441
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
8442
+ to[j] = from9[i];
8438
8443
  return to;
8439
8444
  };
8440
8445
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -8474,9 +8479,9 @@ var require_zipWith = __commonJS({
8474
8479
  }
8475
8480
  return ar;
8476
8481
  };
8477
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
8478
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
8479
- to[j] = from8[i];
8482
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
8483
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
8484
+ to[j] = from9[i];
8480
8485
  return to;
8481
8486
  };
8482
8487
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -9239,9 +9244,9 @@ var require_race2 = __commonJS({
9239
9244
  }
9240
9245
  return ar;
9241
9246
  };
9242
- var __spreadArray = exports && exports.__spreadArray || function(to, from8) {
9243
- for (var i = 0, il = from8.length, j = to.length; i < il; i++, j++)
9244
- to[j] = from8[i];
9247
+ var __spreadArray = exports && exports.__spreadArray || function(to, from9) {
9248
+ for (var i = 0, il = from9.length, j = to.length; i < il; i++, j++)
9249
+ to[j] = from9[i];
9245
9250
  return to;
9246
9251
  };
9247
9252
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -10522,11 +10527,8 @@ Summary:`;
10522
10527
  annotation,
10523
10528
  sourceResource: sourceDoc,
10524
10529
  targetResource: targetDoc,
10525
- ...generationContext ? { context: generationContext } : {},
10526
- ...sourceContext ? { sourceContext } : {},
10527
- // Keep for backward compatibility
10528
- ...targetContext ? { targetContext } : {},
10529
- ...{}
10530
+ context: generationContext,
10531
+ ...targetContext ? { targetContext } : {}
10530
10532
  };
10531
10533
  return response;
10532
10534
  }
@@ -11786,6 +11788,18 @@ async function readTagSchemasProjection(project) {
11786
11788
  throw error;
11787
11789
  }
11788
11790
  }
11791
+ async function assembleResourceGraph(kb, resourceId10) {
11792
+ const eventQuery = new EventQuery(kb.eventStore.log.storage);
11793
+ const events = await eventQuery.getResourceEvents(resourceId10);
11794
+ const stored = await kb.eventStore.views.materializer.materialize(events, resourceId10);
11795
+ if (!stored) return null;
11796
+ const annotations = stored.annotations.annotations;
11797
+ const entityReferences = annotations.filter((a) => {
11798
+ if (a.motivation !== "linking") return false;
11799
+ return getEntityTypes({ body: a.body }).length > 0;
11800
+ });
11801
+ return { resource: stored.resource, annotations, entityReferences };
11802
+ }
11789
11803
 
11790
11804
  // src/browser.ts
11791
11805
  var Browser = class {
@@ -11828,28 +11842,17 @@ var Browser = class {
11828
11842
  // ========================================================================
11829
11843
  async handleBrowseResource(event) {
11830
11844
  try {
11831
- const eventQuery = new EventQuery(this.kb.eventStore.log.storage);
11832
- const events = await eventQuery.getResourceEvents(resourceId(event.resourceId));
11833
- const stored = await this.kb.eventStore.views.materializer.materialize(events, resourceId(event.resourceId));
11834
- if (!stored) {
11845
+ const response = await assembleResourceGraph(this.kb, resourceId(event.resourceId));
11846
+ if (!response) {
11835
11847
  this.eventBus.get("browse:resource-failed").next({
11836
11848
  correlationId: event.correlationId,
11837
11849
  message: "Resource not found"
11838
11850
  });
11839
11851
  return;
11840
11852
  }
11841
- const annotations = stored.annotations.annotations;
11842
- const entityReferences = annotations.filter((a) => {
11843
- if (a.motivation !== "linking") return false;
11844
- return getEntityTypes({ body: a.body }).length > 0;
11845
- });
11846
11853
  this.eventBus.get("browse:resource-result").next({
11847
11854
  correlationId: event.correlationId,
11848
- response: {
11849
- resource: stored.resource,
11850
- annotations,
11851
- entityReferences
11852
- }
11855
+ response
11853
11856
  });
11854
11857
  } catch (error) {
11855
11858
  this.logger.error("Browse resource failed", { resourceId: event.resourceId, error: errField(error) });
@@ -12401,10 +12404,8 @@ var CloneTokenManager = class {
12401
12404
  });
12402
12405
  return;
12403
12406
  }
12404
- const primaryRep = getPrimaryRepresentation(sourceDoc);
12405
- const mediaType = primaryRep?.mediaType || "text/plain";
12406
- const validFormats = ["text/plain", "text/markdown"];
12407
- const format = validFormats.includes(mediaType) ? mediaType : "text/plain";
12407
+ const base = baseMediaType(getPrimaryRepresentation(sourceDoc)?.mediaType ?? "text/plain");
12408
+ const format = isSupportedMediaType(base) && capabilitiesOf(base)?.authorable ? base : "text/plain";
12408
12409
  const resolvedUri = deriveStorageUri(event.name, format);
12409
12410
  const stored = await this.kb.content.store(Buffer.from(event.content), resolvedUri);
12410
12411
  const newResourceId = await ResourceOperations.createResource(
@@ -12774,6 +12775,61 @@ function registerJobCommandHandlers(eventBus, jobQueue, project, parentLogger) {
12774
12775
  });
12775
12776
  }
12776
12777
  });
12778
+ eventBus.get("job:complete").subscribe(async (event) => {
12779
+ try {
12780
+ const moved = await jobQueue.completeJob(
12781
+ jobId(event.jobId),
12782
+ event.result ?? {}
12783
+ );
12784
+ if (!moved) {
12785
+ logger.warn("job:complete for a job not in running", { jobId: event.jobId });
12786
+ }
12787
+ } catch (error) {
12788
+ logger.error("Failed to sync job completion to queue", {
12789
+ jobId: event.jobId,
12790
+ error: error.message
12791
+ });
12792
+ }
12793
+ });
12794
+ eventBus.get("job:fail").subscribe(async (event) => {
12795
+ try {
12796
+ const outcome = await jobQueue.failJob(jobId(event.jobId), event.error);
12797
+ if (outcome === "retried") {
12798
+ logger.info("Job re-queued for retry", { jobId: event.jobId });
12799
+ } else if (outcome === null) {
12800
+ logger.warn("job:fail for a job not in running", { jobId: event.jobId });
12801
+ }
12802
+ } catch (error) {
12803
+ logger.error("Failed to sync job failure to queue", {
12804
+ jobId: event.jobId,
12805
+ error: error.message
12806
+ });
12807
+ }
12808
+ });
12809
+ eventBus.get("job:report-progress").subscribe(async (event) => {
12810
+ try {
12811
+ await jobQueue.recordProgress(
12812
+ jobId(event.jobId),
12813
+ event.progress ?? { percentage: event.percentage }
12814
+ );
12815
+ } catch (error) {
12816
+ logger.error("Failed to record job progress", {
12817
+ jobId: event.jobId,
12818
+ error: error.message
12819
+ });
12820
+ }
12821
+ });
12822
+ eventBus.get("job:cancel-requested").subscribe(async (event) => {
12823
+ try {
12824
+ const cancelled = await jobQueue.cancelPendingJobs(event.jobType);
12825
+ logger.info("Cancel requested", { jobType: event.jobType, cancelled });
12826
+ } catch (error) {
12827
+ logger.error("Failed to cancel pending jobs", {
12828
+ jobType: event.jobType,
12829
+ error: error.message
12830
+ });
12831
+ }
12832
+ });
12777
12833
  }
12778
12834
 
12779
12835
  // src/handlers/index.ts
@@ -12847,6 +12903,8 @@ async function createKnowledgeSystemFromConfig(project, config, eventBus, logger
12847
12903
  embedding: embeddingConfig.type,
12848
12904
  model: embeddingConfig.model
12849
12905
  });
12906
+ const store = vectorStore;
12907
+ registerVectorIndexSizeProvider(() => store.count());
12850
12908
  }
12851
12909
  const kb = await createKnowledgeBase(eventStore, project, graphDb, eventBus, logger, {
12852
12910
  vectorStore,
@@ -12999,10 +13057,6 @@ var LocalTransport = class {
12999
13057
  this.errorsSubject.complete();
13000
13058
  }
13001
13059
  };
13002
- function primaryRepresentation(reps) {
13003
- if (!reps) return void 0;
13004
- return Array.isArray(reps) ? reps[0] : reps;
13005
- }
13006
13060
  var LocalContentTransport = class {
13007
13061
  constructor(ks) {
13008
13062
  this.ks = ks;
@@ -13013,16 +13067,16 @@ var LocalContentTransport = class {
13013
13067
  "LocalContentTransport does not support putBinary() \u2014 create resources via bus emits (mark/yield namespaces) in local mode"
13014
13068
  );
13015
13069
  }
13016
- async getBinary(resourceId10, options) {
13017
- busLog("GET", "content", { resourceId: resourceId10, accept: options?.accept });
13070
+ async getBinary(resourceId10, _options) {
13071
+ busLog("GET", "content", { resourceId: resourceId10 });
13018
13072
  return withSpan(
13019
13073
  "content.get",
13020
13074
  () => this.loadBinary(resourceId10),
13021
13075
  { kind: SpanKind.INTERNAL, attrs: { "resource.id": resourceId10 } }
13022
13076
  );
13023
13077
  }
13024
- async getBinaryStream(resourceId10, options) {
13025
- busLog("GET", "content", { resourceId: resourceId10, accept: options?.accept, stream: true });
13078
+ async getBinaryStream(resourceId10, _options) {
13079
+ busLog("GET", "content", { resourceId: resourceId10, stream: true });
13026
13080
  return withSpan(
13027
13081
  "content.get",
13028
13082
  async () => {
@@ -13045,7 +13099,7 @@ var LocalContentTransport = class {
13045
13099
  async loadBinary(resourceId10) {
13046
13100
  const view = await this.ks.kb.views.get(resourceId10);
13047
13101
  if (!view) throw new Error(`Resource not found: ${resourceId10}`);
13048
- const rep = primaryRepresentation(view.resource.representations);
13102
+ const rep = getPrimaryRepresentation(view.resource);
13049
13103
  if (!rep?.storageUri) {
13050
13104
  throw new Error(`Resource ${resourceId10} has no representation with a storageUri`);
13051
13105
  }
@@ -13053,13 +13107,494 @@ var LocalContentTransport = class {
13053
13107
  const data = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
13054
13108
  return { data, contentType: rep.mediaType };
13055
13109
  }
13110
+ /**
13111
+ * Assemble the resource's JSON-LD graph in-process from the KB — the local
13112
+ * realization of `IContentTransport.getResourceGraph` (symmetric with
13113
+ * getBinary; SIMPLER-JSON-LD.md decision 7). Local mode has no auth.
13114
+ */
13115
+ async getResourceGraph(resourceId10, _options) {
13116
+ const graph = await assembleResourceGraph(this.ks.kb, resourceId10);
13117
+ if (!graph) throw new Error(`Resource not found: ${resourceId10}`);
13118
+ return graph;
13119
+ }
13056
13120
  dispose() {
13057
13121
  }
13058
13122
  };
13059
13123
 
13060
- // src/smelter-actor-state-unit.ts
13124
+ // src/smelter.ts
13061
13125
  var import_rxjs11 = __toESM(require_cjs());
13062
13126
  var import_operators10 = __toESM(require_operators());
13127
+ function isWorkItem(input) {
13128
+ return input.type.startsWith("smelt:");
13129
+ }
13130
+ var Smelter = class _Smelter {
13131
+ constructor(events$, vectorStore, embeddingProvider, content, bus, chunkingConfig, timing, logger) {
13132
+ this.events$ = events$;
13133
+ this.vectorStore = vectorStore;
13134
+ this.embeddingProvider = embeddingProvider;
13135
+ this.content = content;
13136
+ this.bus = bus;
13137
+ this.chunkingConfig = chunkingConfig;
13138
+ this.timing = timing;
13139
+ this.logger = logger;
13140
+ }
13141
+ events$;
13142
+ vectorStore;
13143
+ embeddingProvider;
13144
+ content;
13145
+ bus;
13146
+ chunkingConfig;
13147
+ timing;
13148
+ logger;
13149
+ static RECONCILE_PAGE_SIZE = 200;
13150
+ /** Bound on concurrently in-flight reconcile work — a cold rebuild must not fan out unbounded embedding calls. */
13151
+ static RECONCILE_WAVE = 8;
13152
+ eventSubject = new import_rxjs11.Subject();
13153
+ sourceSubscription = null;
13154
+ pipelineSubscription = null;
13155
+ _eventsProcessed = 0;
13156
+ _reconcileState = { phase: "pending" };
13157
+ workDone = 0;
13158
+ workWaiter = null;
13159
+ get eventsProcessed() {
13160
+ return this._eventsProcessed;
13161
+ }
13162
+ get reconcileState() {
13163
+ return this._reconcileState;
13164
+ }
13165
+ initialize() {
13166
+ this.pipelineSubscription = this.eventSubject.pipe(
13167
+ (0, import_operators10.groupBy)((e) => e.resourceId ?? "__unknown__"),
13168
+ (0, import_operators10.mergeMap)(
13169
+ (group) => group.pipe(
13170
+ burstBuffer({
13171
+ burstWindowMs: this.timing.burstWindowMs,
13172
+ maxBatchSize: this.timing.maxBatchSize,
13173
+ idleTimeoutMs: this.timing.idleTimeoutMs
13174
+ }),
13175
+ (0, import_operators10.concatMap)((inputOrBatch) => {
13176
+ if (Array.isArray(inputOrBatch)) {
13177
+ return (0, import_rxjs11.from)(
13178
+ withActorSpan("smelter", "batch", async () => {
13179
+ this._eventsProcessed += await this.processBatch(inputOrBatch);
13180
+ }, { "batch.size": inputOrBatch.length })
13181
+ );
13182
+ }
13183
+ return (0, import_rxjs11.from)(
13184
+ withActorSpan("smelter", inputOrBatch.type, async () => {
13185
+ const ok = await this.safeProcessEvent(inputOrBatch);
13186
+ if (isWorkItem(inputOrBatch)) this.noteWorkDone(1);
13187
+ else if (ok) this._eventsProcessed++;
13188
+ })
13189
+ );
13190
+ })
13191
+ )
13192
+ )
13193
+ ).subscribe({
13194
+ error: (err) => this.logger.error("Smelter pipeline error", { error: errField(err) })
13195
+ });
13196
+ this.sourceSubscription = this.events$.subscribe((event) => {
13197
+ this.logger.debug("Bus event received", { type: event.type, resourceId: event.resourceId });
13198
+ this.eventSubject.next(event);
13199
+ });
13200
+ this.logger.info("Smelter pipeline initialized");
13201
+ }
13202
+ stop() {
13203
+ this.sourceSubscription?.unsubscribe();
13204
+ this.sourceSubscription = null;
13205
+ this.pipelineSubscription?.unsubscribe();
13206
+ this.pipelineSubscription = null;
13207
+ this.eventSubject.complete();
13208
+ this.logger.info("Smelter stopped");
13209
+ }
13210
+ noteWorkDone(count) {
13211
+ this.workDone += count;
13212
+ if (this.workWaiter && this.workDone >= this.workWaiter.target) {
13213
+ this.workWaiter.resolve();
13214
+ this.workWaiter = null;
13215
+ }
13216
+ }
13217
+ /**
13218
+ * Returns the number of WIRE events processed without error (the S9b
13219
+ * oracle) — `smelt:*` work-item runs tick the drain counter instead.
13220
+ */
13221
+ async processBatch(events) {
13222
+ let wireProcessed = 0;
13223
+ for (const run of partitionByType(events)) {
13224
+ const workRun = isWorkItem(run[0]);
13225
+ try {
13226
+ if (run.length === 1) {
13227
+ const ok = await this.safeProcessEvent(run[0]);
13228
+ if (ok && !workRun) wireProcessed++;
13229
+ } else {
13230
+ const processed = await this.applyBatchByType(run);
13231
+ if (!workRun) wireProcessed += processed;
13232
+ }
13233
+ } catch (error) {
13234
+ this.logger.error("Smelter failed to process batch run", {
13235
+ eventType: run[0].type,
13236
+ runSize: run.length,
13237
+ error: errField(error)
13238
+ });
13239
+ } finally {
13240
+ if (workRun) this.noteWorkDone(run.length);
13241
+ }
13242
+ }
13243
+ return wireProcessed;
13244
+ }
13245
+ /**
13246
+ * Batch-optimized processing for consecutive events of the same type.
13247
+ * Returns the number of events processed without error.
13248
+ */
13249
+ async applyBatchByType(events) {
13250
+ switch (events[0].type) {
13251
+ case "yield:created":
13252
+ case "smelt:embed":
13253
+ return this.batchResourceCreated(events);
13254
+ case "mark:added":
13255
+ case "smelt:embed-annotation":
13256
+ return this.batchAnnotationAdded(events);
13257
+ default: {
13258
+ let processed = 0;
13259
+ for (const event of events) {
13260
+ if (await this.safeProcessEvent(event)) processed++;
13261
+ }
13262
+ return processed;
13263
+ }
13264
+ }
13265
+ }
13266
+ /** Returns true if the input was processed without error. */
13267
+ async safeProcessEvent(event) {
13268
+ try {
13269
+ await this.processEvent(event);
13270
+ return true;
13271
+ } catch (err) {
13272
+ this.logger.error("Smelter failed to process event", {
13273
+ type: event.type,
13274
+ resourceId: event.resourceId,
13275
+ error: errField(err)
13276
+ });
13277
+ return false;
13278
+ }
13279
+ }
13280
+ async processEvent(event) {
13281
+ switch (event.type) {
13282
+ case "yield:created":
13283
+ await this.embedResource(event, "Indexed resource");
13284
+ break;
13285
+ case "yield:updated":
13286
+ case "yield:representation-added":
13287
+ await this.embedResource(event, "Re-embedded resource");
13288
+ break;
13289
+ case "mark:archived":
13290
+ await this.handleResourceArchived(event);
13291
+ break;
13292
+ case "mark:added":
13293
+ await this.handleAnnotationAdded(event);
13294
+ break;
13295
+ case "mark:removed":
13296
+ await this.handleAnnotationRemoved(event);
13297
+ break;
13298
+ // Reconcile work items — same handlers, distinct provenance.
13299
+ case "smelt:embed":
13300
+ await this.embedResource(event, "Reconcile-indexed resource");
13301
+ break;
13302
+ case "smelt:purge":
13303
+ await this.handleResourcePurge(event);
13304
+ break;
13305
+ case "smelt:embed-annotation":
13306
+ await this.handleAnnotationAdded(event);
13307
+ break;
13308
+ case "smelt:purge-annotation":
13309
+ await this.handleAnnotationRemoved(event);
13310
+ break;
13311
+ }
13312
+ }
13313
+ async handleResourcePurge(event) {
13314
+ const rid = event.resourceId;
13315
+ if (!rid) return;
13316
+ await this.vectorStore.deleteResourceVectors(resourceId(rid));
13317
+ this.logger.info("Reconcile deleted orphan resource vectors", { resourceId: rid });
13318
+ }
13319
+ /**
13320
+ * Resolve a resource's embeddable text: bytes via the content transport,
13321
+ * gated to media types that decode as text, decoded charset-aware. The
13322
+ * checksum is over the raw bytes actually read — stamped onto the vectors
13323
+ * so reconciliation can compare against the catalog's claim (S12). Returns
13324
+ * null (logged) when the resource doesn't decode as text, is unavailable,
13325
+ * or is empty — callers skip it.
13326
+ */
13327
+ async fetchEmbeddableText(resourceId10) {
13328
+ try {
13329
+ const { data, contentType } = await this.content.getBinary(resourceId(resourceId10));
13330
+ if (textExtractionOf(contentType) !== "decode") {
13331
+ this.logger.debug("Skipping resource that does not decode as text", { resourceId: resourceId10, contentType });
13332
+ return null;
13333
+ }
13334
+ const bytes = Buffer.from(data);
13335
+ const text = decodeRepresentation(bytes, contentType);
13336
+ return text.trim() ? { text, checksum: calculateChecksum(bytes) } : null;
13337
+ } catch (error) {
13338
+ this.logger.warn("Content unavailable for embedding", { resourceId: resourceId10, error: errField(error) });
13339
+ return null;
13340
+ }
13341
+ }
13342
+ async embedResource(event, logMessage) {
13343
+ const rid = event.resourceId;
13344
+ if (!rid) return;
13345
+ const fetched = await this.fetchEmbeddableText(rid);
13346
+ if (!fetched) return;
13347
+ const chunks = chunkText(fetched.text, this.chunkingConfig);
13348
+ if (chunks.length === 0) return;
13349
+ const embeddings = await this.embeddingProvider.embedBatch(chunks);
13350
+ const embeddingChunks = chunks.map((t, i) => ({
13351
+ chunkIndex: i,
13352
+ text: t,
13353
+ embedding: embeddings[i]
13354
+ }));
13355
+ await this.vectorStore.upsertResourceVectors(resourceId(rid), embeddingChunks, fetched.checksum);
13356
+ this.logger.info(logMessage, { resourceId: rid, chunks: chunks.length });
13357
+ }
13358
+ async handleResourceArchived(event) {
13359
+ const rid = event.resourceId;
13360
+ if (!rid) return;
13361
+ await this.vectorStore.deleteResourceVectors(resourceId(rid));
13362
+ await this.vectorStore.deleteAnnotationVectorsForResource(resourceId(rid));
13363
+ this.logger.info("Deleted vectors for archived resource", { resourceId: rid });
13364
+ }
13365
+ async handleAnnotationAdded(event) {
13366
+ const annotation = event.payload.annotation;
13367
+ if (!annotation?.id) return;
13368
+ const rid = event.resourceId;
13369
+ if (!rid) return;
13370
+ const selector = getTargetSelector(annotation.target);
13371
+ const exactText = getExactText(selector);
13372
+ if (!exactText?.trim()) return;
13373
+ const aid = annotationId(annotation.id);
13374
+ const embedding = await this.embeddingProvider.embed(exactText);
13375
+ const payload = {
13376
+ annotationId: aid,
13377
+ resourceId: resourceId(rid),
13378
+ motivation: annotation.motivation ?? "",
13379
+ entityTypes: annotation.entityTypes ?? [],
13380
+ exactText
13381
+ };
13382
+ await this.vectorStore.upsertAnnotationVector(aid, embedding, payload);
13383
+ this.logger.info("Indexed annotation", { annotationId: String(aid) });
13384
+ }
13385
+ async handleAnnotationRemoved(event) {
13386
+ const annotationId5 = event.payload.annotationId;
13387
+ if (!annotationId5) return;
13388
+ const aid = annotationId(annotationId5);
13389
+ await this.vectorStore.deleteAnnotationVector(aid);
13390
+ this.logger.info("Deleted annotation vector", { annotationId: annotationId5 });
13391
+ }
13392
+ /**
13393
+ * Batch-embed chunks from multiple yield:created events in a single
13394
+ * embedBatch() call, then index per resource.
13395
+ */
13396
+ async batchResourceCreated(events) {
13397
+ const resourceData = [];
13398
+ const allChunks = [];
13399
+ for (const event of events) {
13400
+ const rid = event.resourceId;
13401
+ if (!rid) continue;
13402
+ const fetched = await this.fetchEmbeddableText(rid);
13403
+ if (!fetched) continue;
13404
+ const chunks = chunkText(fetched.text, this.chunkingConfig);
13405
+ if (chunks.length === 0) continue;
13406
+ resourceData.push({ rid: resourceId(rid), chunks, checksum: fetched.checksum });
13407
+ allChunks.push(...chunks);
13408
+ }
13409
+ if (allChunks.length === 0) return events.length;
13410
+ const allEmbeddings = await this.embeddingProvider.embedBatch(allChunks);
13411
+ let offset = 0;
13412
+ for (const { rid, chunks, checksum } of resourceData) {
13413
+ const embeddingChunks = chunks.map((t, i) => ({
13414
+ chunkIndex: i,
13415
+ text: t,
13416
+ embedding: allEmbeddings[offset + i]
13417
+ }));
13418
+ await this.vectorStore.upsertResourceVectors(rid, embeddingChunks, checksum);
13419
+ this.logger.info("Batch-indexed resource", { resourceId: String(rid), chunks: chunks.length });
13420
+ offset += chunks.length;
13421
+ }
13422
+ return events.length;
13423
+ }
13424
+ /**
13425
+ * Batch-embed exact texts from multiple mark:added events in a single
13426
+ * embedBatch() call, then index per annotation.
13427
+ */
13428
+ async batchAnnotationAdded(events) {
13429
+ const annotationData = [];
13430
+ for (const event of events) {
13431
+ const annotation = event.payload.annotation;
13432
+ if (!annotation?.id) continue;
13433
+ const rid = event.resourceId;
13434
+ if (!rid) continue;
13435
+ const selector = getTargetSelector(annotation.target);
13436
+ const exactText = getExactText(selector);
13437
+ if (!exactText?.trim()) continue;
13438
+ annotationData.push({
13439
+ rid: resourceId(rid),
13440
+ aid: annotationId(annotation.id),
13441
+ exactText,
13442
+ motivation: annotation.motivation ?? "",
13443
+ entityTypes: annotation.entityTypes ?? []
13444
+ });
13445
+ }
13446
+ if (annotationData.length === 0) return events.length;
13447
+ const allEmbeddings = await this.embeddingProvider.embedBatch(
13448
+ annotationData.map((a) => a.exactText)
13449
+ );
13450
+ for (let i = 0; i < annotationData.length; i++) {
13451
+ const { rid, aid, exactText, motivation, entityTypes } = annotationData[i];
13452
+ const payload = {
13453
+ annotationId: aid,
13454
+ resourceId: rid,
13455
+ motivation,
13456
+ entityTypes,
13457
+ exactText
13458
+ };
13459
+ await this.vectorStore.upsertAnnotationVector(aid, allEmbeddings[i], payload);
13460
+ this.logger.info("Batch-indexed annotation", { annotationId: String(aid) });
13461
+ }
13462
+ return events.length;
13463
+ }
13464
+ // ── Reconciliation ───────────────────────────────────────────────────
13465
+ /**
13466
+ * Reconcile the vector store against the KS catalog.
13467
+ *
13468
+ * Lists what IS indexed (via the store's id enumeration) and what SHOULD
13469
+ * be (non-archived resources with embeddable media types, plus their
13470
+ * exact-text annotations, via the `browse:*` RPC channels), then plans the
13471
+ * diff as `smelt:*` work items — embeds for what's missing, purges for
13472
+ * what shouldn't be there — and drains them through the pipeline mailbox.
13473
+ * Work items share the per-resource lanes with live events, so a reconcile
13474
+ * re-embed can never interleave with (or stale-overwrite) live processing
13475
+ * of the same resource (axioms S1/S2). Waves of RECONCILE_WAVE bound how
13476
+ * many embedding calls a cold rebuild has in flight.
13477
+ *
13478
+ * Call after the live subscription is attached so nothing falls in the
13479
+ * gap. The index snapshot is taken BEFORE the catalog listing so a
13480
+ * resource indexed by a live event mid-reconcile is never mistaken for an
13481
+ * orphan; convergence holds because every upsert replaces a resource's
13482
+ * full vector set from current content.
13483
+ */
13484
+ async reconcile() {
13485
+ if (!this.pipelineSubscription) {
13486
+ throw new Error("Smelter.reconcile() requires initialize() \u2014 work items drain through the pipeline");
13487
+ }
13488
+ this._reconcileState = { phase: "running" };
13489
+ try {
13490
+ const [indexedResources, indexedAnnotations] = await Promise.all([
13491
+ this.vectorStore.listResourceChecksums(),
13492
+ this.vectorStore.listAnnotationIds()
13493
+ ]);
13494
+ const resources = await this.listAllResources();
13495
+ this.logger.info("Reconcile started", {
13496
+ indexedResources: indexedResources.size,
13497
+ indexedAnnotations: indexedAnnotations.size,
13498
+ liveResources: resources.length
13499
+ });
13500
+ const embeddable = /* @__PURE__ */ new Map();
13501
+ for (const resource of resources) {
13502
+ const mediaType = getPrimaryMediaType(resource);
13503
+ if (resource["@id"] && mediaType && textExtractionOf(mediaType) === "decode") {
13504
+ embeddable.set(resource["@id"], getPrimaryRepresentation(resource)?.checksum);
13505
+ }
13506
+ }
13507
+ const work = [];
13508
+ for (const rid of indexedResources.keys()) {
13509
+ if (!embeddable.has(rid)) work.push({ type: "smelt:purge", resourceId: rid, payload: {} });
13510
+ }
13511
+ for (const [rid, catalogChecksum] of embeddable) {
13512
+ if (!indexedResources.has(rid)) {
13513
+ work.push({ type: "smelt:embed", resourceId: rid, payload: {} });
13514
+ } else if (catalogChecksum !== void 0 && indexedResources.get(rid) !== catalogChecksum) {
13515
+ work.push({ type: "smelt:embed", resourceId: rid, payload: {} });
13516
+ }
13517
+ }
13518
+ const liveAnnotationIds = /* @__PURE__ */ new Set();
13519
+ for (const resource of resources) {
13520
+ const rid = resource["@id"];
13521
+ if (!rid) continue;
13522
+ const { annotations } = await busRequest(
13523
+ this.bus,
13524
+ "browse:annotations-requested",
13525
+ { resourceId: rid },
13526
+ "browse:annotations-result",
13527
+ "browse:annotations-failed"
13528
+ );
13529
+ for (const annotation of annotations) {
13530
+ const exactText = getExactText(getTargetSelector(annotation.target));
13531
+ if (!annotation.id || !exactText?.trim()) continue;
13532
+ liveAnnotationIds.add(annotation.id);
13533
+ if (!indexedAnnotations.has(annotation.id)) {
13534
+ work.push({ type: "smelt:embed-annotation", resourceId: rid, payload: { annotation } });
13535
+ }
13536
+ }
13537
+ }
13538
+ for (const aid of indexedAnnotations) {
13539
+ if (!liveAnnotationIds.has(aid)) {
13540
+ work.push({ type: "smelt:purge-annotation", resourceId: aid, payload: { annotationId: aid } });
13541
+ }
13542
+ }
13543
+ await this.drain(work);
13544
+ const summary = {
13545
+ resourcesEmbedded: work.filter((w) => w.type === "smelt:embed").length,
13546
+ resourceVectorsDeleted: work.filter((w) => w.type === "smelt:purge").length,
13547
+ annotationsEmbedded: work.filter((w) => w.type === "smelt:embed-annotation").length,
13548
+ annotationVectorsDeleted: work.filter((w) => w.type === "smelt:purge-annotation").length
13549
+ };
13550
+ this._reconcileState = { phase: "done", summary };
13551
+ this.logger.info("Reconcile complete", { ...summary });
13552
+ return summary;
13553
+ } catch (error) {
13554
+ this._reconcileState = {
13555
+ phase: "failed",
13556
+ error: error instanceof Error ? error.message : String(error)
13557
+ };
13558
+ this.logger.error("Reconcile failed", { error: errField(error) });
13559
+ throw error;
13560
+ }
13561
+ }
13562
+ /**
13563
+ * Enqueue planner work through the mailbox in bounded waves and await
13564
+ * completion. The pipeline ticks `noteWorkDone` for every consumed work
13565
+ * item (success or failure — failures are logged like any live event), so
13566
+ * each wave's waiter resolves exactly when its items have been processed.
13567
+ */
13568
+ async drain(work) {
13569
+ for (let i = 0; i < work.length; i += _Smelter.RECONCILE_WAVE) {
13570
+ const wave = work.slice(i, i + _Smelter.RECONCILE_WAVE);
13571
+ const done = new Promise((resolve2) => {
13572
+ this.workWaiter = { target: this.workDone + wave.length, resolve: resolve2 };
13573
+ });
13574
+ for (const item of wave) this.eventSubject.next(item);
13575
+ await done;
13576
+ }
13577
+ }
13578
+ /** Page through `browse:resources-requested` until the catalog is exhausted. */
13579
+ async listAllResources() {
13580
+ const all = [];
13581
+ for (; ; ) {
13582
+ const page = await busRequest(
13583
+ this.bus,
13584
+ "browse:resources-requested",
13585
+ { archived: false, offset: all.length, limit: _Smelter.RECONCILE_PAGE_SIZE },
13586
+ "browse:resources-result",
13587
+ "browse:resources-failed"
13588
+ );
13589
+ all.push(...page.resources);
13590
+ if (page.resources.length === 0 || all.length >= page.total) return all;
13591
+ }
13592
+ }
13593
+ };
13594
+
13595
+ // src/smelter-actor-state-unit.ts
13596
+ var import_rxjs12 = __toESM(require_cjs());
13597
+ var import_operators11 = __toESM(require_operators());
13063
13598
  var SMELTER_CHANNELS = [
13064
13599
  "yield:created",
13065
13600
  "yield:updated",
@@ -13071,10 +13606,10 @@ var SMELTER_CHANNELS = [
13071
13606
  function createSmelterActorStateUnit(options) {
13072
13607
  const { bus } = options;
13073
13608
  let started = false;
13074
- const events$ = (0, import_rxjs11.merge)(
13609
+ const events$ = (0, import_rxjs12.merge)(
13075
13610
  ...SMELTER_CHANNELS.map(
13076
13611
  (channel) => bus.on$(channel).pipe(
13077
- (0, import_operators10.map)((payload) => ({
13612
+ (0, import_operators11.map)((payload) => ({
13078
13613
  type: channel,
13079
13614
  resourceId: payload.resourceId,
13080
13615
  payload
@@ -13084,7 +13619,6 @@ function createSmelterActorStateUnit(options) {
13084
13619
  );
13085
13620
  return {
13086
13621
  events$,
13087
- emit: (channel, payload) => bus.emit(channel, payload),
13088
13622
  start: () => {
13089
13623
  if (started) return;
13090
13624
  started = true;
@@ -13215,7 +13749,7 @@ async function exportBackup(options, output) {
13215
13749
  let totalContentBytes = 0;
13216
13750
  for (const [storageUri, mediaType] of contentRefs) {
13217
13751
  const data = await content.retrieve(storageUri);
13218
- const ext = getExtensionForMimeType(mediaType);
13752
+ const ext = extensionForMediaType(mediaType);
13219
13753
  contentBlobs.set(storageUri, { data, ext });
13220
13754
  totalContentBytes += data.length;
13221
13755
  }
@@ -13279,8 +13813,8 @@ function collectContentRefs(streamData) {
13279
13813
  }
13280
13814
 
13281
13815
  // src/exchange/replay.ts
13282
- var import_rxjs12 = __toESM(require_cjs());
13283
- var import_operators11 = __toESM(require_operators());
13816
+ var import_rxjs13 = __toESM(require_cjs());
13817
+ var import_operators12 = __toESM(require_operators());
13284
13818
  var REPLAY_TIMEOUT_MS = 3e4;
13285
13819
  async function replayEventStream(jsonl, eventBus, resolveBlob, contentStore, logger) {
13286
13820
  const lines = jsonl.trim().split("\n").filter((l) => l.length > 0);
@@ -13344,12 +13878,12 @@ async function replayEvent(event, eventBus, resolveBlob, contentStore, stats, lo
13344
13878
  }
13345
13879
  }
13346
13880
  async function replayEntityTypeAdded(event, eventBus, logger) {
13347
- const result$ = (0, import_rxjs12.race)(
13348
- eventBus.get("frame:entity-type-added").pipe((0, import_operators11.map)(() => "ok")),
13349
- eventBus.get("frame:entity-type-add-failed").pipe((0, import_operators11.map)((e) => {
13881
+ const result$ = (0, import_rxjs13.race)(
13882
+ eventBus.get("frame:entity-type-added").pipe((0, import_operators12.map)(() => "ok")),
13883
+ eventBus.get("frame:entity-type-add-failed").pipe((0, import_operators12.map)((e) => {
13350
13884
  throw new Error(e.message);
13351
13885
  })),
13352
- (0, import_rxjs12.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
13886
+ (0, import_rxjs13.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators12.map)(() => {
13353
13887
  throw new Error("Timeout waiting for frame:entity-type-added");
13354
13888
  }))
13355
13889
  );
@@ -13357,7 +13891,7 @@ async function replayEntityTypeAdded(event, eventBus, logger) {
13357
13891
  tag: event.payload.entityType,
13358
13892
  _userId: event.userId
13359
13893
  });
13360
- await (0, import_rxjs12.firstValueFrom)(result$);
13894
+ await (0, import_rxjs13.firstValueFrom)(result$);
13361
13895
  logger?.debug("Replayed entitytype.added", { entityType: event.payload.entityType });
13362
13896
  }
13363
13897
  async function replayResourceCreated(event, eventBus, resolveBlob, contentStore, logger) {
@@ -13366,14 +13900,15 @@ async function replayResourceCreated(event, eventBus, resolveBlob, contentStore,
13366
13900
  if (!blob) {
13367
13901
  throw new Error(`Missing content blob for checksum ${payload.contentChecksum}`);
13368
13902
  }
13369
- const resolvedUri = payload.storageUri || deriveStorageUri(payload.name, payload.format);
13903
+ const base = baseMediaType(payload.format);
13904
+ const resolvedUri = payload.storageUri || deriveStorageUri(payload.name, isSupportedMediaType(base) ? base : "application/octet-stream");
13370
13905
  const stored = await contentStore.store(blob, resolvedUri);
13371
- const result$ = (0, import_rxjs12.race)(
13372
- eventBus.get("yield:create-ok").pipe((0, import_operators11.map)((r) => r)),
13373
- eventBus.get("yield:create-failed").pipe((0, import_operators11.map)((e) => {
13906
+ const result$ = (0, import_rxjs13.race)(
13907
+ eventBus.get("yield:create-ok").pipe((0, import_operators12.map)((r) => r)),
13908
+ eventBus.get("yield:create-failed").pipe((0, import_operators12.map)((e) => {
13374
13909
  throw new Error(e.message);
13375
13910
  })),
13376
- (0, import_rxjs12.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
13911
+ (0, import_rxjs13.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators12.map)(() => {
13377
13912
  throw new Error("Timeout waiting for yield:create-ok");
13378
13913
  }))
13379
13914
  );
@@ -13390,16 +13925,16 @@ async function replayResourceCreated(event, eventBus, resolveBlob, contentStore,
13390
13925
  generatedFrom: payload.generatedFrom,
13391
13926
  generationPrompt: payload.generationPrompt
13392
13927
  });
13393
- await (0, import_rxjs12.firstValueFrom)(result$);
13928
+ await (0, import_rxjs13.firstValueFrom)(result$);
13394
13929
  logger?.debug("Replayed resource.created", { name: payload.name });
13395
13930
  }
13396
13931
  async function replayAnnotationAdded(event, eventBus, logger) {
13397
- const result$ = (0, import_rxjs12.race)(
13398
- eventBus.get("mark:create-ok").pipe((0, import_operators11.map)(() => "ok")),
13399
- eventBus.get("mark:create-failed").pipe((0, import_operators11.map)((e) => {
13932
+ const result$ = (0, import_rxjs13.race)(
13933
+ eventBus.get("mark:create-ok").pipe((0, import_operators12.map)(() => "ok")),
13934
+ eventBus.get("mark:create-failed").pipe((0, import_operators12.map)((e) => {
13400
13935
  throw new Error(e.message);
13401
13936
  })),
13402
- (0, import_rxjs12.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
13937
+ (0, import_rxjs13.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators12.map)(() => {
13403
13938
  throw new Error("Timeout waiting for mark:create-ok");
13404
13939
  }))
13405
13940
  );
@@ -13408,16 +13943,16 @@ async function replayAnnotationAdded(event, eventBus, logger) {
13408
13943
  _userId: event.userId,
13409
13944
  resourceId: event.resourceId
13410
13945
  });
13411
- await (0, import_rxjs12.firstValueFrom)(result$);
13946
+ await (0, import_rxjs13.firstValueFrom)(result$);
13412
13947
  logger?.debug("Replayed annotation.added", { annotationId: event.payload.annotation.id });
13413
13948
  }
13414
13949
  async function replayAnnotationBodyUpdated(event, eventBus, logger) {
13415
- const result$ = (0, import_rxjs12.race)(
13416
- eventBus.get("mark:body-updated").pipe((0, import_operators11.map)(() => "ok")),
13417
- eventBus.get("mark:body-update-failed").pipe((0, import_operators11.map)((e) => {
13950
+ const result$ = (0, import_rxjs13.race)(
13951
+ eventBus.get("mark:body-updated").pipe((0, import_operators12.map)(() => "ok")),
13952
+ eventBus.get("mark:body-update-failed").pipe((0, import_operators12.map)((e) => {
13418
13953
  throw new Error(e.message);
13419
13954
  })),
13420
- (0, import_rxjs12.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
13955
+ (0, import_rxjs13.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators12.map)(() => {
13421
13956
  throw new Error("Timeout waiting for mark:body-updated");
13422
13957
  }))
13423
13958
  );
@@ -13427,16 +13962,16 @@ async function replayAnnotationBodyUpdated(event, eventBus, logger) {
13427
13962
  resourceId: event.resourceId,
13428
13963
  operations: event.payload.operations
13429
13964
  });
13430
- await (0, import_rxjs12.firstValueFrom)(result$);
13965
+ await (0, import_rxjs13.firstValueFrom)(result$);
13431
13966
  logger?.debug("Replayed annotation.body.updated", { annotationId: event.payload.annotationId });
13432
13967
  }
13433
13968
  async function replayAnnotationRemoved(event, eventBus, logger) {
13434
- const result$ = (0, import_rxjs12.race)(
13435
- eventBus.get("mark:delete-ok").pipe((0, import_operators11.map)(() => "ok")),
13436
- eventBus.get("mark:delete-failed").pipe((0, import_operators11.map)((e) => {
13969
+ const result$ = (0, import_rxjs13.race)(
13970
+ eventBus.get("mark:delete-ok").pipe((0, import_operators12.map)(() => "ok")),
13971
+ eventBus.get("mark:delete-failed").pipe((0, import_operators12.map)((e) => {
13437
13972
  throw new Error(e.message);
13438
13973
  })),
13439
- (0, import_rxjs12.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators11.map)(() => {
13974
+ (0, import_rxjs13.timer)(REPLAY_TIMEOUT_MS).pipe((0, import_operators12.map)(() => {
13440
13975
  throw new Error("Timeout waiting for mark:delete-ok");
13441
13976
  }))
13442
13977
  );
@@ -13445,7 +13980,7 @@ async function replayAnnotationRemoved(event, eventBus, logger) {
13445
13980
  _userId: event.userId,
13446
13981
  resourceId: event.resourceId
13447
13982
  });
13448
- await (0, import_rxjs12.firstValueFrom)(result$);
13983
+ await (0, import_rxjs13.firstValueFrom)(result$);
13449
13984
  logger?.debug("Replayed annotation.removed", { annotationId: event.payload.annotationId });
13450
13985
  }
13451
13986
  async function replayResourceArchived(event, eventBus, logger) {
@@ -13625,7 +14160,7 @@ async function exportLinkedData(options, output) {
13625
14160
  for (const [storageUri, mediaType] of contentRefs) {
13626
14161
  try {
13627
14162
  const data = await content.retrieve(storageUri);
13628
- const ext = getExtensionForMimeType(mediaType);
14163
+ const ext = extensionForMediaType(mediaType);
13629
14164
  contentBlobs.set(storageUri, { data, ext });
13630
14165
  } catch (err) {
13631
14166
  logger?.warn("Failed to retrieve content blob", { storageUri, error: String(err) });
@@ -13704,7 +14239,7 @@ function buildResourceJsonLd(resource, annotations, sourceUrl) {
13704
14239
  if (rep.checksum) {
13705
14240
  const rawChecksum = rep.checksum.startsWith("sha256:") ? rep.checksum.slice(7) : rep.checksum;
13706
14241
  mediaObj["sha256"] = rawChecksum;
13707
- const ext = getExtensionForMimeType(rep.mediaType);
14242
+ const ext = extensionForMediaType(rep.mediaType);
13708
14243
  mediaObj["name"] = `${rawChecksum}${ext}`;
13709
14244
  }
13710
14245
  if (rep.language) mediaObj["inLanguage"] = rep.language;
@@ -13730,8 +14265,8 @@ function collectContentRefsFromResource(resource, refs) {
13730
14265
  }
13731
14266
 
13732
14267
  // src/exchange/linked-data-importer.ts
13733
- var import_rxjs13 = __toESM(require_cjs());
13734
- var import_operators12 = __toESM(require_operators());
14268
+ var import_rxjs14 = __toESM(require_cjs());
14269
+ var import_operators13 = __toESM(require_operators());
13735
14270
  var IMPORT_TIMEOUT_MS = 3e4;
13736
14271
  function stripUriToId(uri) {
13737
14272
  if (!uri.includes("/")) return uri;
@@ -13833,12 +14368,12 @@ async function importLinkedData(archive, options) {
13833
14368
  };
13834
14369
  }
13835
14370
  async function addEntityType(entityType2, userId3, eventBus, logger) {
13836
- const result$ = (0, import_rxjs13.race)(
13837
- eventBus.get("frame:entity-type-added").pipe((0, import_operators12.map)(() => "ok")),
13838
- eventBus.get("frame:entity-type-add-failed").pipe((0, import_operators12.map)((e) => {
14371
+ const result$ = (0, import_rxjs14.race)(
14372
+ eventBus.get("frame:entity-type-added").pipe((0, import_operators13.map)(() => "ok")),
14373
+ eventBus.get("frame:entity-type-add-failed").pipe((0, import_operators13.map)((e) => {
13839
14374
  throw new Error(e.message);
13840
14375
  })),
13841
- (0, import_rxjs13.timer)(IMPORT_TIMEOUT_MS).pipe((0, import_operators12.map)(() => {
14376
+ (0, import_rxjs14.timer)(IMPORT_TIMEOUT_MS).pipe((0, import_operators13.map)(() => {
13842
14377
  throw new Error("Timeout waiting for frame:entity-type-added");
13843
14378
  }))
13844
14379
  );
@@ -13846,7 +14381,7 @@ async function addEntityType(entityType2, userId3, eventBus, logger) {
13846
14381
  tag: entityType2,
13847
14382
  _userId: userId3
13848
14383
  });
13849
- await (0, import_rxjs13.firstValueFrom)(result$);
14384
+ await (0, import_rxjs14.firstValueFrom)(result$);
13850
14385
  logger?.debug("Added entity type", { entityType: entityType2 });
13851
14386
  }
13852
14387
  async function importResource(doc, userId3, eventBus, contentStore, resolveBlob, logger) {
@@ -13870,14 +14405,15 @@ async function importResource(doc, userId3, eventBus, contentStore, resolveBlob,
13870
14405
  if (!blob) {
13871
14406
  throw new Error(`Missing content blob for checksum ${contentChecksum} (resource "${name}")`);
13872
14407
  }
13873
- const resolvedUri = deriveStorageUri(name, format);
14408
+ const base = baseMediaType(format);
14409
+ const resolvedUri = deriveStorageUri(name, isSupportedMediaType(base) ? base : "application/octet-stream");
13874
14410
  const stored = await contentStore.store(blob, resolvedUri);
13875
- const createResult$ = (0, import_rxjs13.race)(
13876
- eventBus.get("yield:create-ok").pipe((0, import_operators12.map)((r) => r)),
13877
- eventBus.get("yield:create-failed").pipe((0, import_operators12.map)((e) => {
14411
+ const createResult$ = (0, import_rxjs14.race)(
14412
+ eventBus.get("yield:create-ok").pipe((0, import_operators13.map)((r) => r)),
14413
+ eventBus.get("yield:create-failed").pipe((0, import_operators13.map)((e) => {
13878
14414
  throw new Error(e.message);
13879
14415
  })),
13880
- (0, import_rxjs13.timer)(IMPORT_TIMEOUT_MS).pipe((0, import_operators12.map)(() => {
14416
+ (0, import_rxjs14.timer)(IMPORT_TIMEOUT_MS).pipe((0, import_operators13.map)(() => {
13881
14417
  throw new Error("Timeout waiting for yield:create-ok");
13882
14418
  }))
13883
14419
  );
@@ -13891,7 +14427,7 @@ async function importResource(doc, userId3, eventBus, contentStore, resolveBlob,
13891
14427
  language,
13892
14428
  entityTypes: entityTypes ?? []
13893
14429
  });
13894
- const created = await (0, import_rxjs13.firstValueFrom)(createResult$);
14430
+ const created = await (0, import_rxjs14.firstValueFrom)(createResult$);
13895
14431
  const resourceId10 = resourceId(created.resourceId);
13896
14432
  logger?.debug("Created resource from JSON-LD", { name, resourceId: resourceId10 });
13897
14433
  let annotationsCreated = 0;
@@ -13904,12 +14440,12 @@ async function importResource(doc, userId3, eventBus, contentStore, resolveBlob,
13904
14440
  return { annotationsCreated };
13905
14441
  }
13906
14442
  async function createAnnotation(annotation, resourceId10, userId3, eventBus, logger) {
13907
- const result$ = (0, import_rxjs13.race)(
13908
- eventBus.get("mark:create-ok").pipe((0, import_operators12.map)(() => "ok")),
13909
- eventBus.get("mark:create-failed").pipe((0, import_operators12.map)((e) => {
14443
+ const result$ = (0, import_rxjs14.race)(
14444
+ eventBus.get("mark:create-ok").pipe((0, import_operators13.map)(() => "ok")),
14445
+ eventBus.get("mark:create-failed").pipe((0, import_operators13.map)((e) => {
13910
14446
  throw new Error(e.message);
13911
14447
  })),
13912
- (0, import_rxjs13.timer)(IMPORT_TIMEOUT_MS).pipe((0, import_operators12.map)(() => {
14448
+ (0, import_rxjs14.timer)(IMPORT_TIMEOUT_MS).pipe((0, import_operators13.map)(() => {
13913
14449
  throw new Error("Timeout waiting for mark:create-ok");
13914
14450
  }))
13915
14451
  );
@@ -13918,7 +14454,7 @@ async function createAnnotation(annotation, resourceId10, userId3, eventBus, log
13918
14454
  _userId: userId3,
13919
14455
  resourceId: resourceId10
13920
14456
  });
13921
- await (0, import_rxjs13.firstValueFrom)(result$);
14457
+ await (0, import_rxjs14.firstValueFrom)(result$);
13922
14458
  logger?.debug("Created annotation", { annotationId: annotation.id });
13923
14459
  }
13924
14460
  var AnnotationOperations = class {
@@ -13982,10 +14518,6 @@ var AnnotationOperations = class {
13982
14518
  }
13983
14519
  };
13984
14520
 
13985
- // src/index.ts
13986
- var PACKAGE_NAME = "@semiont/make-meaning";
13987
- var VERSION = "0.1.0";
13988
-
13989
- export { AnnotationContext, AnnotationOperations, BACKUP_FORMAT, Browser, CloneTokenManager, FORMAT_VERSION, Gatherer, GraphContext, LLMContext, LocalContentTransport, LocalTransport, Matcher, PACKAGE_NAME, ResourceContext, ResourceOperations, Stower, VERSION, bootstrapEntityTypes, createKnowledgeBase, createSmelterActorStateUnit, exportBackup, exportLinkedData, generateReferenceSuggestions, generateResourceSummary, importBackup, importLinkedData, isBackupManifest, readEntityTypesProjection, registerAnnotationAssemblyHandler, registerAnnotationLookupHandlers, registerBindUpdateBodyHandler, registerBusHandlers, registerJobCommandHandlers, startMakeMeaning, stopKnowledgeSystem, validateManifestVersion };
14521
+ 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 };
13990
14522
  //# sourceMappingURL=index.js.map
13991
14523
  //# sourceMappingURL=index.js.map