@semiont/jobs 0.5.9 → 0.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +16 -6
- package/dist/index.js +93 -48
- package/dist/index.js.map +1 -1
- package/dist/worker-main.js +139 -88
- package/dist/worker-main.js.map +1 -1
- package/package.json +8 -8
package/dist/worker-main.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createTomlConfigLoader, softwareToAgent, baseUrl, getPrimaryMediaType, textExtractionOf, reconcileSelector, didToAgent, getLocaleEnglishName, isArray, isObject, isString } from '@semiont/core';
|
|
1
|
+
import { createTomlConfigLoader, softwareToAgent, baseUrl, busRequest, getPrimaryMediaType, textExtractionOf, assembleAnnotation, reconcileSelector, didToAgent, getLocaleEnglishName, isArray, isObject, isString, deriveViews } from '@semiont/core';
|
|
2
2
|
import { deriveStorageUri } from '@semiont/content';
|
|
3
3
|
import { withSpan, SpanKind, recordJobOutcome } from '@semiont/observability';
|
|
4
4
|
import { generateAnnotationId } from '@semiont/event-sourcing';
|
|
@@ -326,16 +326,16 @@ var require_timeoutProvider = __commonJS({
|
|
|
326
326
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
327
327
|
exports.timeoutProvider = void 0;
|
|
328
328
|
exports.timeoutProvider = {
|
|
329
|
-
setTimeout: function(handler,
|
|
329
|
+
setTimeout: function(handler, timeout) {
|
|
330
330
|
var args = [];
|
|
331
331
|
for (var _i = 2; _i < arguments.length; _i++) {
|
|
332
332
|
args[_i - 2] = arguments[_i];
|
|
333
333
|
}
|
|
334
334
|
var delegate = exports.timeoutProvider.delegate;
|
|
335
335
|
if (delegate === null || delegate === void 0 ? void 0 : delegate.setTimeout) {
|
|
336
|
-
return delegate.setTimeout.apply(delegate, __spreadArray([handler,
|
|
336
|
+
return delegate.setTimeout.apply(delegate, __spreadArray([handler, timeout], __read(args)));
|
|
337
337
|
}
|
|
338
|
-
return setTimeout.apply(void 0, __spreadArray([handler,
|
|
338
|
+
return setTimeout.apply(void 0, __spreadArray([handler, timeout], __read(args)));
|
|
339
339
|
},
|
|
340
340
|
clearTimeout: function(handle) {
|
|
341
341
|
var delegate = exports.timeoutProvider.delegate;
|
|
@@ -1659,16 +1659,16 @@ var require_intervalProvider = __commonJS({
|
|
|
1659
1659
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1660
1660
|
exports.intervalProvider = void 0;
|
|
1661
1661
|
exports.intervalProvider = {
|
|
1662
|
-
setInterval: function(handler,
|
|
1662
|
+
setInterval: function(handler, timeout) {
|
|
1663
1663
|
var args = [];
|
|
1664
1664
|
for (var _i = 2; _i < arguments.length; _i++) {
|
|
1665
1665
|
args[_i - 2] = arguments[_i];
|
|
1666
1666
|
}
|
|
1667
1667
|
var delegate = exports.intervalProvider.delegate;
|
|
1668
1668
|
if (delegate === null || delegate === void 0 ? void 0 : delegate.setInterval) {
|
|
1669
|
-
return delegate.setInterval.apply(delegate, __spreadArray([handler,
|
|
1669
|
+
return delegate.setInterval.apply(delegate, __spreadArray([handler, timeout], __read(args)));
|
|
1670
1670
|
}
|
|
1671
|
-
return setInterval.apply(void 0, __spreadArray([handler,
|
|
1671
|
+
return setInterval.apply(void 0, __spreadArray([handler, timeout], __read(args)));
|
|
1672
1672
|
},
|
|
1673
1673
|
clearInterval: function(handle) {
|
|
1674
1674
|
var delegate = exports.intervalProvider.delegate;
|
|
@@ -3566,7 +3566,7 @@ var require_firstValueFrom = __commonJS({
|
|
|
3566
3566
|
exports.firstValueFrom = void 0;
|
|
3567
3567
|
var EmptyError_1 = require_EmptyError();
|
|
3568
3568
|
var Subscriber_1 = require_Subscriber();
|
|
3569
|
-
function
|
|
3569
|
+
function firstValueFrom(source, config) {
|
|
3570
3570
|
var hasConfig = typeof config === "object";
|
|
3571
3571
|
return new Promise(function(resolve, reject) {
|
|
3572
3572
|
var subscriber = new Subscriber_1.SafeSubscriber({
|
|
@@ -3586,7 +3586,7 @@ var require_firstValueFrom = __commonJS({
|
|
|
3586
3586
|
source.subscribe(subscriber);
|
|
3587
3587
|
});
|
|
3588
3588
|
}
|
|
3589
|
-
exports.firstValueFrom =
|
|
3589
|
+
exports.firstValueFrom = firstValueFrom;
|
|
3590
3590
|
}
|
|
3591
3591
|
});
|
|
3592
3592
|
|
|
@@ -3673,7 +3673,7 @@ var require_timeout = __commonJS({
|
|
|
3673
3673
|
this.info = info;
|
|
3674
3674
|
};
|
|
3675
3675
|
});
|
|
3676
|
-
function
|
|
3676
|
+
function timeout(config, schedulerArg) {
|
|
3677
3677
|
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;
|
|
3678
3678
|
if (first == null && each == null) {
|
|
3679
3679
|
throw new TypeError("No timeout provided.");
|
|
@@ -3711,7 +3711,7 @@ var require_timeout = __commonJS({
|
|
|
3711
3711
|
!seen && startTimer(first != null ? typeof first === "number" ? first : +first - scheduler.now() : each);
|
|
3712
3712
|
});
|
|
3713
3713
|
}
|
|
3714
|
-
exports.timeout =
|
|
3714
|
+
exports.timeout = timeout;
|
|
3715
3715
|
function timeoutErrorFactory(info) {
|
|
3716
3716
|
throw new exports.TimeoutError(info);
|
|
3717
3717
|
}
|
|
@@ -3725,7 +3725,7 @@ var require_map = __commonJS({
|
|
|
3725
3725
|
exports.map = void 0;
|
|
3726
3726
|
var lift_1 = require_lift();
|
|
3727
3727
|
var OperatorSubscriber_1 = require_OperatorSubscriber();
|
|
3728
|
-
function
|
|
3728
|
+
function map(project, thisArg) {
|
|
3729
3729
|
return lift_1.operate(function(source, subscriber) {
|
|
3730
3730
|
var index = 0;
|
|
3731
3731
|
source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function(value) {
|
|
@@ -3733,7 +3733,7 @@ var require_map = __commonJS({
|
|
|
3733
3733
|
}));
|
|
3734
3734
|
});
|
|
3735
3735
|
}
|
|
3736
|
-
exports.map =
|
|
3736
|
+
exports.map = map;
|
|
3737
3737
|
}
|
|
3738
3738
|
});
|
|
3739
3739
|
|
|
@@ -4633,7 +4633,7 @@ var require_merge = __commonJS({
|
|
|
4633
4633
|
var empty_1 = require_empty();
|
|
4634
4634
|
var args_1 = require_args();
|
|
4635
4635
|
var from_1 = require_from();
|
|
4636
|
-
function
|
|
4636
|
+
function merge() {
|
|
4637
4637
|
var args = [];
|
|
4638
4638
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
4639
4639
|
args[_i] = arguments[_i];
|
|
@@ -4643,7 +4643,7 @@ var require_merge = __commonJS({
|
|
|
4643
4643
|
var sources = args;
|
|
4644
4644
|
return !sources.length ? empty_1.EMPTY : sources.length === 1 ? innerFrom_1.innerFrom(sources[0]) : mergeAll_1.mergeAll(concurrent)(from_1.from(sources, scheduler));
|
|
4645
4645
|
}
|
|
4646
|
-
exports.merge =
|
|
4646
|
+
exports.merge = merge;
|
|
4647
4647
|
}
|
|
4648
4648
|
});
|
|
4649
4649
|
|
|
@@ -4750,7 +4750,7 @@ var require_filter = __commonJS({
|
|
|
4750
4750
|
exports.filter = void 0;
|
|
4751
4751
|
var lift_1 = require_lift();
|
|
4752
4752
|
var OperatorSubscriber_1 = require_OperatorSubscriber();
|
|
4753
|
-
function
|
|
4753
|
+
function filter(predicate, thisArg) {
|
|
4754
4754
|
return lift_1.operate(function(source, subscriber) {
|
|
4755
4755
|
var index = 0;
|
|
4756
4756
|
source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function(value) {
|
|
@@ -4758,7 +4758,7 @@ var require_filter = __commonJS({
|
|
|
4758
4758
|
}));
|
|
4759
4759
|
});
|
|
4760
4760
|
}
|
|
4761
|
-
exports.filter =
|
|
4761
|
+
exports.filter = filter;
|
|
4762
4762
|
}
|
|
4763
4763
|
});
|
|
4764
4764
|
|
|
@@ -5885,7 +5885,7 @@ var require_take = __commonJS({
|
|
|
5885
5885
|
var empty_1 = require_empty();
|
|
5886
5886
|
var lift_1 = require_lift();
|
|
5887
5887
|
var OperatorSubscriber_1 = require_OperatorSubscriber();
|
|
5888
|
-
function
|
|
5888
|
+
function take(count) {
|
|
5889
5889
|
return count <= 0 ? function() {
|
|
5890
5890
|
return empty_1.EMPTY;
|
|
5891
5891
|
} : lift_1.operate(function(source, subscriber) {
|
|
@@ -5900,7 +5900,7 @@ var require_take = __commonJS({
|
|
|
5900
5900
|
}));
|
|
5901
5901
|
});
|
|
5902
5902
|
}
|
|
5903
|
-
exports.take =
|
|
5903
|
+
exports.take = take;
|
|
5904
5904
|
}
|
|
5905
5905
|
});
|
|
5906
5906
|
|
|
@@ -6692,7 +6692,7 @@ var require_merge2 = __commonJS({
|
|
|
6692
6692
|
var mergeAll_1 = require_mergeAll();
|
|
6693
6693
|
var args_1 = require_args();
|
|
6694
6694
|
var from_1 = require_from();
|
|
6695
|
-
function
|
|
6695
|
+
function merge() {
|
|
6696
6696
|
var args = [];
|
|
6697
6697
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
6698
6698
|
args[_i] = arguments[_i];
|
|
@@ -6703,7 +6703,7 @@ var require_merge2 = __commonJS({
|
|
|
6703
6703
|
mergeAll_1.mergeAll(concurrent)(from_1.from(__spreadArray([source], __read(args)), scheduler)).subscribe(subscriber);
|
|
6704
6704
|
});
|
|
6705
6705
|
}
|
|
6706
|
-
exports.merge =
|
|
6706
|
+
exports.merge = merge;
|
|
6707
6707
|
}
|
|
6708
6708
|
});
|
|
6709
6709
|
|
|
@@ -9207,9 +9207,19 @@ var require_cjs = __commonJS({
|
|
|
9207
9207
|
|
|
9208
9208
|
// src/job-claim-adapter.ts
|
|
9209
9209
|
var import_rxjs = __toESM(require_cjs());
|
|
9210
|
-
|
|
9210
|
+
function workerBusAsPrimitive(bus) {
|
|
9211
|
+
return {
|
|
9212
|
+
emit(channel, payload) {
|
|
9213
|
+
return bus.emit(channel, payload);
|
|
9214
|
+
},
|
|
9215
|
+
stream(channel) {
|
|
9216
|
+
return bus.on$(channel);
|
|
9217
|
+
}
|
|
9218
|
+
};
|
|
9219
|
+
}
|
|
9211
9220
|
function createJobClaimAdapter(options) {
|
|
9212
9221
|
const { bus, jobTypes } = options;
|
|
9222
|
+
const requestBus = workerBusAsPrimitive(bus);
|
|
9213
9223
|
const activeJob$ = new import_rxjs.BehaviorSubject(null);
|
|
9214
9224
|
const isProcessing$ = new import_rxjs.BehaviorSubject(false);
|
|
9215
9225
|
const jobsCompleted$ = new import_rxjs.BehaviorSubject(0);
|
|
@@ -9218,22 +9228,7 @@ function createJobClaimAdapter(options) {
|
|
|
9218
9228
|
let started = false;
|
|
9219
9229
|
const claimJob = async (assignment) => {
|
|
9220
9230
|
try {
|
|
9221
|
-
const
|
|
9222
|
-
const result$ = (0, import_rxjs2.merge)(
|
|
9223
|
-
bus.on$("job:claimed").pipe(
|
|
9224
|
-
(0, import_rxjs2.filter)((e) => e.correlationId === correlationId),
|
|
9225
|
-
(0, import_rxjs2.map)((e) => ({ ok: true, response: e.response }))
|
|
9226
|
-
),
|
|
9227
|
-
bus.on$("job:claim-failed").pipe(
|
|
9228
|
-
(0, import_rxjs2.filter)((e) => e.correlationId === correlationId),
|
|
9229
|
-
(0, import_rxjs2.map)(() => ({ ok: false }))
|
|
9230
|
-
)
|
|
9231
|
-
).pipe((0, import_rxjs2.take)(1), (0, import_rxjs2.timeout)(1e4));
|
|
9232
|
-
const resultPromise = (0, import_rxjs2.firstValueFrom)(result$);
|
|
9233
|
-
await bus.emit("job:claim", { correlationId, jobId: assignment.jobId });
|
|
9234
|
-
const result = await resultPromise;
|
|
9235
|
-
if (!result.ok) return null;
|
|
9236
|
-
const job = result.response;
|
|
9231
|
+
const job = await busRequest(requestBus, "job:claim", { jobId: assignment.jobId }, 1e4);
|
|
9237
9232
|
return {
|
|
9238
9233
|
jobId: assignment.jobId,
|
|
9239
9234
|
type: assignment.type,
|
|
@@ -9945,7 +9940,7 @@ Example output:
|
|
|
9945
9940
|
function getLanguageName(locale) {
|
|
9946
9941
|
return getLocaleEnglishName(locale) || locale;
|
|
9947
9942
|
}
|
|
9948
|
-
async function generateResourceFromTopic(topic, entityTypes, client, logger2, userPrompt, locale, context, temperature, maxTokens, sourceLanguage) {
|
|
9943
|
+
async function generateResourceFromTopic(topic, entityTypes, client, logger2, userPrompt, locale, context, temperature, maxTokens, sourceLanguage, outputMediaType = "text/markdown") {
|
|
9949
9944
|
logger2.debug("Generating resource from topic", {
|
|
9950
9945
|
topicPreview: topic.substring(0, 100),
|
|
9951
9946
|
entityTypes,
|
|
@@ -9965,61 +9960,95 @@ IMPORTANT: Write the entire resource in ${getLanguageName(locale)}.` : "";
|
|
|
9965
9960
|
|
|
9966
9961
|
The source resource and embedded context are in ${getLanguageName(sourceLanguage)}.` : "";
|
|
9967
9962
|
let annotationSection = "";
|
|
9963
|
+
let contextSection = "";
|
|
9964
|
+
let resourceSection = "";
|
|
9965
|
+
let graphSection = "";
|
|
9968
9966
|
if (context) {
|
|
9969
|
-
const
|
|
9970
|
-
|
|
9971
|
-
|
|
9972
|
-
|
|
9973
|
-
|
|
9974
|
-
|
|
9975
|
-
|
|
9976
|
-
|
|
9977
|
-
|
|
9978
|
-
|
|
9979
|
-
|
|
9980
|
-
|
|
9967
|
+
const { focus } = context;
|
|
9968
|
+
const mainResourceId = focus.kind === "annotation" ? focus.sourceResource["@id"] : focus.resource["@id"];
|
|
9969
|
+
const focalAnnotationId = focus.kind === "annotation" ? focus.annotation.id : void 0;
|
|
9970
|
+
if (focus.kind === "annotation") {
|
|
9971
|
+
const parts = [];
|
|
9972
|
+
parts.push(`- Annotation motivation: ${focus.annotation.motivation}`);
|
|
9973
|
+
parts.push(`- Source resource: ${focus.sourceResource.name}`);
|
|
9974
|
+
const { motivation, body } = focus.annotation;
|
|
9975
|
+
if (motivation === "commenting" || motivation === "assessing") {
|
|
9976
|
+
const bodyItem = Array.isArray(body) ? body[0] : body;
|
|
9977
|
+
if (bodyItem && "value" in bodyItem && bodyItem.value) {
|
|
9978
|
+
const label = motivation === "commenting" ? "Comment" : "Assessment";
|
|
9979
|
+
parts.push(`- ${label}: ${bodyItem.value}`);
|
|
9980
|
+
}
|
|
9981
|
+
}
|
|
9982
|
+
annotationSection = `
|
|
9981
9983
|
|
|
9982
9984
|
Annotation context:
|
|
9983
9985
|
${parts.join("\n")}`;
|
|
9984
|
-
|
|
9985
|
-
|
|
9986
|
-
|
|
9987
|
-
const { before, selected, after } = context.sourceContext;
|
|
9988
|
-
contextSection = `
|
|
9986
|
+
if (focus.selected) {
|
|
9987
|
+
const { before, text, after } = focus.selected;
|
|
9988
|
+
contextSection = `
|
|
9989
9989
|
|
|
9990
9990
|
Source document context:
|
|
9991
9991
|
---
|
|
9992
9992
|
${before ? `...${before}` : ""}
|
|
9993
|
-
**[${
|
|
9993
|
+
**[${text}]**
|
|
9994
9994
|
${after ? `${after}...` : ""}
|
|
9995
9995
|
---
|
|
9996
9996
|
`;
|
|
9997
|
-
|
|
9998
|
-
|
|
9999
|
-
|
|
10000
|
-
|
|
10001
|
-
|
|
10002
|
-
|
|
10003
|
-
|
|
10004
|
-
|
|
10005
|
-
|
|
10006
|
-
|
|
10007
|
-
|
|
10008
|
-
|
|
10009
|
-
|
|
10010
|
-
|
|
10011
|
-
|
|
10012
|
-
|
|
10013
|
-
|
|
10014
|
-
|
|
10015
|
-
|
|
10016
|
-
|
|
9997
|
+
}
|
|
9998
|
+
} else {
|
|
9999
|
+
const RESOURCE_CONTENT_CAP = 4e3;
|
|
10000
|
+
const parts = [`- Resource: ${focus.resource.name}`];
|
|
10001
|
+
if (focus.summary) parts.push(`- Summary: ${focus.summary}`);
|
|
10002
|
+
if (focus.suggestedReferences && focus.suggestedReferences.length > 0) {
|
|
10003
|
+
parts.push(`- Suggested references: ${focus.suggestedReferences.join(", ")}`);
|
|
10004
|
+
}
|
|
10005
|
+
resourceSection = `
|
|
10006
|
+
|
|
10007
|
+
Resource context:
|
|
10008
|
+
${parts.join("\n")}`;
|
|
10009
|
+
if (focus.content?.main) {
|
|
10010
|
+
resourceSection += `
|
|
10011
|
+
|
|
10012
|
+
Resource content:
|
|
10013
|
+
---
|
|
10014
|
+
${focus.content.main.slice(0, RESOURCE_CONTENT_CAP)}
|
|
10015
|
+
---`;
|
|
10016
|
+
}
|
|
10017
|
+
const related = Object.entries(focus.content?.related ?? {});
|
|
10018
|
+
if (related.length > 0) {
|
|
10019
|
+
const blocks = related.map(([id, text]) => `[${id}]
|
|
10020
|
+
${text.slice(0, RESOURCE_CONTENT_CAP)}`).join("\n\n");
|
|
10021
|
+
resourceSection += `
|
|
10022
|
+
|
|
10023
|
+
Related resource content:
|
|
10024
|
+
---
|
|
10025
|
+
${blocks}
|
|
10026
|
+
---`;
|
|
10027
|
+
}
|
|
10017
10028
|
}
|
|
10018
|
-
if (
|
|
10019
|
-
|
|
10029
|
+
if (mainResourceId) {
|
|
10030
|
+
const views = deriveViews(context.graph, mainResourceId, focalAnnotationId);
|
|
10031
|
+
const parts = [];
|
|
10032
|
+
if (views.connections.length > 0) {
|
|
10033
|
+
const connList = views.connections.map((c) => `${c.resourceName}${c.entityTypes.length ? ` (${c.entityTypes.join(", ")})` : ""}`).join(", ");
|
|
10034
|
+
parts.push(`- Connected resources: ${connList}`);
|
|
10035
|
+
}
|
|
10036
|
+
if (views.citedByCount > 0) {
|
|
10037
|
+
const citedNames = views.citedBy.map((c) => c.resourceName).join(", ");
|
|
10038
|
+
parts.push(`- This resource is cited by ${views.citedByCount} other resource${views.citedByCount > 1 ? "s" : ""}${citedNames ? `: ${citedNames}` : ""}`);
|
|
10039
|
+
}
|
|
10040
|
+
if (views.siblingEntityTypes.length > 0) {
|
|
10041
|
+
parts.push(`- Related entity types in this document: ${views.siblingEntityTypes.join(", ")}`);
|
|
10042
|
+
}
|
|
10043
|
+
if (context.inferredRelationshipSummary) {
|
|
10044
|
+
parts.push(`- Relationship summary: ${context.inferredRelationshipSummary}`);
|
|
10045
|
+
}
|
|
10046
|
+
if (parts.length > 0) {
|
|
10047
|
+
graphSection = `
|
|
10020
10048
|
|
|
10021
10049
|
Knowledge graph context:
|
|
10022
10050
|
${parts.join("\n")}`;
|
|
10051
|
+
}
|
|
10023
10052
|
}
|
|
10024
10053
|
}
|
|
10025
10054
|
let semanticContextSection = "";
|
|
@@ -10031,17 +10060,20 @@ ${parts.join("\n")}`;
|
|
|
10031
10060
|
Related passages from the knowledge base:
|
|
10032
10061
|
${lines.join("\n")}`;
|
|
10033
10062
|
}
|
|
10034
|
-
const
|
|
10063
|
+
const isPlainText = outputMediaType === "text/plain";
|
|
10064
|
+
const structureGuidance = !isPlainText && finalMaxTokens >= 1e3 ? "organized into titled sections (## Section) with well-structured paragraphs" : "organized into well-structured paragraphs";
|
|
10065
|
+
const formatRequirements = isPlainText ? `- Write the response as plain text \u2014 no formatting markup (no #, *, backticks, headings, or links)
|
|
10066
|
+
- Begin with the title on its own first line` : `- Start with a clear heading (# Title)
|
|
10067
|
+
- Use markdown formatting
|
|
10068
|
+
- Write the response as markdown`;
|
|
10035
10069
|
const prompt = `Generate a concise, informative resource about "${topic}".
|
|
10036
10070
|
${entityTypes.length > 0 ? `Focus on these entity types: ${entityTypes.join(", ")}.` : ""}
|
|
10037
|
-
${userPrompt ? `Additional context: ${userPrompt}` : ""}${annotationSection}${contextSection}${
|
|
10071
|
+
${userPrompt ? `Additional context: ${userPrompt}` : ""}${annotationSection}${contextSection}${resourceSection}${graphSection}${semanticContextSection}${sourceLanguageInstruction}${languageInstruction}
|
|
10038
10072
|
|
|
10039
10073
|
Requirements:
|
|
10040
|
-
- Start with a clear heading (# Title)
|
|
10041
10074
|
- Aim for approximately ${finalMaxTokens} tokens of content, ${structureGuidance}
|
|
10042
10075
|
- Be factual and informative
|
|
10043
|
-
|
|
10044
|
-
- Write the response as markdown`;
|
|
10076
|
+
${formatRequirements}`;
|
|
10045
10077
|
const parseResponse = (response2) => {
|
|
10046
10078
|
let content = response2.trim();
|
|
10047
10079
|
if (content.startsWith("```markdown") || content.startsWith("```md")) {
|
|
@@ -10360,6 +10392,13 @@ async function processTagJob(content, inferenceClient, params, userId, generator
|
|
|
10360
10392
|
};
|
|
10361
10393
|
}
|
|
10362
10394
|
async function processGenerationJob(inferenceClient, params, onProgress, logger2) {
|
|
10395
|
+
const GENERATABLE_MEDIA_TYPES = ["text/markdown", "text/plain"];
|
|
10396
|
+
const outputMediaType = params.outputMediaType ?? "text/markdown";
|
|
10397
|
+
if (!GENERATABLE_MEDIA_TYPES.includes(outputMediaType)) {
|
|
10398
|
+
throw new Error(
|
|
10399
|
+
`Unsupported outputMediaType for generation: ${outputMediaType}. Generation produces ${GENERATABLE_MEDIA_TYPES.join(" or ")}.`
|
|
10400
|
+
);
|
|
10401
|
+
}
|
|
10363
10402
|
onProgress(20, "Fetching context...", "fetching");
|
|
10364
10403
|
const title = params.title ?? "Untitled";
|
|
10365
10404
|
const entityTypes = (params.entityTypes ?? []).map(String);
|
|
@@ -10374,13 +10413,14 @@ async function processGenerationJob(inferenceClient, params, onProgress, logger2
|
|
|
10374
10413
|
params.context,
|
|
10375
10414
|
params.temperature,
|
|
10376
10415
|
params.maxTokens,
|
|
10377
|
-
params.sourceLanguage
|
|
10416
|
+
params.sourceLanguage,
|
|
10417
|
+
outputMediaType
|
|
10378
10418
|
);
|
|
10379
10419
|
onProgress(85, "Creating resource...", "creating");
|
|
10380
10420
|
return {
|
|
10381
10421
|
content: generated.content,
|
|
10382
10422
|
title: generated.title ?? title,
|
|
10383
|
-
format:
|
|
10423
|
+
format: outputMediaType,
|
|
10384
10424
|
result: {
|
|
10385
10425
|
resourceId: "",
|
|
10386
10426
|
resourceName: generated.title ?? title
|
|
@@ -10600,6 +10640,17 @@ async function handleJobInner(adapter, config, job) {
|
|
|
10600
10640
|
...genParams.entityTypes && genParams.entityTypes.length > 0 ? { entityTypes: genParams.entityTypes } : {},
|
|
10601
10641
|
generator
|
|
10602
10642
|
});
|
|
10643
|
+
if (!genParams.referenceId) {
|
|
10644
|
+
const { annotation: provenanceRef } = assembleAnnotation(
|
|
10645
|
+
{
|
|
10646
|
+
motivation: "linking",
|
|
10647
|
+
target: { source: String(resourceId) },
|
|
10648
|
+
body: { type: "SpecificResource", source: String(newResourceId), purpose: "linking" }
|
|
10649
|
+
},
|
|
10650
|
+
generator
|
|
10651
|
+
);
|
|
10652
|
+
await emitEvent(session, "mark:create", { annotation: provenanceRef, userId, resourceId });
|
|
10653
|
+
}
|
|
10603
10654
|
await emitEvent(session, "job:complete", {
|
|
10604
10655
|
...lifecycleBase,
|
|
10605
10656
|
result: { resourceId: newResourceId, resourceName: genResult.title }
|
|
@@ -10611,7 +10662,7 @@ async function handleJobInner(adapter, config, job) {
|
|
|
10611
10662
|
}
|
|
10612
10663
|
|
|
10613
10664
|
// src/worker-main.ts
|
|
10614
|
-
var
|
|
10665
|
+
var import_rxjs2 = __toESM(require_cjs());
|
|
10615
10666
|
var ALL_JOB_TYPES = [
|
|
10616
10667
|
"reference-annotation",
|
|
10617
10668
|
"generation",
|
|
@@ -10719,7 +10770,7 @@ async function startAgentWorker(group) {
|
|
|
10719
10770
|
};
|
|
10720
10771
|
const storage = new InMemorySessionStorage();
|
|
10721
10772
|
setStoredSession(storage, kbId, { access: initialToken, refresh: "" });
|
|
10722
|
-
const token$ = new
|
|
10773
|
+
const token$ = new import_rxjs2.BehaviorSubject(null);
|
|
10723
10774
|
let session;
|
|
10724
10775
|
const transport = new HttpTransport({
|
|
10725
10776
|
baseUrl: baseUrl(kbBackendUrl(endpoint)),
|