@semiont/jobs 0.5.11 → 0.5.13
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 +2 -1
- package/dist/index.js +44 -9
- package/dist/index.js.map +1 -1
- package/dist/worker-main.js +155 -23
- package/dist/worker-main.js.map +1 -1
- package/package.json +9 -9
package/dist/index.d.ts
CHANGED
|
@@ -202,7 +202,8 @@ interface DetectionResult {
|
|
|
202
202
|
* Generation job progress
|
|
203
203
|
*/
|
|
204
204
|
interface YieldProgress {
|
|
205
|
-
|
|
205
|
+
/** The two real generation transitions — LLM call running, then persisting. */
|
|
206
|
+
stage: 'generating' | 'creating';
|
|
206
207
|
percentage: number;
|
|
207
208
|
message?: string;
|
|
208
209
|
}
|
package/dist/index.js
CHANGED
|
@@ -419,6 +419,41 @@ function isFailedJob(job) {
|
|
|
419
419
|
function isCancelledJob(job) {
|
|
420
420
|
return job.status === "cancelled";
|
|
421
421
|
}
|
|
422
|
+
|
|
423
|
+
// src/workers/inference-call.ts
|
|
424
|
+
var INFERENCE_TIMEOUT_MS = 10 * 6e4;
|
|
425
|
+
async function withTimeout(work, label) {
|
|
426
|
+
let timer;
|
|
427
|
+
const timedOut = new Promise((_, reject) => {
|
|
428
|
+
timer = setTimeout(() => {
|
|
429
|
+
reject(new Error(
|
|
430
|
+
`Inference call timed out after ${INFERENCE_TIMEOUT_MS / 6e4} minutes (${label}) \u2014 failing the job to keep the claim loop live`
|
|
431
|
+
));
|
|
432
|
+
}, INFERENCE_TIMEOUT_MS);
|
|
433
|
+
timer.unref?.();
|
|
434
|
+
});
|
|
435
|
+
try {
|
|
436
|
+
return await Promise.race([work, timedOut]);
|
|
437
|
+
} catch (err) {
|
|
438
|
+
work.catch(() => {
|
|
439
|
+
});
|
|
440
|
+
throw err;
|
|
441
|
+
} finally {
|
|
442
|
+
clearTimeout(timer);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
function boundedGenerate(client, prompt, maxTokens, temperature, options) {
|
|
446
|
+
return withTimeout(
|
|
447
|
+
client.generateText(prompt, maxTokens, temperature, options),
|
|
448
|
+
`${client.type}:${client.modelId}`
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
function boundedGenerateWithMetadata(client, prompt, maxTokens, temperature, options) {
|
|
452
|
+
return withTimeout(
|
|
453
|
+
client.generateTextWithMetadata(prompt, maxTokens, temperature, options),
|
|
454
|
+
`${client.type}:${client.modelId}`
|
|
455
|
+
);
|
|
456
|
+
}
|
|
422
457
|
function languageName(tag) {
|
|
423
458
|
return getLocaleEnglishName(tag) || tag;
|
|
424
459
|
}
|
|
@@ -900,7 +935,7 @@ var AnnotationDetection = class {
|
|
|
900
935
|
*/
|
|
901
936
|
static async detectComments(content, client, instructions, tone, density, language, sourceLanguage) {
|
|
902
937
|
const prompt = MotivationPrompts.buildCommentPrompt(content, instructions, tone, density, language, sourceLanguage);
|
|
903
|
-
const response = await client
|
|
938
|
+
const response = await boundedGenerateWithMetadata(client, prompt, 3e3, 0.4, { format: "json" });
|
|
904
939
|
assertNotTruncated(response, "comment");
|
|
905
940
|
return MotivationParsers.parseComments(response.text, content);
|
|
906
941
|
}
|
|
@@ -913,7 +948,7 @@ var AnnotationDetection = class {
|
|
|
913
948
|
*/
|
|
914
949
|
static async detectHighlights(content, client, instructions, density, sourceLanguage) {
|
|
915
950
|
const prompt = MotivationPrompts.buildHighlightPrompt(content, instructions, density, sourceLanguage);
|
|
916
|
-
const response = await client
|
|
951
|
+
const response = await boundedGenerateWithMetadata(client, prompt, 2e3, 0.3, { format: "json" });
|
|
917
952
|
assertNotTruncated(response, "highlight");
|
|
918
953
|
return MotivationParsers.parseHighlights(response.text, content);
|
|
919
954
|
}
|
|
@@ -926,7 +961,7 @@ var AnnotationDetection = class {
|
|
|
926
961
|
*/
|
|
927
962
|
static async detectAssessments(content, client, instructions, tone, density, language, sourceLanguage) {
|
|
928
963
|
const prompt = MotivationPrompts.buildAssessmentPrompt(content, instructions, tone, density, language, sourceLanguage);
|
|
929
|
-
const response = await client
|
|
964
|
+
const response = await boundedGenerateWithMetadata(client, prompt, 3e3, 0.3, { format: "json" });
|
|
930
965
|
assertNotTruncated(response, "assessment");
|
|
931
966
|
return MotivationParsers.parseAssessments(response.text, content);
|
|
932
967
|
}
|
|
@@ -957,7 +992,7 @@ var AnnotationDetection = class {
|
|
|
957
992
|
categoryInfo.examples,
|
|
958
993
|
sourceLanguage
|
|
959
994
|
);
|
|
960
|
-
const response = await client
|
|
995
|
+
const response = await boundedGenerateWithMetadata(client, prompt, 4e3, 0.2, { format: "json" });
|
|
961
996
|
assertNotTruncated(response, "tag");
|
|
962
997
|
const parsedTags = MotivationParsers.parseTags(response.text);
|
|
963
998
|
return MotivationParsers.validateTagOffsets(parsedTags, content, category);
|
|
@@ -1013,7 +1048,8 @@ If no entities are found, respond with an empty array [].
|
|
|
1013
1048
|
Example output:
|
|
1014
1049
|
[{"exact":"Alice","entityType":"Person","prefix":"","suffix":" went to"},{"exact":"Paris","entityType":"Location","prefix":"went to ","suffix":" yesterday"}]`;
|
|
1015
1050
|
logger.debug("Sending entity extraction request", { entityTypes: entityTypesDescription });
|
|
1016
|
-
const response = await
|
|
1051
|
+
const response = await boundedGenerateWithMetadata(
|
|
1052
|
+
client,
|
|
1017
1053
|
prompt,
|
|
1018
1054
|
4e3,
|
|
1019
1055
|
// Increased to handle many entities without truncation
|
|
@@ -1263,7 +1299,7 @@ ${formatRequirements}`;
|
|
|
1263
1299
|
temperature: finalTemperature,
|
|
1264
1300
|
maxTokens: finalMaxTokens
|
|
1265
1301
|
});
|
|
1266
|
-
const response = await client
|
|
1302
|
+
const response = await boundedGenerate(client, prompt, finalMaxTokens, finalTemperature);
|
|
1267
1303
|
logger.debug("Got response from inference", { responseLength: response.length });
|
|
1268
1304
|
const result = parseResponse(response);
|
|
1269
1305
|
logger.debug("Parsed response", {
|
|
@@ -1623,10 +1659,9 @@ async function processGenerationJob(inferenceClient, params, onProgress, logger)
|
|
|
1623
1659
|
`Unsupported outputMediaType for generation: ${outputMediaType}. Generation produces ${GENERATABLE_MEDIA_TYPES.join(" or ")}.`
|
|
1624
1660
|
);
|
|
1625
1661
|
}
|
|
1626
|
-
onProgress(20, "Fetching context...", "fetching");
|
|
1627
1662
|
const title = params.title ?? "Untitled";
|
|
1628
1663
|
const entityTypes = (params.entityTypes ?? []).map(String);
|
|
1629
|
-
onProgress(
|
|
1664
|
+
onProgress(5, "Generating resource...", "generating");
|
|
1630
1665
|
const generated = await generateResourceFromTopic(
|
|
1631
1666
|
title,
|
|
1632
1667
|
entityTypes,
|
|
@@ -1650,7 +1685,7 @@ async function processGenerationJob(inferenceClient, params, onProgress, logger)
|
|
|
1650
1685
|
content = resolved.content;
|
|
1651
1686
|
citations = resolved.citations;
|
|
1652
1687
|
}
|
|
1653
|
-
onProgress(
|
|
1688
|
+
onProgress(95, "Creating resource...", "creating");
|
|
1654
1689
|
return {
|
|
1655
1690
|
content,
|
|
1656
1691
|
title: generated.title ?? title,
|