@semiont/jobs 0.5.1 → 0.5.3

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
  ---
@@ -9693,159 +9804,6 @@ var MotivationParsers = class {
9693
9804
  }
9694
9805
  };
9695
9806
 
9696
- // ../ontology/dist/index.js
9697
- var TAG_SCHEMAS = {
9698
- "legal-irac": {
9699
- id: "legal-irac",
9700
- name: "Legal Analysis (IRAC)",
9701
- description: "Issue, Rule, Application, Conclusion framework for legal reasoning",
9702
- domain: "legal",
9703
- tags: [
9704
- {
9705
- name: "Issue",
9706
- description: "The legal question or problem to be resolved",
9707
- examples: [
9708
- "What is the central legal question?",
9709
- "What must the court decide?",
9710
- "What is the dispute about?"
9711
- ]
9712
- },
9713
- {
9714
- name: "Rule",
9715
- description: "The relevant law, statute, or legal principle",
9716
- examples: [
9717
- "What law applies?",
9718
- "What is the legal standard?",
9719
- "What statute governs this case?"
9720
- ]
9721
- },
9722
- {
9723
- name: "Application",
9724
- description: "How the rule applies to the specific facts",
9725
- examples: [
9726
- "How does the law apply to these facts?",
9727
- "Analysis of the case",
9728
- "How do the facts satisfy the legal standard?"
9729
- ]
9730
- },
9731
- {
9732
- name: "Conclusion",
9733
- description: "The resolution or outcome based on the analysis",
9734
- examples: [
9735
- "What is the court's decision?",
9736
- "What is the final judgment?",
9737
- "What is the holding?"
9738
- ]
9739
- }
9740
- ]
9741
- },
9742
- "scientific-imrad": {
9743
- id: "scientific-imrad",
9744
- name: "Scientific Paper (IMRAD)",
9745
- description: "Introduction, Methods, Results, Discussion structure for research papers",
9746
- domain: "scientific",
9747
- tags: [
9748
- {
9749
- name: "Introduction",
9750
- description: "Background, context, and research question",
9751
- examples: [
9752
- "What is the research question?",
9753
- "Why is this important?",
9754
- "What is the hypothesis?"
9755
- ]
9756
- },
9757
- {
9758
- name: "Methods",
9759
- description: "Experimental design and procedures",
9760
- examples: [
9761
- "How was the study conducted?",
9762
- "What methods were used?",
9763
- "What was the experimental design?"
9764
- ]
9765
- },
9766
- {
9767
- name: "Results",
9768
- description: "Findings and observations",
9769
- examples: [
9770
- "What did the study find?",
9771
- "What are the data?",
9772
- "What were the observations?"
9773
- ]
9774
- },
9775
- {
9776
- name: "Discussion",
9777
- description: "Interpretation and implications of results",
9778
- examples: [
9779
- "What do the results mean?",
9780
- "What are the implications?",
9781
- "How do these findings relate to prior work?"
9782
- ]
9783
- }
9784
- ]
9785
- },
9786
- "argument-toulmin": {
9787
- id: "argument-toulmin",
9788
- name: "Argument Structure (Toulmin)",
9789
- description: "Claim, Evidence, Warrant, Counterargument, Rebuttal framework for argumentation",
9790
- domain: "general",
9791
- tags: [
9792
- {
9793
- name: "Claim",
9794
- description: "The main assertion or thesis",
9795
- examples: [
9796
- "What is being argued?",
9797
- "What is the main point?",
9798
- "What position is being taken?"
9799
- ]
9800
- },
9801
- {
9802
- name: "Evidence",
9803
- description: "Data or facts supporting the claim",
9804
- examples: [
9805
- "What supports this claim?",
9806
- "What are the facts?",
9807
- "What data is provided?"
9808
- ]
9809
- },
9810
- {
9811
- name: "Warrant",
9812
- description: "Reasoning connecting evidence to claim",
9813
- examples: [
9814
- "Why does this evidence support the claim?",
9815
- "What is the logic?",
9816
- "How does this reasoning work?"
9817
- ]
9818
- },
9819
- {
9820
- name: "Counterargument",
9821
- description: "Opposing viewpoints or objections",
9822
- examples: [
9823
- "What are the objections?",
9824
- "What do critics say?",
9825
- "What are alternative views?"
9826
- ]
9827
- },
9828
- {
9829
- name: "Rebuttal",
9830
- description: "Response to counterarguments",
9831
- examples: [
9832
- "How is the objection addressed?",
9833
- "Why is the counterargument wrong?",
9834
- "How is the criticism answered?"
9835
- ]
9836
- }
9837
- ]
9838
- }
9839
- };
9840
- function getTagSchema(schemaId) {
9841
- return TAG_SCHEMAS[schemaId] || null;
9842
- }
9843
- function getSchemaCategory(schemaId, categoryName) {
9844
- const schema = getTagSchema(schemaId);
9845
- if (!schema) return null;
9846
- return schema.tags.find((tag) => tag.name === categoryName) || null;
9847
- }
9848
-
9849
9807
  // src/workers/annotation-detection.ts
9850
9808
  var AnnotationDetection = class {
9851
9809
  /**
@@ -9864,40 +9822,58 @@ var AnnotationDetection = class {
9864
9822
  return Buffer.concat(chunks).toString("utf-8");
9865
9823
  }
9866
9824
  /**
9867
- * Detect comments in content
9825
+ * Detect comments in content.
9826
+ *
9827
+ * `language` is the locale the LLM should write comment text in (annotation
9828
+ * body locale). `sourceLanguage` is the locale of the content being analyzed
9829
+ * (source-resource locale). See `types.ts` "Locale conventions" for the
9830
+ * full discussion.
9868
9831
  */
9869
- static async detectComments(content, client, instructions, tone, density) {
9870
- const prompt = MotivationPrompts.buildCommentPrompt(content, instructions, tone, density);
9832
+ static async detectComments(content, client, instructions, tone, density, language, sourceLanguage) {
9833
+ const prompt = MotivationPrompts.buildCommentPrompt(content, instructions, tone, density, language, sourceLanguage);
9871
9834
  const response = await client.generateText(prompt, 3e3, 0.4);
9872
9835
  return MotivationParsers.parseComments(response, content);
9873
9836
  }
9874
9837
  /**
9875
- * Detect highlights in content
9838
+ * Detect highlights in content.
9839
+ *
9840
+ * Highlights have no body — only `sourceLanguage` (source-resource locale)
9841
+ * applies, used in the prompt so the LLM analyzes non-English source
9842
+ * correctly.
9876
9843
  */
9877
- static async detectHighlights(content, client, instructions, density) {
9878
- const prompt = MotivationPrompts.buildHighlightPrompt(content, instructions, density);
9844
+ static async detectHighlights(content, client, instructions, density, sourceLanguage) {
9845
+ const prompt = MotivationPrompts.buildHighlightPrompt(content, instructions, density, sourceLanguage);
9879
9846
  const response = await client.generateText(prompt, 2e3, 0.3);
9880
9847
  return MotivationParsers.parseHighlights(response, content);
9881
9848
  }
9882
9849
  /**
9883
- * Detect assessments in content
9850
+ * Detect assessments in content.
9851
+ *
9852
+ * `language` is the locale the LLM should write assessment text in
9853
+ * (annotation body locale). `sourceLanguage` is the locale of the content
9854
+ * being analyzed (source-resource locale).
9884
9855
  */
9885
- static async detectAssessments(content, client, instructions, tone, density) {
9886
- const prompt = MotivationPrompts.buildAssessmentPrompt(content, instructions, tone, density);
9856
+ static async detectAssessments(content, client, instructions, tone, density, language, sourceLanguage) {
9857
+ const prompt = MotivationPrompts.buildAssessmentPrompt(content, instructions, tone, density, language, sourceLanguage);
9887
9858
  const response = await client.generateText(prompt, 3e3, 0.3);
9888
9859
  return MotivationParsers.parseAssessments(response, content);
9889
9860
  }
9890
9861
  /**
9891
- * Detect tags in content for a specific category
9862
+ * Detect tags in content for a specific category.
9863
+ *
9864
+ * The full `TagSchema` is supplied by the dispatcher (resolved against
9865
+ * the per-KB tag-schema projection at job-creation time) so the worker
9866
+ * is independent of the registry.
9867
+ *
9868
+ * `sourceLanguage` is the locale of the content being analyzed. Body-locale
9869
+ * (`language`) doesn't influence the tag prompt — categories are schema
9870
+ * identifiers, not LLM-generated text — so it's consumed at the body-stamp
9871
+ * site, not here.
9892
9872
  */
9893
- static async detectTags(content, client, schemaId, category) {
9894
- const schema = getTagSchema(schemaId);
9895
- if (!schema) {
9896
- throw new Error(`Invalid tag schema: ${schemaId}`);
9897
- }
9898
- const categoryInfo = getSchemaCategory(schemaId, category);
9873
+ static async detectTags(content, client, schema, category, sourceLanguage) {
9874
+ const categoryInfo = schema.tags.find((t) => t.name === category);
9899
9875
  if (!categoryInfo) {
9900
- throw new Error(`Invalid category "${category}" for schema ${schemaId}`);
9876
+ throw new Error(`Invalid category "${category}" for schema ${schema.id}`);
9901
9877
  }
9902
9878
  const prompt = MotivationPrompts.buildTagPrompt(
9903
9879
  content,
@@ -9906,16 +9882,15 @@ var AnnotationDetection = class {
9906
9882
  schema.description,
9907
9883
  schema.domain,
9908
9884
  categoryInfo.description,
9909
- categoryInfo.examples
9885
+ categoryInfo.examples,
9886
+ sourceLanguage
9910
9887
  );
9911
9888
  const response = await client.generateText(prompt, 4e3, 0.2);
9912
9889
  const parsedTags = MotivationParsers.parseTags(response);
9913
9890
  return MotivationParsers.validateTagOffsets(parsedTags, content, category);
9914
9891
  }
9915
9892
  };
9916
-
9917
- // src/workers/detection/entity-extractor.ts
9918
- async function extractEntities(exact, entityTypes, client, includeDescriptiveReferences = false, logger2) {
9893
+ async function extractEntities(exact, entityTypes, client, includeDescriptiveReferences = false, logger2, sourceLanguage) {
9919
9894
  const entityTypesDescription = entityTypes.map((et) => {
9920
9895
  if (typeof et === "string") {
9921
9896
  return et;
@@ -9944,8 +9919,11 @@ Examples:
9944
9919
  ` : `
9945
9920
  Find direct mentions only (names, proper nouns). Do not include pronouns or descriptive references.
9946
9921
  `;
9922
+ const sourceLangGuidance = sourceLanguage ? `
9923
+ Source text language: ${getLocaleEnglishName(sourceLanguage) || sourceLanguage}.
9924
+ ` : "";
9947
9925
  const prompt = `Identify entity references in the following text. Look for mentions of: ${entityTypesDescription}.
9948
- ${descriptiveReferenceGuidance}
9926
+ ${descriptiveReferenceGuidance}${sourceLangGuidance}
9949
9927
  Text to analyze:
9950
9928
  """
9951
9929
  ${exact}
@@ -10134,12 +10112,15 @@ Example output:
10134
10112
  function getLanguageName(locale) {
10135
10113
  return getLocaleEnglishName(locale) || locale;
10136
10114
  }
10137
- async function generateResourceFromTopic(topic, entityTypes, client, userPrompt, locale, context, temperature, maxTokens, logger2) {
10115
+ async function generateResourceFromTopic(topic, entityTypes, client, userPrompt, locale, context, temperature, maxTokens, logger2, sourceLanguage) {
10138
10116
  const finalTemperature = temperature ?? 0.7;
10139
10117
  const finalMaxTokens = maxTokens ?? 500;
10140
10118
  const languageInstruction = locale && locale !== "en" ? `
10141
10119
 
10142
10120
  IMPORTANT: Write the entire resource in ${getLanguageName(locale)}.` : "";
10121
+ const sourceLanguageInstruction = sourceLanguage ? `
10122
+
10123
+ The source resource and embedded context are in ${getLanguageName(sourceLanguage)}.` : "";
10143
10124
  let annotationSection = "";
10144
10125
  if (context) {
10145
10126
  const parts = [];
@@ -10201,7 +10182,7 @@ ${parts.join("\n")}`;
10201
10182
  const structureGuidance = finalMaxTokens >= 1e3 ? "organized into titled sections (## Section) with well-structured paragraphs" : "organized into well-structured paragraphs";
10202
10183
  const prompt = `Generate a concise, informative resource about "${topic}".
10203
10184
  ${entityTypes.length > 0 ? `Focus on these entity types: ${entityTypes.join(", ")}.` : ""}
10204
- ${userPrompt ? `Additional context: ${userPrompt}` : ""}${annotationSection}${contextSection}${graphContextSection}${languageInstruction}
10185
+ ${userPrompt ? `Additional context: ${userPrompt}` : ""}${annotationSection}${contextSection}${graphContextSection}${sourceLanguageInstruction}${languageInstruction}
10205
10186
 
10206
10187
  Requirements:
10207
10188
  - Start with a clear heading (# Title)
@@ -10266,7 +10247,8 @@ async function processHighlightJob(content, inferenceClient, params, userId, gen
10266
10247
  content,
10267
10248
  inferenceClient,
10268
10249
  params.instructions,
10269
- params.density
10250
+ params.density,
10251
+ params.sourceLanguage
10270
10252
  );
10271
10253
  onProgress(60, `Creating ${highlights.length} annotations...`, "creating");
10272
10254
  const annotations = highlights.map(
@@ -10286,16 +10268,19 @@ async function processCommentJob(content, inferenceClient, params, userId, gener
10286
10268
  inferenceClient,
10287
10269
  params.instructions,
10288
10270
  params.tone,
10289
- params.density
10271
+ params.density,
10272
+ params.language,
10273
+ params.sourceLanguage
10290
10274
  );
10291
10275
  onProgress(60, `Creating ${comments.length} annotations...`, "creating");
10276
+ const bodyLanguage = params.language ?? "en";
10292
10277
  const annotations = comments.map(
10293
10278
  (c) => (
10294
10279
  // Match the pre-#651 CommentAnnotationWorker: include format and
10295
10280
  // language on the body TextualBody. Optional in the schema, but
10296
10281
  // consumers that do language-aware rendering rely on them.
10297
10282
  buildTextAnnotation(params.resourceId, userId, generator, "commenting", c, [
10298
- { type: "TextualBody", value: c.comment, purpose: "commenting", format: "text/plain", language: "en" }
10283
+ { type: "TextualBody", value: c.comment, purpose: "commenting", format: "text/plain", language: bodyLanguage }
10299
10284
  ])
10300
10285
  )
10301
10286
  );
@@ -10313,9 +10298,12 @@ async function processAssessmentJob(content, inferenceClient, params, userId, ge
10313
10298
  inferenceClient,
10314
10299
  params.instructions,
10315
10300
  params.tone,
10316
- params.density
10301
+ params.density,
10302
+ params.language,
10303
+ params.sourceLanguage
10317
10304
  );
10318
10305
  onProgress(60, `Creating ${assessments.length} annotations...`, "creating");
10306
+ const bodyLanguage = params.language ?? "en";
10319
10307
  const annotations = assessments.map(
10320
10308
  (a) => (
10321
10309
  // Single-object body with purpose aligned to motivation, matching the
@@ -10329,7 +10317,7 @@ async function processAssessmentJob(content, inferenceClient, params, userId, ge
10329
10317
  value: a.assessment,
10330
10318
  purpose: "assessing",
10331
10319
  format: "text/plain",
10332
- language: "en"
10320
+ language: bodyLanguage
10333
10321
  })
10334
10322
  )
10335
10323
  );
@@ -10348,6 +10336,7 @@ async function processReferenceJob(content, inferenceClient, params, userId, gen
10348
10336
  let errors = 0;
10349
10337
  const allAnnotations = [];
10350
10338
  onProgress(10, "Loading resource...", "analyzing", { requestParams });
10339
+ const bodyLanguage = params.language ?? "en";
10351
10340
  for (let i = 0; i < entityTypeNames.length; i++) {
10352
10341
  const entityTypeName = entityTypeNames[i];
10353
10342
  if (!entityTypeName) continue;
@@ -10366,11 +10355,14 @@ async function processReferenceJob(content, inferenceClient, params, userId, gen
10366
10355
  [entityTypeName],
10367
10356
  inferenceClient,
10368
10357
  params.includeDescriptiveReferences ?? false,
10369
- logger2
10358
+ logger2,
10359
+ params.sourceLanguage
10370
10360
  );
10371
10361
  totalFound += extractedEntities.length;
10372
10362
  completedEntityTypes.push({ entityType: entityTypeName, foundCount: extractedEntities.length });
10373
- const unresolvedBody = [{ type: "TextualBody", value: entityTypeName, purpose: "tagging" }];
10363
+ const unresolvedBody = [
10364
+ { type: "TextualBody", value: entityTypeName, purpose: "tagging", format: "text/plain", language: bodyLanguage }
10365
+ ];
10374
10366
  for (const entity of extractedEntities) {
10375
10367
  try {
10376
10368
  const validated = validateAndCorrectOffsets(content, entity.startOffset, entity.endOffset, entity.exact);
@@ -10403,20 +10395,22 @@ async function processTagJob(content, inferenceClient, params, userId, generator
10403
10395
  const categoryTags = await AnnotationDetection.detectTags(
10404
10396
  content,
10405
10397
  inferenceClient,
10406
- params.schemaId,
10407
- category
10398
+ params.schema,
10399
+ category,
10400
+ params.sourceLanguage
10408
10401
  );
10409
10402
  allTags.push(...categoryTags);
10410
10403
  }
10411
10404
  const tags = allTags;
10412
10405
  onProgress(60, `Creating ${tags.length} tag annotations...`, "creating");
10406
+ const bodyLanguage = params.language ?? "en";
10413
10407
  const byCategory = {};
10414
10408
  const annotations = tags.map((t) => {
10415
10409
  const category = t.category ?? "unknown";
10416
10410
  byCategory[category] = (byCategory[category] ?? 0) + 1;
10417
10411
  return buildTextAnnotation(params.resourceId, userId, generator, "tagging", t, [
10418
- { type: "TextualBody", value: category, purpose: "tagging", format: "text/plain", language: "en" },
10419
- { type: "TextualBody", value: params.schemaId, purpose: "classifying", format: "text/plain" }
10412
+ { type: "TextualBody", value: category, purpose: "tagging", format: "text/plain", language: bodyLanguage },
10413
+ { type: "TextualBody", value: params.schema.id, purpose: "classifying", format: "text/plain" }
10420
10414
  ]);
10421
10415
  });
10422
10416
  onProgress(100, `Complete! Created ${annotations.length} tags`, "creating");
@@ -10438,7 +10432,10 @@ async function processGenerationJob(inferenceClient, params, onProgress) {
10438
10432
  params.language,
10439
10433
  params.context,
10440
10434
  params.temperature,
10441
- params.maxTokens
10435
+ params.maxTokens,
10436
+ void 0,
10437
+ // logger
10438
+ params.sourceLanguage
10442
10439
  );
10443
10440
  onProgress(85, "Creating resource...", "creating");
10444
10441
  return {
@@ -10463,7 +10460,7 @@ function startWorkerProcess(config) {
10463
10460
  const { session, logger: logger2 } = config;
10464
10461
  const httpTransport = session.client.transport;
10465
10462
  const adapter = createJobClaimAdapter({
10466
- actor: httpTransport.actor,
10463
+ bus: httpTransport.actor,
10467
10464
  jobTypes: config.jobTypes
10468
10465
  });
10469
10466
  adapter.activeJob$.subscribe((job) => {
@@ -10654,6 +10651,7 @@ async function handleJobInner(adapter, config, job) {
10654
10651
  ...genParams.referenceId ? { sourceAnnotationId: genParams.referenceId } : {},
10655
10652
  ...genParams.prompt ? { generationPrompt: genParams.prompt } : {},
10656
10653
  ...genParams.language ? { language: genParams.language } : {},
10654
+ ...genParams.entityTypes && genParams.entityTypes.length > 0 ? { entityTypes: genParams.entityTypes } : {},
10657
10655
  generator
10658
10656
  });
10659
10657
  await emitEvent(session, "job:complete", {
@@ -10667,41 +10665,7 @@ async function handleJobInner(adapter, config, job) {
10667
10665
  }
10668
10666
 
10669
10667
  // 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
10668
+ var import_rxjs3 = __toESM(require_cjs());
10705
10669
  var ALL_JOB_TYPES = [
10706
10670
  "reference-annotation",
10707
10671
  "generation",
@@ -10804,25 +10768,24 @@ async function main() {
10804
10768
  logger.info("Authenticated");
10805
10769
  const { protocol, host, port } = parseBackendUrl(backendBaseUrl);
10806
10770
  const kbId = `worker-${hostname()}`;
10771
+ const endpoint = { kind: "http", host, port, protocol };
10807
10772
  const kb = {
10808
10773
  id: kbId,
10809
10774
  label: `Worker pool @ ${host}`,
10810
- host,
10811
- port,
10812
- protocol,
10813
- email: `worker-pool@${host}`
10775
+ email: `worker-pool@${host}`,
10776
+ endpoint
10814
10777
  };
10815
10778
  const storage = new InMemorySessionStorage();
10816
10779
  setStoredSession(storage, kbId, { access: initialToken, refresh: "" });
10817
- const token$ = new import_rxjs.BehaviorSubject(null);
10780
+ const token$ = new import_rxjs3.BehaviorSubject(null);
10818
10781
  let session;
10819
10782
  const transport = new HttpTransport({
10820
- baseUrl: baseUrl(kbBackendUrl(kb)),
10783
+ baseUrl: baseUrl(kbBackendUrl(endpoint)),
10821
10784
  token$,
10822
10785
  tokenRefresher: () => session.refresh().then((t) => t ?? null)
10823
10786
  });
10824
10787
  const content = new HttpContentTransport(transport);
10825
- const client = new SemiontClient(transport, content);
10788
+ const client = new SemiontClient(transport, content, transport);
10826
10789
  session = new SemiontSession({
10827
10790
  kb,
10828
10791
  storage,