@semiont/jobs 0.5.1 → 0.5.2

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.
@@ -1,15 +1,15 @@
1
- import { InMemorySessionStorage, setStoredSession, kbBackendUrl, SemiontClient, SemiontSession, createJobClaimAdapter } from '@semiont/sdk';
2
1
  import { createTomlConfigLoader, baseUrl, RESOURCE_BROADCAST_TYPES, resourceId, validateAndCorrectOffsets, didToAgent, getLocaleEnglishName } from '@semiont/core';
3
2
  import { deriveStorageUri } from '@semiont/content';
4
- import { getLogTraceContext, withSpan, SpanKind, recordJobOutcome } from '@semiont/observability';
3
+ import { withSpan, SpanKind, recordJobOutcome } from '@semiont/observability';
5
4
  import { generateAnnotationId } from '@semiont/event-sourcing';
6
5
  import { createInferenceClient } from '@semiont/inference';
7
6
  import { createServer } from 'http';
8
7
  import { existsSync, readFileSync } from 'fs';
9
8
  import { homedir, hostname } from 'os';
10
9
  import { join } from 'path';
10
+ import { InMemorySessionStorage, setStoredSession, kbBackendUrl, SemiontClient, SemiontSession } from '@semiont/sdk';
11
11
  import { HttpTransport, HttpContentTransport } from '@semiont/api-client';
12
- import winston from 'winston';
12
+ import { createProcessLogger } from '@semiont/observability/process-logger';
13
13
 
14
14
  var __create = Object.create;
15
15
  var __defProp = Object.defineProperty;
@@ -322,16 +322,16 @@ var require_timeoutProvider = __commonJS({
322
322
  Object.defineProperty(exports$1, "__esModule", { value: true });
323
323
  exports$1.timeoutProvider = void 0;
324
324
  exports$1.timeoutProvider = {
325
- setTimeout: function(handler, timeout) {
325
+ setTimeout: function(handler, timeout2) {
326
326
  var args = [];
327
327
  for (var _i = 2; _i < arguments.length; _i++) {
328
328
  args[_i - 2] = arguments[_i];
329
329
  }
330
330
  var delegate = exports$1.timeoutProvider.delegate;
331
331
  if (delegate === null || delegate === void 0 ? void 0 : delegate.setTimeout) {
332
- return delegate.setTimeout.apply(delegate, __spreadArray([handler, timeout], __read(args)));
332
+ return delegate.setTimeout.apply(delegate, __spreadArray([handler, timeout2], __read(args)));
333
333
  }
334
- return setTimeout.apply(void 0, __spreadArray([handler, timeout], __read(args)));
334
+ return setTimeout.apply(void 0, __spreadArray([handler, timeout2], __read(args)));
335
335
  },
336
336
  clearTimeout: function(handle) {
337
337
  var delegate = exports$1.timeoutProvider.delegate;
@@ -703,19 +703,19 @@ var require_Observable = __commonJS({
703
703
  var config_1 = require_config();
704
704
  var isFunction_1 = require_isFunction();
705
705
  var errorContext_1 = require_errorContext();
706
- var Observable = (function() {
707
- function Observable2(subscribe) {
706
+ var Observable2 = (function() {
707
+ function Observable3(subscribe) {
708
708
  if (subscribe) {
709
709
  this._subscribe = subscribe;
710
710
  }
711
711
  }
712
- Observable2.prototype.lift = function(operator) {
713
- var observable = new Observable2();
712
+ Observable3.prototype.lift = function(operator) {
713
+ var observable = new Observable3();
714
714
  observable.source = this;
715
715
  observable.operator = operator;
716
716
  return observable;
717
717
  };
718
- Observable2.prototype.subscribe = function(observerOrNext, error, complete) {
718
+ Observable3.prototype.subscribe = function(observerOrNext, error, complete) {
719
719
  var _this = this;
720
720
  var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new Subscriber_1.SafeSubscriber(observerOrNext, error, complete);
721
721
  errorContext_1.errorContext(function() {
@@ -724,14 +724,14 @@ var require_Observable = __commonJS({
724
724
  });
725
725
  return subscriber;
726
726
  };
727
- Observable2.prototype._trySubscribe = function(sink) {
727
+ Observable3.prototype._trySubscribe = function(sink) {
728
728
  try {
729
729
  return this._subscribe(sink);
730
730
  } catch (err) {
731
731
  sink.error(err);
732
732
  }
733
733
  };
734
- Observable2.prototype.forEach = function(next, promiseCtor) {
734
+ Observable3.prototype.forEach = function(next, promiseCtor) {
735
735
  var _this = this;
736
736
  promiseCtor = getPromiseCtor(promiseCtor);
737
737
  return new promiseCtor(function(resolve, reject) {
@@ -750,21 +750,21 @@ var require_Observable = __commonJS({
750
750
  _this.subscribe(subscriber);
751
751
  });
752
752
  };
753
- Observable2.prototype._subscribe = function(subscriber) {
753
+ Observable3.prototype._subscribe = function(subscriber) {
754
754
  var _a;
755
755
  return (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber);
756
756
  };
757
- Observable2.prototype[observable_1.observable] = function() {
757
+ Observable3.prototype[observable_1.observable] = function() {
758
758
  return this;
759
759
  };
760
- Observable2.prototype.pipe = function() {
760
+ Observable3.prototype.pipe = function() {
761
761
  var operations = [];
762
762
  for (var _i = 0; _i < arguments.length; _i++) {
763
763
  operations[_i] = arguments[_i];
764
764
  }
765
765
  return pipe_1.pipeFromArray(operations)(this);
766
766
  };
767
- Observable2.prototype.toPromise = function(promiseCtor) {
767
+ Observable3.prototype.toPromise = function(promiseCtor) {
768
768
  var _this = this;
769
769
  promiseCtor = getPromiseCtor(promiseCtor);
770
770
  return new promiseCtor(function(resolve, reject) {
@@ -778,12 +778,12 @@ var require_Observable = __commonJS({
778
778
  });
779
779
  });
780
780
  };
781
- Observable2.create = function(subscribe) {
782
- return new Observable2(subscribe);
781
+ Observable3.create = function(subscribe) {
782
+ return new Observable3(subscribe);
783
783
  };
784
- return Observable2;
784
+ return Observable3;
785
785
  })();
786
- exports$1.Observable = Observable;
786
+ exports$1.Observable = Observable2;
787
787
  function getPromiseCtor(promiseCtor) {
788
788
  var _a;
789
789
  return (_a = promiseCtor !== null && promiseCtor !== void 0 ? promiseCtor : config_1.config.Promise) !== null && _a !== void 0 ? _a : Promise;
@@ -1203,9 +1203,9 @@ var require_Subject = __commonJS({
1203
1203
  var ObjectUnsubscribedError_1 = require_ObjectUnsubscribedError();
1204
1204
  var arrRemove_1 = require_arrRemove();
1205
1205
  var errorContext_1 = require_errorContext();
1206
- var Subject = (function(_super) {
1207
- __extends(Subject2, _super);
1208
- function Subject2() {
1206
+ var Subject2 = (function(_super) {
1207
+ __extends(Subject3, _super);
1208
+ function Subject3() {
1209
1209
  var _this = _super.call(this) || this;
1210
1210
  _this.closed = false;
1211
1211
  _this.currentObservers = null;
@@ -1215,17 +1215,17 @@ var require_Subject = __commonJS({
1215
1215
  _this.thrownError = null;
1216
1216
  return _this;
1217
1217
  }
1218
- Subject2.prototype.lift = function(operator) {
1218
+ Subject3.prototype.lift = function(operator) {
1219
1219
  var subject = new AnonymousSubject(this, this);
1220
1220
  subject.operator = operator;
1221
1221
  return subject;
1222
1222
  };
1223
- Subject2.prototype._throwIfClosed = function() {
1223
+ Subject3.prototype._throwIfClosed = function() {
1224
1224
  if (this.closed) {
1225
1225
  throw new ObjectUnsubscribedError_1.ObjectUnsubscribedError();
1226
1226
  }
1227
1227
  };
1228
- Subject2.prototype.next = function(value) {
1228
+ Subject3.prototype.next = function(value) {
1229
1229
  var _this = this;
1230
1230
  errorContext_1.errorContext(function() {
1231
1231
  var e_1, _a;
@@ -1251,7 +1251,7 @@ var require_Subject = __commonJS({
1251
1251
  }
1252
1252
  });
1253
1253
  };
1254
- Subject2.prototype.error = function(err) {
1254
+ Subject3.prototype.error = function(err) {
1255
1255
  var _this = this;
1256
1256
  errorContext_1.errorContext(function() {
1257
1257
  _this._throwIfClosed();
@@ -1265,7 +1265,7 @@ var require_Subject = __commonJS({
1265
1265
  }
1266
1266
  });
1267
1267
  };
1268
- Subject2.prototype.complete = function() {
1268
+ Subject3.prototype.complete = function() {
1269
1269
  var _this = this;
1270
1270
  errorContext_1.errorContext(function() {
1271
1271
  _this._throwIfClosed();
@@ -1278,11 +1278,11 @@ var require_Subject = __commonJS({
1278
1278
  }
1279
1279
  });
1280
1280
  };
1281
- Subject2.prototype.unsubscribe = function() {
1281
+ Subject3.prototype.unsubscribe = function() {
1282
1282
  this.isStopped = this.closed = true;
1283
1283
  this.observers = this.currentObservers = null;
1284
1284
  };
1285
- Object.defineProperty(Subject2.prototype, "observed", {
1285
+ Object.defineProperty(Subject3.prototype, "observed", {
1286
1286
  get: function() {
1287
1287
  var _a;
1288
1288
  return ((_a = this.observers) === null || _a === void 0 ? void 0 : _a.length) > 0;
@@ -1290,16 +1290,16 @@ var require_Subject = __commonJS({
1290
1290
  enumerable: false,
1291
1291
  configurable: true
1292
1292
  });
1293
- Subject2.prototype._trySubscribe = function(subscriber) {
1293
+ Subject3.prototype._trySubscribe = function(subscriber) {
1294
1294
  this._throwIfClosed();
1295
1295
  return _super.prototype._trySubscribe.call(this, subscriber);
1296
1296
  };
1297
- Subject2.prototype._subscribe = function(subscriber) {
1297
+ Subject3.prototype._subscribe = function(subscriber) {
1298
1298
  this._throwIfClosed();
1299
1299
  this._checkFinalizedStatuses(subscriber);
1300
1300
  return this._innerSubscribe(subscriber);
1301
1301
  };
1302
- Subject2.prototype._innerSubscribe = function(subscriber) {
1302
+ Subject3.prototype._innerSubscribe = function(subscriber) {
1303
1303
  var _this = this;
1304
1304
  var _a = this, hasError = _a.hasError, isStopped = _a.isStopped, observers = _a.observers;
1305
1305
  if (hasError || isStopped) {
@@ -1312,7 +1312,7 @@ var require_Subject = __commonJS({
1312
1312
  arrRemove_1.arrRemove(observers, subscriber);
1313
1313
  });
1314
1314
  };
1315
- Subject2.prototype._checkFinalizedStatuses = function(subscriber) {
1315
+ Subject3.prototype._checkFinalizedStatuses = function(subscriber) {
1316
1316
  var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, isStopped = _a.isStopped;
1317
1317
  if (hasError) {
1318
1318
  subscriber.error(thrownError);
@@ -1320,17 +1320,17 @@ var require_Subject = __commonJS({
1320
1320
  subscriber.complete();
1321
1321
  }
1322
1322
  };
1323
- Subject2.prototype.asObservable = function() {
1323
+ Subject3.prototype.asObservable = function() {
1324
1324
  var observable = new Observable_1.Observable();
1325
1325
  observable.source = this;
1326
1326
  return observable;
1327
1327
  };
1328
- Subject2.create = function(destination, source) {
1328
+ Subject3.create = function(destination, source) {
1329
1329
  return new AnonymousSubject(destination, source);
1330
1330
  };
1331
- return Subject2;
1331
+ return Subject3;
1332
1332
  })(Observable_1.Observable);
1333
- exports$1.Subject = Subject;
1333
+ exports$1.Subject = Subject2;
1334
1334
  var AnonymousSubject = (function(_super) {
1335
1335
  __extends(AnonymousSubject2, _super);
1336
1336
  function AnonymousSubject2(destination, source) {
@@ -1356,7 +1356,7 @@ var require_Subject = __commonJS({
1356
1356
  return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : Subscription_1.EMPTY_SUBSCRIPTION;
1357
1357
  };
1358
1358
  return AnonymousSubject2;
1359
- })(Subject);
1359
+ })(Subject2);
1360
1360
  exports$1.AnonymousSubject = AnonymousSubject;
1361
1361
  }
1362
1362
  });
@@ -1386,26 +1386,26 @@ var require_BehaviorSubject = __commonJS({
1386
1386
  Object.defineProperty(exports$1, "__esModule", { value: true });
1387
1387
  exports$1.BehaviorSubject = void 0;
1388
1388
  var Subject_1 = require_Subject();
1389
- var BehaviorSubject2 = (function(_super) {
1390
- __extends(BehaviorSubject3, _super);
1391
- function BehaviorSubject3(_value) {
1389
+ var BehaviorSubject3 = (function(_super) {
1390
+ __extends(BehaviorSubject4, _super);
1391
+ function BehaviorSubject4(_value) {
1392
1392
  var _this = _super.call(this) || this;
1393
1393
  _this._value = _value;
1394
1394
  return _this;
1395
1395
  }
1396
- Object.defineProperty(BehaviorSubject3.prototype, "value", {
1396
+ Object.defineProperty(BehaviorSubject4.prototype, "value", {
1397
1397
  get: function() {
1398
1398
  return this.getValue();
1399
1399
  },
1400
1400
  enumerable: false,
1401
1401
  configurable: true
1402
1402
  });
1403
- BehaviorSubject3.prototype._subscribe = function(subscriber) {
1403
+ BehaviorSubject4.prototype._subscribe = function(subscriber) {
1404
1404
  var subscription = _super.prototype._subscribe.call(this, subscriber);
1405
1405
  !subscription.closed && subscriber.next(this._value);
1406
1406
  return subscription;
1407
1407
  };
1408
- BehaviorSubject3.prototype.getValue = function() {
1408
+ BehaviorSubject4.prototype.getValue = function() {
1409
1409
  var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, _value = _a._value;
1410
1410
  if (hasError) {
1411
1411
  throw thrownError;
@@ -1413,12 +1413,12 @@ var require_BehaviorSubject = __commonJS({
1413
1413
  this._throwIfClosed();
1414
1414
  return _value;
1415
1415
  };
1416
- BehaviorSubject3.prototype.next = function(value) {
1416
+ BehaviorSubject4.prototype.next = function(value) {
1417
1417
  _super.prototype.next.call(this, this._value = value);
1418
1418
  };
1419
- return BehaviorSubject3;
1419
+ return BehaviorSubject4;
1420
1420
  })(Subject_1.Subject);
1421
- exports$1.BehaviorSubject = BehaviorSubject2;
1421
+ exports$1.BehaviorSubject = BehaviorSubject3;
1422
1422
  }
1423
1423
  });
1424
1424
 
@@ -1655,16 +1655,16 @@ var require_intervalProvider = __commonJS({
1655
1655
  Object.defineProperty(exports$1, "__esModule", { value: true });
1656
1656
  exports$1.intervalProvider = void 0;
1657
1657
  exports$1.intervalProvider = {
1658
- setInterval: function(handler, timeout) {
1658
+ setInterval: function(handler, timeout2) {
1659
1659
  var args = [];
1660
1660
  for (var _i = 2; _i < arguments.length; _i++) {
1661
1661
  args[_i - 2] = arguments[_i];
1662
1662
  }
1663
1663
  var delegate = exports$1.intervalProvider.delegate;
1664
1664
  if (delegate === null || delegate === void 0 ? void 0 : delegate.setInterval) {
1665
- return delegate.setInterval.apply(delegate, __spreadArray([handler, timeout], __read(args)));
1665
+ return delegate.setInterval.apply(delegate, __spreadArray([handler, timeout2], __read(args)));
1666
1666
  }
1667
- return setInterval.apply(void 0, __spreadArray([handler, timeout], __read(args)));
1667
+ return setInterval.apply(void 0, __spreadArray([handler, timeout2], __read(args)));
1668
1668
  },
1669
1669
  clearInterval: function(handle) {
1670
1670
  var delegate = exports$1.intervalProvider.delegate;
@@ -3562,7 +3562,7 @@ var require_firstValueFrom = __commonJS({
3562
3562
  exports$1.firstValueFrom = void 0;
3563
3563
  var EmptyError_1 = require_EmptyError();
3564
3564
  var Subscriber_1 = require_Subscriber();
3565
- function firstValueFrom(source, config) {
3565
+ function firstValueFrom2(source, config) {
3566
3566
  var hasConfig = typeof config === "object";
3567
3567
  return new Promise(function(resolve, reject) {
3568
3568
  var subscriber = new Subscriber_1.SafeSubscriber({
@@ -3582,7 +3582,7 @@ var require_firstValueFrom = __commonJS({
3582
3582
  source.subscribe(subscriber);
3583
3583
  });
3584
3584
  }
3585
- exports$1.firstValueFrom = firstValueFrom;
3585
+ exports$1.firstValueFrom = firstValueFrom2;
3586
3586
  }
3587
3587
  });
3588
3588
 
@@ -3669,7 +3669,7 @@ var require_timeout = __commonJS({
3669
3669
  this.info = info;
3670
3670
  };
3671
3671
  });
3672
- function timeout(config, schedulerArg) {
3672
+ function timeout2(config, schedulerArg) {
3673
3673
  var _a = isDate_1.isValidDate(config) ? { first: config } : typeof config === "number" ? { each: config } : config, first = _a.first, each = _a.each, _b = _a.with, _with = _b === void 0 ? timeoutErrorFactory : _b, _c = _a.scheduler, scheduler = _c === void 0 ? schedulerArg !== null && schedulerArg !== void 0 ? schedulerArg : async_1.asyncScheduler : _c, _d = _a.meta, meta = _d === void 0 ? null : _d;
3674
3674
  if (first == null && each == null) {
3675
3675
  throw new TypeError("No timeout provided.");
@@ -3707,7 +3707,7 @@ var require_timeout = __commonJS({
3707
3707
  !seen && startTimer(first != null ? typeof first === "number" ? first : +first - scheduler.now() : each);
3708
3708
  });
3709
3709
  }
3710
- exports$1.timeout = timeout;
3710
+ exports$1.timeout = timeout2;
3711
3711
  function timeoutErrorFactory(info) {
3712
3712
  throw new exports$1.TimeoutError(info);
3713
3713
  }
@@ -3721,7 +3721,7 @@ var require_map = __commonJS({
3721
3721
  exports$1.map = void 0;
3722
3722
  var lift_1 = require_lift();
3723
3723
  var OperatorSubscriber_1 = require_OperatorSubscriber();
3724
- function map(project, thisArg) {
3724
+ function map2(project, thisArg) {
3725
3725
  return lift_1.operate(function(source, subscriber) {
3726
3726
  var index = 0;
3727
3727
  source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function(value) {
@@ -3729,7 +3729,7 @@ var require_map = __commonJS({
3729
3729
  }));
3730
3730
  });
3731
3731
  }
3732
- exports$1.map = map;
3732
+ exports$1.map = map2;
3733
3733
  }
3734
3734
  });
3735
3735
 
@@ -4629,7 +4629,7 @@ var require_merge = __commonJS({
4629
4629
  var empty_1 = require_empty();
4630
4630
  var args_1 = require_args();
4631
4631
  var from_1 = require_from();
4632
- function merge() {
4632
+ function merge2() {
4633
4633
  var args = [];
4634
4634
  for (var _i = 0; _i < arguments.length; _i++) {
4635
4635
  args[_i] = arguments[_i];
@@ -4639,7 +4639,7 @@ var require_merge = __commonJS({
4639
4639
  var sources = args;
4640
4640
  return !sources.length ? empty_1.EMPTY : sources.length === 1 ? innerFrom_1.innerFrom(sources[0]) : mergeAll_1.mergeAll(concurrent)(from_1.from(sources, scheduler));
4641
4641
  }
4642
- exports$1.merge = merge;
4642
+ exports$1.merge = merge2;
4643
4643
  }
4644
4644
  });
4645
4645
 
@@ -4746,7 +4746,7 @@ var require_filter = __commonJS({
4746
4746
  exports$1.filter = void 0;
4747
4747
  var lift_1 = require_lift();
4748
4748
  var OperatorSubscriber_1 = require_OperatorSubscriber();
4749
- function filter(predicate, thisArg) {
4749
+ function filter2(predicate, thisArg) {
4750
4750
  return lift_1.operate(function(source, subscriber) {
4751
4751
  var index = 0;
4752
4752
  source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function(value) {
@@ -4754,7 +4754,7 @@ var require_filter = __commonJS({
4754
4754
  }));
4755
4755
  });
4756
4756
  }
4757
- exports$1.filter = filter;
4757
+ exports$1.filter = filter2;
4758
4758
  }
4759
4759
  });
4760
4760
 
@@ -5881,7 +5881,7 @@ var require_take = __commonJS({
5881
5881
  var empty_1 = require_empty();
5882
5882
  var lift_1 = require_lift();
5883
5883
  var OperatorSubscriber_1 = require_OperatorSubscriber();
5884
- function take(count) {
5884
+ function take2(count) {
5885
5885
  return count <= 0 ? function() {
5886
5886
  return empty_1.EMPTY;
5887
5887
  } : lift_1.operate(function(source, subscriber) {
@@ -5896,7 +5896,7 @@ var require_take = __commonJS({
5896
5896
  }));
5897
5897
  });
5898
5898
  }
5899
- exports$1.take = take;
5899
+ exports$1.take = take2;
5900
5900
  }
5901
5901
  });
5902
5902
 
@@ -6688,7 +6688,7 @@ var require_merge2 = __commonJS({
6688
6688
  var mergeAll_1 = require_mergeAll();
6689
6689
  var args_1 = require_args();
6690
6690
  var from_1 = require_from();
6691
- function merge() {
6691
+ function merge2() {
6692
6692
  var args = [];
6693
6693
  for (var _i = 0; _i < arguments.length; _i++) {
6694
6694
  args[_i] = arguments[_i];
@@ -6699,7 +6699,7 @@ var require_merge2 = __commonJS({
6699
6699
  mergeAll_1.mergeAll(concurrent)(from_1.from(__spreadArray([source], __read(args)), scheduler)).subscribe(subscriber);
6700
6700
  });
6701
6701
  }
6702
- exports$1.merge = merge;
6702
+ exports$1.merge = merge2;
6703
6703
  }
6704
6704
  });
6705
6705
 
@@ -9201,7 +9201,112 @@ var require_cjs = __commonJS({
9201
9201
  }
9202
9202
  });
9203
9203
 
9204
- // src/workers/detection/motivation-prompts.ts
9204
+ // src/job-claim-adapter.ts
9205
+ var import_rxjs = __toESM(require_cjs());
9206
+ var import_rxjs2 = __toESM(require_cjs());
9207
+ function createJobClaimAdapter(options) {
9208
+ const { bus, jobTypes } = options;
9209
+ const activeJob$ = new import_rxjs.BehaviorSubject(null);
9210
+ const isProcessing$ = new import_rxjs.BehaviorSubject(false);
9211
+ const jobsCompleted$ = new import_rxjs.BehaviorSubject(0);
9212
+ const errors$ = new import_rxjs.Subject();
9213
+ let jobSubscription = null;
9214
+ let started = false;
9215
+ const claimJob = async (assignment) => {
9216
+ try {
9217
+ const correlationId = crypto.randomUUID();
9218
+ const result$ = (0, import_rxjs2.merge)(
9219
+ bus.on$("job:claimed").pipe(
9220
+ (0, import_rxjs2.filter)((e) => e.correlationId === correlationId),
9221
+ (0, import_rxjs2.map)((e) => ({ ok: true, response: e.response }))
9222
+ ),
9223
+ bus.on$("job:claim-failed").pipe(
9224
+ (0, import_rxjs2.filter)((e) => e.correlationId === correlationId),
9225
+ (0, import_rxjs2.map)(() => ({ ok: false }))
9226
+ )
9227
+ ).pipe((0, import_rxjs2.take)(1), (0, import_rxjs2.timeout)(1e4));
9228
+ const resultPromise = (0, import_rxjs2.firstValueFrom)(result$);
9229
+ await bus.emit("job:claim", { correlationId, jobId: assignment.jobId });
9230
+ const result = await resultPromise;
9231
+ if (!result.ok) return null;
9232
+ const job = result.response;
9233
+ return {
9234
+ jobId: assignment.jobId,
9235
+ type: assignment.type,
9236
+ resourceId: assignment.resourceId,
9237
+ userId: job.metadata?.userId ?? "",
9238
+ params: job.params ?? {}
9239
+ };
9240
+ } catch {
9241
+ return null;
9242
+ }
9243
+ };
9244
+ return {
9245
+ activeJob$: activeJob$.asObservable(),
9246
+ isProcessing$: isProcessing$.asObservable(),
9247
+ jobsCompleted$: jobsCompleted$.asObservable(),
9248
+ errors$: errors$.asObservable(),
9249
+ start: () => {
9250
+ if (started) return;
9251
+ started = true;
9252
+ bus.addChannels?.(["job:queued"]);
9253
+ jobSubscription = bus.on$("job:queued").subscribe((event) => {
9254
+ const jobType = event.jobType;
9255
+ if (jobTypes.length > 0 && !jobTypes.includes(jobType)) return;
9256
+ if (isProcessing$.getValue()) return;
9257
+ isProcessing$.next(true);
9258
+ claimJob({ jobId: event.jobId, type: jobType, resourceId: event.resourceId }).then((job) => {
9259
+ if (job) {
9260
+ activeJob$.next(job);
9261
+ } else {
9262
+ isProcessing$.next(false);
9263
+ }
9264
+ }).catch(() => {
9265
+ isProcessing$.next(false);
9266
+ });
9267
+ });
9268
+ },
9269
+ stop: () => {
9270
+ jobSubscription?.unsubscribe();
9271
+ jobSubscription = null;
9272
+ started = false;
9273
+ },
9274
+ completeJob: () => {
9275
+ activeJob$.next(null);
9276
+ isProcessing$.next(false);
9277
+ jobsCompleted$.next(jobsCompleted$.getValue() + 1);
9278
+ },
9279
+ failJob: (jid, error) => {
9280
+ activeJob$.next(null);
9281
+ isProcessing$.next(false);
9282
+ errors$.next({ jobId: jid, error });
9283
+ },
9284
+ dispose: () => {
9285
+ jobSubscription?.unsubscribe();
9286
+ jobSubscription = null;
9287
+ started = false;
9288
+ activeJob$.complete();
9289
+ isProcessing$.complete();
9290
+ jobsCompleted$.complete();
9291
+ errors$.complete();
9292
+ }
9293
+ };
9294
+ }
9295
+ function languageName(tag) {
9296
+ return getLocaleEnglishName(tag) || tag;
9297
+ }
9298
+ function sourceLanguageGuidance(sourceLanguage) {
9299
+ if (!sourceLanguage) return "";
9300
+ return `
9301
+
9302
+ Source text language: ${languageName(sourceLanguage)}.`;
9303
+ }
9304
+ function bodyLanguageGuidance(language, kind) {
9305
+ if (!language || language === "en") return "";
9306
+ return `
9307
+
9308
+ IMPORTANT: Write your ${kind} in ${languageName(language)}.`;
9309
+ }
9205
9310
  var MotivationPrompts = class {
9206
9311
  /**
9207
9312
  * Build a prompt for detecting comment-worthy passages
@@ -9212,8 +9317,10 @@ var MotivationPrompts = class {
9212
9317
  * @param density - Optional target number of comments per 2000 words
9213
9318
  * @returns Formatted prompt string
9214
9319
  */
9215
- static buildCommentPrompt(content, instructions, tone, density) {
9320
+ static buildCommentPrompt(content, instructions, tone, density, language, sourceLanguage) {
9216
9321
  let prompt;
9322
+ const sourceLang = sourceLanguageGuidance(sourceLanguage);
9323
+ const bodyLang = bodyLanguageGuidance(language, "comments");
9217
9324
  if (instructions) {
9218
9325
  const toneGuidance = tone ? ` Use a ${tone} tone.` : "";
9219
9326
  const densityGuidance = density ? `
@@ -9221,7 +9328,7 @@ var MotivationPrompts = class {
9221
9328
  Aim for approximately ${density} comments per 2000 words of text.` : "";
9222
9329
  prompt = `Add comments to passages in this text following these instructions:
9223
9330
 
9224
- ${instructions}${toneGuidance}${densityGuidance}
9331
+ ${instructions}${toneGuidance}${densityGuidance}${sourceLang}${bodyLang}
9225
9332
 
9226
9333
  Text to analyze:
9227
9334
  ---
@@ -9257,7 +9364,7 @@ Guidelines:
9257
9364
  - Provide comments that ADD VALUE beyond restating the text
9258
9365
  - Focus on explanation, background, or connections to other ideas
9259
9366
  - Avoid obvious or trivial comments
9260
- - Keep comments concise (1-3 sentences typically)${densityGuidance}
9367
+ - Keep comments concise (1-3 sentences typically)${densityGuidance}${sourceLang}${bodyLang}
9261
9368
 
9262
9369
  Text to analyze:
9263
9370
  ---
@@ -9289,15 +9396,16 @@ Example format:
9289
9396
  * @param density - Optional target number of highlights per 2000 words
9290
9397
  * @returns Formatted prompt string
9291
9398
  */
9292
- static buildHighlightPrompt(content, instructions, density) {
9399
+ static buildHighlightPrompt(content, instructions, density, sourceLanguage) {
9293
9400
  let prompt;
9401
+ const sourceLang = sourceLanguageGuidance(sourceLanguage);
9294
9402
  if (instructions) {
9295
9403
  const densityGuidance = density ? `
9296
9404
 
9297
9405
  Aim for approximately ${density} highlights per 2000 words of text.` : "";
9298
9406
  prompt = `Identify passages in this text to highlight following these instructions:
9299
9407
 
9300
- ${instructions}${densityGuidance}
9408
+ ${instructions}${densityGuidance}${sourceLang}
9301
9409
 
9302
9410
  Text to analyze:
9303
9411
  ---
@@ -9330,7 +9438,7 @@ Guidelines:
9330
9438
  - Highlight notable quotes or particularly striking statements
9331
9439
  - Highlight critical decisions, action items, or turning points
9332
9440
  - Select passages that are SIGNIFICANT, not just interesting
9333
- - Avoid trivial or obvious content${densityGuidance}
9441
+ - Avoid trivial or obvious content${densityGuidance}${sourceLang}
9334
9442
 
9335
9443
  Text to analyze:
9336
9444
  ---
@@ -9362,8 +9470,10 @@ Example format:
9362
9470
  * @param density - Optional target number of assessments per 2000 words
9363
9471
  * @returns Formatted prompt string
9364
9472
  */
9365
- static buildAssessmentPrompt(content, instructions, tone, density) {
9473
+ static buildAssessmentPrompt(content, instructions, tone, density, language, sourceLanguage) {
9366
9474
  let prompt;
9475
+ const sourceLang = sourceLanguageGuidance(sourceLanguage);
9476
+ const bodyLang = bodyLanguageGuidance(language, "assessments");
9367
9477
  if (instructions) {
9368
9478
  const toneGuidance = tone ? ` Use a ${tone} tone.` : "";
9369
9479
  const densityGuidance = density ? `
@@ -9371,7 +9481,7 @@ Example format:
9371
9481
  Aim for approximately ${density} assessments per 2000 words of text.` : "";
9372
9482
  prompt = `Assess passages in this text following these instructions:
9373
9483
 
9374
- ${instructions}${toneGuidance}${densityGuidance}
9484
+ ${instructions}${toneGuidance}${densityGuidance}${sourceLang}${bodyLang}
9375
9485
 
9376
9486
  Text to analyze:
9377
9487
  ---
@@ -9407,7 +9517,7 @@ Guidelines:
9407
9517
  - Assess evidence quality, logical soundness, or practical implications
9408
9518
  - Provide assessments that ADD INSIGHT beyond restating the text
9409
9519
  - Focus on passages where evaluation would help readers form judgments
9410
- - Keep assessments concise yet substantive (1-3 sentences typically)${densityGuidance}
9520
+ - Keep assessments concise yet substantive (1-3 sentences typically)${densityGuidance}${sourceLang}${bodyLang}
9411
9521
 
9412
9522
  Text to analyze:
9413
9523
  ---
@@ -9443,7 +9553,8 @@ Example format:
9443
9553
  * @param categoryExamples - Example questions/guidance for this category
9444
9554
  * @returns Formatted prompt string
9445
9555
  */
9446
- static buildTagPrompt(content, category, schemaName, schemaDescription, schemaDomain, categoryDescription, categoryExamples) {
9556
+ static buildTagPrompt(content, category, schemaName, schemaDescription, schemaDomain, categoryDescription, categoryExamples, sourceLanguage) {
9557
+ const sourceLang = sourceLanguageGuidance(sourceLanguage);
9447
9558
  const prompt = `You are analyzing a text using the ${schemaName} framework.
9448
9559
 
9449
9560
  Schema: ${schemaDescription}
@@ -9462,7 +9573,7 @@ Guidelines:
9462
9573
  - Look for passages that explicitly fulfill this role
9463
9574
  - Passages can be sentences, paragraphs, or sections
9464
9575
  - Aim for precision - only tag passages that clearly serve this structural role
9465
- - Typical documents have 1-5 instances of each category (some may have 0)
9576
+ - Typical documents have 1-5 instances of each category (some may have 0)${sourceLang}
9466
9577
 
9467
9578
  Text to analyze:
9468
9579
  ---
@@ -9864,33 +9975,51 @@ var AnnotationDetection = class {
9864
9975
  return Buffer.concat(chunks).toString("utf-8");
9865
9976
  }
9866
9977
  /**
9867
- * Detect comments in content
9978
+ * Detect comments in content.
9979
+ *
9980
+ * `language` is the locale the LLM should write comment text in (annotation
9981
+ * body locale). `sourceLanguage` is the locale of the content being analyzed
9982
+ * (source-resource locale). See `types.ts` "Locale conventions" for the
9983
+ * full discussion.
9868
9984
  */
9869
- static async detectComments(content, client, instructions, tone, density) {
9870
- const prompt = MotivationPrompts.buildCommentPrompt(content, instructions, tone, density);
9985
+ static async detectComments(content, client, instructions, tone, density, language, sourceLanguage) {
9986
+ const prompt = MotivationPrompts.buildCommentPrompt(content, instructions, tone, density, language, sourceLanguage);
9871
9987
  const response = await client.generateText(prompt, 3e3, 0.4);
9872
9988
  return MotivationParsers.parseComments(response, content);
9873
9989
  }
9874
9990
  /**
9875
- * Detect highlights in content
9991
+ * Detect highlights in content.
9992
+ *
9993
+ * Highlights have no body — only `sourceLanguage` (source-resource locale)
9994
+ * applies, used in the prompt so the LLM analyzes non-English source
9995
+ * correctly.
9876
9996
  */
9877
- static async detectHighlights(content, client, instructions, density) {
9878
- const prompt = MotivationPrompts.buildHighlightPrompt(content, instructions, density);
9997
+ static async detectHighlights(content, client, instructions, density, sourceLanguage) {
9998
+ const prompt = MotivationPrompts.buildHighlightPrompt(content, instructions, density, sourceLanguage);
9879
9999
  const response = await client.generateText(prompt, 2e3, 0.3);
9880
10000
  return MotivationParsers.parseHighlights(response, content);
9881
10001
  }
9882
10002
  /**
9883
- * Detect assessments in content
10003
+ * Detect assessments in content.
10004
+ *
10005
+ * `language` is the locale the LLM should write assessment text in
10006
+ * (annotation body locale). `sourceLanguage` is the locale of the content
10007
+ * being analyzed (source-resource locale).
9884
10008
  */
9885
- static async detectAssessments(content, client, instructions, tone, density) {
9886
- const prompt = MotivationPrompts.buildAssessmentPrompt(content, instructions, tone, density);
10009
+ static async detectAssessments(content, client, instructions, tone, density, language, sourceLanguage) {
10010
+ const prompt = MotivationPrompts.buildAssessmentPrompt(content, instructions, tone, density, language, sourceLanguage);
9887
10011
  const response = await client.generateText(prompt, 3e3, 0.3);
9888
10012
  return MotivationParsers.parseAssessments(response, content);
9889
10013
  }
9890
10014
  /**
9891
- * Detect tags in content for a specific category
10015
+ * Detect tags in content for a specific category.
10016
+ *
10017
+ * `sourceLanguage` is the locale of the content being analyzed. Body-locale
10018
+ * (`language`) doesn't influence the tag prompt — categories are schema
10019
+ * identifiers, not LLM-generated text — so it's consumed at the body-stamp
10020
+ * site, not here.
9892
10021
  */
9893
- static async detectTags(content, client, schemaId, category) {
10022
+ static async detectTags(content, client, schemaId, category, sourceLanguage) {
9894
10023
  const schema = getTagSchema(schemaId);
9895
10024
  if (!schema) {
9896
10025
  throw new Error(`Invalid tag schema: ${schemaId}`);
@@ -9906,16 +10035,15 @@ var AnnotationDetection = class {
9906
10035
  schema.description,
9907
10036
  schema.domain,
9908
10037
  categoryInfo.description,
9909
- categoryInfo.examples
10038
+ categoryInfo.examples,
10039
+ sourceLanguage
9910
10040
  );
9911
10041
  const response = await client.generateText(prompt, 4e3, 0.2);
9912
10042
  const parsedTags = MotivationParsers.parseTags(response);
9913
10043
  return MotivationParsers.validateTagOffsets(parsedTags, content, category);
9914
10044
  }
9915
10045
  };
9916
-
9917
- // src/workers/detection/entity-extractor.ts
9918
- async function extractEntities(exact, entityTypes, client, includeDescriptiveReferences = false, logger2) {
10046
+ async function extractEntities(exact, entityTypes, client, includeDescriptiveReferences = false, logger2, sourceLanguage) {
9919
10047
  const entityTypesDescription = entityTypes.map((et) => {
9920
10048
  if (typeof et === "string") {
9921
10049
  return et;
@@ -9944,8 +10072,11 @@ Examples:
9944
10072
  ` : `
9945
10073
  Find direct mentions only (names, proper nouns). Do not include pronouns or descriptive references.
9946
10074
  `;
10075
+ const sourceLangGuidance = sourceLanguage ? `
10076
+ Source text language: ${getLocaleEnglishName(sourceLanguage) || sourceLanguage}.
10077
+ ` : "";
9947
10078
  const prompt = `Identify entity references in the following text. Look for mentions of: ${entityTypesDescription}.
9948
- ${descriptiveReferenceGuidance}
10079
+ ${descriptiveReferenceGuidance}${sourceLangGuidance}
9949
10080
  Text to analyze:
9950
10081
  """
9951
10082
  ${exact}
@@ -10134,12 +10265,15 @@ Example output:
10134
10265
  function getLanguageName(locale) {
10135
10266
  return getLocaleEnglishName(locale) || locale;
10136
10267
  }
10137
- async function generateResourceFromTopic(topic, entityTypes, client, userPrompt, locale, context, temperature, maxTokens, logger2) {
10268
+ async function generateResourceFromTopic(topic, entityTypes, client, userPrompt, locale, context, temperature, maxTokens, logger2, sourceLanguage) {
10138
10269
  const finalTemperature = temperature ?? 0.7;
10139
10270
  const finalMaxTokens = maxTokens ?? 500;
10140
10271
  const languageInstruction = locale && locale !== "en" ? `
10141
10272
 
10142
10273
  IMPORTANT: Write the entire resource in ${getLanguageName(locale)}.` : "";
10274
+ const sourceLanguageInstruction = sourceLanguage ? `
10275
+
10276
+ The source resource and embedded context are in ${getLanguageName(sourceLanguage)}.` : "";
10143
10277
  let annotationSection = "";
10144
10278
  if (context) {
10145
10279
  const parts = [];
@@ -10201,7 +10335,7 @@ ${parts.join("\n")}`;
10201
10335
  const structureGuidance = finalMaxTokens >= 1e3 ? "organized into titled sections (## Section) with well-structured paragraphs" : "organized into well-structured paragraphs";
10202
10336
  const prompt = `Generate a concise, informative resource about "${topic}".
10203
10337
  ${entityTypes.length > 0 ? `Focus on these entity types: ${entityTypes.join(", ")}.` : ""}
10204
- ${userPrompt ? `Additional context: ${userPrompt}` : ""}${annotationSection}${contextSection}${graphContextSection}${languageInstruction}
10338
+ ${userPrompt ? `Additional context: ${userPrompt}` : ""}${annotationSection}${contextSection}${graphContextSection}${sourceLanguageInstruction}${languageInstruction}
10205
10339
 
10206
10340
  Requirements:
10207
10341
  - Start with a clear heading (# Title)
@@ -10266,7 +10400,8 @@ async function processHighlightJob(content, inferenceClient, params, userId, gen
10266
10400
  content,
10267
10401
  inferenceClient,
10268
10402
  params.instructions,
10269
- params.density
10403
+ params.density,
10404
+ params.sourceLanguage
10270
10405
  );
10271
10406
  onProgress(60, `Creating ${highlights.length} annotations...`, "creating");
10272
10407
  const annotations = highlights.map(
@@ -10286,16 +10421,19 @@ async function processCommentJob(content, inferenceClient, params, userId, gener
10286
10421
  inferenceClient,
10287
10422
  params.instructions,
10288
10423
  params.tone,
10289
- params.density
10424
+ params.density,
10425
+ params.language,
10426
+ params.sourceLanguage
10290
10427
  );
10291
10428
  onProgress(60, `Creating ${comments.length} annotations...`, "creating");
10429
+ const bodyLanguage = params.language ?? "en";
10292
10430
  const annotations = comments.map(
10293
10431
  (c) => (
10294
10432
  // Match the pre-#651 CommentAnnotationWorker: include format and
10295
10433
  // language on the body TextualBody. Optional in the schema, but
10296
10434
  // consumers that do language-aware rendering rely on them.
10297
10435
  buildTextAnnotation(params.resourceId, userId, generator, "commenting", c, [
10298
- { type: "TextualBody", value: c.comment, purpose: "commenting", format: "text/plain", language: "en" }
10436
+ { type: "TextualBody", value: c.comment, purpose: "commenting", format: "text/plain", language: bodyLanguage }
10299
10437
  ])
10300
10438
  )
10301
10439
  );
@@ -10313,9 +10451,12 @@ async function processAssessmentJob(content, inferenceClient, params, userId, ge
10313
10451
  inferenceClient,
10314
10452
  params.instructions,
10315
10453
  params.tone,
10316
- params.density
10454
+ params.density,
10455
+ params.language,
10456
+ params.sourceLanguage
10317
10457
  );
10318
10458
  onProgress(60, `Creating ${assessments.length} annotations...`, "creating");
10459
+ const bodyLanguage = params.language ?? "en";
10319
10460
  const annotations = assessments.map(
10320
10461
  (a) => (
10321
10462
  // Single-object body with purpose aligned to motivation, matching the
@@ -10329,7 +10470,7 @@ async function processAssessmentJob(content, inferenceClient, params, userId, ge
10329
10470
  value: a.assessment,
10330
10471
  purpose: "assessing",
10331
10472
  format: "text/plain",
10332
- language: "en"
10473
+ language: bodyLanguage
10333
10474
  })
10334
10475
  )
10335
10476
  );
@@ -10348,6 +10489,7 @@ async function processReferenceJob(content, inferenceClient, params, userId, gen
10348
10489
  let errors = 0;
10349
10490
  const allAnnotations = [];
10350
10491
  onProgress(10, "Loading resource...", "analyzing", { requestParams });
10492
+ const bodyLanguage = params.language ?? "en";
10351
10493
  for (let i = 0; i < entityTypeNames.length; i++) {
10352
10494
  const entityTypeName = entityTypeNames[i];
10353
10495
  if (!entityTypeName) continue;
@@ -10366,11 +10508,14 @@ async function processReferenceJob(content, inferenceClient, params, userId, gen
10366
10508
  [entityTypeName],
10367
10509
  inferenceClient,
10368
10510
  params.includeDescriptiveReferences ?? false,
10369
- logger2
10511
+ logger2,
10512
+ params.sourceLanguage
10370
10513
  );
10371
10514
  totalFound += extractedEntities.length;
10372
10515
  completedEntityTypes.push({ entityType: entityTypeName, foundCount: extractedEntities.length });
10373
- const unresolvedBody = [{ type: "TextualBody", value: entityTypeName, purpose: "tagging" }];
10516
+ const unresolvedBody = [
10517
+ { type: "TextualBody", value: entityTypeName, purpose: "tagging", format: "text/plain", language: bodyLanguage }
10518
+ ];
10374
10519
  for (const entity of extractedEntities) {
10375
10520
  try {
10376
10521
  const validated = validateAndCorrectOffsets(content, entity.startOffset, entity.endOffset, entity.exact);
@@ -10404,18 +10549,20 @@ async function processTagJob(content, inferenceClient, params, userId, generator
10404
10549
  content,
10405
10550
  inferenceClient,
10406
10551
  params.schemaId,
10407
- category
10552
+ category,
10553
+ params.sourceLanguage
10408
10554
  );
10409
10555
  allTags.push(...categoryTags);
10410
10556
  }
10411
10557
  const tags = allTags;
10412
10558
  onProgress(60, `Creating ${tags.length} tag annotations...`, "creating");
10559
+ const bodyLanguage = params.language ?? "en";
10413
10560
  const byCategory = {};
10414
10561
  const annotations = tags.map((t) => {
10415
10562
  const category = t.category ?? "unknown";
10416
10563
  byCategory[category] = (byCategory[category] ?? 0) + 1;
10417
10564
  return buildTextAnnotation(params.resourceId, userId, generator, "tagging", t, [
10418
- { type: "TextualBody", value: category, purpose: "tagging", format: "text/plain", language: "en" },
10565
+ { type: "TextualBody", value: category, purpose: "tagging", format: "text/plain", language: bodyLanguage },
10419
10566
  { type: "TextualBody", value: params.schemaId, purpose: "classifying", format: "text/plain" }
10420
10567
  ]);
10421
10568
  });
@@ -10438,7 +10585,10 @@ async function processGenerationJob(inferenceClient, params, onProgress) {
10438
10585
  params.language,
10439
10586
  params.context,
10440
10587
  params.temperature,
10441
- params.maxTokens
10588
+ params.maxTokens,
10589
+ void 0,
10590
+ // logger
10591
+ params.sourceLanguage
10442
10592
  );
10443
10593
  onProgress(85, "Creating resource...", "creating");
10444
10594
  return {
@@ -10463,7 +10613,7 @@ function startWorkerProcess(config) {
10463
10613
  const { session, logger: logger2 } = config;
10464
10614
  const httpTransport = session.client.transport;
10465
10615
  const adapter = createJobClaimAdapter({
10466
- actor: httpTransport.actor,
10616
+ bus: httpTransport.actor,
10467
10617
  jobTypes: config.jobTypes
10468
10618
  });
10469
10619
  adapter.activeJob$.subscribe((job) => {
@@ -10667,41 +10817,7 @@ async function handleJobInner(adapter, config, job) {
10667
10817
  }
10668
10818
 
10669
10819
  // src/worker-main.ts
10670
- var import_rxjs = __toESM(require_cjs());
10671
- var traceContextFormat = winston.format((info) => {
10672
- const trace = getLogTraceContext();
10673
- if (trace) {
10674
- info.trace_id = trace.trace_id;
10675
- info.span_id = trace.span_id;
10676
- }
10677
- return info;
10678
- })();
10679
- function createProcessLogger(component) {
10680
- const level = process.env.LOG_LEVEL ?? "info";
10681
- const format = process.env.LOG_FORMAT === "simple" ? winston.format.combine(
10682
- winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
10683
- winston.format.errors({ stack: true }),
10684
- traceContextFormat,
10685
- winston.format.printf(({ level: lvl, message, timestamp, ...meta }) => {
10686
- const metaStr = Object.keys(meta).length > 0 ? ` ${JSON.stringify(meta)}` : "";
10687
- return `${timestamp} [${lvl.toUpperCase()}] [${component}] ${message}${metaStr}`;
10688
- })
10689
- ) : winston.format.combine(
10690
- winston.format.timestamp(),
10691
- winston.format.errors({ stack: true }),
10692
- traceContextFormat,
10693
- winston.format.json()
10694
- );
10695
- const logger2 = winston.createLogger({
10696
- level,
10697
- defaultMeta: { component },
10698
- format,
10699
- transports: [new winston.transports.Console()]
10700
- });
10701
- return logger2;
10702
- }
10703
-
10704
- // src/worker-main.ts
10820
+ var import_rxjs3 = __toESM(require_cjs());
10705
10821
  var ALL_JOB_TYPES = [
10706
10822
  "reference-annotation",
10707
10823
  "generation",
@@ -10804,25 +10920,24 @@ async function main() {
10804
10920
  logger.info("Authenticated");
10805
10921
  const { protocol, host, port } = parseBackendUrl(backendBaseUrl);
10806
10922
  const kbId = `worker-${hostname()}`;
10923
+ const endpoint = { kind: "http", host, port, protocol };
10807
10924
  const kb = {
10808
10925
  id: kbId,
10809
10926
  label: `Worker pool @ ${host}`,
10810
- host,
10811
- port,
10812
- protocol,
10813
- email: `worker-pool@${host}`
10927
+ email: `worker-pool@${host}`,
10928
+ endpoint
10814
10929
  };
10815
10930
  const storage = new InMemorySessionStorage();
10816
10931
  setStoredSession(storage, kbId, { access: initialToken, refresh: "" });
10817
- const token$ = new import_rxjs.BehaviorSubject(null);
10932
+ const token$ = new import_rxjs3.BehaviorSubject(null);
10818
10933
  let session;
10819
10934
  const transport = new HttpTransport({
10820
- baseUrl: baseUrl(kbBackendUrl(kb)),
10935
+ baseUrl: baseUrl(kbBackendUrl(endpoint)),
10821
10936
  token$,
10822
10937
  tokenRefresher: () => session.refresh().then((t) => t ?? null)
10823
10938
  });
10824
10939
  const content = new HttpContentTransport(transport);
10825
- const client = new SemiontClient(transport, content);
10940
+ const client = new SemiontClient(transport, content, transport);
10826
10941
  session = new SemiontSession({
10827
10942
  kb,
10828
10943
  storage,