@semiont/jobs 0.4.14 → 0.4.16
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/README.md +2 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.js +129 -25
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -146,12 +146,12 @@ Jobs use TypeScript discriminated unions for type safety:
|
|
|
146
146
|
```typescript
|
|
147
147
|
function handleJob(job: AnyJob) {
|
|
148
148
|
if (job.status === 'running') {
|
|
149
|
-
console.log(job
|
|
149
|
+
console.log(job:progress); // Available
|
|
150
150
|
// console.log(job.result); // Compile error
|
|
151
151
|
}
|
|
152
152
|
if (job.status === 'complete') {
|
|
153
153
|
console.log(job.result); // Available
|
|
154
|
-
// console.log(job
|
|
154
|
+
// console.log(job:progress); // Compile error
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Readable } from 'stream';
|
|
|
2
2
|
import { ResourceId, JobId, UserId, EntityType, AnnotationId, components, GatheredContext, Logger, EventBus } from '@semiont/core';
|
|
3
3
|
import { SemiontProject } from '@semiont/core/node';
|
|
4
4
|
import { InferenceClient } from '@semiont/inference';
|
|
5
|
+
import { WorkingTreeStore } from '@semiont/content';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Job Queue Type Definitions - Discriminated Union Design
|
|
@@ -482,7 +483,8 @@ declare class GenerationWorker extends JobWorker {
|
|
|
482
483
|
private inferenceClient;
|
|
483
484
|
private generator;
|
|
484
485
|
private eventBus;
|
|
485
|
-
|
|
486
|
+
private contentStore;
|
|
487
|
+
constructor(jobQueue: JobQueue, inferenceClient: InferenceClient, generator: Agent$4, eventBus: EventBus, contentStore: WorkingTreeStore, logger: Logger);
|
|
486
488
|
protected getWorkerName(): string;
|
|
487
489
|
protected canProcessJob(job: AnyJob): boolean;
|
|
488
490
|
protected executeJob(job: AnyJob): Promise<GenerationResult>;
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,8 @@ import { promises, watch } from 'fs';
|
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import { validateAndCorrectOffsets, getTargetSelector, getExactText, getLocaleEnglishName } from '@semiont/api-client';
|
|
4
4
|
import { generateAnnotationId } from '@semiont/event-sourcing';
|
|
5
|
-
import { userToAgent, userId, jobId, CREATION_METHODS, annotationId } from '@semiont/core';
|
|
5
|
+
import { userToAgent, userId, jobId, CREATION_METHODS, resourceId, annotationId } from '@semiont/core';
|
|
6
|
+
import { deriveStorageUri } from '@semiont/content';
|
|
6
7
|
|
|
7
8
|
var __create = Object.create;
|
|
8
9
|
var __defProp = Object.defineProperty;
|
|
@@ -11267,7 +11268,17 @@ var ReferenceAnnotationWorker = class extends JobWorker {
|
|
|
11267
11268
|
userId: userId(job.metadata.userId),
|
|
11268
11269
|
jobId: jobId(job.metadata.id),
|
|
11269
11270
|
jobType: "reference-annotation",
|
|
11270
|
-
result
|
|
11271
|
+
result
|
|
11272
|
+
});
|
|
11273
|
+
const resourceBus = this.eventBus.scope(String(job.params.resourceId));
|
|
11274
|
+
resourceBus.get("mark:assist-finished").next({
|
|
11275
|
+
motivation: "linking",
|
|
11276
|
+
resourceId: String(job.params.resourceId),
|
|
11277
|
+
status: "complete",
|
|
11278
|
+
percentage: 100,
|
|
11279
|
+
foundCount: result.totalFound,
|
|
11280
|
+
createdCount: result.totalEmitted,
|
|
11281
|
+
message: "Detection complete"
|
|
11271
11282
|
});
|
|
11272
11283
|
}
|
|
11273
11284
|
async handleJobFailure(job, error) {
|
|
@@ -11281,6 +11292,11 @@ var ReferenceAnnotationWorker = class extends JobWorker {
|
|
|
11281
11292
|
jobType: detJob.metadata.type,
|
|
11282
11293
|
error: "Entity detection failed. Please try again later."
|
|
11283
11294
|
});
|
|
11295
|
+
const resourceBus = this.eventBus.scope(String(detJob.params.resourceId));
|
|
11296
|
+
resourceBus.get("mark:assist-failed").next({
|
|
11297
|
+
resourceId: String(detJob.params.resourceId),
|
|
11298
|
+
message: "Entity detection failed. Please try again later."
|
|
11299
|
+
});
|
|
11284
11300
|
}
|
|
11285
11301
|
}
|
|
11286
11302
|
/**
|
|
@@ -11339,10 +11355,14 @@ var ReferenceAnnotationWorker = class extends JobWorker {
|
|
|
11339
11355
|
jobType: detJob.metadata.type,
|
|
11340
11356
|
percentage,
|
|
11341
11357
|
progress: {
|
|
11342
|
-
|
|
11343
|
-
|
|
11344
|
-
|
|
11345
|
-
|
|
11358
|
+
stage: "scanning",
|
|
11359
|
+
percentage,
|
|
11360
|
+
message: detJob.progress.currentEntityType ? `Processing ${detJob.progress.currentEntityType}` : "Processing...",
|
|
11361
|
+
totalEntityTypes: detJob.progress.totalEntityTypes,
|
|
11362
|
+
processedEntityTypes: detJob.progress.processedEntityTypes,
|
|
11363
|
+
entitiesFound: detJob.progress.entitiesFound,
|
|
11364
|
+
entitiesEmitted: detJob.progress.entitiesEmitted,
|
|
11365
|
+
currentEntityType: detJob.progress.currentEntityType
|
|
11346
11366
|
}
|
|
11347
11367
|
});
|
|
11348
11368
|
this.logger?.debug("[EventBus] Emitting mark:progress", {
|
|
@@ -11486,11 +11506,12 @@ Requirements:
|
|
|
11486
11506
|
var import_rxjs = __toESM(require_cjs());
|
|
11487
11507
|
var import_operators = __toESM(require_operators());
|
|
11488
11508
|
var GenerationWorker = class extends JobWorker {
|
|
11489
|
-
constructor(jobQueue, inferenceClient, generator, eventBus, logger) {
|
|
11509
|
+
constructor(jobQueue, inferenceClient, generator, eventBus, contentStore, logger) {
|
|
11490
11510
|
super(jobQueue, void 0, void 0, logger);
|
|
11491
11511
|
this.inferenceClient = inferenceClient;
|
|
11492
11512
|
this.generator = generator;
|
|
11493
11513
|
this.eventBus = eventBus;
|
|
11514
|
+
this.contentStore = contentStore;
|
|
11494
11515
|
}
|
|
11495
11516
|
getWorkerName() {
|
|
11496
11517
|
return "GenerationWorker";
|
|
@@ -11576,28 +11597,32 @@ var GenerationWorker = class extends JobWorker {
|
|
|
11576
11597
|
};
|
|
11577
11598
|
this.logger?.debug("Generation progress", { stage: updatedJob.progress.stage, message: updatedJob.progress.message });
|
|
11578
11599
|
await this.updateJobProgress(updatedJob);
|
|
11600
|
+
const format = "text/markdown";
|
|
11601
|
+
const resolvedUri = job.params.storageUri || deriveStorageUri(resourceName, format);
|
|
11602
|
+
const stored = await this.contentStore.store(Buffer.from(generatedContent.content), resolvedUri);
|
|
11579
11603
|
const createParams = {
|
|
11580
11604
|
name: resourceName,
|
|
11581
|
-
|
|
11582
|
-
|
|
11605
|
+
storageUri: resolvedUri,
|
|
11606
|
+
contentChecksum: stored.checksum,
|
|
11607
|
+
byteSize: stored.byteSize,
|
|
11608
|
+
format,
|
|
11583
11609
|
userId: userId(job.metadata.userId),
|
|
11584
11610
|
entityTypes: job.params.entityTypes || annotationEntityTypes,
|
|
11585
11611
|
language: job.params.language,
|
|
11586
11612
|
creationMethod: CREATION_METHODS.GENERATED,
|
|
11587
11613
|
isDraft: true,
|
|
11588
11614
|
generatedFrom: { resourceId: job.params.sourceResourceId, annotationId: job.params.referenceId },
|
|
11589
|
-
storageUri: job.params.storageUri,
|
|
11590
11615
|
generator: this.generator
|
|
11591
11616
|
};
|
|
11592
11617
|
const result$ = (0, import_rxjs.race)(
|
|
11593
|
-
this.eventBus.get("yield:
|
|
11594
|
-
this.eventBus.get("yield:create-failed").pipe((0, import_operators.take)(1), (0, import_operators.map)((f) => ({ ok: false, error: f.
|
|
11618
|
+
this.eventBus.get("yield:create-ok").pipe((0, import_operators.take)(1), (0, import_operators.map)((r) => ({ ok: true, result: r }))),
|
|
11619
|
+
this.eventBus.get("yield:create-failed").pipe((0, import_operators.take)(1), (0, import_operators.map)((f) => ({ ok: false, error: new Error(f.message) }))),
|
|
11595
11620
|
(0, import_rxjs.timer)(3e4).pipe((0, import_operators.map)(() => ({ ok: false, error: new Error("Resource creation timed out") })))
|
|
11596
11621
|
);
|
|
11597
11622
|
this.eventBus.get("yield:create").next(createParams);
|
|
11598
11623
|
const outcome = await (0, import_rxjs.firstValueFrom)(result$);
|
|
11599
11624
|
if (!outcome.ok) throw outcome.error;
|
|
11600
|
-
const rId = outcome.result.resourceId;
|
|
11625
|
+
const rId = resourceId(outcome.result.resourceId);
|
|
11601
11626
|
this.logger?.info("Resource created via EventBus", { resourceId: rId });
|
|
11602
11627
|
updatedJob = {
|
|
11603
11628
|
...updatedJob,
|
|
@@ -11653,10 +11678,20 @@ var GenerationWorker = class extends JobWorker {
|
|
|
11653
11678
|
jobId: jobId(job.metadata.id),
|
|
11654
11679
|
jobType: "generation",
|
|
11655
11680
|
result: {
|
|
11656
|
-
|
|
11657
|
-
|
|
11681
|
+
resourceId: result.resourceId,
|
|
11682
|
+
resourceName: result.resourceName
|
|
11658
11683
|
}
|
|
11659
11684
|
});
|
|
11685
|
+
const resourceBus = this.eventBus.scope(String(job.params.sourceResourceId));
|
|
11686
|
+
resourceBus.get("yield:finished").next({
|
|
11687
|
+
status: "complete",
|
|
11688
|
+
referenceId: String(job.params.referenceId),
|
|
11689
|
+
resourceName: result.resourceName,
|
|
11690
|
+
resourceId: result.resourceId,
|
|
11691
|
+
sourceResourceId: String(job.params.sourceResourceId),
|
|
11692
|
+
percentage: 100,
|
|
11693
|
+
message: "Draft resource created! Ready for review."
|
|
11694
|
+
});
|
|
11660
11695
|
}
|
|
11661
11696
|
async handleJobFailure(job, error) {
|
|
11662
11697
|
await super.handleJobFailure(job, error);
|
|
@@ -11669,6 +11704,14 @@ var GenerationWorker = class extends JobWorker {
|
|
|
11669
11704
|
jobType: genJob.metadata.type,
|
|
11670
11705
|
error: "Resource generation failed. Please try again later."
|
|
11671
11706
|
});
|
|
11707
|
+
const resourceBus = this.eventBus.scope(String(genJob.params.sourceResourceId));
|
|
11708
|
+
resourceBus.get("yield:failed").next({
|
|
11709
|
+
error: "Resource generation failed. Please try again later.",
|
|
11710
|
+
status: "error",
|
|
11711
|
+
referenceId: String(genJob.params.referenceId),
|
|
11712
|
+
percentage: 0,
|
|
11713
|
+
message: "Resource generation failed. Please try again later."
|
|
11714
|
+
});
|
|
11672
11715
|
}
|
|
11673
11716
|
}
|
|
11674
11717
|
/**
|
|
@@ -11700,8 +11743,9 @@ var GenerationWorker = class extends JobWorker {
|
|
|
11700
11743
|
jobType: genJob.metadata.type,
|
|
11701
11744
|
percentage: genJob.progress.percentage,
|
|
11702
11745
|
progress: {
|
|
11703
|
-
|
|
11704
|
-
|
|
11746
|
+
stage: genJob.progress.stage,
|
|
11747
|
+
percentage: genJob.progress.percentage,
|
|
11748
|
+
message: genJob.progress.message || ""
|
|
11705
11749
|
}
|
|
11706
11750
|
});
|
|
11707
11751
|
resourceBus.get("yield:progress").next({
|
|
@@ -11749,7 +11793,17 @@ var HighlightAnnotationWorker = class extends JobWorker {
|
|
|
11749
11793
|
userId: userId(job.metadata.userId),
|
|
11750
11794
|
jobId: jobId(job.metadata.id),
|
|
11751
11795
|
jobType: "highlight-annotation",
|
|
11752
|
-
result
|
|
11796
|
+
result
|
|
11797
|
+
});
|
|
11798
|
+
const resourceBus = this.eventBus.scope(String(job.params.resourceId));
|
|
11799
|
+
resourceBus.get("mark:assist-finished").next({
|
|
11800
|
+
motivation: "highlighting",
|
|
11801
|
+
resourceId: String(job.params.resourceId),
|
|
11802
|
+
status: "complete",
|
|
11803
|
+
percentage: 100,
|
|
11804
|
+
foundCount: result.highlightsFound,
|
|
11805
|
+
createdCount: result.highlightsCreated,
|
|
11806
|
+
message: "Detection complete"
|
|
11753
11807
|
});
|
|
11754
11808
|
}
|
|
11755
11809
|
/**
|
|
@@ -11777,7 +11831,7 @@ var HighlightAnnotationWorker = class extends JobWorker {
|
|
|
11777
11831
|
jobId: jobId(hlJob.metadata.id),
|
|
11778
11832
|
jobType: hlJob.metadata.type,
|
|
11779
11833
|
percentage: hlJob.progress.percentage,
|
|
11780
|
-
progress: { progress: hlJob.progress }
|
|
11834
|
+
progress: { stage: hlJob.progress.stage, percentage: hlJob.progress.percentage, message: hlJob.progress.message || "" }
|
|
11781
11835
|
});
|
|
11782
11836
|
const resourceBus = this.eventBus.scope(hlJob.params.resourceId);
|
|
11783
11837
|
resourceBus.get("mark:progress").next({
|
|
@@ -11798,6 +11852,11 @@ var HighlightAnnotationWorker = class extends JobWorker {
|
|
|
11798
11852
|
jobType: hlJob.metadata.type,
|
|
11799
11853
|
error: "Highlight detection failed. Please try again later."
|
|
11800
11854
|
});
|
|
11855
|
+
const resourceBus = this.eventBus.scope(String(hlJob.params.resourceId));
|
|
11856
|
+
resourceBus.get("mark:assist-failed").next({
|
|
11857
|
+
resourceId: String(hlJob.params.resourceId),
|
|
11858
|
+
message: "Highlight detection failed. Please try again later."
|
|
11859
|
+
});
|
|
11801
11860
|
}
|
|
11802
11861
|
}
|
|
11803
11862
|
async processHighlightDetectionJob(job) {
|
|
@@ -11942,7 +12001,17 @@ var AssessmentAnnotationWorker = class extends JobWorker {
|
|
|
11942
12001
|
userId: userId(job.metadata.userId),
|
|
11943
12002
|
jobId: jobId(job.metadata.id),
|
|
11944
12003
|
jobType: "assessment-annotation",
|
|
11945
|
-
result
|
|
12004
|
+
result
|
|
12005
|
+
});
|
|
12006
|
+
const resourceBus = this.eventBus.scope(String(job.params.resourceId));
|
|
12007
|
+
resourceBus.get("mark:assist-finished").next({
|
|
12008
|
+
motivation: "assessing",
|
|
12009
|
+
resourceId: String(job.params.resourceId),
|
|
12010
|
+
status: "complete",
|
|
12011
|
+
percentage: 100,
|
|
12012
|
+
foundCount: result.assessmentsFound,
|
|
12013
|
+
createdCount: result.assessmentsCreated,
|
|
12014
|
+
message: "Detection complete"
|
|
11946
12015
|
});
|
|
11947
12016
|
}
|
|
11948
12017
|
/**
|
|
@@ -11970,7 +12039,7 @@ var AssessmentAnnotationWorker = class extends JobWorker {
|
|
|
11970
12039
|
jobId: jobId(assJob.metadata.id),
|
|
11971
12040
|
jobType: assJob.metadata.type,
|
|
11972
12041
|
percentage: assJob.progress.percentage,
|
|
11973
|
-
progress: { progress: assJob.progress }
|
|
12042
|
+
progress: { stage: assJob.progress.stage, percentage: assJob.progress.percentage, message: assJob.progress.message || "" }
|
|
11974
12043
|
});
|
|
11975
12044
|
const resourceBus = this.eventBus.scope(assJob.params.resourceId);
|
|
11976
12045
|
resourceBus.get("mark:progress").next({
|
|
@@ -11991,6 +12060,11 @@ var AssessmentAnnotationWorker = class extends JobWorker {
|
|
|
11991
12060
|
jobType: aJob.metadata.type,
|
|
11992
12061
|
error: "Assessment detection failed. Please try again later."
|
|
11993
12062
|
});
|
|
12063
|
+
const resourceBus = this.eventBus.scope(String(aJob.params.resourceId));
|
|
12064
|
+
resourceBus.get("mark:assist-failed").next({
|
|
12065
|
+
resourceId: String(aJob.params.resourceId),
|
|
12066
|
+
message: "Assessment detection failed. Please try again later."
|
|
12067
|
+
});
|
|
11994
12068
|
}
|
|
11995
12069
|
}
|
|
11996
12070
|
async processAssessmentDetectionJob(job) {
|
|
@@ -12140,7 +12214,17 @@ var CommentAnnotationWorker = class extends JobWorker {
|
|
|
12140
12214
|
userId: userId(job.metadata.userId),
|
|
12141
12215
|
jobId: jobId(job.metadata.id),
|
|
12142
12216
|
jobType: "comment-annotation",
|
|
12143
|
-
result
|
|
12217
|
+
result
|
|
12218
|
+
});
|
|
12219
|
+
const resourceBus = this.eventBus.scope(String(job.params.resourceId));
|
|
12220
|
+
resourceBus.get("mark:assist-finished").next({
|
|
12221
|
+
motivation: "commenting",
|
|
12222
|
+
resourceId: String(job.params.resourceId),
|
|
12223
|
+
status: "complete",
|
|
12224
|
+
percentage: 100,
|
|
12225
|
+
foundCount: result.commentsFound,
|
|
12226
|
+
createdCount: result.commentsCreated,
|
|
12227
|
+
message: "Detection complete"
|
|
12144
12228
|
});
|
|
12145
12229
|
}
|
|
12146
12230
|
/**
|
|
@@ -12168,7 +12252,7 @@ var CommentAnnotationWorker = class extends JobWorker {
|
|
|
12168
12252
|
jobId: jobId(cdJob.metadata.id),
|
|
12169
12253
|
jobType: cdJob.metadata.type,
|
|
12170
12254
|
percentage: cdJob.progress.percentage,
|
|
12171
|
-
progress: { progress: cdJob.progress }
|
|
12255
|
+
progress: { stage: cdJob.progress.stage, percentage: cdJob.progress.percentage, message: cdJob.progress.message || "" }
|
|
12172
12256
|
});
|
|
12173
12257
|
const resourceBus = this.eventBus.scope(cdJob.params.resourceId);
|
|
12174
12258
|
resourceBus.get("mark:progress").next({
|
|
@@ -12189,6 +12273,11 @@ var CommentAnnotationWorker = class extends JobWorker {
|
|
|
12189
12273
|
jobType: cdJob.metadata.type,
|
|
12190
12274
|
error: "Comment detection failed. Please try again later."
|
|
12191
12275
|
});
|
|
12276
|
+
const resourceBus = this.eventBus.scope(String(cdJob.params.resourceId));
|
|
12277
|
+
resourceBus.get("mark:assist-failed").next({
|
|
12278
|
+
resourceId: String(cdJob.params.resourceId),
|
|
12279
|
+
message: "Comment detection failed. Please try again later."
|
|
12280
|
+
});
|
|
12192
12281
|
}
|
|
12193
12282
|
}
|
|
12194
12283
|
async processCommentDetectionJob(job) {
|
|
@@ -12345,7 +12434,17 @@ var TagAnnotationWorker = class extends JobWorker {
|
|
|
12345
12434
|
userId: userId(job.metadata.userId),
|
|
12346
12435
|
jobId: jobId(job.metadata.id),
|
|
12347
12436
|
jobType: "tag-annotation",
|
|
12348
|
-
result
|
|
12437
|
+
result
|
|
12438
|
+
});
|
|
12439
|
+
const resourceBus = this.eventBus.scope(String(job.params.resourceId));
|
|
12440
|
+
resourceBus.get("mark:assist-finished").next({
|
|
12441
|
+
motivation: "tagging",
|
|
12442
|
+
resourceId: String(job.params.resourceId),
|
|
12443
|
+
status: "complete",
|
|
12444
|
+
percentage: 100,
|
|
12445
|
+
foundCount: result.tagsFound,
|
|
12446
|
+
createdCount: result.tagsCreated,
|
|
12447
|
+
message: "Detection complete"
|
|
12349
12448
|
});
|
|
12350
12449
|
}
|
|
12351
12450
|
/**
|
|
@@ -12373,7 +12472,7 @@ var TagAnnotationWorker = class extends JobWorker {
|
|
|
12373
12472
|
jobId: jobId(tdJob.metadata.id),
|
|
12374
12473
|
jobType: tdJob.metadata.type,
|
|
12375
12474
|
percentage: tdJob.progress.percentage,
|
|
12376
|
-
progress: { progress: tdJob.progress }
|
|
12475
|
+
progress: { stage: tdJob.progress.stage, percentage: tdJob.progress.percentage, message: tdJob.progress.message || "", currentCategory: tdJob.progress.currentCategory, processedCategories: tdJob.progress.processedCategories, totalCategories: tdJob.progress.totalCategories }
|
|
12377
12476
|
});
|
|
12378
12477
|
const resourceBus = this.eventBus.scope(tdJob.params.resourceId);
|
|
12379
12478
|
resourceBus.get("mark:progress").next({
|
|
@@ -12397,6 +12496,11 @@ var TagAnnotationWorker = class extends JobWorker {
|
|
|
12397
12496
|
jobType: tdJob.metadata.type,
|
|
12398
12497
|
error: "Tag detection failed. Please try again later."
|
|
12399
12498
|
});
|
|
12499
|
+
const resourceBus = this.eventBus.scope(String(tdJob.params.resourceId));
|
|
12500
|
+
resourceBus.get("mark:assist-failed").next({
|
|
12501
|
+
resourceId: String(tdJob.params.resourceId),
|
|
12502
|
+
message: "Tag detection failed. Please try again later."
|
|
12503
|
+
});
|
|
12400
12504
|
}
|
|
12401
12505
|
}
|
|
12402
12506
|
async processTagDetectionJob(job) {
|